Validation and Refactoring

This commit is contained in:
Sarah Jamie Lewis 2021-01-13 21:18:44 -08:00
parent d0221ba54a
commit c0cf621ee0
7 changed files with 14 additions and 6 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "tapir-cwtch"
version = "0.1.9"
version = "0.1.10"
authors = ["Sarah Jamie Lewis <sarah@openprivacy.ca>"]
edition = "2018"
license = "MIT"

View File

@ -1,4 +1,3 @@
#[cfg(any(feature = "onionv3"))]
pub mod tor;
#[derive(Debug)]

View File

@ -9,6 +9,7 @@ use std::net::TcpStream;
pub mod authentication;
pub mod run;
pub mod torrc;
pub mod validation;
#[derive(Debug)]
pub struct TorDisconnected(());

View File

@ -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;
/// convert the given public key to a tor onion v3 hostname
pub fn public_key_to_hostname(public_key: &PublicKey) -> String {
let mut buf = [0u8; 35];
public_key.to_bytes().iter().copied().enumerate().for_each(|(i, b)| {

View File

@ -1,5 +1,5 @@
use crate::acns::tor::validation::public_key_to_hostname;
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::primitives::identity::Identity;
use crate::primitives::transcript::Transcript;

View File

@ -9,7 +9,6 @@ use std::net::{Shutdown, TcpStream};
/// Connections provides an interface for manage sets of connections on top of a particular
/// ACN.
pub mod service;
pub mod utils;
#[derive(Debug)]
pub enum ServiceError {

View File

@ -1,4 +1,3 @@
use crate::connections::utils::public_key_to_hostname;
use ed25519_dalek::{ExpandedSecretKey, Keypair, PublicKey, Signer};
use rand::rngs::OsRng;
use serde::{Deserialize, Serialize};
@ -7,6 +6,7 @@ use std::sync::Arc;
use x25519_dalek::PublicKey as X25519PublicKey;
use x25519_dalek::{SharedSecret, StaticSecret};
use crate::acns::tor::validation::public_key_to_hostname;
#[cfg(any(feature = "onionv3"))]
use crate::acns::tor::{TorAuthenticated, TorProcess};
#[cfg(any(feature = "onionv3"))]