Try with rustls

trunk
Alona EM 2022-01-11 03:15:46 +00:00
parent 7791a63b1f
commit 98cc51d860
7 changed files with 119 additions and 18 deletions

10
Cargo.lock generated
View File

@ -302,6 +302,7 @@ dependencies = [
"anyhow",
"rustls 0.20.2",
"trust-dns-resolver",
"uuid",
"webpki-roots 0.22.2",
]
@ -740,6 +741,15 @@ dependencies = [
"percent-encoding",
]
[[package]]
name = "uuid"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7"
dependencies = [
"getrandom",
]
[[package]]
name = "wasi"
version = "0.10.2+wasi-snapshot-preview1"

View File

@ -9,6 +9,7 @@ edition = "2021"
anyhow = "1.0.52"
rustls = "0.20.2"
trust-dns-resolver = { version = "0.20.3", features = ["dns-over-rustls"] }
uuid = { version = "0.8.2", features = ["v4"] }
webpki-roots = "0.22.2"
[features]

BIN
cert.der Normal file

Binary file not shown.

34
cert.pem Normal file
View File

@ -0,0 +1,34 @@
-----BEGIN CERTIFICATE-----
MIIF2zCCA8OgAwIBAgIURpfIXSwLAPxhV6n+0+UjlOPY6O4wDQYJKoZIhvcNAQEL
BQAwfTELMAkGA1UEBhMCVVMxDTALBgNVBAgMBEZha2UxDTALBgNVBAcMBEZha2Ux
DTALBgNVBAoMBEZha2UxDTALBgNVBAsMBEZha2UxETAPBgNVBAMMCHRlc3Rjb3Nt
MR8wHQYJKoZIhvcNAQkBFhBmYWtlQGV4YW1wbGUuY29tMB4XDTIyMDExMDE5NTY1
NloXDTMyMDEwODE5NTY1NlowfTELMAkGA1UEBhMCVVMxDTALBgNVBAgMBEZha2Ux
DTALBgNVBAcMBEZha2UxDTALBgNVBAoMBEZha2UxDTALBgNVBAsMBEZha2UxETAP
BgNVBAMMCHRlc3Rjb3NtMR8wHQYJKoZIhvcNAQkBFhBmYWtlQGV4YW1wbGUuY29t
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgE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DfMu
ntGGSeDJ7keF6EwhsyuHYi1xrq0b3gRrUPewspxHsRCvXRlA9bSsEBeS6HyLPwq+
bPVNRWCIfUp38GrL9GkOQNc8rKmjBV6mTrYdSRNLOCHgP0AFoCGWRBZan1KXPlqG
8FJIVthjkShjiyXy7eoaQ3fb9+T1wzBQuUchziU2IEOL//vyA30aNvMn8C4XBOyD
NwYQS7zxRWFhgqYxr4umoQMVkeWhyO11em3ugMMN6sI43S9S2+Pnh8oSPTpGsfqD
lLikJHxjI9zueZdX68dHx/mfuIUo85gP1x6q4U/8GkI4NnxZSvETycsFBVLAgY79
IBWTqQyA9CiT3vIcCTNE6PXvOg5+t/6ooe+XfpdQKvZGhDuduLrGiK9MN7HMjEi1
ZTtrIiXu0coY4AXFT/6SQbb4ZaQ+97Oc49EYi+GYI9m5jNZU+loMT+0O9eyXOo/v
yPTFWAiof8wFX9XiL1Yb
-----END CERTIFICATE-----

BIN
cert.pfx Normal file

Binary file not shown.

52
key.pem Normal file
View File

@ -0,0 +1,52 @@
-----BEGIN PRIVATE KEY-----
MIIJQwIBADANBgkqhkiG9w0BAQEFAASCCS0wggkpAgEAAoICAQCk69I1cp+J5u5B
5d3+krMkcCvX6QS1pkne/WlCef3T69KGOxhQ3L2KfTBqD9Y588gwHA5UfrSvizf5
TiNn6zkRl2VG+Ehg9MzgVdVo+1fJs4xFYnJLj9lmPOca3GRiuWEWIjXMR0FdyB2P
wZvf8v2iiCd9q8MeV7HwOSi5CcV/S2DUQ5mNrpkqGjfzhT8ajchz1jsxng3P0oIU
g5PwFbCA9ERSCkbd9MdZEiHerposkoG6jHOYk0ZeCKbUeiwOrNxFnA8ypNGjKfLL
f8BVwBUApfYK7wX7IgjNqucU8F6EpP7JAn2Ib9uO+fpVJU3eLYkFiEETSE831d8I
VLoItU2M35Qc3BAiQ7zSUQD2X22DJtAq7HWXdW6GzBiTJSCmjaSkU5B93bklZCKc
+JjuFxO5ATgT53EpCTXpSoefhVawXG2p91IU8oZtUs/4cpZ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wLvbbcSfkCSA
dRBvC3mB11eETm9zFlzM3AsKgOjP1GAQFVnLuskMecF7bchTFq5YN/OwB534k04M
VrOqPRhAGDGI1GlD9rQcHjG6tCSL0NSfP4RYhFm4xfR9KVkMqUlvq0TFLwtzirPW
KIlbF9KLo1JRq6VPPeuRtuYUFoFTKfQQUIwUi0UMc3Pcsw7m8MIjkxnh8Zw7zJdx
lGGZAoIBABL4uQTpSEEybo7A2DufWxBTII6howGNBrE8iBYvr/dRv2vzJTNraTHB
cqJiAtTkKhL/2/46x4SizOGi5fCtvrSKCGhA8PFjiFYxKkot23SvWkZzaBRft25J
cVbt/44jDcIKbeLLmUJZ+eZEyU00PjTP1/1WxRLU1h4xmyjObW1Xp9W5vzlVEb7x
mp8tBI7pnFwC4OZd1rB1C3Y/OafwW4m1bp6t1wYQd6iS4DU6YCYfTWjySrDNLzMN
nZJkxHmcjfcFSajgG/rgPffxDIGMLEqLIgrRZvckmxXI52kkFIka3MIuXmb97Pfd
i+VOI1c9EUtr4NnRNVqcz8dqjoCdjSY=
-----END PRIVATE KEY-----

View File

@ -5,37 +5,33 @@ use std::{
sync::Arc,
};
use anyhow::{bail, Result};
use anyhow::{bail, Context, Result};
use rustls::{ClientConfig, ClientConnection, OwnedTrustAnchor, RootCertStore, StreamOwned};
use trust_dns_resolver::{
config::{ResolverConfig, ResolverOpts},
Resolver,
};
use uuid::Uuid;
fn main() -> Result<()> {
let (port, host) = resolve_dns("daeken.dev")?;
dbg!(port);
dbg!(host);
let (port, host) = (443, "example.com".to_owned());
dbg!(&port);
dbg!(&host);
let tls_conf = Arc::new(make_tls_config());
let mut tls_conn = make_tls_connection(tls_conf, &host, port)?;
let mut tls_conn = make_tls_connection(tls_conf, &host, port)
.with_context(|| format!("Can't connect to {}:{}", host, port))?;
tls_conn.write_all(
concat!(
"GET / HTTP/1.1\r\n",
"Host: example.com\r\n",
"Connection: close\r\n",
"\r\n"
)
.as_bytes(),
)?;
// let uuid =// Uuid::new_v4();
let mut pt = Vec::new();
tls_conn.read_to_end(&mut pt)?;
println!("{}", String::from_utf8(pt)?);
let uuid = [b'a'; 16];
dbg!(&uuid);
tls_conn.write_all(&uuid).context("Can't write UUID")?;
let mut serv_uuid = [0; 16];
tls_conn.read_exact(&mut serv_uuid)?;
dbg!(serv_uuid);
Ok(())
}
@ -76,6 +72,14 @@ fn make_tls_config() -> ClientConfig {
ta.name_constraints,
)
}));
let cert_dir = include_bytes!("../cert.der");
assert_eq!(
root_store.add_parsable_certificates(&[cert_dir.to_vec()]),
(1, 0)
);
let config = rustls::ClientConfig::builder()
.with_safe_defaults()
.with_root_certificates(root_store)