MCPcopy Create free account
hub / github.com/grpc/grpc-java / extractCert

Method extractCert

core/src/main/java/io/grpc/internal/SpiffeUtil.java:228–257  ·  view source on GitHub ↗
(List<Map<String, ?>> keysNode,
      String trustDomainName)

Source from the content-addressed store, hash-verified

226 }
227
228 private static List<X509Certificate> extractCert(List<Map<String, ?>> keysNode,
229 String trustDomainName) {
230 List<X509Certificate> result = new ArrayList<>();
231 for (Map<String, ?> keyNode : keysNode) {
232 checkJwkEntry(keyNode, trustDomainName);
233 List<String> rawCerts = JsonUtil.getListOfStrings(keyNode, "x5c");
234 if (rawCerts == null) {
235 break;
236 }
237 if (rawCerts.size() != 1) {
238 throw new IllegalArgumentException(String.format("Exactly 1 certificate is expected, but "
239 + "%s found. Certificate loading for trust domain '%s' failed.", rawCerts.size(),
240 trustDomainName));
241 }
242 InputStream stream = new ByteArrayInputStream((CERTIFICATE_PREFIX + rawCerts.get(0) + "\n"
243 + CERTIFICATE_SUFFIX)
244 .getBytes(StandardCharsets.UTF_8));
245 try {
246 Collection<? extends Certificate> certs = CertificateFactory.getInstance("X509")
247 .generateCertificates(stream);
248 X509Certificate[] certsArray = certs.toArray(new X509Certificate[0]);
249 assert certsArray.length == 1;
250 result.add(certsArray[0]);
251 } catch (CertificateException e) {
252 throw new IllegalArgumentException(String.format("Certificate can't be parsed. Certificate "
253 + "loading for trust domain '%s' failed.", trustDomainName), e);
254 }
255 }
256 return result;
257 }
258
259 /**
260 * Represents a SPIFFE ID as defined in the SPIFFE standard.

Callers 1

Calls 7

checkJwkEntryMethod · 0.95
getListOfStringsMethod · 0.95
getBytesMethod · 0.80
sizeMethod · 0.65
getMethod · 0.65
addMethod · 0.65
getInstanceMethod · 0.45

Tested by

no test coverage detected