From 9edc5710d66a2af7bd6818dd6a4db96dda1d04ea Mon Sep 17 00:00:00 2001 From: webwarrior Date: Mon, 5 Jun 2023 14:20:15 +0200 Subject: [PATCH] NOnion: minor refactoring Renamed IdentityKey type to Fingerprint as technically this is the digest of identity key. --- NOnion.Tests/CircuitHelper.cs | 2 +- NOnion.Tests/TorDirectoryTests.cs | 2 +- NOnion/Directory/TorDirectory.fs | 2 +- NOnion/KeyTypes.fs | 3 ++- NOnion/Network/TorCircuit.fs | 2 +- NOnion/Network/TorGuard.fs | 4 ++-- NOnion/Services/TorServiceClient.fs | 2 +- NOnion/Services/TorServiceHost.fs | 4 ++-- NOnion/TorHandshakes/NTorHandshake.fs | 4 ++-- 9 files changed, 13 insertions(+), 12 deletions(-) diff --git a/NOnion.Tests/CircuitHelper.cs b/NOnion.Tests/CircuitHelper.cs index e2cfe38e..251eda3f 100644 --- a/NOnion.Tests/CircuitHelper.cs +++ b/NOnion.Tests/CircuitHelper.cs @@ -25,7 +25,7 @@ static private CircuitNodeDetail ConvertToCircuitNodeDetail(ServerDescriptorEntr var endpoint = IPEndPoint.Parse($"{server.Address.Value}:{server.OnionRouterPort.Value}"); return CircuitNodeDetail.NewCreate(endpoint, new NTorOnionKey(nTorOnionKeyBytes), - new IdentityKey(fingerprintBytes)); + new Fingerprint(fingerprintBytes)); } /* It's possible that the router returned by GetRandomFallbackDirectory diff --git a/NOnion.Tests/TorDirectoryTests.cs b/NOnion.Tests/TorDirectoryTests.cs index c4256059..8be3c1ad 100644 --- a/NOnion.Tests/TorDirectoryTests.cs +++ b/NOnion.Tests/TorDirectoryTests.cs @@ -56,7 +56,7 @@ private async Task ReturnRandomRouter() TorDirectory directory = await TorDirectory.BootstrapAsync(FallbackDirectorySelector.GetRandomFallbackDirectory(), cachePath); var (endPoint, router) = await directory.GetRouterAsync(RouterType.Normal); Assert.IsTrue(router.IsCreate); - Assert.IsFalse(((CircuitNodeDetail.Create)router).IdentityKey.ToByteArray().All(x => x == 0)); + Assert.IsFalse(((CircuitNodeDetail.Create)router).Fingerprint.ToByteArray().All(x => x == 0)); Assert.IsFalse(((CircuitNodeDetail.Create)router).NTorOnionKey.ToByteArray().All(x => x == 0)); Assert.IsNotNull(((CircuitNodeDetail.Create)router).EndPoint); Assert.That(endPoint, Is.EqualTo(((CircuitNodeDetail.Create)router).EndPoint)); diff --git a/NOnion/Directory/TorDirectory.fs b/NOnion/Directory/TorDirectory.fs index 4286762e..7edd56dd 100644 --- a/NOnion/Directory/TorDirectory.fs +++ b/NOnion/Directory/TorDirectory.fs @@ -277,7 +277,7 @@ type TorDirectory = CircuitNodeDetail.Create( endpoint, NTorOnionKey nTorOnionKeyBytes, - IdentityKey fingerprintBytes + Fingerprint fingerprintBytes ) } diff --git a/NOnion/KeyTypes.fs b/NOnion/KeyTypes.fs index f58f50a3..06aa4a6e 100644 --- a/NOnion/KeyTypes.fs +++ b/NOnion/KeyTypes.fs @@ -57,7 +57,8 @@ type NTorOnionKey(bytes: array) = member self.ToByteArray() = bytes -type IdentityKey(bytes: array) = +/// Digest of identity key. +type Fingerprint(bytes: array) = do if bytes.Length <> Constants.IdentityKeyLength then failwithf diff --git a/NOnion/Network/TorCircuit.fs b/NOnion/Network/TorCircuit.fs index fc50c1ba..6e4672d7 100644 --- a/NOnion/Network/TorCircuit.fs +++ b/NOnion/Network/TorCircuit.fs @@ -26,7 +26,7 @@ type CircuitNodeDetail = | Create of EndPoint: IPEndPoint * NTorOnionKey: NTorOnionKey * - IdentityKey: IdentityKey + Fingerprint: Fingerprint member self.GetIdentityKey() = match self with diff --git a/NOnion/Network/TorGuard.fs b/NOnion/Network/TorGuard.fs index a02b0185..0c215daf 100644 --- a/NOnion/Network/TorGuard.fs +++ b/NOnion/Network/TorGuard.fs @@ -49,7 +49,7 @@ type TorGuard ( client: TcpClient, sslStream: SslStream, - fingerprintOpt: Option + fingerprintOpt: Option ) = let shutdownToken = new CancellationTokenSource() @@ -116,7 +116,7 @@ type TorGuard static member private InnerNewClient (ipEndpoint: IPEndPoint) - (fingerprintOpt: Option) + (fingerprintOpt: Option) = async { let tcpClient = new TcpClient() diff --git a/NOnion/Services/TorServiceClient.fs b/NOnion/Services/TorServiceClient.fs index ee94300c..ef626bcf 100644 --- a/NOnion/Services/TorServiceClient.fs +++ b/NOnion/Services/TorServiceClient.fs @@ -373,7 +373,7 @@ type TorServiceClient = CircuitNodeDetail.Create( endpointSpecifier, introductionPoint.OnionKey.Value, - IdentityKey identityKey + Fingerprint identityKey ) return diff --git a/NOnion/Services/TorServiceHost.fs b/NOnion/Services/TorServiceHost.fs index 52fba205..c66b9085 100644 --- a/NOnion/Services/TorServiceHost.fs +++ b/NOnion/Services/TorServiceHost.fs @@ -31,7 +31,7 @@ type IntroductionPointInfo = AuthKey: AsymmetricCipherKeyPair MasterPublicKey: Ed25519PublicKeyParameters NTorOnionKey: NTorOnionKey - Fingerprint: IdentityKey + Fingerprint: Fingerprint } type TorServiceHost @@ -234,7 +234,7 @@ type TorServiceHost |> Seq.tryExactlyOne match linkSpecifierOpt with - | Some linkSpecifier -> IdentityKey linkSpecifier.Data + | Some linkSpecifier -> Fingerprint linkSpecifier.Data | None -> failwith "No rendezvous fingerprint found!" let connectToRendezvousJob = diff --git a/NOnion/TorHandshakes/NTorHandshake.fs b/NOnion/TorHandshakes/NTorHandshake.fs index 4b78373f..501fd322 100644 --- a/NOnion/TorHandshakes/NTorHandshake.fs +++ b/NOnion/TorHandshakes/NTorHandshake.fs @@ -15,13 +15,13 @@ type NTorHandshake = { RandomClientPrivateKey: X25519PrivateKeyParameters RandomClientPublicKey: X25519PublicKeyParameters - IdentityDigest: IdentityKey + IdentityDigest: Fingerprint NTorOnionKey: X25519PublicKeyParameters } static member Create - (identityDigest: IdentityKey) + (identityDigest: Fingerprint) (nTorOnionKey: NTorOnionKey) =