Skip to content

Commit

Permalink
NOnion: minor refactoring
Browse files Browse the repository at this point in the history
Renamed IdentityKey type to Fingerprint as technically this is
the digest of identity key.
  • Loading branch information
webwarrior-ws committed Jun 5, 2023
1 parent 269e6e1 commit 9edc571
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion NOnion.Tests/CircuitHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion NOnion.Tests/TorDirectoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion NOnion/Directory/TorDirectory.fs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ type TorDirectory =
CircuitNodeDetail.Create(
endpoint,
NTorOnionKey nTorOnionKeyBytes,
IdentityKey fingerprintBytes
Fingerprint fingerprintBytes
)
}

Expand Down
3 changes: 2 additions & 1 deletion NOnion/KeyTypes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ type NTorOnionKey(bytes: array<byte>) =
member self.ToByteArray() =
bytes

type IdentityKey(bytes: array<byte>) =
/// Digest of identity key.
type Fingerprint(bytes: array<byte>) =
do
if bytes.Length <> Constants.IdentityKeyLength then
failwithf
Expand Down
2 changes: 1 addition & 1 deletion NOnion/Network/TorCircuit.fs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type CircuitNodeDetail =
| Create of
EndPoint: IPEndPoint *
NTorOnionKey: NTorOnionKey *
IdentityKey: IdentityKey
Fingerprint: Fingerprint

member self.GetIdentityKey() =
match self with
Expand Down
4 changes: 2 additions & 2 deletions NOnion/Network/TorGuard.fs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type TorGuard
(
client: TcpClient,
sslStream: SslStream,
fingerprintOpt: Option<IdentityKey>
fingerprintOpt: Option<Fingerprint>
) =
let shutdownToken = new CancellationTokenSource()

Expand Down Expand Up @@ -116,7 +116,7 @@ type TorGuard

static member private InnerNewClient
(ipEndpoint: IPEndPoint)
(fingerprintOpt: Option<IdentityKey>)
(fingerprintOpt: Option<Fingerprint>)
=
async {
let tcpClient = new TcpClient()
Expand Down
2 changes: 1 addition & 1 deletion NOnion/Services/TorServiceClient.fs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ type TorServiceClient =
CircuitNodeDetail.Create(
endpointSpecifier,
introductionPoint.OnionKey.Value,
IdentityKey identityKey
Fingerprint identityKey
)

return
Expand Down
4 changes: 2 additions & 2 deletions NOnion/Services/TorServiceHost.fs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type IntroductionPointInfo =
AuthKey: AsymmetricCipherKeyPair
MasterPublicKey: Ed25519PublicKeyParameters
NTorOnionKey: NTorOnionKey
Fingerprint: IdentityKey
Fingerprint: Fingerprint
}

type TorServiceHost
Expand Down Expand Up @@ -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 =
Expand Down
4 changes: 2 additions & 2 deletions NOnion/TorHandshakes/NTorHandshake.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
=

Expand Down

0 comments on commit 9edc571

Please sign in to comment.