diff --git a/NOnion/Network/TorGuard.fs b/NOnion/Network/TorGuard.fs index 33bf4a45..4ffb5834 100644 --- a/NOnion/Network/TorGuard.fs +++ b/NOnion/Network/TorGuard.fs @@ -356,16 +356,25 @@ type TorGuard private (client: TcpClient, sslStream: SslStream) = //TODO: Client authentication isn't implemented yet! do! self.ReceiveExpected() |> Async.Ignore let! netInfo = self.ReceiveExpected() + let maybeOtherAddress = netInfo.MyAddresses |> Seq.tryHead - do! - self.Send - Constants.DefaultCircuitId - { - CellNetInfo.Time = - DateTimeUtils.ToUnixTimestamp DateTime.UtcNow - OtherAddress = netInfo.MyAddresses |> Seq.head - MyAddresses = List.singleton netInfo.OtherAddress - } + match maybeOtherAddress with + | None -> + return + raise + <| GuardConnectionFailedException( + "TorGuard.Handshake: problem in initializing the handshake process" + ) + | Some otherAddress -> + do! + self.Send + Constants.DefaultCircuitId + { + CellNetInfo.Time = + DateTimeUtils.ToUnixTimestamp DateTime.UtcNow + OtherAddress = otherAddress + MyAddresses = List.singleton netInfo.OtherAddress + } TorLogger.Log "TorGuard: finished handshake process" //TODO: do security checks on handshake data