Skip to content

Commit

Permalink
Update handle_tls
Browse files Browse the repository at this point in the history
  • Loading branch information
metame committed Jul 14, 2024
1 parent d05df0e commit 75039da
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
2 changes: 1 addition & 1 deletion dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
(randomconv (= "0.2.0"))
(rio (>= "0.0.1"))
(telemetry (>= "0.0.1"))
(tls (= "0.17.3"))
(tls (= "0.17.5"))
(uri (>= "4.4.0"))
(x509 (and :with-test (>= "0.16.5")))
dune)
Expand Down
46 changes: 28 additions & 18 deletions riot/lib/ssl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -90,28 +90,38 @@ module Tls_unix = struct
let try_write_t t cs =
try write_t t cs with _ -> trace (fun f -> f "try_write_t failed")

let inject_state tls = function
| `Active _ -> `Active tls
| `Eof -> `Eof
| `Error _ as e -> e

let rec read_react t =
trace (fun f -> f "tls.read_react");
let handle tls cs =
match Tls.Engine.handle_tls tls cs with
| Ok (state', `Response resp, `Data data) ->
trace (fun f -> f "tls.read_react->ok");
let state' =
match state' with
| `Ok tls -> `Active tls
| `Eof -> `Eof
| `Alert a ->
trace (fun f -> f "tls.read_react->alert");
`Error (Tls_alert a)
in
t.state <- state';
Option.iter (try_write_t t) resp;
data
| Error (alert, `Response resp) ->
trace (fun f -> f "tls.read_react->error");
t.state <- `Error (Tls_failure alert);
write_t t resp;
read_react t
| Ok (state', eof, `Response resp, `Data data) ->
trace (fun f -> f "tls.read_react->ok");
let state' =
match eof with
| Some `Eof -> `Eof
| _ -> inject_state state' t.state
in
t.state <- state';
Option.iter (try_write_t t) resp;
data
| Error (fail, `Response resp) ->
let state' =
match fail with
| `Alert a ->
trace (fun f -> f "tls.read_react->alert");
`Error (Tls_alert a)
| f ->
trace (fun f -> f "tls.read_react->error");
`Error (Tls_failure f)
in
t.state <- state';
write_t t resp;
read_react t
in

match t.state with
Expand Down

0 comments on commit 75039da

Please sign in to comment.