Add generate_ssl.py source
This commit is contained in:
@@ -109,6 +109,11 @@ If you've installed the certificate for the **Current User**:
|
|||||||
|
|
||||||
If you've installed the certificate for the **Local Machine**, repeat the same steps but instead open `certlm.msc`.
|
If you've installed the certificate for the **Local Machine**, repeat the same steps but instead open `certlm.msc`.
|
||||||
|
|
||||||
|
#### `generate_ssl.exe` is flagged as a virus
|
||||||
|
|
||||||
|
`generate_ssl.exe` is a Python application packed with PyInstaller and some anti-viruses may flag it as a virus.
|
||||||
|
This application is a simple certificate generator and you can find its source code in `utils/generate_ssl.py`.
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
|
|
||||||
TBD
|
TBD
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
from cryptography.hazmat.primitives.asymmetric import rsa
|
||||||
|
from cryptography.hazmat.primitives import serialization, hashes
|
||||||
|
from cryptography.hazmat.primitives.asymmetric import padding
|
||||||
|
from cryptography.x509 import NameOID, CertificateBuilder
|
||||||
|
from cryptography import x509
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
# Generate private key
|
||||||
|
private_key = rsa.generate_private_key(
|
||||||
|
public_exponent=65537,
|
||||||
|
key_size=4096
|
||||||
|
)
|
||||||
|
|
||||||
|
# Generate self-signed certificate
|
||||||
|
subject = issuer = x509.Name([
|
||||||
|
x509.NameAttribute(NameOID.COMMON_NAME, '2EA46.playfabapi.com'),
|
||||||
|
])
|
||||||
|
|
||||||
|
cert = CertificateBuilder().subject_name(
|
||||||
|
subject
|
||||||
|
).issuer_name(
|
||||||
|
issuer
|
||||||
|
).public_key(
|
||||||
|
private_key.public_key()
|
||||||
|
).serial_number(
|
||||||
|
x509.random_serial_number()
|
||||||
|
).not_valid_before(
|
||||||
|
datetime.datetime.utcnow()
|
||||||
|
).not_valid_after(
|
||||||
|
datetime.datetime.utcnow() + datetime.timedelta(days=365)
|
||||||
|
).add_extension(
|
||||||
|
x509.BasicConstraints(ca=True, path_length=None), critical=True
|
||||||
|
).sign(private_key, hashes.SHA256())
|
||||||
|
|
||||||
|
# Export PKCS12 file
|
||||||
|
from cryptography.hazmat.primitives.serialization.pkcs12 import serialize_key_and_certificates
|
||||||
|
|
||||||
|
pfx_data = serialize_key_and_certificates(
|
||||||
|
name=b"The Cycle: Frontier backend",
|
||||||
|
key=private_key,
|
||||||
|
cert=cert,
|
||||||
|
cas=None,
|
||||||
|
encryption_algorithm=serialization.NoEncryption()
|
||||||
|
)
|
||||||
|
|
||||||
|
# Save to file
|
||||||
|
with open("certificate.pfx", "wb") as f:
|
||||||
|
f.write(pfx_data)
|
||||||
|
|
||||||
|
print("PKCS#12 certificate (certificate.pfx) created successfully.")
|
||||||
Reference in New Issue
Block a user