viff

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 diff
     1.1 --- a/viff/runtime.py	Thu Oct 02 13:18:47 2008 +0200
     1.2 +++ b/viff/runtime.py	Tue Oct 14 15:05:37 2008 +0200
     1.3 @@ -1165,14 +1165,19 @@
     1.4                  self.id = id
     1.5                  ctx = SSL.Context(SSL.SSLv3_METHOD)
     1.6                  # TODO: Make the file names configurable.
     1.7 -                ctx.use_certificate_file('player-%d.cert' % id)
     1.8 -                ctx.use_privatekey_file('player-%d.key' % id)
     1.9 -                ctx.check_privatekey()
    1.10 -
    1.11 -                ctx.load_verify_locations('ca.cert')
    1.12 -                ctx.set_verify(SSL.VERIFY_PEER | SSL.VERIFY_FAIL_IF_NO_PEER_CERT,
    1.13 -                               lambda conn, cert, errnum, depth, ok: ok)
    1.14 -                self.ctx = ctx
    1.15 +                try:
    1.16 +                    ctx.use_certificate_file('player-%d.cert' % id)
    1.17 +                    ctx.use_privatekey_file('player-%d.key' % id)
    1.18 +                    ctx.check_privatekey()
    1.19 +                    ctx.load_verify_locations('ca.cert')
    1.20 +                    ctx.set_verify(SSL.VERIFY_PEER | SSL.VERIFY_FAIL_IF_NO_PEER_CERT,
    1.21 +                                   lambda conn, cert, errnum, depth, ok: ok)
    1.22 +                    self.ctx = ctx
    1.23 +                except SSL.Error, e:
    1.24 +                    print "SSL errors - did you forget to generate certificates?"
    1.25 +                    for (lib, func, reason) in e.args[0]:
    1.26 +                        print "* %s in %s: %s" % (func, lib, reason)
    1.27 +                    raise SystemExit("Stopping program")
    1.28  
    1.29              def getContext(self):
    1.30                  return self.ctx