Validation and Refactoring
This commit is contained in:
parent
d0221ba54a
commit
c0cf621ee0
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "tapir-cwtch"
|
name = "tapir-cwtch"
|
||||||
version = "0.1.9"
|
version = "0.1.10"
|
||||||
authors = ["Sarah Jamie Lewis <sarah@openprivacy.ca>"]
|
authors = ["Sarah Jamie Lewis <sarah@openprivacy.ca>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
#[cfg(any(feature = "onionv3"))]
|
|
||||||
pub mod tor;
|
pub mod tor;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
|
@ -9,6 +9,7 @@ use std::net::TcpStream;
|
||||||
pub mod authentication;
|
pub mod authentication;
|
||||||
pub mod run;
|
pub mod run;
|
||||||
pub mod torrc;
|
pub mod torrc;
|
||||||
|
pub mod validation;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct TorDisconnected(());
|
pub struct TorDisconnected(());
|
||||||
|
|
|
@ -1,6 +1,15 @@
|
||||||
use ed25519_dalek::PublicKey;
|
/// check if the given hostname is a valid onion v3 address
|
||||||
|
pub fn validate_hostname(hostname: &str) -> bool {
|
||||||
|
match base32::decode(base32::Alphabet::RFC4648 { padding: false }, hostname) {
|
||||||
|
Some(hostname_bytes) => hostname == public_key_to_hostname(&PublicKey::from_bytes(hostname_bytes.split_at(PUBLIC_KEY_LENGTH).0).unwrap_or_default()),
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
use ed25519_dalek::{PublicKey, PUBLIC_KEY_LENGTH};
|
||||||
use sha3::Digest;
|
use sha3::Digest;
|
||||||
|
|
||||||
|
/// convert the given public key to a tor onion v3 hostname
|
||||||
pub fn public_key_to_hostname(public_key: &PublicKey) -> String {
|
pub fn public_key_to_hostname(public_key: &PublicKey) -> String {
|
||||||
let mut buf = [0u8; 35];
|
let mut buf = [0u8; 35];
|
||||||
public_key.to_bytes().iter().copied().enumerate().for_each(|(i, b)| {
|
public_key.to_bytes().iter().copied().enumerate().for_each(|(i, b)| {
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::acns::tor::validation::public_key_to_hostname;
|
||||||
use crate::applications::authentication_app::AuthenticationAppError::NotAuthenticatedError;
|
use crate::applications::authentication_app::AuthenticationAppError::NotAuthenticatedError;
|
||||||
use crate::connections::utils::public_key_to_hostname;
|
|
||||||
use crate::connections::{Capability, Connection, ConnectionInterface, InboundConnection, OutboundConnection};
|
use crate::connections::{Capability, Connection, ConnectionInterface, InboundConnection, OutboundConnection};
|
||||||
use crate::primitives::identity::Identity;
|
use crate::primitives::identity::Identity;
|
||||||
use crate::primitives::transcript::Transcript;
|
use crate::primitives::transcript::Transcript;
|
||||||
|
|
|
@ -9,7 +9,6 @@ use std::net::{Shutdown, TcpStream};
|
||||||
/// Connections provides an interface for manage sets of connections on top of a particular
|
/// Connections provides an interface for manage sets of connections on top of a particular
|
||||||
/// ACN.
|
/// ACN.
|
||||||
pub mod service;
|
pub mod service;
|
||||||
pub mod utils;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum ServiceError {
|
pub enum ServiceError {
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
use crate::connections::utils::public_key_to_hostname;
|
|
||||||
use ed25519_dalek::{ExpandedSecretKey, Keypair, PublicKey, Signer};
|
use ed25519_dalek::{ExpandedSecretKey, Keypair, PublicKey, Signer};
|
||||||
use rand::rngs::OsRng;
|
use rand::rngs::OsRng;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
@ -7,6 +6,7 @@ use std::sync::Arc;
|
||||||
use x25519_dalek::PublicKey as X25519PublicKey;
|
use x25519_dalek::PublicKey as X25519PublicKey;
|
||||||
use x25519_dalek::{SharedSecret, StaticSecret};
|
use x25519_dalek::{SharedSecret, StaticSecret};
|
||||||
|
|
||||||
|
use crate::acns::tor::validation::public_key_to_hostname;
|
||||||
#[cfg(any(feature = "onionv3"))]
|
#[cfg(any(feature = "onionv3"))]
|
||||||
use crate::acns::tor::{TorAuthenticated, TorProcess};
|
use crate::acns::tor::{TorAuthenticated, TorProcess};
|
||||||
#[cfg(any(feature = "onionv3"))]
|
#[cfg(any(feature = "onionv3"))]
|
||||||
|
|
Loading…
Reference in New Issue