Skip to content

Commit 4a79901

Browse files
committed
Remove fingerprint and verify_fingerprint from Connection
The fingerprint will change from time to time and hard-coding it in this library we cannot forcibly deploy (unlike e.g. the Threema apps) is a surprising footgun since your services may suddenly fail (when Threema changes the fingerprint). As pointed out in #17, hard-coding the fingerprint (over the public key) is also undesirable. Furthermore, we want users to use their custom `aiohttp.ClientSession` instance. Therefore, we have decided to remove it. If you want to retain this feature, all you have to do is provide your own `aiohttp.ClientSession` in the following way: Connection(session=aiohttp.ClientSession( connector=aiohttp.TCPConnector(ssl=<fingerprint>))) See the aiohttp docs for details. Closes #17 Resolves #13 (by providing your own `SSLContext`)
1 parent ad3b718 commit 4a79901

8 files changed

+5
-35
lines changed

examples/e2e.py

-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ async def main():
136136
identity='*YOUR_GATEWAY_THREEMA_ID',
137137
secret='YOUR_GATEWAY_THREEMA_ID_SECRET',
138138
key='private:YOUR_PRIVATE_KEY',
139-
verify_fingerprint=True,
140139
)
141140
try:
142141
async with connection:

examples/e2e_blocking.py

-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ def main():
134134
identity='*YOUR_GATEWAY_THREEMA_ID',
135135
secret='YOUR_GATEWAY_THREEMA_ID_SECRET',
136136
key='private:YOUR_PRIVATE_KEY',
137-
verify_fingerprint=True,
138137
blocking=True,
139138
)
140139
try:

examples/lookup.py

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ async def main():
1919
connection = Connection(
2020
identity='*YOUR_GATEWAY_THREEMA_ID',
2121
secret='YOUR_GATEWAY_THREEMA_ID_SECRET',
22-
verify_fingerprint=True,
2322
)
2423
try:
2524
async with connection:

examples/lookup_blocking.py

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ def main():
1717
connection = Connection(
1818
identity='*YOUR_GATEWAY_THREEMA_ID',
1919
secret='YOUR_GATEWAY_THREEMA_ID_SECRET',
20-
verify_fingerprint=True,
2120
blocking=True,
2221
)
2322
try:

examples/simple.py

-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ async def main():
5555
connection = Connection(
5656
identity='*YOUR_GATEWAY_THREEMA_ID',
5757
secret='YOUR_GATEWAY_THREEMA_ID_SECRET',
58-
verify_fingerprint=True,
5958
)
6059
try:
6160
async with connection:

examples/simple_blocking.py

-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ def main():
5353
connection = Connection(
5454
identity='*YOUR_GATEWAY_THREEMA_ID',
5555
secret='YOUR_GATEWAY_THREEMA_ID_SECRET',
56-
verify_fingerprint=True,
5756
blocking=True,
5857
)
5958
try:

threema/gateway/_gateway.py

+3-15
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,9 @@ class Connection(AioRunMixin):
6969
end-to-end mode.
7070
- `key_file`: A file where the private key is stored
7171
in. Can be used instead of passing the key directly.
72-
- `fingerprint`: A binary fingerprint of an DER-encoded TLS
73-
certificate. Will fall back to a stored fingerprint which will
74-
be invalid as soon as the certificate expires.
75-
- `verify_fingerprint`: Set to `True` if you want to verify the
76-
TLS certificate of the Threema Gateway Server by a
77-
fingerprint. (Recommended)
7872
- `blocking`: Whether to use a blocking API, without the need
7973
for an explicit event loop.
74+
- `session`: An optional :class:`aiohttp.ClientSession`.
8075
"""
8176
async_functions = {
8277
'__exit__',
@@ -89,8 +84,6 @@ class Connection(AioRunMixin):
8984
'upload',
9085
'download',
9186
}
92-
fingerprint = binascii.unhexlify(
93-
b'42b1038e72f00c8c4dad78a3ebdc6d7a50c5ef288da9019b9171e4d675c08a17')
9487
urls = {
9588
'get_public_key': 'https://msgapi.threema.ch/pubkeys/{}',
9689
'get_id_by_phone': 'https://msgapi.threema.ch/lookup/phone/{}',
@@ -108,15 +101,10 @@ class Connection(AioRunMixin):
108101
def __init__(
109102
self, identity, secret,
110103
key=None, key_file=None,
111-
fingerprint=None, verify_fingerprint=False, blocking=False,
104+
blocking=False, session=None,
112105
):
113106
super().__init__(blocking=blocking)
114-
if fingerprint is None and verify_fingerprint:
115-
fingerprint = self.fingerprint
116-
if fingerprint is not None:
117-
fingerprint = aiohttp.Fingerprint(fingerprint)
118-
connector = aiohttp.TCPConnector(ssl=fingerprint)
119-
self._session = aiohttp.ClientSession(connector=connector)
107+
self._session = session if session is not None else aiohttp.ClientSession()
120108
self._key = None
121109
self._key_file = None
122110
self.id = identity

threema/gateway/bin/gateway_client.py

+2-14
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,8 @@ async def get_public_key(self, _):
6060
@click.option('-v', '--verbosity', type=click.IntRange(0, len(_logging_levels)),
6161
default=0, help="Logging verbosity.")
6262
@click.option('-c', '--colored', is_flag=True, help='Colourise logging output.')
63-
@click.option('-vf', '--verify-fingerprint', is_flag=True,
64-
help='Verify the certificate fingerprint.')
65-
@click.option('--fingerprint', type=str, help='A hex-encoded fingerprint.')
6663
@click.pass_context
67-
def cli(ctx, verbosity, colored, verify_fingerprint, fingerprint):
64+
def cli(ctx, verbosity, colored):
6865
"""
6966
Command Line Interface. Use --help for details.
7067
"""
@@ -84,15 +81,8 @@ def cli(ctx, verbosity, colored, verify_fingerprint, fingerprint):
8481
global _logging_handler
8582
_logging_handler = handler
8683

87-
# Fingerprint
88-
if fingerprint is not None:
89-
fingerprint = binascii.unhexlify(fingerprint)
90-
9184
# Store on context
92-
ctx.obj = {
93-
'verify_fingerprint': verify_fingerprint,
94-
'fingerprint': fingerprint
95-
}
85+
ctx.obj = {}
9686

9787

9888
@cli.command(short_help='Show version information.', help="""
@@ -516,8 +506,6 @@ def main():
516506
exc = None
517507
try:
518508
cli()
519-
except aiohttp.client_exceptions.ServerFingerprintMismatch:
520-
error = 'Fingerprints did not match!'
521509
except Exception as exc_:
522510
error = str(exc_)
523511
exc = exc_

0 commit comments

Comments
 (0)