Skip to content

Add mock test cert generation#85

Open
rajeev-0 wants to merge 15 commits intomasterfrom
add_MockTest_cert_generation
Open

Add mock test cert generation#85
rajeev-0 wants to merge 15 commits intomasterfrom
add_MockTest_cert_generation

Conversation

@rajeev-0
Copy link
Collaborator

@rajeev-0 rajeev-0 commented May 6, 2025

Motivation

Script to generate Mock certificates and keys for testing.
Added OpenSSL-3.5 test to CI test.
Added Mock test with PQ algorithm (MLDSA & SLH-DSA) using OpenSSL-3.5.

@rajeev-0 rajeev-0 force-pushed the add_MockTest_cert_generation branch 3 times, most recently from 359b5dc to 57c3c4b Compare May 8, 2025 12:31
@sonarqubecloud
Copy link

sonarqubecloud bot commented May 8, 2025

@rajeev-0 rajeev-0 marked this pull request as ready for review May 8, 2025 12:36
@rajeev-0 rajeev-0 requested a review from DDvO May 8, 2025 12:37
Copy link
Member

@DDvO DDvO left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.
Yet various small improvements.


# This script generates the certificates needed for the CMP server and the signer

if [[ ! -f $mkcert_sh ]]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a concrete use case for setting mkcert_sh externally?
Otherwise I suggest dropping the guard.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to make the script flexible, but here I also don't see the benefit. I will drop the guard.

Comment on lines 11 to 35
# sever certificate algorithms
if [ -z "$server_rootca_keyalg" ]; then
server_rootca_keyalg="MLDSA65"
fi
if [ -z "$server_leaf_keyalg" ]; then
server_leaf_keyalg="SLH-DSA-SHAKE-192s"
fi
# rootCACert update test case
if [ -z "$new_rootca_keyalg" ]; then
new_rootca_keyalg="SLH-DSA-SHAKE-192s"
fi

# End-entity certificate algorithms
if [ -z "$signer_rootca_keyalg" ]; then
signer_rootca_keyalg="MLDSA65"
fi
if [ -z "$signer_interca_keyalg" ]; then
signer_interca_keyalg="MLDSA65"
fi
if [ -z "$signer_subinterca_keyalg" ]; then
signer_subinterca_keyalg="MLDSA65"
fi
if [ -z "$signer_leaf_keyalg" ]; then
signer_leaf_keyalg="SLH-DSA-SHAKE-192s"
fi
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please introduce and use a couple of script parameters, such that the script can be called

  • for updating the hitherto test credentials with the same classical algorithms as before (RSA)
  • for the given PQ tests with MLDSA65 and SLH-DSA-SHAKE-192s
  • for further ones, like KEM

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added only one variable "Algo_used".


remove_serverfiles() {
echo "Removing server files"
rm -f server.key server-crt trusted.crt server_root.crt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo in a file name, and better use same order as above:

Suggested change
rm -f server.key server-crt trusted.crt server_root.crt
rm -f server_root.crt trusted.crt server.key server.crt


gen_servercert() {
remove_serverfiles
sleep 5
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why sleep? Please comment or remove.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment added

fi

gen_demoCAfolder
openssl ca -gencrl -keyfile signer_subinterCA-key.pem -cert signer_subinterCA-cert.pem -out signer_subinterCA-crl.pem -crldays 36525 \
Copy link
Member

@DDvO DDvO May 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use $DAYS after adding early in the script:

if [ -z "$DAYS" ]; then
    DAYS=36524 # 100 years, with 24 leap years per 100 years until 2400
fi

BTW, the 36525 in mkcert.sh typically means 1 day more than 100 years
because a leap year occurs every 4 years, but not every 100 years, but still every 400 years (i.e., in 2000, in 2400, ...)

"database = ./demoCA/index.txt" "crlnumber = ./demoCA/crlnumber" "default_md = default")
cat signer_leaf-cert.pem signer_subinterCA-cert.pem signer_interCA-cert.pem > signer_chain.pem
cat signer_subinterCA-cert.pem signer_interCA-cert.pem signer_root-cert.pem > signer_fullchain.pem
openssl pkcs12 -export -out signer.p12 -inkey signer_leaf-key.pem -in signer_leaf-cert.pem -certfile signer_fullchain.pem -password pass:12345
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
openssl pkcs12 -export -out signer.p12 -inkey signer_leaf-key.pem -in signer_leaf-cert.pem -certfile signer_fullchain.pem -password pass:12345
openssl pkcs12 -export -out signer.p12 -inkey signer_leaf-key.pem -in signer_leaf-cert.pem -certfile signer_fullchain.pem -password file:12345.txt

Comment on lines 100 to 101
openssl pkey -in new.key -out new_pass_12345.key -aes256 -passout pass:12345
echo "12345" > 12345.txt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
openssl pkey -in new.key -out new_pass_12345.key -aes256 -passout pass:12345
echo "12345" > 12345.txt
openssl pkey -in new.key -out new_pass_12345.key -aes256 -passout file:12345.txt

new_rootca_keyalg="SLH-DSA-SHAKE-192s"
fi

# End-entity certificate algorithms
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# End-entity certificate algorithms
# algorithms for client certificate chain

Comment on lines 155 to 156
gen_servercert
gen_signercert
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
gen_servercert
gen_signercert
gen_server_chain
gen_client_chain

@@ -0,0 +1,417 @@
#! /bin/bash
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please mark in the file the part(s) adapted, or was an unchanged copy sufficient?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comment in line 59, to enable PQ algorithms.

openssl pkey -in new.key -out new_pass_12345.key -aes256 -passout pass:12345
echo "12345" > 12345.txt
cp new.key signer.key
mv signer_leaf-cert.pem signer_only.crt
Copy link
Member

@DDvO DDvO May 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a further signer cert with NULL-DN subject and without a subjectKeyIdentifier,
which will be needed in a new test case on senderKID.
If there is no simple way of using for this case mkcert_sh genee, you can also use:

openssl x509 -new -subj "/" -days $DAYS -extfile <(printf "subjectKeyIdentifier=none") -out signer_no_SKID.crt -key signer.key

@DDvO
Copy link
Member

DDvO commented Sep 22, 2025

Please also add a run of make -f Makefile_v1 test_Mock when build with OpenSSL 3.5 (where all test cases are enabled since all new CMP features are present).

@rajeev-0 rajeev-0 force-pushed the add_MockTest_cert_generation branch from 57c3c4b to ba840da Compare October 8, 2025 12:36
@sonarqubecloud
Copy link

sonarqubecloud bot commented Oct 8, 2025

 setup-Mock.sh: add files for rootCaCert test

setup-mock.sh: option to set variables from cli
@rajeev-0 rajeev-0 force-pushed the add_MockTest_cert_generation branch from ba840da to 963edeb Compare February 2, 2026 14:17
@rajeev-0 rajeev-0 force-pushed the add_MockTest_cert_generation branch from c50937a to e206092 Compare February 3, 2026 14:18
Copy link
Collaborator Author

@rajeev-0 rajeev-0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated as per comment.


# This script generates the certificates needed for the CMP server and the signer

if [[ ! -f $mkcert_sh ]]; then
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to make the script flexible, but here I also don't see the benefit. I will drop the guard.

@@ -0,0 +1,417 @@
#! /bin/bash
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comment in line 59, to enable PQ algorithms.

# CMP server certificate
rename_serverfiles() {
echo "Renaming server files"
rm server_root-key.pem server_root-pubkey.pem newWithNew-key.pem newWithNew-pubkey.pem
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, wherever possible its better to remove it a central location incase it is needed in future.


gen_servercert() {
remove_serverfiles
sleep 5
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment added

rm -f signer_root-key.pem signer_interCA-key.pem signer_interCA-cert.pem \
signer_subinterCA-key.pem
mv signer_subinterCA-cert.pem issuing.crt
mv signer_subinterCA-crl.pem newcrl.pem
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated it to crl.der

Comment on lines 140 to 163
gen_demoCAfolder
openssl ca -gencrl -keyfile signer_subinterCA-key.pem -cert signer_subinterCA-cert.pem -out signer_subinterCA-crl.pem -crldays 36525 \
-config <(printf "[ca]\ndefault_ca= CA_default\n[CA_default]\n%s\n%s\n%s\n" \
"database = ./demoCA/index.txt" "crlnumber = ./demoCA/crlnumber" "default_md = default")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is part of client credentials and I don't like the idea of creating a function for one line command.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 4, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants