@@ -88,17 +88,20 @@ STATIC mp_obj_t mod_ssl_wrap_socket(mp_uint_t n_args, const mp_obj_t *pos_args,
8888
8989 // chech if ca validation is required
9090 if (args [4 ].u_int != SSL_CERT_NONE && args [5 ].u_obj == mp_const_none ) {
91- nlr_raise ( mp_obj_new_exception_msg ( & mp_type_ValueError , mpexception_value_invalid_arguments )) ;
91+ goto arg_error ;
9292 }
9393
94- // server side param is irrelevant for us (at least for the moment)
95-
9694 // retrieve the file paths (with an 6 byte offset because to strip the '/flash' prefix)
9795 const char * keyfile = (args [1 ].u_obj == mp_const_none ) ? NULL : & (mp_obj_str_get_str (args [1 ].u_obj )[6 ]);
9896 const char * certfile = (args [2 ].u_obj == mp_const_none ) ? NULL : & (mp_obj_str_get_str (args [2 ].u_obj )[6 ]);
9997 const char * cafile = (args [5 ].u_obj == mp_const_none || args [4 ].u_int != SSL_CERT_REQUIRED ) ?
10098 NULL : & (mp_obj_str_get_str (args [5 ].u_obj )[6 ]);
10199
100+ // server side requires both certfile and keyfile
101+ if (mp_obj_is_true (args [3 ].u_obj ) && (!keyfile || !certfile )) {
102+ goto arg_error ;
103+ }
104+
102105 _i16 sd = ((mod_network_socket_obj_t * )args [0 ].u_obj )-> sock_base .sd ;
103106 _i16 _errno ;
104107 if (keyfile && (_errno = sl_SetSockOpt (sd , SL_SOL_SOCKET , SL_SO_SECURE_FILES_PRIVATE_KEY_FILE_NAME , keyfile , strlen (keyfile ))) < 0 ) {
@@ -123,6 +126,9 @@ STATIC mp_obj_t mod_ssl_wrap_socket(mp_uint_t n_args, const mp_obj_t *pos_args,
123126
124127socket_error :
125128 nlr_raise (mp_obj_new_exception_arg1 (& mp_type_OSError , MP_OBJ_NEW_SMALL_INT (_errno )));
129+
130+ arg_error :
131+ nlr_raise (mp_obj_new_exception_msg (& mp_type_ValueError , mpexception_value_invalid_arguments ));
126132}
127133STATIC MP_DEFINE_CONST_FUN_OBJ_KW (mod_ssl_wrap_socket_obj , 1 , mod_ssl_wrap_socket );
128134
0 commit comments