Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion core/src/main/java/io/grpc/internal/SpiffeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ private static List<X509Certificate> extractCert(List<Map<String, ?>> keysNode,
checkJwkEntry(keyNode, trustDomainName);
List<String> rawCerts = JsonUtil.getListOfStrings(keyNode, "x5c");
if (rawCerts == null) {
break;
throw new IllegalArgumentException(String.format("'x5c' parameter is required. Certificate "
+ "loading for trust domain '%s' failed.", trustDomainName));
}
if (rawCerts.size() != 1) {
throw new IllegalArgumentException(String.format("Exactly 1 certificate is expected, but "
Expand Down
5 changes: 5 additions & 0 deletions core/src/test/java/io/grpc/internal/SpiffeUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ public static class CertificateApiTest {
private static final String SPIFFE_TRUST_BUNDLE_DUPLICATES = "spiffebundle_duplicates.json";
private static final String SPIFFE_TRUST_BUNDLE_WRONG_ROOT = "spiffebundle_wrong_root.json";
private static final String SPIFFE_TRUST_BUNDLE_WRONG_SEQ = "spiffebundle_wrong_seq_type.json";
private static final String SPIFFE_TRUST_BUNDLE_MISSING_X5C = "spiffebundle_missing_x5c.json";
private static final String DOMAIN_ERROR_MESSAGE =
" Certificate loading for trust domain 'google.com' failed.";

Expand Down Expand Up @@ -351,6 +352,10 @@ public void loadTrustBundleFromFileFailureTest() {
iae = assertThrows(IllegalArgumentException.class, () -> SpiffeUtil
.loadTrustBundleFromFile(copyFileToTmp(SPIFFE_TRUST_BUNDLE_CORRUPTED_CERT)));
assertEquals("Certificate can't be parsed." + DOMAIN_ERROR_MESSAGE, iae.getMessage());
// Check the exception if a key entry is missing the 'x5c' parameter
iae = assertThrows(IllegalArgumentException.class, () -> SpiffeUtil
.loadTrustBundleFromFile(copyFileToTmp(SPIFFE_TRUST_BUNDLE_MISSING_X5C)));
assertEquals("'x5c' parameter is required." + DOMAIN_ERROR_MESSAGE, iae.getMessage());
// Check the exception if 'kty' value differs from 'RSA'
iae = assertThrows(IllegalArgumentException.class, () -> SpiffeUtil
.loadTrustBundleFromFile(copyFileToTmp(SPIFFE_TRUST_BUNDLE_WRONG_KTY)));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"trust_domains": {
"google.com": {
"keys": [
{
"kty": "RSA",
"use": "x509-svid"
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a 2nd key with "use": "x509-svid" and "x5c" cert present, to ensure that the test fails even if any one of the entries have a missing x5c.

]
}
}
}
Loading