Skip to content

Commit bdfcfac

Browse files
tgonzalezorlandoarmgowthamsk-arm
authored andcommitted
setup_tls.sh: Generate Client CSR through parsec-tool
Signed-off-by: Tomás González <[email protected]>
1 parent aae33ac commit bdfcfac

File tree

2 files changed

+64
-7
lines changed

2 files changed

+64
-7
lines changed

tests/docker_image/parsec-openssl-provider-test.Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ ENV PATH="/root/.cargo/bin:/opt/rust/bin:${PATH}"
2929
# For running tests Parsec is configured with the socket in /tmp/
3030
ENV PARSEC_SERVICE_ENDPOINT="unix:/tmp/parsec.sock"
3131

32-
RUN git clone https://github.com/parallaxsecond/parsec.git --branch 1.3.0 \
32+
RUN git clone https://github.com/parallaxsecond/parsec.git --branch main \
3333
&& cd parsec \
3434
&& cargo build --features "mbed-crypto-provider,direct-authenticator"
3535

3636
#TODO: This change is temporary and will be removed after a new parsec-tool version is released
3737
RUN git clone https://github.com/parallaxsecond/parsec-tool.git --branch main \
3838
&& cd parsec-tool \
39+
&& cargo install patch-crate \
40+
&& cargo patch-crate \
3941
&& cargo build \
4042
&& cp target/debug/parsec-tool /opt/rust/bin/parsec-tool

tests/setup_tls.sh

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
# Generate the CA key and self signed certificate
11-
# inputs:
11+
# inputs:
1212
# certificate directory
1313
generate_ca_certs() {
1414
CA_DIRECTORY=$1
@@ -36,7 +36,7 @@ generate_ca_certs() {
3636
}
3737

3838
# Generate the server key and certificate signed by CA
39-
# inputs:
39+
# inputs:
4040
# server directory
4141
# certificate directory
4242
generate_server_certs() {
@@ -85,8 +85,7 @@ generate_server_certs() {
8585
fi
8686
}
8787

88-
# ToDo: This function needs to be updated to use the parsec-tool
89-
# for key, CSR generation for hardware backed keys.
88+
# Use the openssl for key, CSR generation for sofware backed keys.
9089
# Generate the client key and certificate signed by CA
9190
# inputs:
9291
# client directory
@@ -107,7 +106,56 @@ generate_client_certs() {
107106

108107
# Generate private key
109108
openssl genrsa -out "${CLIENT_PRIV_KEY}" 2048 > /dev/null 2>&1
109+
if [ $? -ne 0 ]; then
110+
echo "FAILED TO GENERATE KEY"
111+
exit 1
112+
fi
113+
114+
# Generate certificate request via OpenSSL
115+
openssl req -new \
116+
-key "${CLIENT_PRIV_KEY}" \
117+
-out "${CLIENT_CSR}" \
118+
-subj "/C=UK/ST=Parsec /L=Parsec/O=Parsec/CN=parsec_client.com" > /dev/null 2>&1
110119
if [ $? -ne 0 ]; then
120+
echo "FAILED TO GENERATE CERTIFICATE REQUEST"
121+
exit 1
122+
fi
123+
124+
# Generate certificate
125+
openssl x509 -req -days 1000 -in "${CLIENT_CSR}" \
126+
-CA "${CA_CERTIFICATE}" -CAkey "${CA_PRIV_KEY}" \
127+
-CAcreateserial -out "${CLIENT_CERTIFICATE}" > /dev/null 2>&1
128+
129+
echo "SUCCESS"
130+
else
131+
echo "SKIPPED"
132+
fi
133+
}
134+
135+
# use the parsec-tool for key, CSR generation for hardware backed keys.
136+
# Generate the client key and certificate signed by CA
137+
# inputs:
138+
# client directory
139+
# certificate directory
140+
# certificate request name (without extension)
141+
# name of parsec key
142+
generate_client_certs_parsec() {
143+
CLIENT_DIRECTORY=$1
144+
CLIENT_CERTIFICATE=${CLIENT_DIRECTORY}/$3.pem
145+
CLIENT_CSR=${CLIENT_DIRECTORY}/$3.csr
146+
CLIENT_PRIV_KEY=${CLIENT_DIRECTORY}/client_priv_key.pem
147+
148+
CA_DIRECTORY=$2
149+
CA_CERTIFICATE=${CA_DIRECTORY}/ca_cert.pem
150+
CA_PRIV_KEY=${CA_DIRECTORY}/ca_priv_key.pem
151+
152+
if [ ! -f "${CLIENT_CSR}" ]; then
153+
mkdir -p "${CLIENT_DIRECTORY}" > /dev/null 2>&1
154+
chmod 700 "${CLIENT_DIRECTORY}"
155+
156+
# Generate private key
157+
openssl genrsa -out "${CLIENT_PRIV_KEY}" 2048 > /dev/null 2>&1
158+
if [ $? -ne 0 ]; then
111159
echo "FAILED TO GENERATE KEY"
112160
exit 1
113161
fi
@@ -122,10 +170,13 @@ generate_client_certs() {
122170
exit 1
123171
fi
124172

173+
# Generate certificate request via Parsec
174+
parsec-tool create-csr --cn parsec_client.com --l Parsec --c UK --st Parsec --o Parsec --key-name $4 > ${CLIENT_CSR}
175+
125176
# Generate certificate
126177
openssl x509 -req -days 1000 -in "${CLIENT_CSR}" \
127178
-CA "${CA_CERTIFICATE}" -CAkey "${CA_PRIV_KEY}" \
128-
-CAcreateserial -out "${CLIENT_CERTIFICATE}" > /dev/null 2>&1
179+
-CAcreateserial -out "${CLIENT_CERTIFICATE}"
129180
if [ $? -ne 0 ]; then
130181
echo "FAILED"
131182
exit 1
@@ -143,7 +194,11 @@ generate_ca_certs ./tls/ca
143194
echo -n "Generating server private key and certificate: "
144195
generate_server_certs ./tls/server ./tls/ca
145196

146-
echo -n "Generating client private key and certificate: "
197+
echo -n "Generating client certificate: "
198+
generate_client_certs_parsec ./tls/client ./tls/ca parsec_rsa PARSEC_TEST_RSA_KEY
199+
generate_client_certs_parsec ./tls/client ./tls/ca parsec_ecdsa PARSEC_TEST_ECDSA_KEY
200+
201+
echo -n "Generating openssl client private key and certificate: "
147202
generate_client_certs ./tls/client ./tls/ca
148203

149204
echo -n "Generating fake certificate authority private key and certificate: "

0 commit comments

Comments
 (0)