@@ -88,17 +88,20 @@ STATIC mp_obj_t mod_ssl_wrap_socket(mp_uint_t n_args, const mp_obj_t *pos_args,
88
88
89
89
// chech if ca validation is required
90
90
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 ;
92
92
}
93
93
94
- // server side param is irrelevant for us (at least for the moment)
95
-
96
94
// retrieve the file paths (with an 6 byte offset because to strip the '/flash' prefix)
97
95
const char * keyfile = (args [1 ].u_obj == mp_const_none ) ? NULL : & (mp_obj_str_get_str (args [1 ].u_obj )[6 ]);
98
96
const char * certfile = (args [2 ].u_obj == mp_const_none ) ? NULL : & (mp_obj_str_get_str (args [2 ].u_obj )[6 ]);
99
97
const char * cafile = (args [5 ].u_obj == mp_const_none || args [4 ].u_int != SSL_CERT_REQUIRED ) ?
100
98
NULL : & (mp_obj_str_get_str (args [5 ].u_obj )[6 ]);
101
99
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
+
102
105
_i16 sd = ((mod_network_socket_obj_t * )args [0 ].u_obj )-> sock_base .sd ;
103
106
_i16 _errno ;
104
107
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,
123
126
124
127
socket_error :
125
128
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 ));
126
132
}
127
133
STATIC MP_DEFINE_CONST_FUN_OBJ_KW (mod_ssl_wrap_socket_obj , 1 , mod_ssl_wrap_socket );
128
134
0 commit comments