This allows callers to verify certificates using algorithms that Go
does not support (yet).
For instance, here we're verifying the ML-KEM-512 example certificate
from the LAMPS WG signed by a ML-DSA-44 public key.
https://github.com/lamps-wg/dilithium-certificates/blob/main/examples/ML-DSA-44.crt
https://github.com/lamps-wg/kyber-certificates/blob/main/example/ML-KEM-512.crt
package main
import (
"crypto/x509"
"crypto/x509/pkix"
"encoding/asn1"
"encoding/pem"
"errors"
"fmt"
"github.com/cloudflare/circl/sign/schemes"
"os"
)
func loadCert(path string) (*x509.Certificate, error) {
raw, err := os.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("ReadFile(%s): %w", path, err)
}
block, _ := pem.Decode(raw)
if block == nil {
return nil, fmt.Errorf("pem.Decode(%s) failed", path)
}
return x509.ParseCertificate(block.Bytes)
}
func main() {
dsaCert, err := loadCert("ML-DSA-44.crt")
if err != nil {
panic(err)
}
kemCert, err := loadCert("ML-KEM-512.crt")
if err != nil {
panic(err)
}
roots := x509.NewCertPool()
roots.AddCert(dsaCert)
_, err = kemCert.Verify(x509.VerifyOptions{
Roots: roots,
UnknownAlgorithmVerifier: func(alg pkix.AlgorithmIdentifier,
signed, signature, pk []byte) error {
if !alg.Algorithm.Equal(asn1.ObjectIdentifier{2, 16, 840, 1, 101, 3, 4, 3, 17}) {
return errors.New("unsupported scheme")
}
scheme := schemes.ByName("ML-DSA-44")
ppk, err := scheme.UnmarshalBinaryPublicKey(pk)
if err != nil {
return err
}
if !scheme.Verify(ppk, signed, signature, nil) {
return errors.New("invalid signature")
}
return nil
},
})
if err != nil {
panic(err)
}
}
|
||
|---|---|---|
| .github | ||
| api | ||
| doc | ||
| lib | ||
| misc | ||
| src | ||
| test | ||
| .gitattributes | ||
| .gitignore | ||
| CONTRIBUTING.md | ||
| LICENSE | ||
| PATENTS | ||
| README.md | ||
| SECURITY.md | ||
| codereview.cfg | ||
| go.env | ||
README.md
The Go Programming Language
Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.
Gopher image by Renee French, licensed under Creative Commons 4.0 Attribution license.
Our canonical Git repository is located at https://go.googlesource.com/go. There is a mirror of the repository at https://github.com/golang/go.
Unless otherwise noted, the Go source files are distributed under the BSD-style license found in the LICENSE file.
Download and Install
Binary Distributions
Official binary distributions are available at https://go.dev/dl/.
After downloading a binary release, visit https://go.dev/doc/install for installation instructions.
Install From Source
If a binary distribution is not available for your combination of operating system and architecture, visit https://go.dev/doc/install/source for source installation instructions.
Contributing
Go is the work of thousands of contributors. We appreciate your help!
To contribute, please read the contribution guidelines at https://go.dev/doc/contribute.
Note that the Go project uses the issue tracker for bug reports and proposals only. See https://go.dev/wiki/Questions for a list of places to ask questions about the Go language.