blob: 0973defb26efdac2ea2937aba883eee50d70c12e [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001
2***** Create a self signed cert ************
3
41) openssl genrsa 1024 > client-key.pem
5
62) openssl req -new -x509 -nodes -sha1 -days 1000 -key client-key.pem > client-cert.pem
7
83) note md5 would be -md5
9
10-- adding metadata to beginning
11
123) openssl x509 -in client-cert.pem -text > tmp.pem
13
144) mv tmp.pem client-cert.pem
15
16
17***** Create a CA, signing authority **********
18
19same as self signed, use ca prefix instead of client
20
21
22***** Create a cert signed by CA **************
23
241) openssl req -newkey rsa:1024 -sha1 -days 1000 -nodes -keyout server-key.pem > server-req.pem
25
26* note if using existing key do: -new -key keyName
27
282) copy ca-key.pem ca-cert.srl (why ????)
29
303) openssl x509 -req -in server-req.pem -days 1000 -sha1 -CA ca-cert.pem -CAkey ca-key.pem -set_serial 01 > server-cert.pem
31
32
33***** Adding Subject Key ID and Authentication Key ID extensions to a cert *****
34
35Create a config file for OpenSSL with the example contents:
36
37 [skidakid]
38 subjectKeyIdentifier=hash
39 authorityKeyIdentifier=keyid
40
41Add to the openssl command for creating a cert signed by a CA step 3 the
42following options:
43
44 -extfile <file.cnf> -extensions skidakid
45
46anywhere before the redirect. This will add the cert's public key hash as the
47Subject Key Identifier, and the signer's SKID as the Authentication Key ID.
48
49
50***** To create a dsa cert ********************
51
521) openssl dsaparam 512 > dsa512.param # creates group params
53
542) openssl gendsa dsa512.param > dsa512.pem # creates private key
55
563) openssl req -new -x509 -nodes -days 1000 -key dsa512.pem > dsa-cert.pem
57
58
59
60
61***** To convert from PEM to DER **************
62
63a) openssl x509 -in cert.pem -inform PEM -out cert.der -outform DER
64
65to convert rsa private PEM to DER :
66
67b) openssl rsa -in key.pem -outform DER -out key.der
68
69
70**** To encrypt rsa key already in pem **********
71
72a) openssl rsa <server-key.pem.bak -des >server-keyEnc.pem
73
74note location of des, pass = yassl123
75
76
77*** To make a public key from a private key ******
78
79
80openssl rsa -in 1024rsa.priv -pubout -out 1024rsa.pub
81
82
83**** To convert to pkcs8 *******
84
85openssl pkcs8 -nocrypt -topk8 -in server-key.pem -out server-keyPkcs8.pem
86
87
88**** To convert to pkcs8 encrypted *******
89
90openssl pkcs8 -topk8 -in server-key.pem -out server-keyPkcs8Enc.pem
91
92passwd: yassl123
93
94to use PKCS#5 v2 instead of v1.5 which is default add
95
96-v2 des3 # file Pkcs8Enc2
97
98to use PKCS#12 instead use -v1 witch a 12 algo like
99
100-v1 PBE-SHA1-3DES # file Pkcs8Enc12 , see man pkcs8 for more info
101-v1 PBE-SHA1-RC4-128 # no longer file Pkcs8Enc12, arc4 now off by default
102
103
104**** To convert from pkcs8 to traditional ****
105
106openssl pkcs8 -nocrypt -in server-keyPkcs8.pem -out server-key.pem
107
108
109*** DH parameters ***
110
111openssl dhparam 2048 > dh2048.param
112
113to add metadata
114
115openssl dhparam -in dh2048.param -text > dh2048.pem
116
117**** ECC ******
118
1191) make a key
120
121 to see types available do
122 openssl ecparam -list_curves
123
124 make a new key
125 openssl ecparam -genkey -text -name secp256r1 -out ecc-key.pem
126
127 convert to compressed
128 openssl ec -in ecc-key.pem -conv_form compressed -out ecc-key-comp.pem
129
130*** CRL ***
131
1321) create a crl
133
134a) openssl ca -gencrl -crldays 120 -out crl.pem -keyfile ./ca-key.pem -cert ./ca-cert.pem
135
136Error No ./CA root/index.txt so:
137
138b) touch ./CA root/index.txt
139
140a) again
141
142Error No ./CA root/crlnumber so:
143
144c) touch ./CA root/crlnumber
145
146a) again
147
148Error unable to load CRL number
149
150d) add '01' to crlnumber file
151
152a) again
153
1542) view crl file
155
156openssl crl -in crl.pem -text
157
1583) revoke
159
160openssl ca -revoke server-cert.pem -keyfile ./ca-key.pem -cert ./ca-cert.pem
161
162Then regenerate crl with a)
163
1644) verify
165
166openssl verify -CAfile ./ca-cert.pem ./server-cert.pem
167
168OK
169
170Make file with both ca and crl
171
172cat ca-cert.pem crl.pem > ca-crl.pem
173
174openssl verify -CAfile ./ca-crl.pem -crl_check ./ca-cert.pem
175
176revoked