Debian Codegraph @

tests/auto/network/ssl/qsslcertificate/certificates/gencertificates.sh

raw
1 #!/bin/sh
2 #############################################################################
3 ##
4 ## Copyright (C) 2016 The Qt Company Ltd.
5 ## Contact: https://www.qt.io/licensing/
6 ##
7 ## This file is the build configuration utility of the Qt Toolkit.
8 ##
9 ## $QT_BEGIN_LICENSE:GPL-EXCEPT$
10 ## Commercial License Usage
11 ## Licensees holding valid commercial Qt licenses may use this file in
12 ## accordance with the commercial license agreement provided with the
13 ## Software or, alternatively, in accordance with the terms contained in
14 ## a written agreement between you and The Qt Company. For licensing terms
15 ## and conditions see https://www.qt.io/terms-conditions. For further
16 ## information use the contact form at https://www.qt.io/contact-us.
17 ##
18 ## GNU General Public License Usage
19 ## Alternatively, this file may be used under the terms of the GNU
20 ## General Public License version 3 as published by the Free Software
21 ## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
22 ## included in the packaging of this file. Please review the following
23 ## information to ensure the GNU General Public License requirements will
24 ## be met: https://www.gnu.org/licenses/gpl-3.0.html.
25 ##
26 ## $QT_END_LICENSE$
27 ##
28 #############################################################################
29
30 # This script generates digital certificates of different types.
31
32 #--- RSA Certificates -----------------------------------------------------------------------
33
34 echo -e "\ngenerating 1024-bit RSA private key to PEM file ..."
35 openssl genrsa -out rsa-pri-1024.pem 1024
36
37 echo -e "\ngenerating the corresponding public key to PEM and DER file ..."
38 openssl rsa -in rsa-pri-1024.pem -pubout -out rsa-pub-1024.pem
39 openssl rsa -in rsa-pri-1024.pem -pubout -out rsa-pub-1024.der -outform der
40
41 echo -e "\ngenerating certificate signing request (CSR) ..."
42 openssl req -out req.pem -new -key rsa-pri-1024.pem -subj "/CN=name\/with\/slashes/C=NO"
43
44 echo -e "\n generating a self-signed certifificate to PEM file ..."
45 openssl x509 -req -in req.pem -out cert-ss.pem -signkey rsa-pri-1024.pem
46
47 echo -e "\n generating a self-signed certifificate to DER file ..."
48 openssl x509 -req -in req.pem -out cert-ss.der -signkey rsa-pri-1024.pem -outform der
49
50 echo -e "\n generating a certifificate signed by a dummy CA to PEM file ..."
51 openssl x509 -req -in req.pem -out cert.pem -CA ca-cert.pem -set_serial 17
52
53 echo -e "\n generating a certifificate signed by a dummy CA to DER file ..."
54 openssl x509 -req -in req.pem -out cert.der -CA ca-cert.pem -set_serial 17 -outform der
55
56 #--- DSA Certificates -----------------------------------------------------------------------
57 echo -e "\ngenerating DSA parameters to PEM file ..."
58 openssl dsaparam -out dsapar-1024.pem 1024
59
60 echo -e "\ngenerating DSA private key to PEM file ..."
61 openssl gendsa dsapar-1024.pem -out dsa-pri-1024.pem
62 /bin/rm dsapar-1024.pem
63
64 echo -e "\ngenerating DSA public key to PEM and DER file ..."
65 openssl dsa -in dsa-pri-1024.pem -pubout -out dsa-pub-1024.pem
66 openssl dsa -in dsa-pri-1024.pem -pubout -out dsa-pub-1024.der -outform der
67
68 echo -e "\ngenerating certificate signing request (CSR) ..."
69 openssl req -out req.pem -new -key dsa-pri-1024.pem -subj "/CN=name\/with\/slashes/C=NO"
70
71 echo -e "\n generating a self-signed certifificate to PEM file ..."
72 openssl x509 -req -in req.pem -out dsa-cert-ss.pem -signkey dsa-pri-1024.pem
73
74 #--- EC Certificates ------------------------------------------------------------------------
75 echo -e "\ngenerating EC private key to PEM file ..."
76 openssl ecparam -name secp384r1 -genkey -noout -out ec-pri-384.pem
77
78 echo -e "\ngenerating EC public key to PEM and DER file ..."
79 openssl ec -in ec-pri-384.pem -pubout -out ec-pub-384.pem
80 openssl ec -in ec-pri-384.pem -pubout -out ec-pub-384.der -outform DER
81
82 echo -e "\ngenerating certificate signing request (CSR) ..."
83 openssl req -out req.pem -new -key ec-pri-384.pem -subj "/CN=name\/with\/slashes/C=NO"
84
85 echo -e "\n generating a self-signed certifificate to PEM file ..."
86 openssl x509 -req -in req.pem -out ec-cert-ss.pem -signkey ec-pri-384.pem
87
88 #--- Public keys --------------------------------------------------------------------------------
89 echo -e "\n associate public keys with all certificates ..."
90 # Note: For now, there is only one public key (encoded in both PEM and DER), but that could change.
91 /bin/cp rsa-pub-1024.pem cert-ss.pem.pubkey
92 /bin/cp rsa-pub-1024.der cert-ss.der.pubkey
93 /bin/cp rsa-pub-1024.pem cert.pem.pubkey
94 /bin/cp rsa-pub-1024.der cert.der.pubkey
95 /bin/cp dsa-pub-1024.pem dsa-cert-ss.pem.pubkey
96 /bin/cp dsa-pub-1024.der dsa-cert-ss.der.pubkey
97 /bin/cp ec-pub-384.pem ec-cert-ss.pem.pubkey
98 /bin/cp ec-pub-384.der ec-cert-ss.der.pubkey
99
100 #--- Digests --------------------------------------------------------------------------------
101 echo -e "\n generating md5 and sha1 digests of all certificates ..."
102 for digest in md5 sha1
103 do
104 openssl x509 -in ca-cert.pem -noout -fingerprint -$digest > ca-cert.pem.digest-$digest
105 openssl x509 -in cert-ss.pem -noout -fingerprint -$digest > cert-ss.pem.digest-$digest
106 openssl x509 -in cert.pem -noout -fingerprint -$digest > cert.pem.digest-$digest
107 openssl x509 -in dsa-cert-ss.pem -noout -fingerprint -$digest > dsa-cert-ss.pem.digest-$digest
108 openssl x509 -in ec-cert-ss.pem -noout -fingerprint -$digest > ec-cert-ss.pem.digest-$digest
109 done
110
111 #--- Subjet Alternative Name extension ----------------------------------------------------
112 echo -e "\n generating self signed root cert. with Subject Alternative Name extension (X509v3) ..."
113 outname=cert-ss-san.pem
114 openssl req -out req-san.pem -new -key rsa-pri-1024.pem -subj "/CN=Johnny GuitarC=NO"
115 openssl req -x509 -in req-san.pem -out $outname -key rsa-pri-1024.pem \
116 -config san.cnf -extensions subj_alt_name
117 /bin/cp san.cnf $outname.san
118
119 #--- Non-ASCII Subject ---------------------------------------------------------------------
120 echo -e "\n generating self signed root cert. with Subject containing UTF-8 characters ..."
121 outname=cert-ss-san-utf8.pem
122 #subject="/O=HĕĂƲÿ ʍếʈặḻ Récördŝ/OU=㈧A㉁ォBC/CN=Johnny Guitar/C=NO"
123 subject=$'/O=H\xc4\x95\xc4\x82\xc6\xb2\xc3\xbf \xca\x8d\xe1\xba\xbf\xca\x88\xe1\xba\xb7\xe1\xb8\xbb R\xc3\xa9c\xc3\xb6rd\xc5\x9d/OU=\xe3\x88\xa7A\xe3\x89\x81\xef\xbd\xabBC/CN=Johnny Guitar/C=NO'
124 openssl req -out req-san.pem -new -key rsa-pri-1024.pem -utf8 -subj "$subject"
125 openssl req -x509 -in req-san.pem -out $outname -key rsa-pri-1024.pem \
126 -config san.cnf -extensions subj_alt_name -nameopt multiline,utf8,-esc_msb
127 /bin/cp san.cnf $outname.san
128
129 echo -e "\n cleaning up ..."
130 /bin/rm rsa-pri-1024.pem rsa-pub-1024.*
131 /bin/rm dsa-pri-1024.pem dsa-pub-1024.*
132 /bin/rm ec-pri-384.pem ec-pub-384.*
133 /bin/rm req*.pem