-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Forward client certificate from central gateway to domain gatew…
…ay in request header (#3046) * Add new filter for re-sending auth source. Signed-off-by: Petr Weinfurt <[email protected]> * add license text Signed-off-by: Petr Weinfurt <[email protected]> * Read certificate from request header Signed-off-by: at670475 <[email protected]> * add integration test Signed-off-by: at670475 <[email protected]> * add header to test Signed-off-by: at670475 <[email protected]> * add unit test Signed-off-by: at670475 <[email protected]> * add error to the log Signed-off-by: at670475 <[email protected]> * optmize code and check for certificate in the attibute Signed-off-by: at670475 <[email protected]> * Add certificate signature to the additional header Signed-off-by: Petr Weinfurt <[email protected]> * Add public rest endpoint to provide JWK set. Signed-off-by: Petr Weinfurt <[email protected]> * WellKnownRestController and tests Signed-off-by: Petr Weinfurt <[email protected]> * add licenses Signed-off-by: Petr Weinfurt <[email protected]> * Add simple integration test Signed-off-by: Petr Weinfurt <[email protected]> * Add integration tests for well-known endpoint. Signed-off-by: Petr Weinfurt <[email protected]> * Add some javadoc. Signed-off-by: Petr Weinfurt <[email protected]> * Fix integration test Signed-off-by: Petr Weinfurt <[email protected]> * validate cert Signed-off-by: at670475 <[email protected]> * Simplify retrieving the public key. Signed-off-by: Petr Weinfurt <[email protected]> * Fix for integration tests Signed-off-by: Petr Weinfurt <[email protected]> * Cloud gateway provides certificate chain on public endpoint (instead of public key). Certificate is sent in Client-Cert header. Signed-off-by: Petr Weinfurt <[email protected]> * Cloud gateway implementation fixes Signed-off-by: Petr Weinfurt <[email protected]> * Categorize certs filter WIP Signed-off-by: Petr Weinfurt <[email protected]> * Merge with master branch Signed-off-by: Petr Weinfurt <[email protected]> * Fix casting exception Signed-off-by: Petr Weinfurt <[email protected]> * Cleanup. Add log messages. Signed-off-by: Petr Weinfurt <[email protected]> * Fixes Signed-off-by: Petr Weinfurt <[email protected]> * Add tests for CategorizeCertsFilter Signed-off-by: Petr Weinfurt <[email protected]> * Add CertificateValidatorTest Signed-off-by: Petr Weinfurt <[email protected]> * Add caching trusted certificates Signed-off-by: Petr Weinfurt <[email protected]> * Fix message types Signed-off-by: Petr Weinfurt <[email protected]> * Add javadoc Signed-off-by: Petr Weinfurt <[email protected]> * remove unnecessary dependency Signed-off-by: Petr Weinfurt <[email protected]> * Prepare SSL Auth for integration test. Signed-off-by: Petr Weinfurt <[email protected]> * Remove obsolete test Signed-off-by: Petr Weinfurt <[email protected]> * Add new runtime variables to start.sh files. Signed-off-by: Petr Weinfurt <[email protected]> * Add new options to manifest.yaml files Signed-off-by: Petr Weinfurt <[email protected]> * fix integration test Signed-off-by: Petr Weinfurt <[email protected]> * Update IT Signed-off-by: Petr Weinfurt <[email protected]> * Update keystore for IT Signed-off-by: Petr Weinfurt <[email protected]> * Update error messages Signed-off-by: Petr Weinfurt <[email protected]> * Update common name in the certificate Signed-off-by: Petr Weinfurt <[email protected]> * Update common name in the certificate Signed-off-by: Petr Weinfurt <[email protected]> * Update common name in the certificate Signed-off-by: Petr Weinfurt <[email protected]> * Update common name in the certificate Signed-off-by: Petr Weinfurt <[email protected]> * Add tests for CategorizeCertsFilter Signed-off-by: Petr Weinfurt <[email protected]> * Add CA certificate to keystore Signed-off-by: Petr Weinfurt <[email protected]> * Add unit tests Signed-off-by: Petr Weinfurt <[email protected]> * disable forwarded cert in gateway on localhost Signed-off-by: Petr Weinfurt <[email protected]> * Resolve code review Signed-off-by: Petr Weinfurt <[email protected]> * Increase coverage Signed-off-by: Petr Weinfurt <[email protected]> * Externalize the update public keys function to the CategorizeCertsFilter. Update tests. Signed-off-by: Petr Weinfurt <[email protected]> * Increase coverage. Signed-off-by: Petr Weinfurt <[email protected]> --------- Signed-off-by: Petr Weinfurt <[email protected]> Signed-off-by: at670475 <[email protected]> Co-authored-by: Andrea Tabone <[email protected]> Co-authored-by: achmelo <[email protected]>
- Loading branch information
1 parent
3c1bb91
commit eda4750
Showing
37 changed files
with
1,986 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
...rity-common/src/main/java/org/zowe/apiml/security/common/verify/CertificateValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* This program and the accompanying materials are made available under the terms of the | ||
* Eclipse Public License v2.0 which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Copyright Contributors to the Zowe Project. | ||
*/ | ||
|
||
package org.zowe.apiml.security.common.verify; | ||
|
||
import lombok.Getter; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
import org.zowe.apiml.message.log.ApimlLogger; | ||
import org.zowe.apiml.product.logging.annotations.InjectApimlLogger; | ||
|
||
import java.security.cert.Certificate; | ||
import java.security.cert.X509Certificate; | ||
import java.util.Base64; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
/** | ||
* Service to verify if given certificate chain can be trusted. | ||
*/ | ||
@Service | ||
@Slf4j | ||
public class CertificateValidator { | ||
|
||
final TrustedCertificatesProvider trustedCertificatesProvider; | ||
|
||
@InjectApimlLogger | ||
private final ApimlLogger apimlLog = ApimlLogger.empty(); | ||
|
||
@Getter | ||
@Value("${apiml.security.x509.acceptForwardedCert:false}") | ||
private boolean forwardingEnabled; | ||
|
||
@Value("${apiml.security.x509.certificatesUrl:}") | ||
private String proxyCertificatesEndpoint; | ||
private final Set<String> publicKeyCertificatesBase64; | ||
|
||
|
||
@Autowired | ||
public CertificateValidator(TrustedCertificatesProvider trustedCertificatesProvider, | ||
@Qualifier("publicKeyCertificatesBase64") Set<String> publicKeyCertificatesBase64) { | ||
this.trustedCertificatesProvider = trustedCertificatesProvider; | ||
this.publicKeyCertificatesBase64 = publicKeyCertificatesBase64; | ||
} | ||
|
||
/** | ||
* Compare given certificates with a list of trusted certs. | ||
* | ||
* @param certs Certificates to compare with known trusted ones | ||
* @return true if all given certificates are known false otherwise | ||
*/ | ||
public boolean isTrusted(X509Certificate[] certs) { | ||
List<Certificate> trustedCerts = trustedCertificatesProvider.getTrustedCerts(proxyCertificatesEndpoint); | ||
for (X509Certificate cert : certs) { | ||
if (!trustedCerts.contains(cert)) { | ||
apimlLog.log("org.zowe.apiml.security.common.verify.untrustedCert"); | ||
log.debug("Untrusted certificate is {}", cert); | ||
return false; | ||
} | ||
} | ||
log.debug("All certificates are trusted."); | ||
return true; | ||
} | ||
|
||
/** | ||
* Updates the list of public keys from certificates that belong to APIML | ||
* | ||
* @param certs List of certificates coming from the central Gateway | ||
*/ | ||
public void updateAPIMLPublicKeyCertificates(X509Certificate[] certs) { | ||
for (X509Certificate cert : certs) { | ||
String publicKey = Base64.getEncoder().encodeToString(cert.getPublicKey().getEncoded()); | ||
publicKeyCertificatesBase64.add(publicKey); | ||
} | ||
} | ||
} |
Oops, something went wrong.