@@ -117,7 +117,7 @@ void verifySpiffeId_givenAnEmptySupplier_throwsCertificateException() {
117117
118118 @ Test
119119 void verifySpiffeId_leafWithCaFlagSetToTrue_throwsCertificateException () throws Exception {
120- X509Certificate certificate = mockLeafCertificate ("spiffe://example.org/test" , false , false , true );
120+ X509Certificate certificate = mockLeafCertificate ("spiffe://example.org/test" , true , false , false , true );
121121 try {
122122 X509SvidValidator .verifySpiffeId (certificate , () -> Sets .newHashSet (SpiffeId .parse ("spiffe://example.org/test" )));
123123 fail ("Should have thrown CertificateException" );
@@ -126,9 +126,20 @@ void verifySpiffeId_leafWithCaFlagSetToTrue_throwsCertificateException() throws
126126 }
127127 }
128128
129+ @ Test
130+ void verifySpiffeId_leafWithoutDigitalSignature_throwsCertificateException () throws Exception {
131+ X509Certificate certificate = mockLeafCertificate ("spiffe://example.org/test" , false , false , false , false );
132+ try {
133+ X509SvidValidator .verifySpiffeId (certificate , () -> Sets .newHashSet (SpiffeId .parse ("spiffe://example.org/test" )));
134+ fail ("Should have thrown CertificateException" );
135+ } catch (CertificateException e ) {
136+ assertEquals ("Leaf certificate must have 'digitalSignature' as key usage" , e .getMessage ());
137+ }
138+ }
139+
129140 @ Test
130141 void verifySpiffeId_leafWithKeyCertSign_throwsCertificateException () throws Exception {
131- X509Certificate certificate = mockLeafCertificate ("spiffe://example.org/test" , true , false , false );
142+ X509Certificate certificate = mockLeafCertificate ("spiffe://example.org/test" , true , true , false , false );
132143 try {
133144 X509SvidValidator .verifySpiffeId (certificate , () -> Sets .newHashSet (SpiffeId .parse ("spiffe://example.org/test" )));
134145 fail ("Should have thrown CertificateException" );
@@ -139,7 +150,7 @@ void verifySpiffeId_leafWithKeyCertSign_throwsCertificateException() throws Exce
139150
140151 @ Test
141152 void verifySpiffeId_leafWithCRLSign_throwsCertificateException () throws Exception {
142- X509Certificate certificate = mockLeafCertificate ("spiffe://example.org/test" , false , true , false );
153+ X509Certificate certificate = mockLeafCertificate ("spiffe://example.org/test" , true , false , true , false );
143154 try {
144155 X509SvidValidator .verifySpiffeId (certificate , () -> Sets .newHashSet (SpiffeId .parse ("spiffe://example.org/test" )));
145156 fail ("Should have thrown CertificateException" );
@@ -150,7 +161,7 @@ void verifySpiffeId_leafWithCRLSign_throwsCertificateException() throws Exceptio
150161
151162 @ Test
152163 void verifySpiffeId_leafSpiffeIdWithoutPath_throwsCertificateException () throws Exception {
153- X509Certificate certificate = mockLeafCertificate ("spiffe://example.org" , false , false , false );
164+ X509Certificate certificate = mockLeafCertificate ("spiffe://example.org" , true , false , false , false );
154165 try {
155166 X509SvidValidator .verifySpiffeId (certificate , () -> Sets .newHashSet (SpiffeId .parse ("spiffe://example.org" )));
156167 fail ("Should have thrown CertificateException" );
@@ -219,11 +230,15 @@ void verifyChain_nullBundleSource_throwsNullPointerException() throws Certificat
219230 }
220231 }
221232
222- private X509Certificate mockLeafCertificate (String uriSan , boolean keyCertSign , boolean crlSign , boolean isCa )
233+ private X509Certificate mockLeafCertificate (String uriSan ,
234+ boolean digitalSignature ,
235+ boolean keyCertSign ,
236+ boolean crlSign ,
237+ boolean isCa )
223238 throws Exception {
224239 X509Certificate certificate = Mockito .mock (X509Certificate .class );
225240 boolean [] keyUsage = new boolean [9 ];
226- keyUsage [0 ] = true ;
241+ keyUsage [0 ] = digitalSignature ;
227242 keyUsage [5 ] = keyCertSign ;
228243 keyUsage [6 ] = crlSign ;
229244
0 commit comments