changeset 997:4a31eebed787

Terminate upon OpenSSL errors (Issue62).
author Martin Geisler <mg@daimi.au.dk>
date Tue, 14 Oct 2008 15:05:37 +0200
parents 5d64a7bf429c
children 42eb1cf66ac1
files viff/runtime.py
diffstat 1 files changed, 13 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/viff/runtime.py	Thu Oct 02 13:18:47 2008 +0200
+++ b/viff/runtime.py	Tue Oct 14 15:05:37 2008 +0200
@@ -1165,14 +1165,19 @@
                 self.id = id
                 ctx = SSL.Context(SSL.SSLv3_METHOD)
                 # TODO: Make the file names configurable.
-                ctx.use_certificate_file('player-%d.cert' % id)
-                ctx.use_privatekey_file('player-%d.key' % id)
-                ctx.check_privatekey()
-
-                ctx.load_verify_locations('ca.cert')
-                ctx.set_verify(SSL.VERIFY_PEER | SSL.VERIFY_FAIL_IF_NO_PEER_CERT,
-                               lambda conn, cert, errnum, depth, ok: ok)
-                self.ctx = ctx
+                try:
+                    ctx.use_certificate_file('player-%d.cert' % id)
+                    ctx.use_privatekey_file('player-%d.key' % id)
+                    ctx.check_privatekey()
+                    ctx.load_verify_locations('ca.cert')
+                    ctx.set_verify(SSL.VERIFY_PEER | SSL.VERIFY_FAIL_IF_NO_PEER_CERT,
+                                   lambda conn, cert, errnum, depth, ok: ok)
+                    self.ctx = ctx
+                except SSL.Error, e:
+                    print "SSL errors - did you forget to generate certificates?"
+                    for (lib, func, reason) in e.args[0]:
+                        print "* %s in %s: %s" % (func, lib, reason)
+                    raise SystemExit("Stopping program")
 
             def getContext(self):
                 return self.ctx