send times to welist

ED25519 times signing
This commit is contained in:
2025-11-01 18:34:35 -04:00
parent d937ee9364
commit 7c8ed123aa
5 changed files with 91 additions and 49 deletions

View File

@@ -24,6 +24,7 @@ use reqwest::Client as rClient;
use openssl::hash::MessageDigest;
use openssl::pkey::{PKey};
use openssl::sign::Signer;
use openssl::sign::Verifier;
use base64::{engine::general_purpose, Engine as _};
use std::fs;
@@ -327,7 +328,7 @@ async fn send_stats_report(cfg: &MyConfig, bcinfo: GetBlockchainInfoResult) -> R
}))
.send().await?;
let body = &(response.text().await?);
println!("Body: {}", body);
trace!("Body: {}", body);
}else {
debug!("Not sending stats");
}
@@ -339,16 +340,14 @@ fn sign_message(private_key_path: &str, message: &str) -> String {
let key_data = fs::read(private_key_path).unwrap();
let private_key = PKey::private_key_from_pem(&key_data).unwrap();
let mut signer = Signer::new_without_digest(&private_key).unwrap();
let mut signer = Signer::new(MessageDigest::sha256(), &private_key).unwrap();
let signature = signer.sign_oneshot_to_vec(message.as_bytes()).unwrap();
signer.update(message.as_bytes()).unwrap();
let firma = signer.sign_to_vec().unwrap();
let signature_b64 = general_purpose::STANDARD.encode(&signature);
let firma_b64 = general_purpose::STANDARD.encode(&firma);
firma_b64
signature_b64
}
fn parse_env(cfg: &mut MyConfig){

View File

@@ -11,6 +11,7 @@ use std::net::IpAddr;
use std::env;
//use std::time::{SystemTime,UNIX_EPOCH};
use std::fs;
use std::sync::{ Arc, Mutex, MutexGuard };
//use std::net::SocketAddr;
use std::collections::HashMap;
@@ -48,26 +49,27 @@ struct NetConfig {
impl NetConfig {
fn default_network(name:String, network: Network) -> Self {
NetConfig {
address: "".to_string(),
fixed_fee: 50000,
xpub: false,
address: "".to_string(),
fixed_fee: 50000,
xpub: false,
name,
network,
enabled: false,
enabled: false,
}
}
}
#[derive(Debug, Serialize, Deserialize,Clone)]
struct MyConfig {
regtest: NetConfig,
signet: NetConfig,
testnet: NetConfig,
mainnet: NetConfig,
info: String,
bind_address: String,
bind_port: u16, // Changed to u16 for port numbers
db_file: String,
regtest: NetConfig,
signet: NetConfig,
testnet: NetConfig,
mainnet: NetConfig,
info: String,
bind_address: String,
bind_port: u16, // Changed to u16 for port numbers
db_file: String,
pub_key_path: String,
}
#[derive(Debug,Serialize, Deserialize)]
@@ -83,14 +85,15 @@ pub struct Info {
impl Default for MyConfig {
fn default() -> Self {
MyConfig {
regtest: NetConfig::default_network("regtest".to_string(), Network::Regtest),
signet: NetConfig::default_network("signet".to_string(), Network::Signet),
testnet: NetConfig::default_network("testnet".to_string(), Network::Testnet),
mainnet: NetConfig::default_network("bitcoin".to_string(), Network::Bitcoin),
bind_address: "127.0.0.1".to_string(),
bind_port: 9137,
db_file: "bal.db".to_string(),
info:"Will Executor Server".to_string()
regtest: NetConfig::default_network("regtest".to_string(), Network::Regtest),
signet: NetConfig::default_network("signet".to_string(), Network::Signet),
testnet: NetConfig::default_network("testnet".to_string(), Network::Testnet),
mainnet: NetConfig::default_network("bitcoin".to_string(), Network::Bitcoin),
bind_address: "127.0.0.1".to_string(),
bind_port: 9137,
db_file: "bal.db".to_string(),
info: "Will Executor Server".to_string(),
pub_key_path: "public_key.pem".to_string(),
}
}
}
@@ -109,6 +112,13 @@ async fn echo_version(
) -> Result<Response<BoxBody<Bytes, hyper::Error>>, hyper::Error> {
Ok(Response::new(full(VERSION)))
}
async fn echo_pub_key(
cfg: &MyConfig,
) -> Result<Response<BoxBody<Bytes, hyper::Error>>, hyper::Error> {
let pub_key = fs::read_to_string(&cfg.pub_key_path)
.expect(format!("Failed to read public key file {}",cfg.pub_key_path).as_str());
Ok(Response::new(full(pub_key)))
}
async fn echo_info(
param: &str,
cfg: &MyConfig,
@@ -441,6 +451,9 @@ async fn echo(
if uri=="/version"{
ret= echo_version().await;
}
if uri=="/.pub_key.pem" {
ret = echo_pub_key(cfg).await;
}
ret
}
@@ -479,6 +492,11 @@ fn parse_env(cfg: &Arc<Mutex<MyConfig>>){
cfg_lock.bind_port = v;
}
}
if let Ok(value) = env::var("BAL_SERVER_PUB_KEY_PATH") {
debug!("BAL_SERVER_PUB_KEY_PATH: {}",value);
cfg_lock.pub_key_path = value;
}
if let Ok(value) = env::var("BAL_SERVER_INFO"){