Skip to content

Commit 85b0eb6

Browse files
olszomalmtrojnar
authored andcommitted
improve maketest
1 parent 858e903 commit 85b0eb6

File tree

4 files changed

+184
-21
lines changed

4 files changed

+184
-21
lines changed

tests/certs/makecerts.sh

Lines changed: 55 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ make_certs() {
2020
mkdir "tmp/"
2121

2222
# OpenSSL settings
23-
CONF="${script_path}/openssltest.cnf"
23+
CONF="${script_path}/openssl_intermediate.cnf"
2424
TEMP_LD_LIBRARY_PATH=$LD_LIBRARY_PATH
2525
if test -n "$1"
2626
then
@@ -44,12 +44,33 @@ make_certs() {
4444
TZ=GMT faketime -f '@2017-01-01 00:00:00' /bin/bash -c '
4545
script_path=$(pwd)
4646
OPENSSL=openssl
47-
CONF="${script_path}/openssltest.cnf"
47+
CONF="${script_path}/openssl_root.cnf"
4848
$OPENSSL req -config $CONF -new -x509 -days 3600 -key demoCA/CA.key -out tmp/CACert.pem \
49-
-subj "/C=PL/O=osslsigncode/OU=Root CA/CN=CA/[email protected]" \
49+
-subj "/C=PL/O=osslsigncode/OU=Certification Authority/CN=Root CA" \
5050
2>> "makecerts.log" 1>&2'
5151
test_result $?
5252

53+
printf "\nGenerate intermediate CA certificate\n" >> "makecerts.log"
54+
$OPENSSL genrsa -out demoCA/intermediate.key \
55+
2>> "makecerts.log" 1>&2
56+
TZ=GMT faketime -f '@2017-01-01 00:00:00' /bin/bash -c '
57+
script_path=$(pwd)
58+
OPENSSL=openssl
59+
CONF="${script_path}/openssl_intermediate.cnf"
60+
$OPENSSL req -config $CONF -new -key demoCA/intermediate.key -out demoCA/intermediate.csr \
61+
-subj "/C=PL/O=osslsigncode/OU=Certification Authority/CN=Intermediate CA" \
62+
2>> "makecerts.log" 1>&2'
63+
test_result $?
64+
TZ=GMT faketime -f '@2017-01-01 00:00:00' /bin/bash -c '
65+
script_path=$(pwd)
66+
OPENSSL=openssl
67+
CONF="${script_path}/openssl_root.cnf"
68+
$OPENSSL ca -config $CONF -batch -in demoCA/intermediate.csr -out demoCA/intermediate.cer \
69+
2>> "makecerts.log" 1>&2'
70+
test_result $?
71+
$OPENSSL x509 -in demoCA/intermediate.cer -out tmp/intermediate.pem \
72+
2>> "makecerts.log" 1>&2
73+
5374
printf "\nGenerate private RSA encrypted key\n" >> "makecerts.log"
5475
$OPENSSL genrsa -des3 -out demoCA/private.key -passout pass:$password \
5576
2>> "makecerts.log" 1>&2
@@ -63,40 +84,48 @@ make_certs() {
6384

6485
printf "\nGenerate a certificate to revoke\n" >> "makecerts.log"
6586
$OPENSSL req -config $CONF -new -key demoCA/private.key -passin pass:$password -out demoCA/revoked.csr \
66-
-subj "/C=PL/O=osslsigncode/OU=CA/CN=revoked/emailAddress=revoked@example.com" \
87+
-subj "/C=PL/O=osslsigncode/OU=CSP/CN=Revoked/emailAddress=osslsigncode@example.com" \
6788
2>> "makecerts.log" 1>&2
6889
$OPENSSL ca -config $CONF -batch -in demoCA/revoked.csr -out demoCA/revoked.cer \
6990
2>> "makecerts.log" 1>&2
7091
$OPENSSL x509 -in demoCA/revoked.cer -out tmp/revoked.pem \
7192
2>> "makecerts.log" 1>&2
7293

7394
printf "\nRevoke above certificate\n" >> "makecerts.log"
74-
$OPENSSL ca -config $CONF -revoke demoCA/1000.pem \
95+
$OPENSSL ca -config $CONF -revoke demoCA/1001.pem \
7596
2>> "makecerts.log" 1>&2
7697

98+
printf "\nAttach intermediate certificate to revoked certificate\n" >> "makecerts.log"
99+
cat tmp/intermediate.pem >> tmp/revoked.pem
100+
77101
printf "\nGenerate CRL file\n" >> "makecerts.log"
78102
TZ=GMT faketime -f '@2019-01-01 00:00:00' /bin/bash -c '
79103
script_path=$(pwd)
80104
OPENSSL=openssl
81-
CONF="${script_path}/openssltest.cnf"
105+
CONF="${script_path}/openssl_intermediate.cnf"
82106
$OPENSSL ca -config $CONF -gencrl -crldays 8766 -out tmp/CACertCRL.pem \
83107
2>> "makecerts.log" 1>&2'
84108

109+
printf "\nConvert revoked certificate to SPC format\n" >> "makecerts.log"
110+
$OPENSSL crl2pkcs7 -in tmp/CACertCRL.pem -certfile tmp/revoked.pem -outform DER -out tmp/revoked.spc \
111+
2>> "makecerts.log" 1>&2
112+
test_result $?
113+
85114
printf "\nGenerate CSP Cross-Certificate\n" >> "makecerts.log"
86115
$OPENSSL genrsa -out demoCA/cross.key \
87116
2>> "makecerts.log" 1>&2
88117
TZ=GMT faketime -f '@2018-01-01 00:00:00' /bin/bash -c '
89118
script_path=$(pwd)
90119
OPENSSL=openssl
91-
CONF="${script_path}/openssltest.cnf"
92-
$OPENSSL req -config $CONF -new -x509 -days 900 -key demoCA/cross.key -out tmp/crosscert.pem \
93-
-subj "/C=PL/O=osslsigncode/OU=CSP/CN=crosscert/emailAddress=CA@example.com" \
120+
CONF="${script_path}/openssl_intermediate.cnf"
121+
$OPENSSL req -config $CONF -new -x509 -days 900 -key demoCA/cross.key -out tmp/crosscert.pem \
122+
-subj "/C=PL/O=osslsigncode/OU=CSP/CN=crosscert/emailAddress=osslsigncode@example.com" \
94123
2>> "makecerts.log" 1>&2'
95124
test_result $?
96125

97126
printf "\nGenerate code signing certificate\n" >> "makecerts.log"
98127
$OPENSSL req -config $CONF -new -key demoCA/private.key -passin pass:$password -out demoCA/cert.csr \
99-
-subj "/C=PL/ST=Mazovia Province/L=Warsaw/O=osslsigncode/OU=CA/CN=localhost/[email protected]" \
128+
-subj "/C=PL/ST=Mazovia Province/L=Warsaw/O=osslsigncode/OU=CSP/CN=Certificate/[email protected]" \
100129
2>> "makecerts.log" 1>&2
101130
test_result $?
102131
$OPENSSL ca -config $CONF -batch -in demoCA/cert.csr -out demoCA/cert.cer \
@@ -111,11 +140,19 @@ make_certs() {
111140
2>> "makecerts.log" 1>&2
112141
test_result $?
113142

143+
printf "\nConvert the key to PVK format\n" >> "makecerts.log"
144+
$OPENSSL rsa -in tmp/key.pem -outform PVK -out tmp/key.pvk -pvk-none \
145+
2>> "makecerts.log" 1>&2
146+
test_result $?
147+
114148
printf "\nConvert the certificate to DER format\n" >> "makecerts.log"
115149
$OPENSSL x509 -in tmp/cert.pem -outform DER -out tmp/cert.der \
116150
2>> "makecerts.log" 1>&2
117151
test_result $?
118152

153+
printf "\nAttach intermediate certificate to code signing certificate\n" >> "makecerts.log"
154+
cat tmp/intermediate.pem >> tmp/cert.pem
155+
119156
printf "\nConvert the certificate to SPC format\n" >> "makecerts.log"
120157
$OPENSSL crl2pkcs7 -nocrl -certfile tmp/cert.pem -outform DER -out tmp/cert.spc \
121158
2>> "makecerts.log" 1>&2
@@ -128,7 +165,7 @@ make_certs() {
128165

129166
printf "\nGenerate expired certificate\n" >> "makecerts.log"
130167
$OPENSSL req -config $CONF -new -key demoCA/private.key -passin pass:$password -out demoCA/expired.csr \
131-
-subj "/C=PL/ST=Mazovia Province/L=Warsaw/O=osslsigncode/OU=CA/CN=expired/emailAddress=expired@example.com" \
168+
-subj "/C=PL/ST=Mazovia Province/L=Warsaw/O=osslsigncode/OU=CSP/CN=Expired/emailAddress=osslsigncode@example.com" \
132169
2>> "makecerts.log" 1>&2
133170
test_result $?
134171
$OPENSSL ca -config $CONF -enddate "190101000000Z" -batch -in demoCA/expired.csr -out demoCA/expired.cer \
@@ -138,10 +175,14 @@ make_certs() {
138175
2>> "makecerts.log" 1>&2
139176
test_result $?
140177

178+
printf "\nAttach intermediate certificate to expired certificate\n" >> "makecerts.log"
179+
cat tmp/intermediate.pem >> tmp/expired.pem
180+
141181
# copy new files
142-
if test -s tmp/CACert.pem -a -s tmp/crosscert.pem -a -s tmp/expired.pem -a -s tmp/cert.pem \
143-
-a -s tmp/CACertCRL.pem -a -s tmp/revoked.pem -a -s tmp/key.pem -a -s tmp/keyp.pem \
144-
-a -s tmp/key.der -a -s tmp/cert.der -a -s tmp/cert.spc -a -s tmp/cert.p12
182+
if test -s tmp/intermediate.pem -a -s tmp/CACert.pem -a -s tmp/CACertCRL.pem \
183+
-a -s tmp/key.pem -a -s tmp/keyp.pem -a -s tmp/key.der -a -s tmp/key.pvk \
184+
-a -s tmp/cert.pem -a -s tmp/cert.p12 -a -s tmp/cert.der -a -s tmp/cert.spc \
185+
-a -s tmp/crosscert.pem -a -s tmp/expired.pem -a -s tmp/revoked.pem -a -s tmp/revoked.spc
145186
then
146187
cp tmp/* ./
147188
printf "%s\n" "keys & certificates successfully generated"
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# OpenSSL intermediate CA configuration file
2+
3+
[ ca ]
4+
default_ca = CA_default
5+
6+
[ CA_default ]
7+
# Directory and file locations
8+
dir = .
9+
certs = $dir/demoCA
10+
crl_dir = $dir/demoCA
11+
new_certs_dir = $dir/demoCA
12+
database = $dir/demoCA/index.txt
13+
serial = $dir/demoCA/serial
14+
private_key = $dir/demoCA/intermediate.key
15+
certificate = $dir/tmp/intermediate.pem
16+
crl_extensions = crl_ext
17+
default_md = sha256
18+
preserve = no
19+
policy = policy_loose
20+
default_startdate = 180101000000Z
21+
default_enddate = 210101000000Z
22+
23+
[ req ]
24+
# Options for the `req` tool
25+
encrypt_key = no
26+
default_bits = 2048
27+
default_md = sha256
28+
string_mask = utf8only
29+
distinguished_name = req_distinguished_name
30+
x509_extensions = usr_extensions
31+
32+
[ crl_ext ]
33+
# Extension for CRLs
34+
authorityKeyIdentifier = keyid:always
35+
36+
[ usr_extensions ]
37+
# Extension to add when the -x509 option is used
38+
basicConstraints = CA:FALSE
39+
subjectKeyIdentifier = hash
40+
authorityKeyIdentifier = keyid, issuer
41+
extendedKeyUsage = codeSigning
42+
43+
[ policy_loose ]
44+
# Allow the intermediate CA to sign a more diverse range of certificates.
45+
# See the POLICY FORMAT section of the `ca` man page.
46+
countryName = optional
47+
stateOrProvinceName = optional
48+
localityName = optional
49+
organizationName = optional
50+
organizationalUnitName = optional
51+
commonName = supplied
52+
emailAddress = optional
53+
54+
[ req_distinguished_name ]
55+
countryName = Country Name (2 letter code)
56+
stateOrProvinceName = State or Province Name
57+
localityName = Locality Name
58+
0.organizationName = Organization Name
59+
organizationalUnitName = Organizational Unit Name
60+
commonName = Common Name
61+
emailAddress = Email Address

tests/certs/openssl_root.cnf

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# OpenSSL root CA configuration file
2+
3+
[ ca ]
4+
default_ca = CA_default
5+
6+
[ CA_default ]
7+
# Directory and file locations.
8+
dir = .
9+
certs = $dir/demoCA
10+
crl_dir = $dir/demoCA
11+
new_certs_dir = $dir/demoCA
12+
database = $dir/demoCA/index.txt
13+
serial = $dir/demoCA/serial
14+
private_key = $dir/demoCA/CA.key
15+
certificate = $dir/tmp/CACert.pem
16+
crl_extensions = crl_ext
17+
default_md = sha256
18+
preserve = no
19+
policy = policy_match
20+
default_startdate = 180101000000Z
21+
default_enddate = 260101000000Z
22+
x509_extensions = v3_intermediate_ca
23+
24+
[ req ]
25+
# Options for the `req` tool
26+
encrypt_key = no
27+
default_bits = 2048
28+
default_md = sha256
29+
string_mask = utf8only
30+
x509_extensions = ca_extensions
31+
distinguished_name = req_distinguished_name
32+
33+
[ ca_extensions ]
34+
# Extension to add when the -x509 option is used
35+
basicConstraints = critical, CA:true
36+
subjectKeyIdentifier = hash
37+
authorityKeyIdentifier = keyid:always,issuer
38+
keyUsage = critical, digitalSignature, cRLSign, keyCertSign
39+
40+
[ v3_intermediate_ca ]
41+
# Extensions for a typical intermediate CA (`man x509v3_config`)
42+
basicConstraints = critical, CA:true, pathlen:0
43+
subjectKeyIdentifier = hash
44+
authorityKeyIdentifier = keyid:always,issuer
45+
keyUsage = critical, digitalSignature, cRLSign, keyCertSign
46+
47+
[ policy_match ]
48+
countryName = match
49+
organizationName = match
50+
organizationalUnitName = optional
51+
commonName = supplied
52+
emailAddress = optional
53+
54+
[ req_distinguished_name ]
55+
countryName = Country Name (2 letter code)
56+
stateOrProvinceName = State or Province Name
57+
localityName = Locality Name
58+
0.organizationName = Organization Name
59+
organizationalUnitName = Organizational Unit Name
60+
commonName = Common Name
61+
emailAddress = Email Address
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
#!/bin/sh
22
# Sign a PE/CAB/MSI file with the certificate file in the SPC format
3-
# and the private key file in the PEM format.
3+
# and the private key file in the Microsoft Private Key (PVK) format.
44

55
. $(dirname $0)/../test_library
66
script_path=$(pwd)
77

88
# PE file
9-
test_name="041. Sign a PE file a SPC certificate file"
9+
test_name="041. Sign a PE file a SPC certificate file and a PVK private key file"
1010
printf "\n%s\n" "$test_name"
1111
if test -s "test.exe"
1212
then
1313
../../osslsigncode sign -h sha256 \
1414
-st "1556668800" \
15-
-certs "${script_path}/../certs/cert.spc" -key "${script_path}/../certs/keyp.pem" \
15+
-spc "${script_path}/../certs/cert.spc" -key "${script_path}/../certs/key.pvk" \
1616
-pass passme \
1717
-in "test.exe" -out "test_041.exe"
1818
verify_signature "$?" "041" "exe" "success" "@2019-09-01 12:00:00" \
@@ -23,13 +23,13 @@ if test -s "test.exe"
2323
fi
2424

2525
# CAB file
26-
test_name="042. Sign a CAB file a SPC certificate file"
26+
test_name="042. Sign a CAB file a SPC certificate file and a PVK private key file"
2727
printf "\n%s\n" "$test_name"
2828
if test -s "test.ex_"
2929
then
3030
../../osslsigncode sign -h sha256 \
3131
-st "1556668800" \
32-
-certs "${script_path}/../certs/cert.spc" -key "${script_path}/../certs/keyp.pem" \
32+
-spc "${script_path}/../certs/cert.spc" -key "${script_path}/../certs/key.pvk" \
3333
-pass passme \
3434
-in "test.ex_" -out "test_042.ex_"
3535
verify_signature "$?" "042" "ex_" "success" "@2019-09-01 12:00:00" \
@@ -40,13 +40,13 @@ if test -s "test.ex_"
4040
fi
4141

4242
# MSI file
43-
test_name="043. Sign a MSI file a SPC certificate file"
43+
test_name="043. Sign a MSI file a SPC certificate file and a PVK private key file"
4444
printf "\n%s\n" "$test_name"
4545
if test -s "sample.msi"
4646
then
4747
../../osslsigncode sign -h sha256 \
4848
-st "1556668800" \
49-
-certs "${script_path}/../certs/cert.spc" -key "${script_path}/../certs/keyp.pem" \
49+
-spc "${script_path}/../certs/cert.spc" -key "${script_path}/../certs/key.pvk" \
5050
-pass passme \
5151
-in "sample.msi" -out "test_043.msi"
5252
verify_signature "$?" "043" "msi" "success" "@2019-09-01 12:00:00" \

0 commit comments

Comments
 (0)