Skip to content

Commit 3a2c907

Browse files
committed
tmp
1 parent 21d417c commit 3a2c907

File tree

1 file changed

+41
-8
lines changed
  • tools/error-sink-service/src

1 file changed

+41
-8
lines changed

tools/error-sink-service/src/main.rs

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ const MINA_PUBLIC_KEY_LENGTH: usize = 44;
1717
// List of valid error report categories
1818
const VALID_CATEGORIES: [&str; 1] = ["blockProofFailure"];
1919

20+
// Context string for signature verification
21+
// const SIGNATURE_CONTEXT: &[u8] = b"OpenminaErrorReport";
22+
2023
#[derive(Clone)]
2124
struct ServerConfig {
2225
port: u16,
@@ -34,6 +37,24 @@ struct ErrorReport {
3437
signature: String, // Base64 encoded cryptographic signature
3538
}
3639

40+
fn verify_signature(
41+
public_key_bs58: &str,
42+
_message: &[u8],
43+
signature_b64: &str,
44+
) -> Result<bool, String> {
45+
if let Err(e) = bs58::decode(public_key_bs58).into_vec() {
46+
return Err(format!("Invalid public key encoding: {}", e));
47+
}
48+
49+
if let Err(e) = BASE64.decode(signature_b64) {
50+
return Err(format!("Invalid signature encoding: {}", e));
51+
}
52+
53+
// Stub implementation - always return true
54+
// TODO: Replace with actual signature verification
55+
Ok(true)
56+
}
57+
3758
/// Handles POST requests to the /error-report endpoint
3859
async fn handle_error_report(
3960
payload: web::Json<ErrorReport>,
@@ -80,18 +101,30 @@ async fn handle_error_report(
80101
})?;
81102

82103
if data.verify_signatures {
83-
let _sig_bytes = match BASE64.decode(&payload.signature) {
84-
Ok(bytes) => bytes,
104+
// Verify the signature using the submitter's public key and the data
105+
match verify_signature(&payload.submitter, &data_bytes, &payload.signature) {
106+
Ok(true) => {
107+
info!(
108+
"Signature verification successful for submitter: {}",
109+
payload.submitter
110+
);
111+
}
112+
Ok(false) => {
113+
error!(
114+
"Signature verification failed for submitter: {}",
115+
payload.submitter
116+
);
117+
return Err(actix_web::error::ErrorBadRequest(
118+
"Invalid signature: verification failed",
119+
));
120+
}
85121
Err(e) => {
86-
warn!("Invalid signature format: {}", e);
122+
error!("Signature verification error: {}", e);
87123
return Err(actix_web::error::ErrorBadRequest(
88-
"Invalid signature format",
124+
"Signature verification error",
89125
));
90126
}
91-
};
92-
93-
// TODO: verify signature here
94-
info!("Signature verification would occur here (not implemented yet)");
127+
}
95128
}
96129

97130
let mut file = File::create(&file_name).map_err(|e| {

0 commit comments

Comments
 (0)