Added tlspool_configvar() to libtlspool
[tlspool] / lib / python / tlspool.py
index 065d4a0..5c7339d 100644 (file)
@@ -319,6 +319,10 @@ def _prng(label, opt_ctxvalue, prng_len, prng_buf, ctlkey):
     return _tlspool._prng(label, opt_ctxvalue, prng_len, prng_buf, ctlkey)
 _prng = _tlspool._prng
 
+def tlspool_configvar(cfgfile, varname):
+    return _tlspool.tlspool_configvar(cfgfile, varname)
+tlspool_configvar = _tlspool.tlspool_configvar
+
 def raise_errno():
     return _tlspool.raise_errno()
 raise_errno = _tlspool.raise_errno
@@ -381,7 +385,7 @@ def ping (YYYYMMDD_producer=_tlspool.TLSPOOL_IDENTITY_V2,
 def make_tlsdata (localid='', remoteid='',
                flags=0, local_flags=0,
                ipproto=socket.IPPROTO_TCP, streamid=0, service='',
-               timeout=0, ctlkey=None):
+               timeout=0, ctlkey='TODOTODOTODOTODO'):
        """Make a new tlsdata structure, based the fields that may be supplied
           as flags, or otherwise as defaults.  Note that the field "local" is
           renamed to "local_flags" for reasons of clarity.  This helper function
@@ -478,12 +482,18 @@ class Connection:
                   The procedure has been described in RFC 5705.
 #TODO# Find a way to return the random bytes, and use the length
                """
+               assert (length > 0)
+               assert (1 <= len (label) <= 254)
+               assert (1 <= len (ctxvalue or 'X') <= 254)
                buf = prng_data ()
-               rv = _prng (label, ctxvalue, length, buf, self.tlsdata.ctlkey)
+# buf.in1_len = len (label)
+# buf.in2_len = len (ctxvalue) if ctxvalue is not None else 255
+# buf.prng_len = length
+               rv = _prng (label, ctxvalue, length, buf.buffer, self.tlsdata.ctlkey)
                if rv < 0:
                        _tlspool.raise_errno ()
                else:
-                       return buf
+                       return buf.buffer [:length]
 
        def control_detach (self):
                """Detach control of this connection.  Although the connection
@@ -612,6 +622,7 @@ class SecurityMixIn:
                else:
                        self.request     = sox2
                self.handle_secure ()
+               sox2.close ()
 
        def startssh (self):
                raise NotImplementedError ("Python wrapper does not implement STARTSSH")
@@ -627,9 +638,7 @@ class SecurityMixIn:
                   does nothing but invoke starttls(), which in turn invokes
                   handle_secure() after the TLS handshake has succeeded.
                """
-               print 'STARTTLS.BEGIN'
                self.starttls ()
-               print 'STARTTLS.END'
 
        def handle_secure (self):
                """This method may be overridden to handle the secure part of the