genmtpki: use mldsa
diff --git a/issuance/issuer.go b/issuance/issuer.go index f1bbffb..d48b601 100644 --- a/issuance/issuer.go +++ b/issuance/issuer.go
@@ -2,9 +2,6 @@ import ( "crypto" - "crypto/ecdsa" - "crypto/elliptic" - "crypto/rsa" "crypto/x509" "encoding/json" "errors" @@ -209,24 +206,9 @@ // newIssuer constructs a new Issuer from the in-memory certificate and signer. // It exists as a helper for LoadIssuer to make testing simpler. func newIssuer(config IssuerConfig, cert *Certificate, signer crypto.Signer, clk clock.Clock) (*Issuer, error) { - var keyAlg x509.PublicKeyAlgorithm - var sigAlg x509.SignatureAlgorithm - switch k := cert.PublicKey.(type) { - case *rsa.PublicKey: - keyAlg = x509.RSA - sigAlg = x509.SHA256WithRSA - case *ecdsa.PublicKey: - keyAlg = x509.ECDSA - switch k.Curve { - case elliptic.P256(): - sigAlg = x509.ECDSAWithSHA256 - case elliptic.P384(): - sigAlg = x509.ECDSAWithSHA384 - default: - return nil, fmt.Errorf("unsupported ECDSA curve: %q", k.Curve.Params().Name) - } - default: - return nil, errors.New("unsupported issuer key type") + keyAlg, sigAlg, err := pubkeyParams(cert.PublicKey) + if err != nil { + return nil, err } if config.IssuerURL == "" { @@ -274,8 +256,8 @@ return i, nil } -// KeyType returns either x509.RSA or x509.ECDSA, depending on whether the -// issuer has an RSA or ECDSA keypair. This is useful for determining which +// KeyType returns x509.RSA, x509.ECDSA, or x509.MLDSA depending on the +// keypair of the issuer. This is useful for determining which // issuance requests should be routed to this issuer. func (i *Issuer) KeyType() x509.PublicKeyAlgorithm { return i.keyAlg
diff --git a/test/certs/genmtpki/genmtpki.go b/test/certs/genmtpki/genmtpki.go index 1723a36..b3f620a 100644 --- a/test/certs/genmtpki/genmtpki.go +++ b/test/certs/genmtpki/genmtpki.go
@@ -3,13 +3,13 @@ package main import ( - "crypto/ecdsa" - "crypto/elliptic" + "crypto/mldsa" "crypto/rand" "crypto/x509" "crypto/x509/pkix" "encoding/asn1" "encoding/pem" + "flag" "log" "math/big" "os" @@ -23,10 +23,13 @@ } } -const basename = "test/certs/mtpki/mtca1" +const basename = "mtca1" func main2() error { - key, err := ecdsa.GenerateKey(elliptic.P256(), nil) + outputDir := flag.String("output-dir", "/tmp/", "Directory to write outputs to") + flag.Parse() + + key, err := mldsa.GenerateKey(mldsa.MLDSA44()) if err != nil { return err } @@ -36,7 +39,7 @@ return err } - keyFile, err := os.OpenFile(basename+".key.pem", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) + keyFile, err := os.OpenFile(*outputDir+basename+".key.pem", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) if err != nil { return err } @@ -79,7 +82,7 @@ return err } - certFile, err := os.OpenFile(basename+".cert.pem", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) + certFile, err := os.OpenFile(*outputDir+basename+".cert.pem", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) if err != nil { return err } @@ -124,7 +127,8 @@ // Copied from https://cs.opensource.google/go/go/+/refs/tags/go1.26.3:src/crypto/x509/x509.go;l=345-350 oidSHA256 := asn1.ObjectIdentifier{2, 16, 840, 1, 101, 3, 4, 2, 1} - oidSignatureECDSAWithSHA256 := asn1.ObjectIdentifier{1, 2, 840, 10045, 4, 3, 2} + // https://www.rfc-editor.org/info/rfc9881/ + oidSignatureMLDSA44 := asn1.ObjectIdentifier{1, 2, 840, 1, 101, 3, 4, 3, 17} extnMarshaled, err := asn1.Marshal(struct { LogHash pkix.AlgorithmIdentifier @@ -132,7 +136,7 @@ MinSerial int64 }{ LogHash: pkix.AlgorithmIdentifier{Algorithm: oidSHA256}, - SigAlg: pkix.AlgorithmIdentifier{Algorithm: oidSignatureECDSAWithSHA256}, + SigAlg: pkix.AlgorithmIdentifier{Algorithm: oidSignatureMLDSA44}, // Just for fun, exercise MinSerial functionality. MinSerial: 999, })