Skip to content

Commit 1e3b242

Browse files
committed
tests/extmod: Adjust ssl/tls tests to run on targets with axTLS.
Signed-off-by: Damien George <[email protected]>
1 parent 7d44237 commit 1e3b242

8 files changed

+49
-23
lines changed

tests/extmod/ssl_cadata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# Invalid cadata.
1111
try:
1212
ssl.wrap_socket(io.BytesIO(), cadata=b"!")
13-
except TypeError:
13+
except AttributeError:
1414
# "cadata" keyword argument is not supported by axtls.
1515
print("SKIP")
1616
raise SystemExit

tests/extmod/ssl_keycert.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@
99

1010
key = b"0\x82\x019\x02\x01\x00\x02A\x00\xf9\xe0}\xbd\xd7\x9cI\x18\x06\xc3\xcb\xb5\xec@r\xfbD\x18\x80\xaaWoZ{\xcc\xa3\xeb!\"\x0fY\x9e]-\xee\xe4\t!BY\x9f{7\xf3\xf2\x8f}}\r|.\xa8<\ta\xb2\xd7W\xb3\xc9\x19A\xc39\x02\x03\x01\x00\x01\x02@\x07:\x9fh\xa6\x9c6\xe1#\x10\xf7\x0b\xc4Q\xf9\x01\x9b\xee\xb9\x8a4\r\\\xa8\xc8:\xd5\xca\x97\x99\xaa\x16\x04)\xa8\xf9\x13\xdeq\x0ev`\xa7\x83\xc5\x8b`\xdb\xef \x9d\x93\xe8g\x84\x96\xfaV\\\xf4R\xda\xd0\xa1\x02!\x00\xfeR\xbf\n\x91Su\x87L\x98{\xeb%\xed\xfb\x06u)@\xfe\x1b\xde\xa0\xc6@\xab\xc5\xedg\x8e\x10[\x02!\x00\xfb\x86=\x85\xa4'\xde\x85\xb5L\xe0)\x99\xfaL\x8c3A\x02\xa8<\xdew\xad\x00\xe3\x1d\x05\xd8\xb4N\xfb\x02 \x08\xb0M\x04\x90hx\x88q\xcew\xd5U\xcbf\x9b\x16\xdf\x9c\xef\xd1\x85\xee\x9a7Ug\x02\xb0Z\x03'\x02 9\xa0D\xe2$|\xf9\xefz]5\x92rs\xb5+\xfd\xe6,\x1c\xadmn\xcf\xd5?3|\x0em)\x17\x02 5Z\xcc/\xa5?\n\x04%\x9b{N\x9dX\xddI\xbe\xd2\xb0\xa0\x03BQ\x02\x82\xc2\xe0u)\xbd\xb8\xaf"
1111

12-
# This particular key was generated with:
13-
# $ openssl genrsa -out key.pem 512
14-
# $ openssl rsa -in key.pem -outform DER -out key.der
15-
keypkcs8 = b'0\x82\x01U\x02\x01\x000\r\x06\t*\x86H\x86\xf7\r\x01\x01\x01\x05\x00\x04\x82\x01?0\x82\x01;\x02\x01\x00\x02A\x00\xae\x07\xbb\xbf \x8eL\\ G\x91\x1b\xc45\x89\x96\x0c\xca\x94\xa5\xc2%F\x84z\xea\xb2Y\xdd\x943\x1a\xe0\x1e\xfe%\xd3\xbc\x85\xf0\x05\x8eI\xca\x83\x8b\x86\xfd\x15P,\xa9t8\xc2s\x11\x7fk*[[w\xdd\x02\x03\x01\x00\x01\x02@?\x02-\xc7\x95Q\xef\xf3\xaa\xfc>]\x7f<\xa3\x03\xe0\xbd\xb7\xf4\x0b\xc6\xd31D\x0f\x95cT\x06D9\xed\xf0X\xa6\x18\xb4\xe7\x96\x8f\x91\xd6\xd7\xbfR\\V\xfd\x0e{\xd3\xa4e\xb4M\x01\xbb\xdf\xf1\xf0\xbcEA\x02!\x00\xd5\xd7f\xcc\x84\xf5Y&\xa7]\x00\x91\xc9\x8e\xb0\xf37\x108D\x7f&!JJ\x836\x83\x9f\n\xf2\x0f\x02!\x00\xd0W\x0ec\xa6\x86C\xf7\x8d\xbe\xf0\xbc2\xe3)|\xbb\xd6\xbb;\xb2\xafG\x05S\x0f-\x14X\n3S\x02 A\xf5\xb20\xcd\xa6<<\x8f\rA\xda\xb68<^\x99\x12x\xb8\xb0\x1b\x9b\xd3%\x8e\xb9\xa6\xf9\xcc\xcf\x83\x02!\x00\xa8.\xee\xdd\xc0\xeb8h\xda\x13^\xb0\xfe\x7fd\xd9]\xa5m\xc66k\xcap`\xe9\xaaav\xe4\xdd#\x02!\x00\xd1\xd0\x93\xe7wZ\xe0p\xd0M\x07\x9e\x13\xa7\xa7\x12\x95\x1e\x13h0O\xc0\x18\x1fa\x10")\x9f&U'
16-
1712
# Invalid key
1813
try:
1914
ssl.wrap_socket(io.BytesIO(), key=b"!")
@@ -31,9 +26,3 @@
3126
ssl.wrap_socket(io.BytesIO(), key=key, cert=b"!")
3227
except ValueError as er:
3328
print(repr(er))
34-
35-
# Valid key in PKCS8 format, invalid cert
36-
try:
37-
ssl.wrap_socket(io.BytesIO(), key=keypkcs8, cert=b"!")
38-
except ValueError as er:
39-
print(repr(er))

tests/extmod/ssl_keycert.py.exp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
ValueError('invalid key',)
22
TypeError("can't convert 'NoneType' object to str implicitly",)
33
ValueError('invalid cert',)
4-
ValueError('invalid cert',)

tests/extmod/ssl_keycert_pkcs8.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Test ssl with key/cert passed in
2+
3+
try:
4+
import io
5+
import ssl
6+
except ImportError:
7+
print("SKIP")
8+
raise SystemExit
9+
10+
# Only mbedTLS supports PKCS8 keys.
11+
if not hasattr(ssl, "MBEDTLS_VERSION"):
12+
print("SKIP")
13+
raise SystemExit
14+
15+
# This particular key was generated with:
16+
# $ openssl genrsa -out key.pem 512
17+
# $ openssl rsa -in key.pem -outform DER -out key.der
18+
keypkcs8 = b'0\x82\x01U\x02\x01\x000\r\x06\t*\x86H\x86\xf7\r\x01\x01\x01\x05\x00\x04\x82\x01?0\x82\x01;\x02\x01\x00\x02A\x00\xae\x07\xbb\xbf \x8eL\\ G\x91\x1b\xc45\x89\x96\x0c\xca\x94\xa5\xc2%F\x84z\xea\xb2Y\xdd\x943\x1a\xe0\x1e\xfe%\xd3\xbc\x85\xf0\x05\x8eI\xca\x83\x8b\x86\xfd\x15P,\xa9t8\xc2s\x11\x7fk*[[w\xdd\x02\x03\x01\x00\x01\x02@?\x02-\xc7\x95Q\xef\xf3\xaa\xfc>]\x7f<\xa3\x03\xe0\xbd\xb7\xf4\x0b\xc6\xd31D\x0f\x95cT\x06D9\xed\xf0X\xa6\x18\xb4\xe7\x96\x8f\x91\xd6\xd7\xbfR\\V\xfd\x0e{\xd3\xa4e\xb4M\x01\xbb\xdf\xf1\xf0\xbcEA\x02!\x00\xd5\xd7f\xcc\x84\xf5Y&\xa7]\x00\x91\xc9\x8e\xb0\xf37\x108D\x7f&!JJ\x836\x83\x9f\n\xf2\x0f\x02!\x00\xd0W\x0ec\xa6\x86C\xf7\x8d\xbe\xf0\xbc2\xe3)|\xbb\xd6\xbb;\xb2\xafG\x05S\x0f-\x14X\n3S\x02 A\xf5\xb20\xcd\xa6<<\x8f\rA\xda\xb68<^\x99\x12x\xb8\xb0\x1b\x9b\xd3%\x8e\xb9\xa6\xf9\xcc\xcf\x83\x02!\x00\xa8.\xee\xdd\xc0\xeb8h\xda\x13^\xb0\xfe\x7fd\xd9]\xa5m\xc66k\xcap`\xe9\xaaav\xe4\xdd#\x02!\x00\xd1\xd0\x93\xe7wZ\xe0p\xd0M\x07\x9e\x13\xa7\xa7\x12\x95\x1e\x13h0O\xc0\x18\x1fa\x10")\x9f&U'
19+
20+
# Valid key in PKCS8 format, invalid cert
21+
try:
22+
ssl.wrap_socket(io.BytesIO(), key=keypkcs8, cert=b"!")
23+
except ValueError as er:
24+
print(repr(er))

tests/extmod/ssl_keycert_pkcs8.py.exp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ValueError('invalid cert',)
Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,15 @@
11
# Test ssl.SSLContext.verify_mode attribute.
2-
# It's not available in the axtls implementation, so has an independent test.
32

43
try:
54
import ssl
65
except ImportError:
76
print("SKIP")
87
raise SystemExit
98

10-
if not hasattr(ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT), "verify_mode"):
11-
print("SKIP")
12-
raise SystemExit
13-
149
# Test default verify_mode for server (client default is different in MicroPython).
1510
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
1611
print(ctx.verify_mode == ssl.CERT_NONE)
1712

1813
# Test setting and getting verify_mode.
1914
ctx.verify_mode = ssl.CERT_NONE
2015
print(ctx.verify_mode == ssl.CERT_NONE)
21-
ctx.verify_mode = ssl.CERT_OPTIONAL
22-
print(ctx.verify_mode == ssl.CERT_OPTIONAL)
23-
ctx.verify_mode = ssl.CERT_REQUIRED
24-
print(ctx.verify_mode == ssl.CERT_REQUIRED)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Test ssl.SSLContext.verify_mode attribute, with additional CERT_xxx constants.
2+
# These aren't available in the axtls implementation.
3+
4+
try:
5+
import ssl
6+
except ImportError:
7+
print("SKIP")
8+
raise SystemExit
9+
10+
if not hasattr(ssl, "OPENSSL_VERSION") and not hasattr(ssl, "MBEDTLS_VERSION"):
11+
print("SKIP")
12+
raise SystemExit
13+
14+
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
15+
16+
# Test setting and getting verify_mode.
17+
ctx.verify_mode = ssl.CERT_OPTIONAL
18+
print(ctx.verify_mode == ssl.CERT_OPTIONAL)
19+
ctx.verify_mode = ssl.CERT_REQUIRED
20+
print(ctx.verify_mode == ssl.CERT_REQUIRED)

tests/extmod/tls_sslcontext_ciphers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
try:
44
import tls
5-
except ImportError:
5+
6+
tls.SSLContext.get_ciphers
7+
except (ImportError, AttributeError):
68
print("SKIP")
79
raise SystemExit
810

0 commit comments

Comments
 (0)