mirror of
https://github.com/tlsnotary/tlsn-plugin-boilerplate.git
synced 2026-01-08 20:38:05 -05:00
Review feedback
This commit is contained in:
@@ -8,7 +8,8 @@ edition = "2021"
|
|||||||
crate-type = ["cdylib"]
|
crate-type = ["cdylib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
anyhow = "1.0.89"
|
||||||
base64 = "0.22.1"
|
base64 = "0.22.1"
|
||||||
extism-pdk = "1.1.0"
|
extism-pdk = "1.1.0"
|
||||||
serde = { version = "1.0.197", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0.125"
|
serde_json = "1.0"
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
BSD 3-Clause License
|
|
||||||
|
|
||||||
Copyright (c) 2024, Extism
|
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
|
||||||
modification, are permitted provided that the following conditions are met:
|
|
||||||
|
|
||||||
1. Redistributions of source code must retain the above copyright notice, this
|
|
||||||
list of conditions and the following disclaimer.
|
|
||||||
|
|
||||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
this list of conditions and the following disclaimer in the documentation
|
|
||||||
and/or other materials provided with the distribution.
|
|
||||||
|
|
||||||
3. Neither the name of the copyright holder nor the names of its
|
|
||||||
contributors may be used to endorse or promote products derived from
|
|
||||||
this software without specific prior written permission.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
||||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
||||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
||||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
||||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
||||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
@@ -72,43 +72,36 @@ pub fn start() -> FnResult<Json<bool>> {
|
|||||||
|
|
||||||
#[plugin_fn]
|
#[plugin_fn]
|
||||||
pub fn two() -> FnResult<Json<Option<String>>> {
|
pub fn two() -> FnResult<Json<Option<String>>> {
|
||||||
let a = "oauth_access_token";
|
let cookies = get_cookies_by_host("www.fitbit.com")?;
|
||||||
match get_cookies_by_host("www.fitbit.com") {
|
log!(LogLevel::Info, "cookies: {cookies:?}");
|
||||||
Ok(cookies) => {
|
|
||||||
log!(LogLevel::Info, "cookies: {cookies:?}");
|
|
||||||
match cookies.get(a) {
|
|
||||||
Some(token) => {
|
|
||||||
log!(LogLevel::Info, "found token: {token:?}");
|
|
||||||
let bearer_header = format!("Bearer {}", token);
|
|
||||||
let headers: HashMap<&str, &str> = [
|
|
||||||
("authorization", bearer_header.as_str()),
|
|
||||||
("Accept-Encoding", "identity"),
|
|
||||||
("Connection", "close"),
|
|
||||||
]
|
|
||||||
.into_iter()
|
|
||||||
.collect();
|
|
||||||
let secret_headers = vec![bearer_header.as_str()];
|
|
||||||
let request = RequestConfig {
|
|
||||||
url: "https://web-api.fitbit.com/1/user/4G7WVQ/profile.json",
|
|
||||||
method: "GET",
|
|
||||||
headers,
|
|
||||||
secret_headers,
|
|
||||||
};
|
|
||||||
|
|
||||||
let request_json = serde_json::to_string(&request)?;
|
let token = cookies
|
||||||
log!(LogLevel::Info, "request: {:?}", &request_json);
|
.get("oauth_access_token")
|
||||||
let id = unsafe {
|
.ok_or_else(|| Error::msg("oauth_access_token not found"))?;
|
||||||
let id = notarize(&request_json);
|
log!(LogLevel::Info, "found token: {token:?}");
|
||||||
log!(LogLevel::Info, "Notarization result: {:?}", id);
|
let bearer_header = format!("Bearer {}", token);
|
||||||
id?
|
let headers: HashMap<&str, &str> = [
|
||||||
};
|
("authorization", bearer_header.as_str()),
|
||||||
|
("Accept-Encoding", "identity"),
|
||||||
|
("Connection", "close"),
|
||||||
|
]
|
||||||
|
.into_iter()
|
||||||
|
.collect();
|
||||||
|
let secret_headers = vec![bearer_header.as_str()];
|
||||||
|
let request = RequestConfig {
|
||||||
|
url: "https://web-api.fitbit.com/1/user/4G7WVQ/profile.json",
|
||||||
|
method: "GET",
|
||||||
|
headers,
|
||||||
|
secret_headers,
|
||||||
|
};
|
||||||
|
|
||||||
return Ok(Json(Some(id)));
|
let request_json = serde_json::to_string(&request)?;
|
||||||
}
|
log!(LogLevel::Info, "request: {:?}", &request_json);
|
||||||
_ => log!(LogLevel::Error, "TODO"),
|
let id = unsafe {
|
||||||
}
|
let id = notarize(&request_json);
|
||||||
}
|
log!(LogLevel::Info, "Notarization result: {:?}", id);
|
||||||
Err(err) => log!(LogLevel::Error, "{:?}", err),
|
id?
|
||||||
}
|
};
|
||||||
Ok(Json(None))
|
|
||||||
|
return Ok(Json(Some(id)));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,19 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use anyhow::Context;
|
||||||
use config::get;
|
use config::get;
|
||||||
use extism_pdk::*;
|
use extism_pdk::*;
|
||||||
|
|
||||||
pub fn get_cookies_by_host(hostname: &str) -> Result<HashMap<String, String>, String> {
|
pub fn get_cookies_by_host(hostname: &str) -> Result<HashMap<String, String>, Error> {
|
||||||
let cookies_result = get("cookies");
|
// Get Cookies via Extism
|
||||||
|
let cookies_json: String = get("cookies")?.context("No cookies found in the configuration.")?;
|
||||||
// Check if the cookies were retrieved successfully
|
|
||||||
let cookies_json = match cookies_result {
|
|
||||||
Ok(Some(json_str)) => json_str,
|
|
||||||
Ok(None) => return Err("No cookies found in the configuration.".to_string()),
|
|
||||||
Err(e) => return Err(format!("Error retrieving cookies: {}", e)),
|
|
||||||
};
|
|
||||||
|
|
||||||
// Parse the JSON string directly into a HashMap
|
// Parse the JSON string directly into a HashMap
|
||||||
let cookies: HashMap<String, HashMap<String, String>> =
|
let cookies: HashMap<String, HashMap<String, String>> = serde_json::from_str(&cookies_json)?;
|
||||||
serde_json::from_str(&cookies_json).map_err(|e| format!("Failed to parse JSON: {}", e))?;
|
|
||||||
|
|
||||||
// Attempt to find the hostname in the map
|
// Attempt to find the hostname in the map
|
||||||
if let Some(host_cookies) = cookies.get(hostname) {
|
cookies
|
||||||
Ok(host_cookies.clone())
|
.get(hostname)
|
||||||
} else {
|
.cloned()
|
||||||
Err(format!("Cannot find cookies for {}", hostname))
|
.context(format!("Cannot find cookies for {}", hostname))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
9
examples/fitbit-rs/testing.md
Normal file
9
examples/fitbit-rs/testing.md
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# Testing
|
||||||
|
|
||||||
|
1. start notary server (**TLS off** for local testing, check version!)
|
||||||
|
2. Start proxy server:
|
||||||
|
```
|
||||||
|
websocat --binary -v ws-l:0.0.0.0:55688 tcp:web-api.fitbit.com:443
|
||||||
|
```
|
||||||
|
3. `cargo build --release`
|
||||||
|
4. Load plugin in browser extension
|
||||||
Reference in New Issue
Block a user