Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
gry8t opened this issue Feb 4, 2025 · 0 comments
Open

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

gry8t opened this issue Feb 4, 2025 · 0 comments

Comments

@gry8t
Copy link

gry8t commented Feb 4, 2025

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant