add current progress on verifying jwt signatures
This commit is contained in:
parent
3493fe534d
commit
200a19c276
@ -8,4 +8,5 @@ edition = "2021"
|
||||
[dependencies]
|
||||
base64 = "0.13.0"
|
||||
miniz_oxide = "0.5.1"
|
||||
serde_json = "1.0.78"
|
||||
serde_json = "1.0.78"
|
||||
reqwest = { version = "0.11", features = ["json","blocking"] }
|
91
src/main.rs
91
src/main.rs
@ -1,47 +1,76 @@
|
||||
use miniz_oxide::inflate::decompress_to_vec;
|
||||
use serde_json::json;
|
||||
|
||||
fn main() {
|
||||
let shc_file = std::fs::read_to_string("shc.txt")
|
||||
.expect("error opening file/file not found");
|
||||
|
||||
let base64_split = convert_to_base64(shc_file);
|
||||
|
||||
let jwt_compressed = decode_base64(base64_split.0[1].to_string());
|
||||
|
||||
let jwt = decompress(jwt_compressed);
|
||||
|
||||
let jwt: serde_json::Value = serde_json::from_str(&jwt).unwrap();
|
||||
println!("{}", serde_json::to_string_pretty(&jwt).unwrap());
|
||||
let shc_file = std::fs::read_to_string("shc.txt").expect("error opening file/file not found");
|
||||
|
||||
let base64_split = convert_to_base64(shc_file);
|
||||
|
||||
let jwt_value_compressed = decode_base64(base64_split.0[1].to_string());
|
||||
|
||||
let jwt_value = decompress(jwt_value_compressed);
|
||||
|
||||
let jwt_value: serde_json::Value = serde_json::from_str(&jwt_value).unwrap();
|
||||
|
||||
let jwt_header: serde_json::Value = serde_json::from_str(
|
||||
String::from_utf8(decode_base64(base64_split.0[0].to_string()))
|
||||
.unwrap()
|
||||
.as_str(),
|
||||
)
|
||||
.unwrap();
|
||||
let mut jsonwebkeyseturl: String = jwt_value["iss"].as_str().unwrap().to_string();
|
||||
jsonwebkeyseturl.push_str("/.well-known/jwks.json");
|
||||
|
||||
assert_eq!(jwt_header["alg"], json!("ES256"));
|
||||
|
||||
|
||||
// this is still wip
|
||||
//
|
||||
// need to find out how to verify the signatures but idk how to
|
||||
|
||||
/*
|
||||
let signing_keys: serde_json::Value = serde_json::from_str(reqwest::blocking::get(&jsonwebkeyseturl).unwrap().text().unwrap().as_str()).unwrap();
|
||||
|
||||
for x in signing_keys["keys"].as_array().unwrap()
|
||||
{
|
||||
if x["kid"] == jwt_header["kid"]
|
||||
{
|
||||
println!("{:#?}",x)
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// also did you know that you can pretty print json by using :# instead of the helper function
|
||||
//println!("{:#}", jwt_header);
|
||||
println!("{:#}", jwt_value);
|
||||
}
|
||||
|
||||
fn convert_to_base64(str: String) -> (Vec<String>, String) {
|
||||
let str = str.trim().as_bytes();
|
||||
let iter: Vec<char> = str
|
||||
let str = str.trim().as_bytes();
|
||||
let iter: Vec<char> = str
|
||||
.chunks(2)
|
||||
.into_iter()
|
||||
.map(|chunk| (String::from_utf8(chunk.to_vec()).unwrap().parse::<u8>().unwrap()+45) as char)
|
||||
.map(|chunk| {
|
||||
(String::from_utf8(chunk.to_vec())
|
||||
.unwrap()
|
||||
.parse::<u8>()
|
||||
.unwrap() + 45) as char
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let str = String::from_iter(iter);
|
||||
|
||||
(str.split(".").map(str::to_string).collect(), str)
|
||||
let str = String::from_iter(iter);
|
||||
|
||||
(str.split(".").map(str::to_string).collect(), str)
|
||||
}
|
||||
|
||||
|
||||
fn decode_base64(base64: String) -> Vec<u8> {
|
||||
let decoded = base64::decode_config(
|
||||
base64,
|
||||
base64::URL_SAFE_NO_PAD
|
||||
).expect("failed decoding base64");
|
||||
let decoded =
|
||||
base64::decode_config(base64, base64::URL_SAFE_NO_PAD).expect("failed decoding base64");
|
||||
|
||||
decoded
|
||||
decoded
|
||||
}
|
||||
|
||||
fn decompress(data: Vec<u8>) -> String {
|
||||
let decompressed = decompress_to_vec(
|
||||
data.as_slice()
|
||||
).expect("Failed to decompress!");
|
||||
|
||||
std::str::from_utf8(&decompressed)
|
||||
.unwrap()
|
||||
.to_string()
|
||||
}
|
||||
let decompressed = decompress_to_vec(data.as_slice()).expect("Failed to decompress!");
|
||||
|
||||
std::str::from_utf8(&decompressed).unwrap().to_string()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user