I'm looking at this example and I'm trying to understand how to read the client certificate to extract subject
from it.
There is a make_service_fn
function that processes requests, which is called first. It would technically be possible to extract the stream and its data:
let make_svc = make_service_fn(move |stream: &TlsStream| {
let custom_field = stream.custom_field;
async move { Ok::<_, Infallible>(service_fn(move |req| req_handler(req, api_key))) }
});
But the problem is that poll_read
is called after the body of make_service_fn
, which is too late. This is capable of extracting the client certificate and its data but since it's called second, it results in an uninitialized field.
State::Streaming(ref mut stream) => {
let client_certificates = stream.get_ref().1.peer_certificates();
// extract data from the certificate and initialize custom_field
}
I don't think it's possible to extract it in req_handler
, which is why I'm trying this way.