Files
kryptkeeper/internal/ca/csr_algorithm_test.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

71 lines
1.9 KiB
Go

// Copyright 2026 Kryptkeeper Authors
//
// SPDX-License-Identifier: Apache-2.0
package ca
import (
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"crypto/x509"
"crypto/x509/pkix"
"encoding/pem"
"os"
"testing"
)
func TestCSRPublicKeyAlgorithmOID_ClassicalIsNotMLDSA(t *testing.T) {
key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
if err != nil {
t.Fatal(err)
}
der, err := x509.CreateCertificateRequest(rand.Reader, &x509.CertificateRequest{Subject: pkix.Name{CommonName: "c"}}, key)
if err != nil {
t.Fatal(err)
}
oid, err := CSRPublicKeyAlgorithmOID(der)
if err != nil {
t.Fatalf("CSRPublicKeyAlgorithmOID: %v", err)
}
if oid.String() != "1.2.840.10045.2.1" {
t.Errorf("oid = %s, want id-ecPublicKey", oid)
}
if IsMLDSACSR(der) {
t.Error("ECDSA CSR must not be routed to the ML-DSA parser")
}
}
func TestIsMLDSACSR_MalformedDERIsFalse(t *testing.T) {
if IsMLDSACSR([]byte("not der")) {
t.Error("malformed DER must not report ML-DSA")
}
if IsMLDSACSR(nil) {
t.Error("empty input must not report ML-DSA")
}
}
// The fixture is a real openssl 3.6 PKCS#10 request (public data only; the
// throwaway key was discarded) emitted under the standard PEM label, the
// shape the label-only router used to send to crypto/x509.
func TestOpenSSLMLDSA65StandardLabelCSR(t *testing.T) {
raw, err := os.ReadFile("testdata/openssl_mldsa65_std_label.csr")
if err != nil {
t.Fatal(err)
}
block, _ := pem.Decode(raw)
if block == nil || block.Type != "CERTIFICATE REQUEST" {
t.Fatalf("fixture must carry the standard label, got %+v", block)
}
if !IsMLDSACSR(block.Bytes) {
t.Fatal("openssl ML-DSA-65 CSR not recognised by OID")
}
parsed, err := ParseCertificateRequestMLDSA(block.Bytes)
if err != nil {
t.Fatalf("ParseCertificateRequestMLDSA (verifies self-signature): %v", err)
}
if parsed.Subject.CommonName != "pq.example.test" {
t.Errorf("CN = %q", parsed.Subject.CommonName)
}
}