Support cert/key combo files in args. Improve argument names in SSLOptions

This commit is contained in:
Aldo Cortesi 2014-03-02 15:56:36 +13:00
parent 234d326080
commit 0177eb899a
3 changed files with 17 additions and 12 deletions

View File

@ -14,19 +14,19 @@ class PathodError(Exception): pass
class SSLOptions: class SSLOptions:
def __init__(self, confdir=CONFDIR, cn=None, certfile=None, cacert=None, def __init__(self, confdir=CONFDIR, cn=None, certfile=None, keyfile=None,
not_after_connect=None, request_client_cert=False, not_after_connect=None, request_client_cert=False,
sslversion=tcp.SSLv23_METHOD, ciphers=None): sslversion=tcp.SSLv23_METHOD, ciphers=None):
self.confdir = confdir self.confdir = confdir
self.cn = cn self.cn = cn
if cacert: if keyfile:
self.cacert = os.path.expanduser(cacert) self.keyfile = os.path.expanduser(keyfile)
else: else:
cacert = os.path.join(confdir, CA_CERT_NAME) keyfile = os.path.join(confdir, CA_CERT_NAME)
self.cacert = os.path.expanduser(cacert) self.keyfile = os.path.expanduser(keyfile)
if not os.path.exists(self.cacert): if not os.path.exists(self.keyfile):
certutils.dummy_ca(self.cacert) certutils.dummy_ca(self.keyfile)
self.certstore = certutils.CertStore(self.cacert) self.certstore = certutils.CertStore(self.keyfile)
self.certfile = certfile self.certfile = certfile
self.not_after_connect = not_after_connect self.not_after_connect = not_after_connect
self.request_client_cert = request_client_cert self.request_client_cert = request_client_cert
@ -104,7 +104,7 @@ class PathodHandler(tcp.BaseHandler):
try: try:
self.convert_to_ssl( self.convert_to_ssl(
self.server.ssloptions.get_cert(None), self.server.ssloptions.get_cert(None),
self.server.ssloptions.cacert, self.server.ssloptions.keyfile,
handle_sni = self.handle_sni, handle_sni = self.handle_sni,
request_client_cert = self.server.ssloptions.request_client_cert, request_client_cert = self.server.ssloptions.request_client_cert,
cipher_list = self.server.ssloptions.ciphers, cipher_list = self.server.ssloptions.ciphers,
@ -212,7 +212,7 @@ class PathodHandler(tcp.BaseHandler):
try: try:
self.convert_to_ssl( self.convert_to_ssl(
self.server.ssloptions.get_cert(None), self.server.ssloptions.get_cert(None),
self.server.ssloptions.cacert, self.server.ssloptions.keyfile,
handle_sni = self.handle_sni, handle_sni = self.handle_sni,
request_client_cert = self.server.ssloptions.request_client_cert, request_client_cert = self.server.ssloptions.request_client_cert,
cipher_list = self.server.ssloptions.ciphers, cipher_list = self.server.ssloptions.ciphers,

7
pathod
View File

@ -35,6 +35,7 @@ def main(parser, args):
cn = args.cn, cn = args.cn,
confdir = args.confdir, confdir = args.confdir,
certfile = args.ssl_certfile, certfile = args.ssl_certfile,
keyfile = args.ssl_keyfile or args.ssl_certfile,
not_after_connect = args.ssl_not_after_connect, not_after_connect = args.ssl_not_after_connect,
ciphers = args.ciphers, ciphers = args.ciphers,
sslversion = utils.SSLVERSIONS[args.sslversion] sslversion = utils.SSLVERSIONS[args.sslversion]
@ -174,7 +175,11 @@ if __name__ == "__main__":
) )
group.add_argument( group.add_argument(
"--certfile", dest='ssl_certfile', default=None, type=str, "--certfile", dest='ssl_certfile', default=None, type=str,
help='SSL cert file. If not specified, a default cert is used.' help='SSL certificate in PEM format, optionally with the key in the same file.'
)
group.add_argument(
"--keyfile", dest='ssl_keyfile', default=None, type=str,
help='Key matching certfile.'
) )
group.add_argument( group.add_argument(
"--ciphers", dest="ciphers", type=str, default=False, "--ciphers", dest="ciphers", type=str, default=False,

View File

@ -67,7 +67,7 @@ class TestCustomCert(tutils.DaemonTests):
ssl = True ssl = True
ssloptions = dict( ssloptions = dict(
certfile = tutils.test_data.path("data/testkey.pem"), certfile = tutils.test_data.path("data/testkey.pem"),
cacert = tutils.test_data.path("data/testkey.pem"), keyfile = tutils.test_data.path("data/testkey.pem"),
) )
def test_connect(self): def test_connect(self):
r = self.pathoc(r"get:/p/202") r = self.pathoc(r"get:/p/202")