(store_name: PyStrRef, vm: &VirtualMachine)
| 4102 | |
| 4103 | #[pyfunction] |
| 4104 | fn enum_certificates(store_name: PyStrRef, vm: &VirtualMachine) -> PyResult<Vec<PyObjectRef>> { |
| 4105 | use schannel::{RawPointer, cert_context::ValidUses, cert_store::CertStore}; |
| 4106 | use windows_sys::Win32::Security::Cryptography; |
| 4107 | |
| 4108 | // TODO: check every store for it, not just 2 of them: |
| 4109 | // https://github.com/python/cpython/blob/3.8/Modules/_ssl.c#L5603-L5610 |
| 4110 | let open_fns = [CertStore::open_current_user, CertStore::open_local_machine]; |
| 4111 | let stores = open_fns |
| 4112 | .iter() |
| 4113 | .filter_map(|open| open(store_name.as_str()).ok()) |
| 4114 | .collect::<Vec<_>>(); |
| 4115 | let certs = stores.iter().flat_map(|s| s.certs()).map(|c| { |
| 4116 | let cert = vm.ctx.new_bytes(c.to_der().to_owned()); |
| 4117 | let enc_type = unsafe { |
| 4118 | let ptr = c.as_ptr() as *const Cryptography::CERT_CONTEXT; |
| 4119 | (*ptr).dwCertEncodingType |
| 4120 | }; |
| 4121 | let enc_type = match enc_type { |
| 4122 | Cryptography::X509_ASN_ENCODING => vm.new_pyobj(ascii!("x509_asn")), |
| 4123 | Cryptography::PKCS_7_ASN_ENCODING => vm.new_pyobj(ascii!("pkcs_7_asn")), |
| 4124 | other => vm.new_pyobj(other), |
| 4125 | }; |
| 4126 | let usage: PyObjectRef = match c.valid_uses().map_err(|e| e.to_pyexception(vm))? { |
| 4127 | ValidUses::All => vm.ctx.new_bool(true).into(), |
| 4128 | ValidUses::Oids(oids) => PyFrozenSet::from_iter( |
| 4129 | vm, |
| 4130 | oids.into_iter().map(|oid| vm.ctx.new_str(oid).into()), |
| 4131 | )? |
| 4132 | .into_ref(&vm.ctx) |
| 4133 | .into(), |
| 4134 | }; |
| 4135 | Ok(vm.new_tuple((cert, enc_type, usage)).into()) |
| 4136 | }); |
| 4137 | let certs: Vec<PyObjectRef> = certs.collect::<PyResult<Vec<_>>>()?; |
| 4138 | Ok(certs) |
| 4139 | } |
| 4140 | } |
| 4141 | |
| 4142 | mod bio { |
nothing calls this directly
no test coverage detected