Implement Context.set_session_id
diff --git a/src/OpenSSL/SSL.py b/src/OpenSSL/SSL.py
index 160cfd8..800ae1e 100644
--- a/src/OpenSSL/SSL.py
+++ b/src/OpenSSL/SSL.py
@@ -689,23 +689,39 @@
def load_client_ca(self, cafile):
"""
- Load the trusted certificates that will be sent to the client
- (basically telling the client "These are the guys I trust"). Does not
- actually imply any of the certificates are trusted; that must be
+ Load the trusted certificates that will be sent to the client. Does
+ not actually imply any of the certificates are trusted; that must be
configured separately.
- :param cafile: The name of the certificates file
+ :param bytes cafile: The path to a certificates file in PEM format.
:return: None
"""
+ ca_list = _lib.SSL_load_client_CA_file(
+ _text_to_bytes_and_warn("cafile", cafile)
+ )
+ _openssl_assert(ca_list != _ffi.NULL)
+ # SSL_CTX_set_client_CA_list doesn't return anything.
+ _lib.SSL_CTX_set_client_CA_list(self._context, ca_list)
def set_session_id(self, buf):
"""
- Set the session identifier. This is needed if you want to do session
- resumption.
+ Set the session id to *buf* within which a session can be reused for
+ this Context object. This is needed when doing session resumption,
+ because there is no way for a stored session to know which Context
+ object it is associated with.
- :param buf: A Python object that can be safely converted to a string
+ :param bytes buf: The session id.
+
:returns: None
"""
+ buf = _text_to_bytes_and_warn("buf", buf)
+ _openssl_assert(
+ _lib.SSL_CTX_set_session_id_context(
+ self._context,
+ buf,
+ len(buf),
+ ) == 1
+ )
def set_session_cache_mode(self, mode):
"""
@@ -1406,10 +1422,15 @@
def renegotiate(self):
"""
- Renegotiate the session
+ Renegotiate the session.
- :return: True if the renegotiation can be started, false otherwise
+ :return: True if the renegotiation can be started, False otherwise
+ :rtype: bool
"""
+ if not self.renegotiate_pending():
+ _openssl_assert(_lib.SSL_renegotiate(self._ssl) == 1)
+ return True
+ return False
def do_handshake(self):
"""
@@ -1423,17 +1444,20 @@
def renegotiate_pending(self):
"""
- Check if there's a renegotiation in progress, it will return false once
+ Check if there's a renegotiation in progress, it will return False once
a renegotiation is finished.
:return: Whether there's a renegotiation in progress
+ :rtype: bool
"""
+ return _lib.SSL_renegotiate_pending(self._ssl) == 1
def total_renegotiations(self):
"""
Find out the total number of renegotiations.
:return: The number of renegotiations.
+ :rtype: int
"""
return _lib.SSL_total_renegotiations(self._ssl)