Skip to content

Passing client TLS info to handler no longer possible? #162

Description

@gry8t

I need my app to have access to the tls cert used by the client. The only "possible" way was generated by AI but is no longer valid on newer versions of axum_server as tls backend has switched to rustls or openssl:

// Handler to extract client TLS info
async fn client_tls_info(req: Request<axum::body::Body>) -> String {
    // Extract TLS information from request extensions
    if let Some(tls_connection) = req.extensions().get::<axum_server::tls::TlsConnection>() {
        // Extract client certificate information
        let client_certificates = tls_connection.peer_certificates();
        if let Some(certificates) = client_certificates {
            // Extract some details about the client certificate
            let cert_info: Vec<String> = certificates
                .iter()
                .map(|cert| format!("Subject: {}", cert.subject()))
                .collect();
            return format!("Client certificates: {:?}", cert_info);
        }
    }

    "No client certificates found".to_string()
}

axum_server::tls no longer exists. Is this feature no longer possible?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions