mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-08-22 22:23:36 -07:00
Update helpers.py
This commit is contained in:
parent
49fb4540a2
commit
ffc9db17e3
1 changed files with 17 additions and 13 deletions
|
@ -348,24 +348,28 @@ def create_https_certificates(ssl_cert, ssl_key):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from plexpy import logger
|
from plexpy import logger
|
||||||
|
|
||||||
from OpenSSL import crypto
|
from OpenSSL import crypto
|
||||||
from certgen import createKeyPair, createCertRequest, createCertificate, \
|
import time
|
||||||
TYPE_RSA, serial
|
|
||||||
|
|
||||||
# Create the CA Certificate
|
# Create self-signed Certificate
|
||||||
cakey = createKeyPair(TYPE_RSA, 2048)
|
key = crypto.PKey()
|
||||||
careq = createCertRequest(cakey, CN="Certificate Authority")
|
key.generate_key(crypto.TYPE_RSA, 2048)
|
||||||
cacert = createCertificate(careq, (careq, cakey), serial, (0, 60 * 60 * 24 * 365 * 10)) # ten years
|
|
||||||
|
cert = crypto.X509()
|
||||||
pkey = createKeyPair(TYPE_RSA, 2048)
|
cert.set_version(2)
|
||||||
req = createCertRequest(pkey, CN="PlexPy")
|
cert.set_serial_number(int(time.time()))
|
||||||
cert = createCertificate(req, (cacert, cakey), serial, (0, 60 * 60 * 24 * 365 * 10)) # ten years
|
cert.get_subject().CN = "PlexPy"
|
||||||
|
cert.gmtime_adj_notBefore(0)
|
||||||
|
cert.gmtime_adj_notAfter(60 * 60 * 24 * 365 * 10)
|
||||||
|
cert.set_issuer(cert.get_subject())
|
||||||
|
cert.set_pubkey(key)
|
||||||
|
cert.add_extensions([crypto.X509Extension("subjectAltName", False, "DNS:plex.myserver.com,IP:10.11.12.13")])
|
||||||
|
cert.sign(key, "sha256")
|
||||||
|
|
||||||
# Save the key and certificate to disk
|
# Save the key and certificate to disk
|
||||||
try:
|
try:
|
||||||
with open(ssl_key, "w") as fp:
|
with open(ssl_key, "w") as fp:
|
||||||
fp.write(crypto.dump_privatekey(crypto.FILETYPE_PEM, pkey))
|
fp.write(crypto.dump_privatekey(crypto.FILETYPE_PEM, key))
|
||||||
with open(ssl_cert, "w") as fp:
|
with open(ssl_cert, "w") as fp:
|
||||||
fp.write(crypto.dump_certificate(crypto.FILETYPE_PEM, cert))
|
fp.write(crypto.dump_certificate(crypto.FILETYPE_PEM, cert))
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
|
@ -455,4 +459,4 @@ def sanitize(string):
|
||||||
if string:
|
if string:
|
||||||
return unicode(string).replace('<','<').replace('>','>')
|
return unicode(string).replace('<','<').replace('>','>')
|
||||||
else:
|
else:
|
||||||
return ''
|
return ''
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue