Skip to content

Commit

Permalink
Support for connect to URL SSL authentication #9
Browse files Browse the repository at this point in the history
  • Loading branch information
Rathna committed Jan 21, 2021
1 parent d41c18a commit 7e504b0
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 7 deletions.
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,29 @@ ZGIu5manaCW4XJKyZU/Kp04JR6ojQai65R/OLaFOxQhdZ9rtIN1DAsyTBp/6tqqC
s2+QnHEKNi5n6eyF81l1X3AGOMp2uUF4CfU=
-----END CERTIFICATE-----"
```
- PKCS12 - To update the https listener certificate. There are two environment variables used to setup certificate on Listener interface
- Connect to URL SSL ( 2-Way SSL / Mutual SSL) Authentication
To update Connect to URL SSL certificate, there are two environment variables used to set up certificate for SSL Authentication
-- connecttourl_certandkey_sslauth
-- certandkeypassword_sslauth
```bash
$export connecttourl_certandkey_sslauth="MIIL5gIBAzCCC7AGCSqGSIb3DQEHAaCCC6EEggudMIILmTCCBi8GCSqGSIb3DQEHBqCCBiAwggYcAgEAMIIGFQYJKoZIhvcNAQcBMBwGCiqGSIb3DQEMAQYwDgQI9bSw5/Kr0SsCAggAgIIF6DTG3vfPtoc4NPgJE9FU43PRyMpBcv/JIefNDTvC5CNQ+7b47Afqo6mJFIndSxTEbHcnWNG/ufC2/C+7oTn8aZyrgi868fgysv9knhOe+tPJ1O6RyF690m00CmoRhE4kCDKMPaAeRR2ZAMAqj9nPrxjWMXKdrS8+LeEhq2SYSozP8VR+llaTrDPtO8+mC9KRfJIgrKpbB0G/qdnJNtrhJJ8fhaE+/Ufkhydwe0tldu+kOGMODCWVpCY5q2MRrQlhvQhLOYJ7LA/Ovz1ZDjOAE9oujqvhegDxwHj4I6sxHYhGsPUYstNiiqpI5ZcODxUajd5JmEGytk9LU/9PtKEQrXMB4/H7RsRV2bVMWtDaHVW5g0h0oUTw5SBJuPEZMljfLSIXiazerlDC5wybVKVoImDcSiYqHzEKj4DivSclrNfFk4JMMaK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A+8orsU5r9BCv7NZFh278fSo3fpPut9+ZpmSaYDPpDjAuYlpzv1NFTyAz8Q2myFWFHSxh+KnSfhrEtf4euDRgQ/9gZ2IqXUsZ3FXUNtymfMUYwHwYJKoZIhvcNAQkUMRIeEABDAE4APQBhAHgAdwBhAHkwIwYJKoZIhvcNAQkVMRYEFFnwiPQwNks1gKUHDM3ye/ArMTPaMC0wITAJBgUrDgMCGgUABBQMVJgNbDx/sDqV37rk+lgsiaWPhgQIXKMl/uHVEFw"

# Use file path - file should be created via config map / mount
$export connecttourl_certandkey_sslauth = /opt/Axway/apigateway/certs/cert.p12

# Use k8s secret to manage password
$export connecttourl_certandkey_sslauth=changeit
```
**sslauth** is the name of Connect to URL filter.

![secureport Interface](images/https_interface.png)

- PKCS12 - To update the https listener certificate. There are two environment variables used to set up certificate on Listener interface

-- certandkey_secureport

Expand All @@ -196,7 +218,6 @@ $export certandkeypassword_secureport=changeit

![secureport Interface](images/https_interface.png)

The PKCS12 file is base64 encoded, it will be changed to file ( reading from an external drive or ??)

## Build the project

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.axway</groupId>
<artifactId>apim-env-module</artifactId>
<version>1.1.2</version>
<version>1.1.3</version>

<name>apim-env-module</name>
<url>https://axway.com</url>
Expand Down
49 changes: 45 additions & 4 deletions src/main/java/com/axway/ExternalConfigLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ private void updatePassword(EntityStore entityStore) {
} catch (Exception e) {
Trace.error("Unable to add the p12 from Environment variable", e);
}
}else if (key.startsWith("connecttourl_certandkey_")) {
try {
char[] password = System.getenv("connecttourl_certandkeypassword" + "_" + filterName).toCharArray();
String alias = importP12(entityStore, passwordValue, password);
Trace.info("P12 file alias name :" + alias);
connectToURLConfigureP12(entityStore, filterName, alias);
} catch (Exception e) {
Trace.error("Unable to add the p12 from Environment variable", e);
}
}
}

Expand Down Expand Up @@ -362,22 +371,54 @@ private String importPublicCertificate(X509Certificate certificate, EntityStore
private void configureP12(EntityStore entityStore, String name, String alias) {

String shorthandKey = "/[NetService]name=Service/[HTTP]**/[SSLInterface]name=" + name;
ShorthandKeyFinder shorthandKeyFinder = new ShorthandKeyFinder(entityStore);
List<Entity> entities = shorthandKeyFinder.getEntities(shorthandKey);
//ShorthandKeyFinder shorthandKeyFinder = new ShorthandKeyFinder(entityStore);
//List<Entity> entities = shorthandKeyFinder.getEntities(shorthandKey);
List<Entity> entities = getEntities(entityStore, shorthandKey);
if (entities.isEmpty()) {
Trace.error("Listener interface is not available");
return;
}else if(entities.size() > 1){
Trace.error("Found more than one Listener interface");
return;
}
Entity entity = entities.get(0);
String fieldName = "serverCert";
updateP12Cert(entityStore, entity, alias, fieldName);
}

private List<Entity> getEntities(EntityStore entityStore, String shorthandKey){
ShorthandKeyFinder shorthandKeyFinder = new ShorthandKeyFinder(entityStore);
return shorthandKeyFinder.getEntities(shorthandKey);
}

private void updateP12Cert(EntityStore entityStore, Entity entity, String alias, String fieldName){

String escapedAlias = ShorthandKeyFinder.escapeFieldValue(alias);
Entity certEntity = getCertEntity(entityStore, escapedAlias);
//Trace.info("Certificate entity set to listener interface "+ certEntity);
PortableESPK portableESPK = PortableESPK.toPortableKey(entityStore, certEntity.getPK());
//Trace.info("Portable : " + portableESPK);
entity.setReferenceField("serverCert", portableESPK);
entity.setReferenceField(fieldName, portableESPK);
entityStore.updateEntity(entity);
}

private void connectToURLConfigureP12(EntityStore entityStore, String name, String alias) {

String shorthandKey = "/[FilterCircuit]**/[ConnectToURLFilter]name=" + name;
//ShorthandKeyFinder shorthandKeyFinder = new ShorthandKeyFinder(entityStore);
List<Entity> entities = getEntities(entityStore, shorthandKey);
if (entities.isEmpty()) {
Trace.error("Unable to find connect to URL filter");
return;
}else if(entities.size() > 1){
Trace.error("Found more than one connect to URL filter");
return;
}
Entity entity = entities.get(0);
String fieldName = "sslusers";
updateP12Cert(entityStore, entity, alias, fieldName);
}

private Entity getCertEntity(EntityStore entityStore, String alias) {
String shorthandKey = "/[Certificates]name=Certificate Store";
ShorthandKeyFinder shorthandKeyFinder = new ShorthandKeyFinder(entityStore);
Expand All @@ -393,7 +434,7 @@ private Entity getCertEntity(EntityStore entityStore, String alias) {

private String importP12(EntityStore entityStore, String cert, char[] password) throws Exception {

PKCS12 pkcs12 = null;
PKCS12 pkcs12;
File file = new File(cert);
if(file.exists()){
pkcs12 = certHelper.parseP12(file, password);
Expand Down

0 comments on commit 7e504b0

Please sign in to comment.