Files
kryptkeeper/internal/ca/public_key_algorithm.go
bpmforge 5ebfc7dc3e Kryptkeeper 0.9.1
ML-DSA certificates are stored (signed-but-not-recorded on SQLite and
PostgreSQL in 0.9.0); standard OpenSSL ML-DSA CSRs issue; ML-DSA CAs can be
created; PQC readiness numbers share one definition; 400/409 instead of 503
on issue and renew; template issued counts; UI shows names instead of IDs.
See CHANGELOG.md and docs/release/RELEASE_NOTES_v0.9.1.md.
2026-10-14 14:10:17 -04:00

43 lines
1.2 KiB
Go

// Copyright 2026 Kryptkeeper Authors
//
// SPDX-License-Identifier: Apache-2.0
package ca
import (
"crypto/x509"
"encoding/asn1"
)
// StoredPublicKeyAlgorithm names a certificate's subject key algorithm in the
// vocabulary the certificates.public_key_algorithm CHECK admits (RSA, ECDSA,
// Ed25519, ML-DSA). crypto/x509 reports an ML-DSA SubjectPublicKeyInfo as
// UnknownPublicKeyAlgorithm ("unknown") on the pinned toolchain, which the
// CHECK rejects -- so every ML-DSA issuance was signed but never recorded.
// The SPKI OID is the authority; a hybrid cert's subject SPKI is classical by
// design, so it keeps its classical name.
func StoredPublicKeyAlgorithm(cert *x509.Certificate) string {
if isMLDSASPKI(cert.RawSubjectPublicKeyInfo) {
return "ML-DSA"
}
return cert.PublicKeyAlgorithm.String()
}
func isMLDSASPKI(rawSPKI []byte) bool {
if len(rawSPKI) == 0 {
return false
}
var spki struct {
Algorithm struct {
Algorithm asn1.ObjectIdentifier
Parameters asn1.RawValue `asn1:"optional"`
}
PublicKey asn1.BitString
}
if _, err := asn1.Unmarshal(rawSPKI, &spki); err != nil {
return false
}
_, ok := mldsaAlgoFromOID(spki.Algorithm.Algorithm)
return ok
}