mirror of
https://github.com/tlsnotary/tlsn.git
synced 2026-01-09 14:48:13 -05:00
misc(notary): add common crate for server and client (#871)
* Add notary-common crate. * Add cargo lock changes. * Add copy. --------- Co-authored-by: yuroitaki <>
This commit is contained in:
11
Cargo.lock
generated
11
Cargo.lock
generated
@@ -4669,7 +4669,7 @@ dependencies = [
|
||||
"http-body-util",
|
||||
"hyper 1.6.0",
|
||||
"hyper-util",
|
||||
"notary-server",
|
||||
"notary-common",
|
||||
"serde_json",
|
||||
"thiserror 1.0.69",
|
||||
"tokio",
|
||||
@@ -4678,6 +4678,13 @@ dependencies = [
|
||||
"webpki-roots 0.26.11",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "notary-common"
|
||||
version = "0.1.0-alpha.11-pre"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "notary-server"
|
||||
version = "0.1.0-alpha.11-pre"
|
||||
@@ -4701,6 +4708,7 @@ dependencies = [
|
||||
"hyper-util",
|
||||
"k256",
|
||||
"mc-sgx-dcap-types",
|
||||
"notary-common",
|
||||
"notify",
|
||||
"p256",
|
||||
"pkcs8",
|
||||
@@ -4741,6 +4749,7 @@ dependencies = [
|
||||
"hyper-tls",
|
||||
"hyper-util",
|
||||
"notary-client",
|
||||
"notary-common",
|
||||
"notary-server",
|
||||
"rstest",
|
||||
"rustls 0.21.12",
|
||||
|
||||
@@ -15,6 +15,7 @@ members = [
|
||||
"crates/examples",
|
||||
"crates/formats",
|
||||
"crates/notary/client",
|
||||
"crates/notary/common",
|
||||
"crates/notary/server",
|
||||
"crates/notary/tests-integration",
|
||||
"crates/prover",
|
||||
@@ -45,6 +46,7 @@ opt-level = 1
|
||||
|
||||
[workspace.dependencies]
|
||||
notary-client = { path = "crates/notary/client" }
|
||||
notary-common = { path = "crates/notary/common" }
|
||||
notary-server = { path = "crates/notary/server" }
|
||||
tls-server-fixture = { path = "crates/tls/server-fixture" }
|
||||
tlsn-cipher = { path = "crates/components/cipher" }
|
||||
|
||||
@@ -7,7 +7,7 @@ edition = "2021"
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
notary-server = { workspace = true }
|
||||
notary-common = { workspace = true }
|
||||
|
||||
derive_builder = { workspace = true }
|
||||
futures = { workspace = true }
|
||||
|
||||
@@ -10,7 +10,7 @@ use hyper::{
|
||||
Request, Response, StatusCode,
|
||||
};
|
||||
use hyper_util::rt::TokioIo;
|
||||
use notary_server::{
|
||||
use notary_common::{
|
||||
ClientType, NotarizationSessionRequest, NotarizationSessionResponse, X_API_KEY_HEADER,
|
||||
};
|
||||
use std::{
|
||||
|
||||
11
crates/notary/common/Cargo.toml
Normal file
11
crates/notary/common/Cargo.toml
Normal file
@@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "notary-common"
|
||||
version = "0.1.0-alpha.11-pre"
|
||||
description = "Common code shared between notary-server and notary-client"
|
||||
edition = "2021"
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
serde = { workspace = true, features = ["derive"] }
|
||||
34
crates/notary/common/src/lib.rs
Normal file
34
crates/notary/common/src/lib.rs
Normal file
@@ -0,0 +1,34 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Custom HTTP header used for specifying a whitelisted API key.
|
||||
pub const X_API_KEY_HEADER: &str = "X-API-Key";
|
||||
|
||||
/// Types of client that the prover is using.
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub enum ClientType {
|
||||
/// Client that has access to the transport layer.
|
||||
Tcp,
|
||||
/// Client that cannot directly access the transport layer, e.g. browser
|
||||
/// extension.
|
||||
Websocket,
|
||||
}
|
||||
|
||||
/// Request object of the /session API.
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct NotarizationSessionRequest {
|
||||
pub client_type: ClientType,
|
||||
/// Maximum data that can be sent by the prover.
|
||||
pub max_sent_data: Option<usize>,
|
||||
/// Maximum data that can be received by the prover.
|
||||
pub max_recv_data: Option<usize>,
|
||||
}
|
||||
|
||||
/// Response object of the /session API.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct NotarizationSessionResponse {
|
||||
/// Unique session id that is generated by the notary and shared to the
|
||||
/// prover.
|
||||
pub session_id: String,
|
||||
}
|
||||
@@ -13,6 +13,7 @@ tee_quote = [
|
||||
]
|
||||
|
||||
[dependencies]
|
||||
notary-common = { workspace = true }
|
||||
tlsn-core = { workspace = true }
|
||||
tlsn-common = { workspace = true }
|
||||
tlsn-verifier = { workspace = true }
|
||||
|
||||
@@ -12,9 +12,6 @@ use tracing::{debug, error, info};
|
||||
|
||||
use crate::{util::parse_csv_file, NotaryServerProperties};
|
||||
|
||||
/// Custom HTTP header used for specifying a whitelisted API key
|
||||
pub const X_API_KEY_HEADER: &str = "X-API-Key";
|
||||
|
||||
/// Structure of each whitelisted record of the API key whitelist for
|
||||
/// authorization purpose
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
|
||||
@@ -12,7 +12,6 @@ mod tee;
|
||||
mod types;
|
||||
mod util;
|
||||
|
||||
pub use auth::X_API_KEY_HEADER;
|
||||
pub use cli::CliFields;
|
||||
pub use config::{
|
||||
AuthorizationProperties, LogProperties, NotarizationProperties, NotaryServerProperties,
|
||||
@@ -21,5 +20,4 @@ pub use config::{
|
||||
pub use error::NotaryServerError;
|
||||
pub use server::{read_pem_file, run_server};
|
||||
pub use server_tracing::init_tracing;
|
||||
pub use types::{ClientType, NotarizationSessionRequest, NotarizationSessionResponse};
|
||||
pub use util::parse_config_file;
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
use axum::http::request::Parts;
|
||||
use axum_core::extract::{FromRef, FromRequestParts};
|
||||
use notary_common::X_API_KEY_HEADER;
|
||||
use std::collections::HashMap;
|
||||
use tracing::{error, trace};
|
||||
|
||||
use crate::{
|
||||
auth::{AuthorizationWhitelistRecord, X_API_KEY_HEADER},
|
||||
types::NotaryGlobals,
|
||||
NotaryServerError,
|
||||
};
|
||||
use crate::{auth::AuthorizationWhitelistRecord, types::NotaryGlobals, NotaryServerError};
|
||||
|
||||
/// Auth middleware to prevent DOS
|
||||
pub struct AuthorizationMiddleware;
|
||||
|
||||
@@ -10,6 +10,7 @@ use axum::{
|
||||
};
|
||||
use axum_macros::debug_handler;
|
||||
use eyre::eyre;
|
||||
use notary_common::{NotarizationSessionRequest, NotarizationSessionResponse};
|
||||
use std::time::Duration;
|
||||
use tlsn_common::config::ProtocolConfigValidator;
|
||||
use tlsn_core::attestation::AttestationConfig;
|
||||
@@ -29,10 +30,7 @@ use crate::{
|
||||
tcp::{tcp_notarize, TcpUpgrade},
|
||||
websocket::websocket_notarize,
|
||||
},
|
||||
types::{
|
||||
NotarizationRequestQuery, NotarizationSessionRequest, NotarizationSessionResponse,
|
||||
NotaryGlobals,
|
||||
},
|
||||
types::{NotarizationRequestQuery, NotaryGlobals},
|
||||
};
|
||||
|
||||
/// A wrapper enum to facilitate extracting TCP connection for either WebSocket
|
||||
|
||||
@@ -25,25 +25,6 @@ pub struct InfoResponse {
|
||||
pub quote: Quote,
|
||||
}
|
||||
|
||||
/// Response object of the /session API
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct NotarizationSessionResponse {
|
||||
/// Unique session id that is generated by notary and shared to prover
|
||||
pub session_id: String,
|
||||
}
|
||||
|
||||
/// Request object of the /session API
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct NotarizationSessionRequest {
|
||||
pub client_type: ClientType,
|
||||
/// Maximum data that can be sent by the prover
|
||||
pub max_sent_data: Option<usize>,
|
||||
/// Maximum data that can be received by the prover
|
||||
pub max_recv_data: Option<usize>,
|
||||
}
|
||||
|
||||
/// Request query of the /notarize API
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
@@ -52,16 +33,6 @@ pub struct NotarizationRequestQuery {
|
||||
pub session_id: String,
|
||||
}
|
||||
|
||||
/// Types of client that the prover is using
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub enum ClientType {
|
||||
/// Client that has access to the transport layer
|
||||
Tcp,
|
||||
/// Client that cannot directly access transport layer, e.g. browser
|
||||
/// extension
|
||||
Websocket,
|
||||
}
|
||||
|
||||
/// Global data that needs to be shared with the axum handlers
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct NotaryGlobals {
|
||||
|
||||
@@ -9,6 +9,7 @@ workspace = true
|
||||
|
||||
[dev-dependencies]
|
||||
notary-client = { workspace = true }
|
||||
notary-common = { workspace = true }
|
||||
notary-server = { workspace = true }
|
||||
tls-server-fixture = { workspace = true }
|
||||
tlsn-common = { workspace = true }
|
||||
|
||||
@@ -10,6 +10,7 @@ use hyper_util::{
|
||||
rt::{TokioExecutor, TokioIo},
|
||||
};
|
||||
use notary_client::{Accepted, ClientError, NotarizationRequest, NotaryClient, NotaryConnection};
|
||||
use notary_common::{ClientType, NotarizationSessionRequest, NotarizationSessionResponse};
|
||||
use rstest::rstest;
|
||||
use rustls::{Certificate, RootCertStore};
|
||||
use std::{string::String, time::Duration};
|
||||
@@ -29,7 +30,7 @@ use ws_stream_tungstenite::WsStream;
|
||||
|
||||
use notary_server::{
|
||||
read_pem_file, run_server, AuthorizationProperties, NotarizationProperties,
|
||||
NotarizationSessionRequest, NotarizationSessionResponse, NotaryServerProperties, TLSProperties,
|
||||
NotaryServerProperties, TLSProperties,
|
||||
};
|
||||
|
||||
const MAX_SENT_DATA: usize = 1 << 13;
|
||||
@@ -301,7 +302,7 @@ async fn test_websocket_prover() {
|
||||
|
||||
// Build the HTTP request to configure notarization
|
||||
let payload = serde_json::to_string(&NotarizationSessionRequest {
|
||||
client_type: notary_server::ClientType::Websocket,
|
||||
client_type: ClientType::Websocket,
|
||||
max_sent_data: Some(MAX_SENT_DATA),
|
||||
max_recv_data: Some(MAX_RECV_DATA),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user