-
Notifications
You must be signed in to change notification settings - Fork 628
Commit
Add an utility class for gateway certificate management Add new configuration enable_certificate_chain_validation to api-manager.xml.j2
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com) All Rights Reserved. | ||
* | ||
* WSO2 LLC. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.wso2.carbon.apimgt.impl.utils; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.wso2.carbon.apimgt.api.APIManagementException; | ||
import org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder; | ||
|
||
import java.security.KeyStore; | ||
import java.security.KeyStoreException; | ||
import java.security.cert.Certificate; | ||
import java.util.Enumeration; | ||
|
||
public class GatewayCertificateMgtUtil { | ||
Check warning on line 30 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/GatewayCertificateMgtUtil.java Codecov / codecov/patchcomponents/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/GatewayCertificateMgtUtil.java#L30
|
||
|
||
private static final Log log = LogFactory.getLog(GatewayCertificateMgtUtil.class); | ||
Check warning on line 32 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/GatewayCertificateMgtUtil.java Codecov / codecov/patchcomponents/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/GatewayCertificateMgtUtil.java#L32
|
||
|
||
/** | ||
* Fetches all the trusted certificate aliases from listener trust store. | ||
* | ||
* @return Trusted certificate aliases | ||
* @throws APIManagementException | ||
*/ | ||
public static Enumeration<String> getAliasesFromListenerTrustStore() throws APIManagementException { | ||
|
||
try { | ||
KeyStore trustStore = ServiceReferenceHolder.getInstance().getListenerTrustStore(); | ||
Check warning on line 43 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/GatewayCertificateMgtUtil.java Codecov / codecov/patchcomponents/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/GatewayCertificateMgtUtil.java#L43
|
||
if (trustStore != null) { | ||
return trustStore.aliases(); | ||
Check warning on line 45 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/GatewayCertificateMgtUtil.java Codecov / codecov/patchcomponents/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/GatewayCertificateMgtUtil.java#L45
|
||
} | ||
} catch (KeyStoreException e) { | ||
String msg = "Error getting certificate aliases from trust store"; | ||
log.error(msg, e); | ||
throw new APIManagementException(msg, e); | ||
} | ||
return null; | ||
Check warning on line 52 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/GatewayCertificateMgtUtil.java Codecov / codecov/patchcomponents/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/GatewayCertificateMgtUtil.java#L47-L52
|
||
} | ||
|
||
/** | ||
* Fetches certificate for given certificate alias from listener trust store. | ||
* | ||
* @param certAlias Certificate alias | ||
* @return Certificate | ||
* @throws APIManagementException | ||
*/ | ||
public static Certificate getCertificateFromListenerTrustStore(String certAlias) throws APIManagementException { | ||
|
||
Certificate publicCert = null; | ||
Check warning on line 64 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/GatewayCertificateMgtUtil.java Codecov / codecov/patchcomponents/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/GatewayCertificateMgtUtil.java#L64
|
||
try { | ||
KeyStore trustStore = ServiceReferenceHolder.getInstance().getListenerTrustStore(); | ||
Check warning on line 66 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/GatewayCertificateMgtUtil.java Codecov / codecov/patchcomponents/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/GatewayCertificateMgtUtil.java#L66
|
||
if (trustStore != null) { | ||
// Read public certificate from trust store | ||
publicCert = trustStore.getCertificate(certAlias); | ||
Check warning on line 69 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/GatewayCertificateMgtUtil.java Codecov / codecov/patchcomponents/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/GatewayCertificateMgtUtil.java#L69
|
||
} | ||
} catch (KeyStoreException e) { | ||
String msg = "Error while retrieving public certificate with alias : " + certAlias; | ||
log.error(msg, e); | ||
throw new APIManagementException(msg, e); | ||
} | ||
return publicCert; | ||
Check warning on line 76 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/GatewayCertificateMgtUtil.java Codecov / codecov/patchcomponents/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/GatewayCertificateMgtUtil.java#L71-L76
|
||
} | ||
} |