Skip to content

Commit f272407

Browse files
brentrubrentru
brentru
authored and
brentru
committed
check private key/cert starting text
1 parent 602250a commit f272407

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

adafruit_esp32spi/adafruit_esp32spi.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
from digitalio import Direction
4949
from adafruit_bus_device.spi_device import SPIDevice
5050

51-
__version__ = "0.0.0-auto.0"
51+
__version__ = "3.0.1"
5252
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_ESP32SPI.git"
5353

5454
# pylint: disable=bad-whitespace
@@ -794,16 +794,17 @@ def get_time(self):
794794
def set_certificate(self, client_certificate):
795795
"""Sets client certificate. Must be called
796796
BEFORE a network connection is established.
797-
Begins with -----BEGIN CERTIFICATE-----.
798-
:param str client_certificate: User-provided X.509 certificate up to 1300 bytes.
797+
:param str client_certificate: User-provided .PEM certificate up to 1300 bytes.
799798
"""
800799
if self._debug:
801800
print("** Setting client certificate")
802801
if self.status == WL_CONNECTED:
803802
raise RuntimeError("set_certificate must be called BEFORE a connection is established.")
804803
if isinstance(client_certificate, str):
805804
client_certificate = bytes(client_certificate, 'utf-8')
806-
assert len(client_certificate) < 1300, "X.509 certificate must be less than 1300 bytes."
805+
if "-----BEGIN CERTIFICATE" not in client_certificate:
806+
raise TypeError(".PEM must start with -----BEGIN CERTIFICATE")
807+
assert len(client_certificate) < 1300, ".PEM must be less than 1300 bytes."
807808
resp = self._send_command_get_response(_SET_CLI_CERT, (client_certificate,))
808809
if resp[0][0] != 1:
809810
raise RuntimeError("Failed to set client certificate")
@@ -813,15 +814,17 @@ def set_certificate(self, client_certificate):
813814
def set_private_key(self, private_key):
814815
"""Sets private key. Must be called
815816
BEFORE a network connection is established.
816-
:param str private_key: User-provided private key up to 1700 bytes.
817+
:param str private_key: User-provided .PEM file up to 1700 bytes.
817818
"""
818819
if self._debug:
819820
print("** Setting client's private key.")
820821
if self.status == WL_CONNECTED:
821822
raise RuntimeError("set_private_key must be called BEFORE a connection is established.")
822823
if isinstance(private_key, str):
823824
private_key = bytes(private_key, 'utf-8')
824-
assert len(private_key) < 1700, "Private key must be less than 1700 bytes."
825+
if "-----BEGIN RSA" not in private_key:
826+
raise TypeError(".PEM must start with -----BEGIN RSA")
827+
assert len(private_key) < 1700, ".PEM must be less than 1700 bytes."
825828
resp = self._send_command_get_response(_SET_PK, (private_key,))
826829
if resp[0][0] != 1:
827830
raise RuntimeError("Failed to set private key.")

0 commit comments

Comments
 (0)