Skip to content

Commit c78fa55

Browse files
committed
Merge branch 'master' of github.com:yaroslaff/showcert
2 parents 72ff442 + 1fc7233 commit c78fa55

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ jobs:
3737
- name: List files
3838
run: ls -al
3939

40+
- name: Print coverage.xml
41+
run: cat coverage.xml
42+
4043
- name: Upload results to Codecov
4144
uses: codecov/codecov-action@v5
4245
with:

showcert/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.4.4'
1+
__version__ = '0.4.6'

showcert/getremote.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,19 @@ def get_certificate_chain(host, name=None, port=443, insecure=False, starttls='a
138138
conn.set_tlsext_host_name(name.encode())
139139

140140
conn.set_connect_state()
141-
conn.do_handshake()
141+
142+
try:
143+
conn.do_handshake()
144+
except SSL.Error as e:
145+
# rare case, e.g. RabbitMQ on 5671 which reset connection if client certificate is not sent
146+
# never happens on webservers
147+
if insecure and 'ssl/tls alert handshake failure' in str(e):
148+
print("# Server likely requires a client certificate (handshake failure)")
149+
else:
150+
raise
151+
152+
if conn.get_client_ca_list():
153+
print("# Remote asks for a client certificate")
142154

143155
chain = conn.get_peer_cert_chain()
144156
return sock_host, chain

tests/test_client.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from showcert import process_cert
2+
from OpenSSL import SSL
3+
4+
import pytest
5+
6+
class TestClient:
7+
def test_client(self):
8+
srv = "client.badssl.com"
9+
process_cert(srv)
10+
11+
def test_handshake_failure(self, monkeypatch):
12+
def fake_handshake(self):
13+
original_handshake(self)
14+
raise SSL.Error([('SSL routines', '', 'ssl/tls alert handshake failure')])
15+
16+
original_handshake = SSL.Connection.do_handshake
17+
monkeypatch.setattr("OpenSSL.SSL.Connection.do_handshake", fake_handshake)
18+
process_cert("client.badssl.com", insecure=True)
19+

0 commit comments

Comments
 (0)