Skip to content

Commit

Permalink
Merge pull request #46 from Axway-API-Management-Plus/junit
Browse files Browse the repository at this point in the history
Support non rsa private key and storing cert to cert store
  • Loading branch information
rathnapandi authored Feb 16, 2022
2 parents eac69d1 + 5b24a0c commit 1070c02
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/badges/jacoco.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.7</version>
<version>1.1.9</version>

<name>apim-env-module</name>
<url>https://axway.com</url>
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/axway/CertHelper.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.axway;


import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
import org.bouncycastle.openssl.PEMKeyPair;
import org.bouncycastle.openssl.PEMParser;
import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter;
Expand Down Expand Up @@ -68,6 +69,9 @@ public PrivateKey parsePrivateKey(String base64EncodedCertOrFilePath) throws IOE
PEMKeyPair pemKeyPair = (PEMKeyPair) pemContent;
KeyPair keyPair = jcaPEMKeyConverter.getKeyPair(pemKeyPair);
return keyPair.getPrivate();
}else if(pemContent instanceof PrivateKeyInfo){
PrivateKeyInfo privateKeyInfo = (PrivateKeyInfo) pemContent;
return jcaPEMKeyConverter.getPrivateKey(privateKeyInfo);
}
return null;
} finally {
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/axway/ExternalConfigLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ public void updatePassword(EntityStore entityStore) {
String mTLS = System.getenv("certandkeymtls" + "_" + filterName);
PKCS12 pkcs12 = importP12(entityStore, passwordValue, password);
Trace.info("P12 file alias name :" + pkcs12.getAlias());
configureP12(entityStore, filterName, pkcs12, mTLS);
if(!filterName.equalsIgnoreCase("certstore")) {
configureP12(entityStore, filterName, pkcs12, mTLS);
}
} catch (Exception e) {
Trace.error("Unable to add the p12 from Environment variable", e);
}
Expand Down Expand Up @@ -634,6 +636,7 @@ public PKCS12 importCertAndKeyAndCA(EntityStore entityStore, String cert, String

PKCS12 pkcs12 = new PKCS12();
List<X509Certificate> caCerts = new ArrayList<>();
Trace.info("ca cert "+ca);
if (ca != null) {
caCerts = certHelper.parseX509(ca);
}
Expand Down
17 changes: 17 additions & 0 deletions src/test/java/com/axway/CertHelperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,5 +179,22 @@ public void testInvalidCertificateFormat() {
}
}

@Test
public void testNonRSAPrivateKey() {


try {

PrivateKey privateKey = certHelper.parsePrivateKey("src/test/resources/privkey.pem");
} catch (CertificateException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

}


}
28 changes: 28 additions & 0 deletions src/test/resources/privkey.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCsrx6BDT7bqjAG
XKHYR3GS9SBCUQ3ZiFd7nM6ZDWbTILoF2Fe70NAPMY7PdNUg+xBADLGKDqkcKjBv
mpLnqcF/YX6wTx5NJbRKTQZxLA/IDCbn1uvlC3cD6vLfwYX3LCbxUl9kKQy2aM+G
T3KQ6ldpIcTJCzabeoLP3KHVh7FPvJdmIFIDWlc4gWPl19G/UWekcvTmt5sREwWh
IOJ0EFrNG+RCe7tOjOn0ujj2cj/yErrXwJXoDky4irn15ReD1otcR9T3Hts3dqi6
g9L+ToRyXwOxSZQYVmPwLZwNGB9docVazCtidMHVNJd6g3WIAS1RhyPKJzKkLGqO
EmtKvD0/AgMBAAECggEAJJikTVNCTAlgTijZf918O1nJsWQ+HCj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