(t *testing.T)
| 356 | } |
| 357 | |
| 358 | func TestValidateCertificateSignatureAlgorithms(t *testing.T) { |
| 359 | // Helper to create a test certificate with specific signature algorithm |
| 360 | createTestCert := func(sigAlg x509.SignatureAlgorithm, isCA bool) *x509.Certificate { |
| 361 | return &x509.Certificate{ |
| 362 | SerialNumber: big.NewInt(1), |
| 363 | SignatureAlgorithm: sigAlg, |
| 364 | IsCA: isCA, |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | t.Run("Empty allowed list passes", func(t *testing.T) { |
| 369 | certs := []*x509.Certificate{ |
| 370 | createTestCert(x509.SHA256WithRSA, false), |
| 371 | } |
| 372 | err := validateCertificateSignatureAlgorithms(certs, nil) |
| 373 | assert.NoError(t, err) |
| 374 | }) |
| 375 | |
| 376 | t.Run("Single cert with allowed algorithm passes", func(t *testing.T) { |
| 377 | certs := []*x509.Certificate{ |
| 378 | createTestCert(x509.SHA256WithRSA, false), |
| 379 | createTestCert(x509.SHA256WithRSA, true), // Root |
| 380 | } |
| 381 | allowed := []signaturehash.Algorithm{ |
| 382 | {Hash: hash.SHA256, Signature: signature.RSA}, |
| 383 | } |
| 384 | err := validateCertificateSignatureAlgorithms(certs, allowed) |
| 385 | assert.NoError(t, err) |
| 386 | }) |
| 387 | |
| 388 | t.Run("Single cert with disallowed algorithm fails", func(t *testing.T) { |
| 389 | certs := []*x509.Certificate{ |
| 390 | createTestCert(x509.SHA256WithRSA, false), |
| 391 | createTestCert(x509.SHA256WithRSA, true), // Root |
| 392 | } |
| 393 | allowed := []signaturehash.Algorithm{ |
| 394 | {Hash: hash.SHA384, Signature: signature.ECDSA}, // Different algorithm |
| 395 | } |
| 396 | err := validateCertificateSignatureAlgorithms(certs, allowed) |
| 397 | assert.ErrorIs(t, err, errInvalidCertificateSignatureAlgorithm) |
| 398 | }) |
| 399 | |
| 400 | t.Run("Root certificate is not validated", func(t *testing.T) { |
| 401 | certs := []*x509.Certificate{ |
| 402 | createTestCert(x509.SHA256WithRSA, false), // Leaf - validated |
| 403 | createTestCert(x509.SHA384WithRSA, true), // Root - NOT validated |
| 404 | } |
| 405 | allowed := []signaturehash.Algorithm{ |
| 406 | {Hash: hash.SHA256, Signature: signature.RSA}, // Only allows SHA256 |
| 407 | } |
| 408 | // Should pass because root (SHA384) is not validated |
| 409 | err := validateCertificateSignatureAlgorithms(certs, allowed) |
| 410 | assert.NoError(t, err) |
| 411 | }) |
| 412 | |
| 413 | t.Run("Multi-cert chain with all allowed algorithms passes", func(t *testing.T) { |
| 414 | certs := []*x509.Certificate{ |
| 415 | createTestCert(x509.SHA256WithRSA, false), // Leaf |
nothing calls this directly
no test coverage detected
searching dependent graphs…