mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-20 09:03:28 +00:00
convert mtxchat to use tls.root_store()
a ureq::Agent is configured to use tls.root_store(), and used for all comms with the matrix server
This commit is contained in:
parent
c22419f7c7
commit
a06d84d8a9
4 changed files with 53 additions and 33 deletions
|
|
@ -36,8 +36,8 @@ percent-encoding = "2.2"
|
||||||
rkyv = {version = "0.4.3", default-features = false, features = ["const_generics"]}
|
rkyv = {version = "0.4.3", default-features = false, features = ["const_generics"]}
|
||||||
rustls = { version = "0.21.7" }
|
rustls = { version = "0.21.7" }
|
||||||
serde = { version = "1.0", features = [ "derive" ] }
|
serde = { version = "1.0", features = [ "derive" ] }
|
||||||
|
tls = { path = "../../libs/tls" }
|
||||||
|
|
||||||
ureq = { version = "2.7.1", features = ["json"] }
|
ureq = { version = "2.7.1", features = ["json"] }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,13 @@ use chat::{Chat, ChatOp};
|
||||||
use locales::t;
|
use locales::t;
|
||||||
use modals::Modals;
|
use modals::Modals;
|
||||||
use pddb::Pddb;
|
use pddb::Pddb;
|
||||||
|
use std::sync::Arc;
|
||||||
use std::fmt::Write as _;
|
use std::fmt::Write as _;
|
||||||
use std::io::{Error, ErrorKind, Read, Write as StdWrite};
|
use std::io::{Error, ErrorKind, Read, Write as StdWrite};
|
||||||
use std::time::{SystemTime, UNIX_EPOCH};
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
use tls::Tls;
|
||||||
use trng::*;
|
use trng::*;
|
||||||
|
use ureq::Agent;
|
||||||
use xous_ipc::Buffer;
|
use xous_ipc::Buffer;
|
||||||
|
|
||||||
/// PDDB Dict for mtxchat keys
|
/// PDDB Dict for mtxchat keys
|
||||||
|
|
@ -69,6 +72,7 @@ pub struct MtxChat<'a> {
|
||||||
user_id: String,
|
user_id: String,
|
||||||
user_name: String,
|
user_name: String,
|
||||||
user_domain: String,
|
user_domain: String,
|
||||||
|
agent: Agent,
|
||||||
token: String,
|
token: String,
|
||||||
logged_in: bool,
|
logged_in: bool,
|
||||||
room_id: String,
|
room_id: String,
|
||||||
|
|
@ -88,6 +92,7 @@ impl<'a> MtxChat<'a> {
|
||||||
let trng = Trng::new(&xns).unwrap();
|
let trng = Trng::new(&xns).unwrap();
|
||||||
let pddb = pddb::Pddb::new();
|
let pddb = pddb::Pddb::new();
|
||||||
pddb.try_mount();
|
pddb.try_mount();
|
||||||
|
let tls = Tls::new();
|
||||||
MtxChat {
|
MtxChat {
|
||||||
chat: chat,
|
chat: chat,
|
||||||
trng: trng,
|
trng: trng,
|
||||||
|
|
@ -96,6 +101,9 @@ impl<'a> MtxChat<'a> {
|
||||||
user_id: EMPTY.to_string(),
|
user_id: EMPTY.to_string(),
|
||||||
user_name: EMPTY.to_string(),
|
user_name: EMPTY.to_string(),
|
||||||
user_domain: DOMAIN_MATRIX.to_string(),
|
user_domain: DOMAIN_MATRIX.to_string(),
|
||||||
|
agent: ureq::builder()
|
||||||
|
.tls_config(Arc::new(tls.client_config()))
|
||||||
|
.build(),
|
||||||
token: EMPTY.to_string(),
|
token: EMPTY.to_string(),
|
||||||
logged_in: false,
|
logged_in: false,
|
||||||
room_id: EMPTY.to_string(),
|
room_id: EMPTY.to_string(),
|
||||||
|
|
@ -290,7 +298,7 @@ impl<'a> MtxChat<'a> {
|
||||||
)
|
)
|
||||||
.expect("failed to write server");
|
.expect("failed to write server");
|
||||||
if self.token.len() > 0 {
|
if self.token.len() > 0 {
|
||||||
if let Some(user_id) = web::whoami(&server, &self.token) {
|
if let Some(user_id) = web::whoami(&server, &self.token, &mut self.agent) {
|
||||||
let i = match user_id.find('@') {
|
let i = match user_id.find('@') {
|
||||||
Some(index) => index + 1,
|
Some(index) => index + 1,
|
||||||
None => 0,
|
None => 0,
|
||||||
|
|
@ -309,10 +317,10 @@ impl<'a> MtxChat<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !self.logged_in {
|
if !self.logged_in {
|
||||||
if web::get_login_type(&server) {
|
if web::get_login_type(&server, &mut self.agent) {
|
||||||
self.login_modal();
|
self.login_modal();
|
||||||
let password = self.get_or(PASSWORD_KEY, EMPTY);
|
let password = self.get_or(PASSWORD_KEY, EMPTY);
|
||||||
if let Some(new_token) = web::authenticate_user(&server, &self.user_id, &password) {
|
if let Some(new_token) = web::authenticate_user(&server, &self.user_id, &password, &mut self.agent) {
|
||||||
self.set_debug(TOKEN_KEY, &new_token);
|
self.set_debug(TOKEN_KEY, &new_token);
|
||||||
self.logged_in = true;
|
self.logged_in = true;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -403,7 +411,7 @@ impl<'a> MtxChat<'a> {
|
||||||
write!(room, "#{}:{}", &self.room_name, &self.room_domain).expect("failed to write room");
|
write!(room, "#{}:{}", &self.room_name, &self.room_domain).expect("failed to write room");
|
||||||
let mut server = String::new();
|
let mut server = String::new();
|
||||||
write!(server, "{}{}", HTTPS, &self.user_domain).expect("failed to write server");
|
write!(server, "{}{}", HTTPS, &self.user_domain).expect("failed to write server");
|
||||||
if let Some(room_id) = web::get_room_id(&server, &room, &self.token) {
|
if let Some(room_id) = web::get_room_id(&server, &room, &self.token, &mut self.agent) {
|
||||||
self.set_debug(ROOM_ID_KEY, &room_id);
|
self.set_debug(ROOM_ID_KEY, &room_id);
|
||||||
Some(room)
|
Some(room)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -480,7 +488,7 @@ impl<'a> MtxChat<'a> {
|
||||||
&self.token
|
&self.token
|
||||||
);
|
);
|
||||||
if let Some(new_filter) =
|
if let Some(new_filter) =
|
||||||
web::get_filter(&self.user_id, &server, &self.room_id, &self.token)
|
web::get_filter(&self.user_id, &server, &self.room_id, &self.token, &mut self.agent)
|
||||||
{
|
{
|
||||||
self.set_debug(FILTER_KEY, &new_filter);
|
self.set_debug(FILTER_KEY, &new_filter);
|
||||||
true
|
true
|
||||||
|
|
@ -519,6 +527,7 @@ impl<'a> MtxChat<'a> {
|
||||||
&self.get_or(ROOM_DOMAIN_KEY, DOMAIN_MATRIX)
|
&self.get_or(ROOM_DOMAIN_KEY, DOMAIN_MATRIX)
|
||||||
)
|
)
|
||||||
.expect("failed to write server");
|
.expect("failed to write server");
|
||||||
|
let mut agent = self.agent.clone();
|
||||||
let filter = self.filter.clone();
|
let filter = self.filter.clone();
|
||||||
let since = self.since.clone();
|
let since = self.since.clone();
|
||||||
let room_id = self.room_id.clone();
|
let room_id = self.room_id.clone();
|
||||||
|
|
@ -529,7 +538,7 @@ impl<'a> MtxChat<'a> {
|
||||||
let modals = Modals::new(&xns).expect("can't connect to Modals server");
|
let modals = Modals::new(&xns).expect("can't connect to Modals server");
|
||||||
log::info!("client_sync for {} ms...", MTX_LONG_TIMEOUT);
|
log::info!("client_sync for {} ms...", MTX_LONG_TIMEOUT);
|
||||||
if let Some((_since, events)) =
|
if let Some((_since, events)) =
|
||||||
web::client_sync(&server, &filter, &since, MTX_LONG_TIMEOUT, &room_id, &token)
|
web::client_sync(&server, &filter, &since, MTX_LONG_TIMEOUT, &room_id, &token, &mut agent)
|
||||||
{
|
{
|
||||||
// TODO send "since" to mtxchat server
|
// TODO send "since" to mtxchat server
|
||||||
// and you probably want to have a look at Dialogue::MAX_BYTES
|
// and you probably want to have a look at Dialogue::MAX_BYTES
|
||||||
|
|
@ -607,7 +616,7 @@ impl<'a> MtxChat<'a> {
|
||||||
log::info!("txn_id = {}", txn_id);
|
log::info!("txn_id = {}", txn_id);
|
||||||
let mut server = String::new();
|
let mut server = String::new();
|
||||||
write!(server, "{}{}", HTTPS, &self.user_domain).expect("failed to write server");
|
write!(server, "{}{}", HTTPS, &self.user_domain).expect("failed to write server");
|
||||||
if web::send_message(&server, &self.room_id, &text, &txn_id, &self.token) {
|
if web::send_message(&server, &self.room_id, &text, &txn_id, &self.token, &mut self.agent) {
|
||||||
log::info!("SENT: {}", text);
|
log::info!("SENT: {}", text);
|
||||||
} else {
|
} else {
|
||||||
log::info!("FAILED TO SEND");
|
log::info!("FAILED TO SEND");
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use ureq;
|
use ureq::Agent;
|
||||||
use ureq::serde_json::{Map, Value};
|
use ureq::serde_json::{Map, Value};
|
||||||
|
|
||||||
use crate::{url, Msg};
|
use crate::{url, Msg};
|
||||||
|
|
@ -58,21 +58,21 @@ pub fn handle_response(maybe_response: Result<ureq::Response, ureq::Error>) -> O
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_json(url: &str) -> Result<ureq::Response, ureq::Error> {
|
pub fn get_json(url: &str, agent: &mut Agent) -> Result<ureq::Response, ureq::Error> {
|
||||||
ureq::get(&url).set(ACCEPT, ACCEPT_JSON).call()
|
agent.get(&url).set(ACCEPT, ACCEPT_JSON).call()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_json_auth(url: &str, token: &str) -> Result<ureq::Response, ureq::Error> {
|
pub fn get_json_auth(url: &str, token: &str, agent: &mut Agent) -> Result<ureq::Response, ureq::Error> {
|
||||||
let mut authorization = String::from(BEARER);
|
let mut authorization = String::from(BEARER);
|
||||||
authorization.push_str(token);
|
authorization.push_str(token);
|
||||||
ureq::get(&url)
|
agent.get(&url)
|
||||||
.set(ACCEPT, ACCEPT_JSON)
|
.set(ACCEPT, ACCEPT_JSON)
|
||||||
.set(AUTHORIZATION, &authorization)
|
.set(AUTHORIZATION, &authorization)
|
||||||
.call()
|
.call()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn post_string(url: &str, request_body: &str) -> Result<ureq::Response, ureq::Error> {
|
pub fn post_string(url: &str, request_body: &str, agent: &mut Agent) -> Result<ureq::Response, ureq::Error> {
|
||||||
ureq::post(&url)
|
agent.post(&url)
|
||||||
.set(ACCEPT, ACCEPT_JSON)
|
.set(ACCEPT, ACCEPT_JSON)
|
||||||
.send_string(request_body)
|
.send_string(request_body)
|
||||||
}
|
}
|
||||||
|
|
@ -81,10 +81,11 @@ pub fn post_string_auth(
|
||||||
url: &str,
|
url: &str,
|
||||||
request_body: &str,
|
request_body: &str,
|
||||||
token: &str,
|
token: &str,
|
||||||
|
agent: &mut Agent,
|
||||||
) -> Result<ureq::Response, ureq::Error> {
|
) -> Result<ureq::Response, ureq::Error> {
|
||||||
let mut authorization = String::from(BEARER);
|
let mut authorization = String::from(BEARER);
|
||||||
authorization.push_str(token);
|
authorization.push_str(token);
|
||||||
ureq::post(&url)
|
agent.post(&url)
|
||||||
.set(ACCEPT, ACCEPT_JSON)
|
.set(ACCEPT, ACCEPT_JSON)
|
||||||
.set(AUTHORIZATION, &authorization)
|
.set(AUTHORIZATION, &authorization)
|
||||||
.send_string(request_body)
|
.send_string(request_body)
|
||||||
|
|
@ -94,10 +95,11 @@ pub fn put_string_auth(
|
||||||
url: &str,
|
url: &str,
|
||||||
request_body: &str,
|
request_body: &str,
|
||||||
token: &str,
|
token: &str,
|
||||||
|
agent: &mut Agent,
|
||||||
) -> Result<ureq::Response, ureq::Error> {
|
) -> Result<ureq::Response, ureq::Error> {
|
||||||
let mut authorization = String::from(BEARER);
|
let mut authorization = String::from(BEARER);
|
||||||
authorization.push_str(token);
|
authorization.push_str(token);
|
||||||
ureq::put(&url)
|
agent.put(&url)
|
||||||
.set(ACCEPT, ACCEPT_JSON)
|
.set(ACCEPT, ACCEPT_JSON)
|
||||||
.set(AUTHORIZATION, &authorization)
|
.set(AUTHORIZATION, &authorization)
|
||||||
.send_string(request_body)
|
.send_string(request_body)
|
||||||
|
|
@ -105,10 +107,10 @@ pub fn put_string_auth(
|
||||||
|
|
||||||
// --------------------------------
|
// --------------------------------
|
||||||
|
|
||||||
pub fn whoami(server: &str, token: &str) -> Option<String> {
|
pub fn whoami(server: &str, token: &str, agent: &mut Agent) -> Option<String> {
|
||||||
let mut url = String::from(server);
|
let mut url = String::from(server);
|
||||||
url.push_str("/_matrix/client/r0/account/whoami");
|
url.push_str("/_matrix/client/r0/account/whoami");
|
||||||
if let Some(value) = handle_response(get_json_auth(&url, token)) {
|
if let Some(value) = handle_response(get_json_auth(&url, token, agent)) {
|
||||||
if let Value::Object(body) = value {
|
if let Value::Object(body) = value {
|
||||||
if let Some(Value::String(device_id)) = body.get("device_id") {
|
if let Some(Value::String(device_id)) = body.get("device_id") {
|
||||||
log::info!("device_id = {}", device_id);
|
log::info!("device_id = {}", device_id);
|
||||||
|
|
@ -122,11 +124,11 @@ pub fn whoami(server: &str, token: &str) -> Option<String> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_login_type(server: &str) -> bool {
|
pub fn get_login_type(server: &str, agent: &mut Agent) -> bool {
|
||||||
let mut url = String::from(server);
|
let mut url = String::from(server);
|
||||||
url.push_str("/_matrix/client/r0/login");
|
url.push_str("/_matrix/client/r0/login");
|
||||||
let mut found = false;
|
let mut found = false;
|
||||||
if let Some(value) = handle_response(get_json(&url)) {
|
if let Some(value) = handle_response(get_json(&url, agent)) {
|
||||||
if let Value::Object(body) = value {
|
if let Value::Object(body) = value {
|
||||||
if let Some(Value::Array(flows)) = body.get("flows") {
|
if let Some(Value::Array(flows)) = body.get("flows") {
|
||||||
for flow in flows.iter() {
|
for flow in flows.iter() {
|
||||||
|
|
@ -173,13 +175,13 @@ impl AuthRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
// fn authenticate_user() -> Result<String, ureq::Error> {
|
// fn authenticate_user() -> Result<String, ureq::Error> {
|
||||||
pub fn authenticate_user(server: &str, user: &str, password: &str) -> Option<String> {
|
pub fn authenticate_user(server: &str, user: &str, password: &str, agent: &mut Agent) -> Option<String> {
|
||||||
let mut maybe_token: Option<String> = None;
|
let mut maybe_token: Option<String> = None;
|
||||||
let mut url = String::from(server);
|
let mut url = String::from(server);
|
||||||
url.push_str("/_matrix/client/r0/login");
|
url.push_str("/_matrix/client/r0/login");
|
||||||
let auth_request = AuthRequest::new(user, password);
|
let auth_request = AuthRequest::new(user, password);
|
||||||
if let Some(request_body) = serialize(&auth_request) {
|
if let Some(request_body) = serialize(&auth_request) {
|
||||||
if let Some(value) = handle_response(post_string(&url, &request_body)) {
|
if let Some(value) = handle_response(post_string(&url, &request_body, agent)) {
|
||||||
if let Value::Object(body) = value {
|
if let Value::Object(body) = value {
|
||||||
if let Some(Value::String(access_token)) = body.get("access_token") {
|
if let Some(Value::String(access_token)) = body.get("access_token") {
|
||||||
maybe_token = Some(access_token.to_string())
|
maybe_token = Some(access_token.to_string())
|
||||||
|
|
@ -190,13 +192,13 @@ pub fn authenticate_user(server: &str, user: &str, password: &str) -> Option<Str
|
||||||
maybe_token
|
maybe_token
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_room_id(server: &str, room_server: &str, token: &str) -> Option<String> {
|
pub fn get_room_id(server: &str, room_server: &str, token: &str, agent: &mut Agent) -> Option<String> {
|
||||||
let room_encoded = url::encode(room_server);
|
let room_encoded = url::encode(room_server);
|
||||||
let mut url = String::from(server);
|
let mut url = String::from(server);
|
||||||
url.push_str("/_matrix/client/v3/directory/room/");
|
url.push_str("/_matrix/client/v3/directory/room/");
|
||||||
url.push_str(&room_encoded);
|
url.push_str(&room_encoded);
|
||||||
log::info!("get_room_id = {}", url);
|
log::info!("get_room_id = {}", url);
|
||||||
if let Some(value) = handle_response(get_json_auth(&url, token)) {
|
if let Some(value) = handle_response(get_json_auth(&url, token, agent)) {
|
||||||
if let Value::Object(body) = value {
|
if let Value::Object(body) = value {
|
||||||
if let Some(Value::String(room_id)) = body.get("room_id") {
|
if let Some(Value::String(room_id)) = body.get("room_id") {
|
||||||
Some(room_id.to_string())
|
Some(room_id.to_string())
|
||||||
|
|
@ -303,7 +305,7 @@ impl FilterRequest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_filter(user: &str, server: &str, room_id: &str, token: &str) -> Option<String> {
|
pub fn get_filter(user: &str, server: &str, room_id: &str, token: &str, agent: &mut Agent) -> Option<String> {
|
||||||
let user_encoded = url::encode(user);
|
let user_encoded = url::encode(user);
|
||||||
let mut url = String::from(server);
|
let mut url = String::from(server);
|
||||||
url.push_str("/_matrix/client/v3/user/");
|
url.push_str("/_matrix/client/v3/user/");
|
||||||
|
|
@ -312,7 +314,7 @@ pub fn get_filter(user: &str, server: &str, room_id: &str, token: &str) -> Optio
|
||||||
log::info!("get_filter = {}", url);
|
log::info!("get_filter = {}", url);
|
||||||
let filter_request = FilterRequest::new(room_id);
|
let filter_request = FilterRequest::new(room_id);
|
||||||
if let Some(request_body) = serialize(&filter_request) {
|
if let Some(request_body) = serialize(&filter_request) {
|
||||||
if let Some(value) = handle_response(post_string_auth(&url, &request_body, token)) {
|
if let Some(value) = handle_response(post_string_auth(&url, &request_body, token, agent)) {
|
||||||
if let Value::Object(body) = value {
|
if let Value::Object(body) = value {
|
||||||
if let Some(Value::String(filter_id)) = body.get("filter_id") {
|
if let Some(Value::String(filter_id)) = body.get("filter_id") {
|
||||||
log::info!("filter_id = {}", filter_id);
|
log::info!("filter_id = {}", filter_id);
|
||||||
|
|
@ -377,6 +379,7 @@ pub fn client_sync(
|
||||||
timeout: i32,
|
timeout: i32,
|
||||||
room_id: &str,
|
room_id: &str,
|
||||||
token: &str,
|
token: &str,
|
||||||
|
agent: &mut Agent,
|
||||||
) -> Option<(String, Vec<Msg>)> {
|
) -> Option<(String, Vec<Msg>)> {
|
||||||
log::info!("heap usage: {}", crate::heap_usage());
|
log::info!("heap usage: {}", crate::heap_usage());
|
||||||
let mut url = String::from(server);
|
let mut url = String::from(server);
|
||||||
|
|
@ -389,7 +392,7 @@ pub fn client_sync(
|
||||||
url.push_str(since);
|
url.push_str(since);
|
||||||
}
|
}
|
||||||
log::info!("client_sync = {}", url);
|
log::info!("client_sync = {}", url);
|
||||||
if let Some(value) = handle_response(get_json_auth(&url, token)) {
|
if let Some(value) = handle_response(get_json_auth(&url, token, agent)) {
|
||||||
if let Value::Object(body) = value {
|
if let Value::Object(body) = value {
|
||||||
if let Some(Value::String(next_batch)) = body.get("next_batch") {
|
if let Some(Value::String(next_batch)) = body.get("next_batch") {
|
||||||
Some((next_batch.to_string(), get_messages(body, room_id)))
|
Some((next_batch.to_string(), get_messages(body, room_id)))
|
||||||
|
|
@ -420,7 +423,7 @@ impl MessageRequest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn send_message(server: &str, room_id: &str, text: &str, txn_id: &str, token: &str) -> bool {
|
pub fn send_message(server: &str, room_id: &str, text: &str, txn_id: &str, token: &str, agent: &mut Agent) -> bool {
|
||||||
log::info!("heap usage: {}", crate::heap_usage());
|
log::info!("heap usage: {}", crate::heap_usage());
|
||||||
let room_id_encoded = url::encode(room_id);
|
let room_id_encoded = url::encode(room_id);
|
||||||
let mut url = String::from(server);
|
let mut url = String::from(server);
|
||||||
|
|
@ -431,7 +434,7 @@ pub fn send_message(server: &str, room_id: &str, text: &str, txn_id: &str, token
|
||||||
log::info!("send_message = {}", url);
|
log::info!("send_message = {}", url);
|
||||||
let message_request = MessageRequest::new(text);
|
let message_request = MessageRequest::new(text);
|
||||||
if let Some(request_body) = serialize(&message_request) {
|
if let Some(request_body) = serialize(&message_request) {
|
||||||
if let Some(value) = handle_response(put_string_auth(&url, &request_body, token)) {
|
if let Some(value) = handle_response(put_string_auth(&url, &request_body, token, agent)) {
|
||||||
if let Value::Object(_body) = value {
|
if let Value::Object(_body) = value {
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ use rkyv::{
|
||||||
ser::{serializers::WriteSerializer, Serializer},
|
ser::{serializers::WriteSerializer, Serializer},
|
||||||
Deserialize,
|
Deserialize,
|
||||||
};
|
};
|
||||||
use rustls::{Certificate, RootCertStore};
|
use rustls::{Certificate, ClientConfig, RootCertStore};
|
||||||
use sha2::Digest;
|
use sha2::Digest;
|
||||||
use std::convert::{Into, TryFrom};
|
use std::convert::{Into, TryFrom};
|
||||||
use std::io::{Error, Read, Write};
|
use std::io::{Error, Read, Write};
|
||||||
|
|
@ -199,7 +199,8 @@ impl Tls {
|
||||||
rkyv::archived_value::<RustlsOwnedTrustAnchor>(&bytes, pos)
|
rkyv::archived_value::<RustlsOwnedTrustAnchor>(&bytes, pos)
|
||||||
};
|
};
|
||||||
let ta = archive.deserialize(&mut AllocDeserializer {}).ok();
|
let ta = archive.deserialize(&mut AllocDeserializer {}).ok();
|
||||||
log::info!("get '{}' = '{:?}'", key, &ta);
|
log::info!("get {}", key);
|
||||||
|
log::trace!("get '{}' = '{:?}'", key, &ta);
|
||||||
ta
|
ta
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
|
@ -244,6 +245,13 @@ impl Tls {
|
||||||
}
|
}
|
||||||
root_store
|
root_store
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn client_config(&self) -> ClientConfig {
|
||||||
|
rustls::ClientConfig::builder()
|
||||||
|
.with_safe_defaults()
|
||||||
|
.with_root_certificates(self.root_store())
|
||||||
|
.with_no_client_auth()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://stackoverflow.com/questions/57029974/how-to-split-string-into-chunks-in-rust-to-insert-spaces
|
// https://stackoverflow.com/questions/57029974/how-to-split-string-into-chunks-in-rust-to-insert-spaces
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue