forked from fportantier/vulpy
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathca-csr-create.py
executable file
·39 lines (31 loc) · 1.21 KB
/
ca-csr-create.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python3
import datetime
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.hazmat.primitives import serialization
from cryptography import x509
from cryptography.x509.oid import NameOID
from cryptography.hazmat.primitives import hashes
with open("/tmp/acme.key", "rb") as key_file:
private_key = serialization.load_pem_private_key(
key_file.read(),
password=None,
backend=default_backend()
)
# Generate a CSR
csr = x509.CertificateSigningRequestBuilder()
csr = csr.subject_name(x509.Name([
# Provide various details about who we are.
x509.NameAttribute(NameOID.COUNTRY_NAME, "AR"),
x509.NameAttribute(NameOID.STATE_OR_PROVINCE_NAME, "BA"),
x509.NameAttribute(NameOID.LOCALITY_NAME, "Buenos Aires"),
x509.NameAttribute(NameOID.ORGANIZATION_NAME, "ACME CORP"),
x509.NameAttribute(NameOID.COMMON_NAME, "acme.com"),
])
)
# Sign the CSR with our private key.
csr = csr.sign(private_key, hashes.SHA256(), default_backend())
# Write our CSR out to disk.
with open("/tmp/acme.csr", "wb") as out:
out.write(csr.public_bytes(serialization.Encoding.PEM))
print('Created /tmp/acme.csr')