6
6
import subprocess
7
7
import datetime
8
8
9
- from asn1crypto .x509 import Certificate
9
+ from asn1crypto import pem
10
+ from asn1crypto .x509 import Certificate , TbsCertificate , Time , Name
11
+ from asn1crypto .keys import RSAPublicKey
12
+ from asn1crypto .csr import CertificationRequest , CertificationRequestInfo
10
13
11
14
import pkcs11
12
15
from pkcs11 .util .rsa import encode_rsa_public_key
29
32
# -out cert.pem \
30
33
# -days 365 \
31
34
# -nodes
32
- CERT = base64 .b64decode ("""
35
+ _ , _ , CERT = pem .unarmor (b"""
36
+ -----BEGIN CERTIFICATE-----
33
37
MIICKzCCAdWgAwIBAgIJAK3BO9rnLZd9MA0GCSqGSIb3DQEBBQUAMEUxCzAJBgNV
34
38
BAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBX
35
39
aWRnaXRzIFB0eSBMdGQwHhcNMTcwNjAyMDI0ODMyWhcNMTgwNjAyMDI0ODMyWjBF
42
46
cm5ldCBXaWRnaXRzIFB0eSBMdGSCCQCtwTva5y2XfTAMBgNVHRMEBTADAQH/MA0G
43
47
CSqGSIb3DQEBBQUAA0EAOdvMKLrIFOYF3aVLGharY196heO0fndm39sZAXJ4PItx
44
48
n28DytHEdAoltksfJ2Ds3XAjQqcpI5eBbhIoN9Ckxg==
49
+ -----END CERTIFICATE-----
45
50
""" )
46
51
47
52
@@ -163,9 +168,6 @@ def test_self_sign_certificate(self):
163
168
# Warning: proof of concept code only!
164
169
pub , priv = self .session .generate_keypair (KeyType .RSA , 1024 )
165
170
166
- from asn1crypto .x509 import TbsCertificate , Time , Name
167
- from asn1crypto .keys import RSAPublicKey
168
-
169
171
tbs = TbsCertificate ({
170
172
'version' : 'v1' ,
171
173
'serial_number' : 1 ,
@@ -214,9 +216,7 @@ def test_self_sign_certificate(self):
214
216
stdin = subprocess .PIPE ,
215
217
stdout = subprocess .DEVNULL ) as proc :
216
218
217
- proc .stdin .write (b'-----BEGIN CERTIFICATE-----\n ' )
218
- proc .stdin .write (base64 .encodebytes (cert .dump ()))
219
- proc .stdin .write (b'-----END CERTIFICATE-----\n ' )
219
+ proc .stdin .write (pem .armor ('CERTIFICATE' , cert .dump ()))
220
220
proc .stdin .close ()
221
221
222
222
self .assertEqual (proc .wait (), 0 )
@@ -226,11 +226,6 @@ def test_sign_csr(self):
226
226
# Warning: proof of concept code only!
227
227
pub , priv = self .session .generate_keypair (KeyType .RSA , 1024 )
228
228
229
- from asn1crypto .csr import (CertificationRequest ,
230
- CertificationRequestInfo )
231
- from asn1crypto .x509 import Name
232
- from asn1crypto .keys import RSAPublicKey
233
-
234
229
info = CertificationRequestInfo ({
235
230
'version' : 0 ,
236
231
'subject' : Name .build ({
0 commit comments