I want to pull my ssl certificate and key from environment variables and not store them on the filesystem. But I am running into a road block with twisted ssl
from io import StringIO
from twisted.internet import reactor, task, threads, ssl
key = StringIO()
key.write(os.environ['SSLKEY'])
cert = StringIO()
cert.write(os.environ['SSLCERT'])
contextFactory = ssl.DefaultOpenSSLContextFactory(key, cert)
gives me the following exception
2018-04-03 16:01:28-0500 [-] TypeError: Path must be represented as bytes or unicode string
or
contextFactory = ssl.DefaultOpenSSLContextFactory(key.getvalue(), cert.getvalue())
gives me the following exception.
2018-04-03 16:02:44-0500 [-] OpenSSL.SSL.Error: [('system library', 'fopen', 'File name too long'), ('BIO routines', 'file_ctrl', 'system lib'), ('SSL routines', 'SSL_CTX_use_certificate_file', 'system lib')]
twisted.internet.ssl is looking for a string or bytes object of the filename and io.StringIO gives me a io.StringIO object.
Is there anyway to accomplish this?