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

Load client cert from format *.crt and *.key (native-tls) #1655

Merged
merged 8 commits into from Oct 19, 2022

Conversation

mirecl
Copy link
Contributor

@mirecl mirecl commented Oct 17, 2022

Add new optional fn from_pkcs8_pem for easy load client certificate (*.crt and *.key) for feature native-tls.
Example usage:

use reqwest::blocking::Client;
use reqwest::{Certificate, Identity};
use std::fs;

const URL: &str = "hostname server with mTLS";

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let ca = Certificate::from_pem(&read_file("ca.crt"))?;
    let cert = Identity::from_pkcs8_pem(&read_file("client.crt"), &read_file("client.key"))?;

    let client = Client::builder()
        .add_root_certificate(ca)
        .identity(cert)
        .build()?;

    let status = client.get(URL).send()?.status();

    println!("Status Code: {status}");
    Ok(())
}

fn read_file(path: &str) -> Vec<u8> {
    fs::read(path).unwrap()
}

@mirecl mirecl changed the title Native tls pem Load client cert from format *.crt and *.key (native-tls) Oct 17, 2022
@mirecl mirecl changed the title Load client cert from format *.crt and *.key (native-tls) Load client cert from format *.crt and *.key (native-tls) Oct 18, 2022
@mirecl
Copy link
Contributor Author

mirecl commented Oct 18, 2022

@seanmonstar, what do you think about this idea?

@seanmonstar
Copy link
Owner

Yea, seems like a useful feature to me :)

@mirecl
Copy link
Contributor Author

mirecl commented Oct 19, 2022

@seanmonstar, i fix failed CI for my PR:

  • Upgrade minimal version native-tls from 0.2.8 to 0.2.10 (support new function load certificate from_pkcs8);
  • Fix test docs.

Pls run again CI check.

src/tls.rs Outdated Show resolved Hide resolved
@mirecl
Copy link
Contributor Author

mirecl commented Oct 19, 2022

@seanmonstar, tell me when to expect a new release with this feature?

@seanmonstar seanmonstar merged commit 231b18f into seanmonstar:master Oct 19, 2022
@seanmonstar
Copy link
Owner

Probably later this week, possible early next week.

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

Successfully merging this pull request may close these issues.

None yet

2 participants