From 82cb02447bcf75a5922da8f07d700cf66c124b12 Mon Sep 17 00:00:00 2001 From: Malik Zharykov Date: Fri, 23 Aug 2024 07:34:50 +0500 Subject: [PATCH] fix(key-usage): Fix nullpointer error --- .../kz/ncanode/wrapper/CertificateWrapper.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/java/kz/ncanode/wrapper/CertificateWrapper.java b/src/main/java/kz/ncanode/wrapper/CertificateWrapper.java index a1c832c..299200f 100644 --- a/src/main/java/kz/ncanode/wrapper/CertificateWrapper.java +++ b/src/main/java/kz/ncanode/wrapper/CertificateWrapper.java @@ -193,19 +193,23 @@ public PublicKey getPublicKey() { return x509Certificate.getPublicKey(); } - private Set getKeyUser() { + public List getExtendedKeyUsage() { try { - return getX509Certificate().getExtendedKeyUsage().stream() - .map(CertificateKeyUser::fromOID) - .filter(Optional::isPresent) - .map(Optional::get) - .collect(Collectors.toSet()); + return getX509Certificate().getExtendedKeyUsage(); } catch (CertificateParsingException e) { log.error("Certificate key user extracting error", e); - return Collections.emptySet(); + return Collections.emptyList(); } } + private Set getKeyUser() { + return getExtendedKeyUsage().stream() + .map(CertificateKeyUser::fromOID) + .filter(Optional::isPresent) + .map(Optional::get) + .collect(Collectors.toSet()); + } + public static Optional fromBase64(final String encodedCert) { return fromBytes(Base64.getDecoder().decode(encodedCert.replaceAll("\\s", ""))); }