Skip to content

Commit 0f60878

Browse files
committed
Network,TorHandshakes: handshake fail exception
1 parent d16f92f commit 0f60878

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

NOnion/Exceptions.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ type CircuitDestroyedException internal (reason: DestroyReason) =
2929
type CircuitDecryptionFailedException internal () =
3030
inherit NOnionException(sprintf "Circuit Decryption Failed")
3131

32+
type HandshakeFailedException internal () =
33+
inherit NOnionException(sprintf "Key handshake failed!")
34+
3235
type TimeoutErrorException internal () =
3336
inherit NOnionException("Time limit exceeded for operation")
3437

NOnion/Network/TorGuard.fs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ module ExceptionUtil =
4141
| None -> return raise <| FSharpUtil.ReRaise exn
4242
}
4343

44+
let HandleIncomingCallException<'T when 'T :> NOnionException>
45+
(cell: ICell)
46+
(ex: 'T)
47+
=
48+
sprintf
49+
"TorGuard: exception when trying to handle incoming cell type=%i, ex=%s"
50+
cell.Command
51+
(ex.ToString())
52+
|> TorLogger.Log
53+
4454
type TorGuard private (client: TcpClient, sslStream: SslStream) =
4555
let shutdownToken = new CancellationTokenSource()
4656

@@ -332,12 +342,16 @@ type TorGuard private (client: TcpClient, sslStream: SslStream) =
332342
try
333343
do! circuit.HandleIncomingCell cell
334344
with
345+
| :? HandshakeFailedException as ex ->
346+
ExceptionUtil.HandleIncomingCallException<HandshakeFailedException>
347+
cell
348+
ex
349+
350+
self.KillChildCircuits()
335351
| :? CircuitDecryptionFailedException as ex ->
336-
sprintf
337-
"TorGuard: exception when trying to handle incoming cell type=%i, ex=%s"
338-
cell.Command
339-
(ex.ToString())
340-
|> TorLogger.Log
352+
ExceptionUtil.HandleIncomingCallException<CircuitDecryptionFailedException>
353+
cell
354+
ex
341355

342356
self.KillChildCircuits()
343357
| ex -> return raise <| FSharpUtil.ReRaise ex

NOnion/TorHandshakes/FastHandshake.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ type FastHandshake =
3636
|> Kdf.ComputeLegacyKdf
3737

3838
if kdfResult.KeyHandshake <> serverSideData.DerivativeKey then
39-
failwith "Key handshake failed!"
39+
raise <| HandshakeFailedException()
4040
else
4141
kdfResult

NOnion/TorHandshakes/NTorHandshake.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,6 @@ type NTorHandshake =
107107
let auth = calculateHmacSha256 authInput Constants.NTorTMac
108108

109109
if auth <> serverSideData.DerivativeKey then
110-
failwith "Key handshake failed!"
110+
raise <| HandshakeFailedException()
111111
else
112112
Kdf.ComputeRfc5869Kdf secretInput

0 commit comments

Comments
 (0)