From 79fa543e41549a58b63c1a9df88ba527cabc85a8 Mon Sep 17 00:00:00 2001 From: Sahan Randika Date: Fri, 22 Mar 2024 11:21:47 +0530 Subject: [PATCH] change to java.security.cert.X509Certificate class --- .../apimgt/common/gateway/dto/TokenIssuerDto.java | 2 +- .../carbon/apimgt/impl/factory/KeyManagerHolder.java | 3 +-- .../org/wso2/carbon/apimgt/impl/utils/APIUtil.java | 12 +++++++----- .../api/util/impl/OAuthJwtAuthenticatorImpl.java | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/components/apimgt/org.wso2.carbon.apimgt.common.gateway/src/main/java/org/wso2/carbon/apimgt/common/gateway/dto/TokenIssuerDto.java b/components/apimgt/org.wso2.carbon.apimgt.common.gateway/src/main/java/org/wso2/carbon/apimgt/common/gateway/dto/TokenIssuerDto.java index a9aea891309f..216d2e958f2b 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.common.gateway/src/main/java/org/wso2/carbon/apimgt/common/gateway/dto/TokenIssuerDto.java +++ b/components/apimgt/org.wso2.carbon.apimgt.common.gateway/src/main/java/org/wso2/carbon/apimgt/common/gateway/dto/TokenIssuerDto.java @@ -18,9 +18,9 @@ package org.wso2.carbon.apimgt.common.gateway.dto; +import java.security.cert.Certificate; import java.util.HashMap; import java.util.Map; -import javax.security.cert.Certificate; /** * Holds data related to token issuers. diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/factory/KeyManagerHolder.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/factory/KeyManagerHolder.java index 2aa3891f3115..b5ec7ff146b6 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/factory/KeyManagerHolder.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/factory/KeyManagerHolder.java @@ -46,8 +46,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; - -import javax.security.cert.X509Certificate; +import java.security.cert.X509Certificate; /** * This is a factory class.you have to use this when you need to initiate classes by reading config file. diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/APIUtil.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/APIUtil.java index 8a6dcef69f7b..9a8cb7596ea3 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/APIUtil.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/APIUtil.java @@ -287,7 +287,7 @@ import javax.cache.CacheConfiguration; import javax.cache.CacheManager; import javax.cache.Caching; -import javax.security.cert.X509Certificate; +import java.security.cert.X509Certificate; import javax.validation.constraints.NotNull; import javax.xml.namespace.QName; import javax.xml.parsers.DocumentBuilderFactory; @@ -9268,8 +9268,9 @@ public static X509Certificate retrieveCertificateFromURLEncodedContent(String ba base64EncodedCertificate = APIUtil.getX509certificateContent(base64EncodedCertificate); byte[] bytes = Base64.decodeBase64(base64EncodedCertificate); try (InputStream inputStream = new ByteArrayInputStream(bytes)) { - return X509Certificate.getInstance(inputStream); - } catch (IOException | javax.security.cert.CertificateException e) { + CertificateFactory cf = CertificateFactory.getInstance("X.509"); + return (X509Certificate) cf.generateCertificate(inputStream); + } catch (IOException | CertificateException e) { String msg = "Error while converting into X509Certificate"; log.error(msg, e); throw new APIManagementException(msg, e); @@ -9292,8 +9293,9 @@ public static X509Certificate retrieveCertificateFromContent(String base64Encode base64EncodedCertificate = APIUtil.getX509certificateContent(base64EncodedCertificate); byte[] bytes = Base64.decodeBase64(base64EncodedCertificate.getBytes()); try (InputStream inputStream = new ByteArrayInputStream(bytes)) { - return X509Certificate.getInstance(inputStream); - } catch (IOException | javax.security.cert.CertificateException e) { + CertificateFactory cf = CertificateFactory.getInstance("X.509"); + return (X509Certificate) cf.generateCertificate(inputStream); + } catch (IOException | CertificateException e) { String msg = "Error while converting into X509Certificate"; log.error(msg, e); throw new APIManagementException(msg, e); diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.util/src/main/java/org/wso2/carbon/apimgt/rest/api/util/impl/OAuthJwtAuthenticatorImpl.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.util/src/main/java/org/wso2/carbon/apimgt/rest/api/util/impl/OAuthJwtAuthenticatorImpl.java index 04cb49a34cf7..9e6d760f5a85 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.util/src/main/java/org/wso2/carbon/apimgt/rest/api/util/impl/OAuthJwtAuthenticatorImpl.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.util/src/main/java/org/wso2/carbon/apimgt/rest/api/util/impl/OAuthJwtAuthenticatorImpl.java @@ -55,7 +55,7 @@ import org.wso2.carbon.utils.multitenancy.MultitenantConstants; import org.wso2.carbon.utils.multitenancy.MultitenantUtils; -import javax.security.cert.X509Certificate; +import java.security.cert.X509Certificate; import java.net.MalformedURLException; import java.net.URL; import java.text.ParseException;