@@ -794,16 +794,17 @@ def get_time(self):
794
794
def set_certificate (self , client_certificate ):
795
795
"""Sets client certificate. Must be called
796
796
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.
799
798
"""
800
799
if self ._debug :
801
800
print ("** Setting client certificate" )
802
801
if self .status == WL_CONNECTED :
803
802
raise RuntimeError ("set_certificate must be called BEFORE a connection is established." )
804
803
if isinstance (client_certificate , str ):
805
804
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."
807
808
resp = self ._send_command_get_response (_SET_CLI_CERT , (client_certificate ,))
808
809
if resp [0 ][0 ] != 1 :
809
810
raise RuntimeError ("Failed to set client certificate" )
@@ -813,15 +814,17 @@ def set_certificate(self, client_certificate):
813
814
def set_private_key (self , private_key ):
814
815
"""Sets private key. Must be called
815
816
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.
817
818
"""
818
819
if self ._debug :
819
820
print ("** Setting client's private key." )
820
821
if self .status == WL_CONNECTED :
821
822
raise RuntimeError ("set_private_key must be called BEFORE a connection is established." )
822
823
if isinstance (private_key , str ):
823
824
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."
825
828
resp = self ._send_command_get_response (_SET_PK , (private_key ,))
826
829
if resp [0 ][0 ] != 1 :
827
830
raise RuntimeError ("Failed to set private key." )
0 commit comments