Last active
December 25, 2019 08:49
-
-
Save davidB/bed8ea360f859a23889d9c9cc4eefb85 to your computer and use it in GitHub Desktop.
GKE access failed via reqwest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "test_gke_cert" | |
version = "0.1.0" | |
authors = ["David Bernard"] | |
edition = "2018" | |
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | |
[dependencies] | |
openssl = { version = "^0.10", features = ["vendored"] } | |
tokio = { version = "^0.2.5", features = ["full"]} | |
[dependencies.reqwest] | |
#version = "0.10.0" | |
# version = " 0.10.0-alpha.2" | |
git = "https://github.com/seanmonstar/reqwest" | |
rev = "18fd9a63b0eb7bf51d2e2b7fe31b4567f0b05779" | |
features = ["json", "gzip", "rustls-tls"] | |
# features = ["rustls-tls"] | |
# # TODO: rustls |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Mac OSX (Catalina 10.15.2): | |
// ``` | |
// Error: reqwest::Error { kind: Request, url: "https://35.232.6.83/", source: hyper::Error(Connect, Error { code: -67843, message: "The certificate was not trusted." }) } | |
// ``` | |
// | |
// Linux: | |
// ``` | |
// Response { | |
// url: "https://35.232.6.83/", | |
// status: 403, | |
// headers: { | |
// "audit-id": "83ac14e8-8beb-4456-b495-35c81ba9b348", | |
// "content-type": "application/json", | |
// "x-content-type-options": "nosniff", | |
// "date": "Sat, 21 Dec 2019 18:21:52 GMT", | |
// "content-length": "185", | |
// }, | |
// } | |
///``` | |
use openssl::x509::X509; | |
use reqwest; | |
#[tokio::main] | |
async fn main() -> Result<(), Box<dyn std::error::Error>> { | |
let pem = r#" | |
-----BEGIN CERTIFICATE----- | |
MIIDDDCCAfSgAwIBAgIRANMRvVXXaTbXyxpbqXtlgyEwDQYJKoZIhvcNAQELBQAw | |
LzEtMCsGA1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es())?; | |
let cert = reqwest::Certificate::from_der(&ca.to_der()?)?; | |
// dbg!(&ca.subject_name()); | |
// dbg!(&ca.subject_name()); | |
// dbg!(&cert); | |
let mut client_builder = reqwest::Client::builder(); | |
client_builder = client_builder | |
.add_root_certificate(cert) | |
// .danger_accept_invalid_certs(true) | |
; | |
let client = client_builder.build()?; | |
let resp = client.get("https://35.232.6.83").send().await?; | |
println!("{:#?}", resp); | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment