Setup Serialization/Deserialization for Identity
This commit is contained in:
parent
a29c662221
commit
629cca918e
|
@ -15,17 +15,17 @@ name = "simple_setup"
|
|||
rand = "0.7.3"
|
||||
curve25519-dalek = "3.0.0"
|
||||
x25519-dalek = "1.1"
|
||||
ed25519-dalek = "1.0.1"
|
||||
ed25519-dalek = {version = "1.0.1", features=["serde"]}
|
||||
merlin = "2.0.0"
|
||||
hex = "0.4.2"
|
||||
base32 = "0.4.0"
|
||||
base64 = "0.13.0"
|
||||
sha3 = "0.9.1"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0.59"
|
||||
serde_json = "1.0.61"
|
||||
byteorder = "1.3.4"
|
||||
socks = "0.3.3"
|
||||
integer-encoding = "2.1.1"
|
||||
secretbox = "0.1.2"
|
||||
subtle = "2.3.0"
|
||||
hashbrown = "0.9.1"
|
||||
hashbrown = "0.9.1"
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
use crate::connections::utils::public_key_to_hostname;
|
||||
use ed25519_dalek::{ExpandedSecretKey, Keypair, PublicKey};
|
||||
use rand::rngs::OsRng;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::intrinsics::transmute;
|
||||
use std::sync::Arc;
|
||||
use x25519_dalek::PublicKey as X25519PublicKey;
|
||||
use x25519_dalek::{SharedSecret, StaticSecret};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
/// Identity - An ed25519 keypair, required for established a Tor v3 onion service and used to
|
||||
/// maintain a consistent cryptographic identity for a peer.
|
||||
pub struct Identity {
|
||||
|
@ -21,7 +23,7 @@ impl Identity {
|
|||
/// Initialize an ephemeral identity - used for both ephemeral diffie hellman key exchanges
|
||||
/// in addition to anonymous primitives connections to various onion services.
|
||||
pub fn initialize_ephemeral_identity() -> Identity {
|
||||
let mut csprng = OsRng {};
|
||||
let mut csprng = OsRng::default();
|
||||
let keypair = ed25519_dalek::Keypair::generate(&mut csprng);
|
||||
Identity { keypair }
|
||||
}
|
||||
|
@ -58,6 +60,7 @@ impl Identity {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::primitives::identity::Identity;
|
||||
use ed25519_dalek::Signer;
|
||||
|
||||
#[test]
|
||||
fn test_identity() {
|
||||
|
@ -68,4 +71,22 @@ mod tests {
|
|||
println!("Alice Shared Secret: {} {:?}", alice.hostname(), alice.edh(bob.keypair.public).to_bytes());
|
||||
println!("Bob Shared Secret: {} {:?}", bob.hostname(), bob.edh(alice.keypair.public).to_bytes());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_serialize() {
|
||||
// Create an emphemeral identity
|
||||
let alice = Identity::initialize_ephemeral_identity();
|
||||
|
||||
// Serialize
|
||||
let json = serde_json::to_string(&alice).unwrap();
|
||||
println!("{}", json);
|
||||
|
||||
// Deserialize
|
||||
let deserialized: Identity = serde_json::from_str(&json).unwrap();
|
||||
println!("deserialized = {:?}", deserialized);
|
||||
|
||||
// Check that we can sign something with the deserialized key and check it with the original
|
||||
let sig = deserialized.keypair.sign("message".as_bytes());
|
||||
assert_eq!(true, alice.keypair.public.verify_strict("message".as_bytes(), &sig).is_ok());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ mod test {
|
|||
use tapir_cwtch::connections::{Connection, InboundConnection, OutboundConnection};
|
||||
use tapir_cwtch::primitives::transcript::Transcript;
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_simple_setup() {
|
||||
let mut auth_control_port = TorProcess::connect(9051)
|
||||
|
|
Loading…
Reference in New Issue