Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
dae06d1
Expose retrieving certificate chains in SSL module
matiuszka Sep 7, 2023
676f9b1
Merge branch 'main' into main
matiuszka Sep 7, 2023
1418dd1
Review remarks applied
matiuszka Sep 8, 2023
0cdfe19
Trim white spaces
matiuszka Sep 8, 2023
4a51db2
Review fixes.
matiuszka Sep 11, 2023
6206f4f
Merge branch 'main' into main
matiuszka Sep 12, 2023
701c62a
Update Lib/ssl.py
matiuszka Sep 13, 2023
4c31619
Merge branch 'main' into main
matiuszka Sep 19, 2023
f925937
Review fixes
matiuszka Sep 19, 2023
5cb139d
NEWS entry.
gpshead Sep 20, 2023
45a19dc
Merge branch 'python:main' into main
matiuszka May 6, 2024
d276aeb
Return consistent types for `get_un/verified_chain` in `SSLObject` an…
matiuszka May 6, 2024
0d15ad0
Merge branch 'main' into main
matiuszka May 6, 2024
0574858
Merge branch 'main' into main
matiuszka May 7, 2024
3039cc7
Merge branch 'main' into main
matiuszka May 9, 2024
c690d4d
Merge branch 'main' into main
matiuszka May 13, 2024
c29d0fe
Merge branch 'main' into main
matiuszka May 17, 2024
c1a55be
Merge branch 'main' into main
matiuszka May 22, 2024
b3aeb06
Merge branch 'main' into main
matiuszka Jul 14, 2024
10ab5f0
Merge branch 'main' into main
matiuszka Jul 17, 2024
19bf5f1
Simple test for un/verified chain
matiuszka Aug 7, 2024
d962206
Merge branch 'main' into main
matiuszka Aug 7, 2024
c8c8fcb
Merge branch 'main' into main
matiuszka Aug 7, 2024
44166ad
Merge branch 'main' into main
matiuszka Aug 14, 2024
e0a1dc6
Tests improvements
matiuszka Aug 14, 2024
f2c6a18
Merge branch 'main' into main
matiuszka Aug 14, 2024
5595d6e
Merge branch 'main' into main
matiuszka Aug 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Expose retrieving certificate chains in SSL module
  • Loading branch information
matiuszka committed Sep 7, 2023
commit dae06d1921b3e96b8a2d44b3a67dfef90f37b6d9
23 changes: 19 additions & 4 deletions Doc/library/ssl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ This module provides a class, :class:`ssl.SSLSocket`, which is derived from the
:class:`socket.socket` type, and provides a socket-like wrapper that also
encrypts and decrypts the data going over the socket with SSL. It supports
additional methods such as :meth:`getpeercert`, which retrieves the
certificate of the other side of the connection, and :meth:`cipher`, which
retrieves the cipher being used for the secure connection.
certificate of the other side of the connection, :meth:`cipher`, which
retrieves the cipher being used for the secure connection or
:meth:`get_verified_chain`, :meth:`get_unverified_chain` which retrieves
certificate chain.

For more sophisticated applications, the :class:`ssl.SSLContext` class
helps manage settings and certificates, which can then be inherited
Expand Down Expand Up @@ -1221,6 +1223,16 @@ SSL sockets also have the following additional methods and attributes:
.. versionchanged:: 3.9
IPv6 address strings no longer have a trailing new line.

.. method:: SSLSocket.get_verified_chain()

Returns verified verified certificate chain provided by the other
end of the SSL channel. Return ``None`` if no certificates were provided.

.. method:: SSLSocket.get_unverified_chain()

Returns unverified verified certificate chain provided by the other
end of the SSL channel. Return ``None`` if no certificates were provided.

.. method:: SSLSocket.cipher()

Returns a three-value tuple containing the name of the cipher being used, the
Expand Down Expand Up @@ -1670,8 +1682,9 @@ to speed up repeated connections from the same clients.
Due to the early negotiation phase of the TLS connection, only limited
methods and attributes are usable like
:meth:`SSLSocket.selected_alpn_protocol` and :attr:`SSLSocket.context`.
The :meth:`SSLSocket.getpeercert`,
:meth:`SSLSocket.cipher` and :meth:`SSLSocket.compression` methods require that
The :meth:`SSLSocket.getpeercert`, :meth:`SSLSocket.get_verified_chain`,
:meth:`SSLSocket.get_unverified_chain` :meth:`SSLSocket.cipher`
and :meth:`SSLSocket.compression` methods require that
the TLS connection has progressed beyond the TLS Client Hello and therefore
will not return meaningful values nor can they be called safely.

Expand Down Expand Up @@ -2428,6 +2441,8 @@ provided.
- :meth:`~SSLSocket.read`
- :meth:`~SSLSocket.write`
- :meth:`~SSLSocket.getpeercert`
- :meth:`~SSLSocket.get_verified_chain`
- :meth:`~SSLSocket.get_unverified_chain`
- :meth:`~SSLSocket.selected_alpn_protocol`
- :meth:`~SSLSocket.selected_npn_protocol`
- :meth:`~SSLSocket.cipher`
Expand Down
24 changes: 24 additions & 0 deletions Lib/ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,22 @@ def getpeercert(self, binary_form=False):
"""
return self._sslobj.getpeercert(binary_form)

def get_verified_chain(self):
"""Returns verified verified certificate chain provided by the other
end of the SSL channel.

Return None if no certificates were provided.
"""
return self._sslobj.get_verified_chain()

def get_unverified_chain(self):
"""Returns unverified verified certificate chain provided by the other
end of the SSL channel.

Return None if no certificates were provided.
"""
return self._sslobj.get_unverified_chain()

def selected_npn_protocol(self):
"""Return the currently selected NPN protocol as a string, or ``None``
if a next protocol was not negotiated or if NPN is not supported by one
Expand Down Expand Up @@ -1096,6 +1112,14 @@ def getpeercert(self, binary_form=False):
self._check_connected()
return self._sslobj.getpeercert(binary_form)

@_sslcopydoc
def get_verified_chain(self):
return self._sslobj.get_verified_chain()

@_sslcopydoc
def get_unverified_chain(self):
return self._sslobj.get_unverified_chain()

@_sslcopydoc
def selected_npn_protocol(self):
self._checkClosed()
Expand Down