mirror of
https://github.com/RustySamovar/RustySamovar.git
synced 2024-11-22 02:45:34 +00:00
Fix encryption and key deserialization. Signing still fails
This commit is contained in:
parent
69450ae7ea
commit
3e51d30b9b
@ -20,6 +20,7 @@ use actix_web::{rt::System, web, get, App, HttpRequest, HttpResponse, HttpServer
|
|||||||
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod, SslVerifyMode, SslOptions, SslMode};
|
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod, SslVerifyMode, SslOptions, SslMode};
|
||||||
use openssl::rsa::{Rsa, Padding};
|
use openssl::rsa::{Rsa, Padding};
|
||||||
use openssl::symm::Cipher;
|
use openssl::symm::Cipher;
|
||||||
|
use openssl::sha::Sha256;
|
||||||
use rand::{distributions::Alphanumeric, Rng};
|
use rand::{distributions::Alphanumeric, Rng};
|
||||||
|
|
||||||
use prost::Message;
|
use prost::Message;
|
||||||
@ -49,7 +50,7 @@ fn deserialize_pub_key<'de, D>(deserializer: D) -> Result<Rsa<Public>, D::Error>
|
|||||||
where
|
where
|
||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
{
|
{
|
||||||
let public_key_pem: &str = Deserialize::deserialize(deserializer)?;
|
let public_key_pem: String = Deserialize::deserialize(deserializer)?;
|
||||||
|
|
||||||
Rsa::public_key_from_pem(public_key_pem.as_bytes()).map_err(D::Error::custom)
|
Rsa::public_key_from_pem(public_key_pem.as_bytes()).map_err(D::Error::custom)
|
||||||
}
|
}
|
||||||
@ -58,7 +59,7 @@ fn deserialize_priv_key<'de, D>(deserializer: D) -> Result<Rsa<Private>, D::Erro
|
|||||||
where
|
where
|
||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
{
|
{
|
||||||
let private_key_pem: &str = Deserialize::deserialize(deserializer)?;
|
let private_key_pem: String = Deserialize::deserialize(deserializer)?;
|
||||||
|
|
||||||
Rsa::private_key_from_pem(private_key_pem.as_bytes()).map_err(D::Error::custom)
|
Rsa::private_key_from_pem(private_key_pem.as_bytes()).map_err(D::Error::custom)
|
||||||
}
|
}
|
||||||
@ -319,15 +320,15 @@ impl DispatchServer {
|
|||||||
let mut out_buf: Vec<u8> = Vec::new();
|
let mut out_buf: Vec<u8> = Vec::new();
|
||||||
let mut enc_buf: Vec<u8> = vec![0; keys.public_key.size() as usize];
|
let mut enc_buf: Vec<u8> = vec![0; keys.public_key.size() as usize];
|
||||||
|
|
||||||
for chunk in region_conf_buf.chunks(245) { // TODO: value hardcoded for the 2048-bit key!
|
for chunk in region_conf_buf.chunks((keys.public_key.size() - 11) as usize) { // TODO: value hardcoded for the PKCS1 v1.5!
|
||||||
keys.public_key.public_encrypt(chunk, &mut enc_buf, Padding::PKCS1).unwrap();
|
let len = keys.private_key.public_encrypt(chunk, &mut enc_buf, Padding::PKCS1).unwrap();
|
||||||
out_buf.append(&mut enc_buf);
|
out_buf.append(&mut enc_buf);
|
||||||
|
enc_buf.resize(keys.public_key.size() as usize, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
let keypair = PKey::from_rsa(keys.private_key.clone()).unwrap();
|
let keypair = PKey::from_rsa(keys.private_key.clone()).unwrap(); // TODO: this is not a correct private key!
|
||||||
let mut signer = Signer::new(MessageDigest::sha256(), &keypair).unwrap();
|
let mut signer = Signer::new(MessageDigest::sha256(), &keypair).unwrap();
|
||||||
signer.update(®ion_conf_buf).unwrap();
|
let signature = signer.sign_oneshot_to_vec(®ion_conf_buf).unwrap();
|
||||||
let signature = signer.sign_to_vec().unwrap();
|
|
||||||
|
|
||||||
return format!("
|
return format!("
|
||||||
{{
|
{{
|
||||||
|
Loading…
Reference in New Issue
Block a user