Skip to content

Commit 766eb22

Browse files
authored
Merge pull request #483 from hannesm/prep-release
Engine.epoch: return a result instead of a custom polymorphic variant
2 parents 8c4594b + 80635f4 commit 766eb22

File tree

7 files changed

+22
-37
lines changed

7 files changed

+22
-37
lines changed

CHANGES.md

+11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
## v0.17.3 (2023-11-20)
2+
3+
* tls: provide Engine.export_key_material, which implements RFC 5705 (and 8446)
4+
TLS EKM (#482 @hannesm)
5+
* tls: fix protocol_version in Engine.epoch (TLS 1.3 always pretended TLS 1.0)
6+
(#482 @hannesm)
7+
* tls: add the side (`` `Client `` or `` `Server ``) to epoch_data
8+
(#482 @hannesm)
9+
* BREAKING tls: Engine.epoch - return result instead of custom variant
10+
(#483 @hannesm)
11+
112
## v0.17.2 (2023-09-24)
213

314
* tls-eio: update to eio 0.12 (#479 @talex5)

async/io.ml

+3-4
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,9 @@ module Make (Fd : Fd) : S with module Fd := Fd = struct
193193

194194
let epoch t =
195195
match t.state with
196-
| Active tls ->
197-
(match Tls.Engine.epoch tls with
198-
| `InitialEpoch -> assert false (* can never occur! *)
199-
| `Epoch data -> Ok data)
196+
| Active tls -> (match Tls.Engine.epoch tls with
197+
| Ok _ as o -> o
198+
| Error () -> Or_error.error_string "no TLS state available yet")
200199
| Eof -> Or_error.error_string "TLS state is end of file"
201200
| Error _ -> Or_error.error_string "TLS state is error"
202201
;;

eio/tls_eio.ml

+2-5
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,8 @@ module Raw = struct
199199

200200
let epoch t =
201201
match t.state with
202-
| `Active tls -> ( match Tls.Engine.epoch tls with
203-
| `InitialEpoch -> assert false (* can never occur! *)
204-
| `Epoch data -> Ok data )
205-
| `Eof -> Error ()
206-
| `Error _ -> Error ()
202+
| `Active tls -> Tls.Engine.epoch tls
203+
| `Eof | `Error _ -> Error ()
207204

208205
let copy t ~src = Eio.Flow.Pi.simple_copy ~single_write t ~src
209206

lib/engine.ml

+1-8
Original file line numberDiff line numberDiff line change
@@ -735,15 +735,8 @@ let client config =
735735

736736
let server config = new_state Config.(of_server config) `Server
737737

738-
type epoch = [
739-
| `InitialEpoch
740-
| `Epoch of epoch_data
741-
]
742-
743738
let epoch state =
744-
match epoch_of_hs state.handshake with
745-
| None -> `InitialEpoch
746-
| Some e -> `Epoch e
739+
Option.to_result ~none:() (epoch_of_hs state.handshake)
747740

748741
let export_key_material (e : epoch_data) ?context label length =
749742
match e.protocol_version with

lib/engine.mli

+2-11
Original file line numberDiff line numberDiff line change
@@ -188,18 +188,9 @@ val key_update : ?request:bool -> state -> (state * Cstruct.t, failure) result
188188

189189
(** {1 Session information} *)
190190

191-
(** polymorphic variant of session information. The first variant
192-
[`InitialEpoch] will only be used for TLS states without completed
193-
handshake. The second variant, [`Epoch], contains actual session
194-
data. *)
195-
type epoch = [
196-
| `InitialEpoch
197-
| `Epoch of Core.epoch_data
198-
]
199-
200191
(** [epoch state] is [epoch], which contains the session
201-
information. *)
202-
val epoch : state -> epoch
192+
information. If there's no established session yet, an error is returned. *)
193+
val epoch : state -> (Core.epoch_data, unit) result
203194

204195
(** [export_key_material epoch_data ?context label length] is the RFC 5705
205196
exported key material of [length] bytes using [label] and, if provided,

lwt/tls_lwt.ml

+2-5
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,8 @@ module Unix = struct
237237

238238
let epoch t =
239239
match t.state with
240-
| `Active tls -> ( match Tls.Engine.epoch tls with
241-
| `InitialEpoch -> assert false (* can never occur! *)
242-
| `Epoch data -> Ok data )
243-
| `Eof -> Error ()
244-
| `Error _ -> Error ()
240+
| `Active tls -> Tls.Engine.epoch tls
241+
| `Eof | `Error _ -> Error ()
245242
end
246243

247244

mirage/tls_mirage.ml

+1-4
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,7 @@ module Make (F : Mirage_flow.S) = struct
193193
let epoch flow =
194194
match flow.state with
195195
| `Eof | `Error _ -> Error ()
196-
| `Active tls ->
197-
match Tls.Engine.epoch tls with
198-
| `InitialEpoch -> assert false (* `drain_handshake` invariant. *)
199-
| `Epoch e -> Ok e
196+
| `Active tls -> Tls.Engine.epoch tls
200197

201198
(* let create_connection t tls_params host (addr, port) =
202199
|+ XXX addr -> (host : string) +|

0 commit comments

Comments
 (0)