Skip to content

Commit 6e29d24

Browse files
authored
Merge pull request #16 from Axway-API-Management-Plus/domaincert
Domaincert
2 parents ac6394c + 12fe70e commit 6e29d24

File tree

9 files changed

+606
-49
lines changed

9 files changed

+606
-49
lines changed

domain.md

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
# Externalize API Gateway domain certificates
2+
3+
## Admin Node manager
4+
5+
- Create a CSR file
6+
```bash
7+
./gen_domain_cert.py --domain-id=dss --out=csr --O=Axway --OU=DSS --C=US --ST=AZ --L=Scottsdale --pass-file=rootcerts/pass.txt
8+
```
9+
command creates a folder named dss under apigw-emt-scripts-2.1.0-SNAPSHOT/certs/ with following files
10+
11+
- dss.csr
12+
- dss-key.pem
13+
14+
- Create CA CSR, certificate and key
15+
```bash
16+
openssl genrsa -aes256 -out CA.key 2048
17+
openssl req -new -sha256 -key CA.key -out CA.csr -subj "/C=US/ST=AZ/L=Scottsdale/O=AXWAY/CN=CACERTIFICATE"
18+
openssl x509 -signkey CA.key -in CA.csr -req -days 3650 -out CA.pem
19+
```
20+
command creates following files
21+
22+
- CA.key
23+
- CA.csr
24+
- CA.pem
25+
- CA.srl
26+
27+
- Create a file openssl.cnf with following content
28+
29+
```text
30+
[policy_any]
31+
domainComponent = optional
32+
organizationalUnitName = optional
33+
commonName = supplied
34+
35+
[req]
36+
distinguished_name = req_distinguished_name
37+
38+
[req_distinguished_name]
39+
40+
[x509_extensions]
41+
42+
[domain_extensions]
43+
basicConstraints = CA:TRUE, pathlen:0
44+
keyUsage = digitalSignature, keyEncipherment, dataEncipherment, keyAgreement, keyCertSign
45+
46+
[admin_node_manager_extensions]
47+
basicConstraints = CA:FALSE
48+
keyUsage = digitalSignature, dataEncipherment, keyAgreement, keyEncipherment
49+
extendedKeyUsage = serverAuth, clientAuth, 1.3.6.1.4.1.17998.10.1.1.2.1, 1.3.6.1.4.1.17998.10.1.1.2.2
50+
subjectAltName = @alt_names
51+
52+
[node_manager_extensions]
53+
basicConstraints = CA:FALSE
54+
keyUsage = digitalSignature, dataEncipherment, keyAgreement
55+
extendedKeyUsage = serverAuth, clientAuth, 1.3.6.1.4.1.17998.10.1.1.2.1
56+
subjectAltName = @alt_names
57+
58+
[gateway_extensions]
59+
basicConstraints = CA:FALSE
60+
keyUsage = digitalSignature, dataEncipherment, keyAgreement
61+
extendedKeyUsage = serverAuth, clientAuth, 1.3.6.1.4.1.17998.10.1.1.2.3
62+
subjectAltName = @alt_names
63+
64+
[alt_names]
65+
66+
DNS.1 = localhost
67+
IP.1 = 127.0.0.1
68+
69+
```
70+
71+
- Sign dss.csr with CA certificate and key using openssl configuration
72+
73+
```bash
74+
openssl x509 -req -days 360 -in dss.csr -CA CA.pem -CAkey CA.key -CAcreateserial -out signedbyCA.crt -sha256 -extensions admin_node_manager_extensions -extfile openssl.cnf
75+
```
76+
77+
- Create a P12 file from CA signed certificate and key file
78+
79+
```bash
80+
openssl pkcs12 -export -in signedbyCA.crt -inkey dss-key.pem -out domain.p12 -chain -CAfile CA.pem -name 'topology-cert'
81+
```
82+
**alias name should be 'topology-cert'**
83+
84+
- Prepare Admin Node Manager fed file
85+
86+
- Export Admin Node manager fed from classic installation, remove existing topology-cert and change remove / rename port name without blank space (e.g sslport)
87+
88+
- Import loadable module
89+
Policystudio using File -> Import -> Import Custom filters -> select apim-policy-password-cert-env/src/main/resources/typeSet.xml.
90+
91+
- Export fed file
92+
93+
- Configure environment variable (docker-compose / kubernetes deployment)
94+
95+
```yaml
96+
# docker-compose.yaml example
97+
environment:
98+
EMT_TOPOLOGY_LOG_ENABLED: 'true'
99+
EMT_TOPOLOGY_LOG_DEST: 3
100+
certandkey_sslport: /opt/Axway/apigateway/domain.p12
101+
certandkeypassword_sslport: changeme
102+
certandkeymtls_sslport: 'true'
103+
```
104+
105+
- comment lines related to certificate generation in apigw-emt-scripts-2.1.0-SNAPSHOT/Dockerfiles/emt-nodemanager/scripts/setup_emt_nodemanager.py
106+
```python
107+
try:
108+
# self._generateTopologyCert(nmHandler)
109+
# self._storeCertsInEntityStore(nmHandler)
110+
111+
localNodeManager, topology, topologyParams = self._createTopologyJson()
112+
# print("Enabling SSL on management interface")
113+
# nmHandler.enableSSLInterface(True, TopologyCertificate.CERT_ALIAS, topologyParams)
114+
# self._updateConfigFiles(localNodeManager, topology)
115+
116+
# Delete the cert generation temp directory
117+
shutil.rmtree(nmHandler.tempCertPath)
118+
119+
except Exception, e:
120+
_fail("Error generating topology cert: %s" % e)
121+
```
122+
- Build Admin Node Manger Image
123+
124+
```bash
125+
./build_anm_image.py --default-cert --default-user --parent-image=apigw-base --merge-dir=/Users/rnatarajan/APIM/apigw-emt-scripts-2.1.0-SNAPSHOT/apigateway --fed extanm.fed --out-image=admin-node-manager-ext-ca-env:latest
126+
```
127+
**param default-cert is not used, but it is a mandatory argument for building anm image**
128+
129+
## Configure Gateway
130+
131+
- Create a CSR file
132+
133+
```bash
134+
./gen_domain_cert.py --domain-id=dssgateway --out=csr --O=Axway --OU=DSS --C=US --ST=AZ --L=Scottsdale --pass-file=rootcerts/pass.txt
135+
```
136+
command creates a folder named dssgateway under apigw-emt-scripts-2.1.0-SNAPSHOT/certs/ with following files
137+
138+
- dssgateway.csr
139+
- dssgateway-key.pem
140+
- Copy CA.pem, CA.key, CA.srl and openssl files from dss folder to dssgateway folder
141+
142+
```bash
143+
dssgateway$cp ../dss/CA.pem .
144+
dssgateway$cp ../dss/CA.key .
145+
dssgateway$cp ../dss/CA.srl .
146+
dssgateway$cp ../dss/openssl.cnf .
147+
```
148+
- Sign dss.csr with CA certificate and key using openssl configuration
149+
150+
```bash
151+
openssl x509 -req -days 360 -in dssgateway.csr -CA CA.pem -CAkey CA.key -CAcreateserial -out signedbygatewayCA.crt -sha256 -extensions gateway_extensions -extfile openssl.cnf
152+
```
153+
154+
command creates a file named signedbygatewayCA.crt
155+
156+
- Create p12 file **without password**
157+
158+
```bash
159+
openssl pkcs12 -export -in signedbygatewayCA.crt -inkey dssgateway-key.pem -out topology.p12 -chain -CAfile CA.pem -name 'topology-cert' -passout pass:
160+
```
161+
162+
- Prepare Admin Node Manager fed file
163+
164+
- Import loadable module
165+
Policystudio using File -> Import -> Import Custom filters -> select apim-policy-password-cert-env/src/main/resources/typeSet.xml.
166+
167+
- Export fed file
168+
169+
- Configure environment variable (docker-compose / kubernetes deployment)
170+
171+
```yaml
172+
# docker-compose.yaml example
173+
# Mandatory
174+
volumes:
175+
- /Users/rnatarajan/APIM/apigw-emt-scripts-2.1.0-SNAPSHOT/certs/dssgateway/p12:/opt/Axway/apigateway/groups/certs/
176+
environment:
177+
EMT_ANM_HOSTS: nodemgr:8090
178+
CASS0: host.docker.internal
179+
CASS_HOST: host.docker.internal
180+
CASS_USER: dba
181+
CASS_PASSWORD: super
182+
CASS_KEYSPACE: axwayapim
183+
# We should use same path
184+
gatewaytoplogycertandkey_domain: /opt/Axway/apigateway/groups/certs/topology.p12
185+
gatewaytoplogycertandkeypassword_domain: ''
186+
```
187+
188+
- comment lines related to certificate generation in apigw-emt-scripts-2.1.0-SNAPSHOT/Dockerfiles/emt-gateway/scripts/setup_emt_instance.py
189+
190+
```python
191+
def _setup():
192+
_mergePolAndEnvToFed()
193+
_installCustomFedFile()
194+
_setupApiManager()
195+
_createInstanceDirStructure()
196+
_customizeInstallation()
197+
_checkLicense()
198+
199+
# ch = CertHandler()
200+
# ch.generateCert()
201+
# ch.enableSSLInterface()
202+
```
203+
204+
- Build API Gateway Image
205+
```bash
206+
./build_gw_image.py --default-cert --license=/Users/rnatarajan/APIM/apigw-emt-scripts-2.1.0-SNAPSHOT/licenses/apim.lic --parent-image=apigw-base --merge-dir=/Users/rnatarajan/APIM/apigw-emt-scripts-2.1.0-SNAPSHOT/apigateway --fed=container_env.fed --out-image=apim-cert-ca-env:latest
207+
```

pom.xml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.axway</groupId>
88
<artifactId>apim-env-module</artifactId>
9-
<version>1.1.3</version>
9+
<version>1.1.4</version>
1010

1111
<name>apim-env-module</name>
1212
<url>https://axway.com</url>
@@ -48,7 +48,6 @@
4848
<systemPath>${apim.lib.path}/vordel-apigateway-7.7.0.20201130-5.jar</systemPath>
4949
</dependency>
5050
<dependency>
51-
5251
<groupId>vordel-core-runtime</groupId>
5352
<artifactId>vordel-core-runtime</artifactId>
5453
<scope>system</scope>
@@ -86,12 +85,12 @@
8685
<dependency>
8786
<groupId>org.apache.logging.log4j</groupId>
8887
<artifactId>log4j-api</artifactId>
89-
<version>2.11.2</version>
88+
<version>2.13.3</version>
9089
</dependency>
9190
<dependency>
9291
<groupId>org.apache.logging.log4j</groupId>
9392
<artifactId>log4j-core</artifactId>
94-
<version>2.13.2</version>
93+
<version>2.13.3</version>
9594
</dependency>
9695
</dependencies>
9796
<build>

src/main/java/com/axway/CertHelper.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
import java.security.cert.CertificateException;
88
import java.security.cert.CertificateFactory;
99
import java.security.cert.X509Certificate;
10-
import java.util.Base64;
11-
import java.util.Enumeration;
10+
import java.util.*;
1211

1312
public class CertHelper {
1413

@@ -63,18 +62,25 @@ public PKCS12 parseP12(String content, char[] password) throws KeyStoreException
6362
}
6463

6564

66-
public X509Certificate parseX509(String base64EncodedCert) throws CertificateException, FileNotFoundException {
65+
public List<X509Certificate> parseX509(String base64EncodedCertOrFilePath) throws CertificateException, FileNotFoundException {
6766

68-
File file = new File(base64EncodedCert);
67+
File file = new File(base64EncodedCertOrFilePath);
6968
InputStream inputStream = null;
7069
if(file.exists()){
7170
inputStream = new FileInputStream(file);
7271
}else {
73-
inputStream = new ByteArrayInputStream(base64EncodedCert.getBytes());
72+
inputStream = new ByteArrayInputStream(base64EncodedCertOrFilePath.getBytes());
7473
}
7574

7675
CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
77-
return (X509Certificate) certificateFactory.generateCertificate(inputStream);
76+
Collection<? extends Certificate> parsedCertificates = certificateFactory.generateCertificates(inputStream);
77+
List<X509Certificate> certificates = new ArrayList<>();
78+
79+
for (Certificate certificate: parsedCertificates) {
80+
certificates.add ((X509Certificate)certificate);
81+
}
82+
return certificates;
83+
// return (X509Certificate) certificateFactory.generateCertificate(inputStream);
7884
}
7985

8086
}

0 commit comments

Comments
 (0)