Skip to content

Commit 2a0b165

Browse files
authored
Merge pull request #8624 from dhalbert/load-verify-locations
correct SSLContext.load_verify_locations() args
2 parents 64f6db1 + 9bdf1db commit 2a0b165

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

shared-bindings/ssl/SSLContext.c

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,25 +93,43 @@ STATIC mp_obj_t ssl_sslcontext_load_cert_chain(size_t n_args, const mp_obj_t *po
9393
}
9494
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(ssl_sslcontext_load_cert_chain_obj, 1, ssl_sslcontext_load_cert_chain);
9595

96-
//| def load_verify_locations(self, cadata: Optional[str] = None) -> None:
97-
//| """Load a set of certification authority (CA) certificates used to validate
98-
//| other peers' certificates."""
99-
96+
//| def load_verify_locations(
97+
//| self,
98+
//| cafile: Optional[str] = None,
99+
//| capath: Optional[str] = None,
100+
//| cadata: Optional[str] = None,
101+
//| ) -> None:
102+
//| """
103+
//| Load a set of certification authority (CA) certificates used to validate
104+
//| other peers' certificates.
105+
//|
106+
//| :param str cafile: path to a file of contcatenated CA certificates in PEM format. **Not implemented**.
107+
//| :param str capath: path to a directory of CA certificate files in PEM format. **Not implemented**.
108+
//| :param str cadata: A single CA certificate in PEM format. **Limitation**: CPython allows one
109+
//| or more certificates, but this implementation is limited to one.
110+
//| """
100111
STATIC mp_obj_t ssl_sslcontext_load_verify_locations(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
101-
enum { ARG_cadata };
112+
enum { ARG_cafile, ARG_capath, ARG_cadata };
102113
static const mp_arg_t allowed_args[] = {
114+
{ MP_QSTR_cafile, MP_ARG_OBJ, {.u_obj = mp_const_none} },
115+
{ MP_QSTR_capath, MP_ARG_OBJ, {.u_obj = mp_const_none} },
103116
{ MP_QSTR_cadata, MP_ARG_OBJ, {.u_obj = mp_const_none} },
104117
};
105118
ssl_sslcontext_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
106119

107120
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
108121
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
109122

110-
const char *cadata = NULL;
111-
if (args[ARG_cadata].u_obj != mp_const_none) {
112-
cadata = mp_obj_str_get_str(args[ARG_cadata].u_obj);
123+
if (args[ARG_cafile].u_obj != mp_const_none) {
124+
mp_raise_NotImplementedError_varg(MP_ERROR_TEXT("%q"), MP_QSTR_cafile);
125+
}
126+
127+
if (args[ARG_capath].u_obj != mp_const_none) {
128+
mp_raise_NotImplementedError_varg(MP_ERROR_TEXT("%q"), MP_QSTR_capath);
113129
}
114130

131+
const char *cadata = mp_obj_str_get_str(args[ARG_cadata].u_obj);
132+
115133
common_hal_ssl_sslcontext_load_verify_locations(self, cadata);
116134
return mp_const_none;
117135
}

0 commit comments

Comments
 (0)