You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
returnfmt.Errorf("certificate with subject %q: key usage must not have the bit positions for %s set", cert.Subject, kuLeafCertBlockedString)
205
+
iflen(invalidKeyUsages) >0 {
206
+
returnfmt.Errorf("The certificate with subject %q is invalid. The key usage must be \"Digital Signature\" only, but found %s", cert.Subject, strings.Join(invalidKeyUsages, ", "))
assertErrorEqual("certificate with subject \"CN=Hello\": key usage must have the bit positions for digital signature set", err, t)
515
+
assertErrorEqual("The certificate with subject \"CN=Hello\" is invalid. The key usage must have the bit positions for \"Digital Signature\" set", err, t)
assertErrorEqual("certificate with subject \"CN=Hello\": key usage must not have the bit positions for ContentCommitment, KeyEncipherment, DataEncipherment, KeyAgreement, CertSign, CRLSign, EncipherOnly, DecipherOnly set", err, t)
539
+
assertErrorEqual("The certificate with subject \"CN=Hello\" is invalid. The key usage must be \"Digital Signature\" only, but found \"CertSign\", \"CRLSign\"", err, t)
expectedErrMsg: "The certificate with subject \"CN=Test CN\" is invalid. The key usage must be \"Digital Signature\" only, but found \"ContentCommitment\"",
733
+
},
734
+
{
735
+
name: "Missing DigitalSignature usage",
736
+
cert: &x509.Certificate{
737
+
Subject: pkix.Name{CommonName: "Test CN"},
738
+
KeyUsage: x509.KeyUsageCertSign,
739
+
Extensions: extensions,
740
+
},
741
+
expectedErrMsg: "The certificate with subject \"CN=Test CN\" is invalid. The key usage must have the bit positions for \"Digital Signature\" set",
expectedErrMsg: "The certificate with subject \"CN=Test CN\" is invalid. The key usage must be \"Digital Signature\" only, but found \"KeyEncipherment\"",
expectedErrMsg: "The certificate with subject \"CN=Test CN\" is invalid. The key usage must be \"Digital Signature\" only, but found \"KeyEncipherment\", \"DataEncipherment\", \"KeyAgreement\", \"CertSign\", \"CRLSign\", \"EncipherOnly\", \"DecipherOnly\"",
760
+
},
761
+
}
762
+
763
+
for_, tt:=rangetests {
764
+
t.Run(tt.name, func(t*testing.T) {
765
+
err:=validateLeafKeyUsage(tt.cert)
766
+
iferr!=nil&&tt.expectedErrMsg=="" {
767
+
t.Fatalf("expected no error, but got: %s", err)
768
+
} elseiferr==nil&&tt.expectedErrMsg!="" {
769
+
t.Fatalf("expected error %q, but got none", tt.expectedErrMsg)
0 commit comments