Fix formatting with black
This commit is contained in:
@ -15,38 +15,43 @@ def generate_self_signed_cert(cert_file: str, key_file: str):
|
||||
)
|
||||
# Write private key to file
|
||||
with open(key_file, "wb") as f:
|
||||
f.write(key.private_bytes(
|
||||
encoding=serialization.Encoding.PEM,
|
||||
format=serialization.PrivateFormat.TraditionalOpenSSL,
|
||||
encryption_algorithm=serialization.NoEncryption(),
|
||||
))
|
||||
f.write(
|
||||
key.private_bytes(
|
||||
encoding=serialization.Encoding.PEM,
|
||||
format=serialization.PrivateFormat.TraditionalOpenSSL,
|
||||
encryption_algorithm=serialization.NoEncryption(),
|
||||
)
|
||||
)
|
||||
|
||||
# Generate self-signed certificate
|
||||
subject = issuer = x509.Name([
|
||||
x509.NameAttribute(NameOID.COUNTRY_NAME, u"CH"),
|
||||
x509.NameAttribute(NameOID.STATE_OR_PROVINCE_NAME, u"Argau"),
|
||||
x509.NameAttribute(NameOID.LOCALITY_NAME, u"Villigen"),
|
||||
x509.NameAttribute(NameOID.ORGANIZATION_NAME, u"Paul Scherrer Institut"),
|
||||
x509.NameAttribute(NameOID.COMMON_NAME, u"PSI.CH"),
|
||||
])
|
||||
cert = x509.CertificateBuilder().subject_name(
|
||||
subject
|
||||
).issuer_name(
|
||||
issuer
|
||||
).public_key(
|
||||
key.public_key()
|
||||
).serial_number(
|
||||
x509.random_serial_number()
|
||||
).not_valid_before(
|
||||
datetime.datetime.utcnow()
|
||||
).not_valid_after(
|
||||
# Our certificate will be valid for 10 days
|
||||
datetime.datetime.utcnow() + datetime.timedelta(days=10)
|
||||
).add_extension(
|
||||
x509.SubjectAlternativeName([x509.DNSName(u"localhost")]),
|
||||
critical=False,
|
||||
).sign(key, hashes.SHA256())
|
||||
subject = issuer = x509.Name(
|
||||
[
|
||||
x509.NameAttribute(NameOID.COUNTRY_NAME, "CH"),
|
||||
x509.NameAttribute(NameOID.STATE_OR_PROVINCE_NAME, "Argau"),
|
||||
x509.NameAttribute(NameOID.LOCALITY_NAME, "Villigen"),
|
||||
x509.NameAttribute(NameOID.ORGANIZATION_NAME, "Paul Scherrer Institut"),
|
||||
x509.NameAttribute(NameOID.COMMON_NAME, "PSI.CH"),
|
||||
]
|
||||
)
|
||||
cert = (
|
||||
x509.CertificateBuilder()
|
||||
.subject_name(subject)
|
||||
.issuer_name(issuer)
|
||||
.public_key(key.public_key())
|
||||
.serial_number(x509.random_serial_number())
|
||||
.not_valid_before(datetime.datetime.utcnow())
|
||||
.not_valid_after(
|
||||
# Our certificate will be valid for 10 days
|
||||
datetime.datetime.utcnow()
|
||||
+ datetime.timedelta(days=10)
|
||||
)
|
||||
.add_extension(
|
||||
x509.SubjectAlternativeName([x509.DNSName("localhost")]),
|
||||
critical=False,
|
||||
)
|
||||
.sign(key, hashes.SHA256())
|
||||
)
|
||||
|
||||
# Write certificate to file
|
||||
with open(cert_file, "wb") as f:
|
||||
f.write(cert.public_bytes(Encoding.PEM))
|
||||
f.write(cert.public_bytes(Encoding.PEM))
|
||||
|
Reference in New Issue
Block a user