94
94
_SET_ENT_UNAME_CMD = const (0x4B )
95
95
_SET_ENT_PASSWD_CMD = const (0x4C )
96
96
_SET_ENT_ENABLE_CMD = const (0x4F )
97
+ _SET_CLI_CERT = const (0x00 ) # TODO: Decl in nina-fw handler.
98
+ _SET_PK = const (0x00 ) # TODO: Decl in nina-fw handler.
97
99
98
100
_SET_PIN_MODE_CMD = const (0x50 )
99
101
_SET_DIGITAL_WRITE_CMD = const (0x51 )
@@ -786,3 +788,36 @@ def get_time(self):
786
788
if self .status in (WL_AP_LISTENING , WL_AP_CONNECTED ):
787
789
raise RuntimeError ("Cannot obtain NTP while in AP mode, must be connected to internet" )
788
790
raise RuntimeError ("Must be connected to WiFi before obtaining NTP." )
791
+
792
+ def set_certificate (self , client_certificate ):
793
+ """Sets client certificate. Must be called and set
794
+ BEFORE a network connection is established.
795
+ Begins with -----BEGIN CERTIFICATE-----.
796
+ :param str client_certificate: User-provided client certificate.
797
+ """
798
+ if self ._debug :
799
+ print ("** Setting client certificate" )
800
+ if self .status == WL_CONNECTED :
801
+ raise RuntimeError ("set_certificate must be called BEFORE a connection is established." )
802
+ if isinstance (client_certificate , str ):
803
+ client_certificate = bytes (client_certificate , 'utf-8' )
804
+ resp = self ._send_command_get_response (_SET_CLI_CERT , (client_certificate ,))
805
+ if resp [0 ][0 ] != 1 :
806
+ raise RuntimeError ("Failed to set client certificate" )
807
+ return resp [0 ]
808
+
809
+ def set_private_key (self , private_key ):
810
+ """Sets client certificate. Must be called and set
811
+ BEFORE a network connection is established.
812
+ :param str private_key: User-provided private key.
813
+ """
814
+ if self ._debug :
815
+ print ("** Setting client's private key." )
816
+ if self .status == WL_CONNECTED :
817
+ raise RuntimeError ("set_private_key must be called BEFORE a connection is established." )
818
+ if isinstance (private_key , str ):
819
+ private_key = bytes (private_key , 'utf-8' )
820
+ resp = self ._send_command_get_response (_SET_PK , (private_key ,))
821
+ if resp [0 ][0 ] != 1 :
822
+ raise RuntimeError ("Failed to set private key." )
823
+ return resp [0 ]
0 commit comments