Skip to content

Commit

Permalink
extended master secret support: only resume an extended_ms session (o…
Browse files Browse the repository at this point in the history
…therwise, do full handshake), always send extended_ms in clienthello, use in serverhello if sent by client
  • Loading branch information
hannesm committed Jul 2, 2015
1 parent af8f145 commit 97eb00f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
15 changes: 11 additions & 4 deletions lib/handshake_client.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ let default_client_hello config =
| TLS_1_2 -> cs
and sessionid =
match config.session_cache None with
| None -> None
| Some { session_id ; _ } -> Some session_id
| Some { session_id ; extended_ms ; _ } when extended_ms = true -> Some session_id
| _ -> None
in
let ch = {
version = Supported version ;
random = Rng.generate 32 ;
sessionid = sessionid ;
ciphersuites = List.map Ciphersuite.ciphersuite_to_any_ciphersuite ciphers ;
extensions = host @ signature_algos
extensions = host @ signature_algos @ [ExtendedMasterSecret]
}
in
(ch , version)
Expand Down Expand Up @@ -64,7 +64,9 @@ let answer_server_hello state ch (sh : server_hello) raw log =
validate_reneg (get_secure_renegotiation sh.extensions) >|= fun () ->

let epoch_matches (epoch : epoch_data) =
epoch.ciphersuite = sh.ciphersuites && epoch.protocol_version = sh.version
epoch.ciphersuite = sh.ciphersuites &&
epoch.protocol_version = sh.version &&
epoch.extended_ms = List.mem ExtendedMasterSecret sh.extensions
in

match state.config.session_cache sh.sessionid with
Expand All @@ -85,12 +87,17 @@ let answer_server_hello state ch (sh : server_hello) raw log =
let machina =
let cipher = sh.ciphersuites in
let session_id = match sh.sessionid with None -> Cstruct.create 0 | Some x -> x in
let extended_ms =
let ems = List.mem ExtendedMasterSecret in
ems ch.extensions && ems sh.extensions
in
let session = { empty_session with
client_random = ch.random ;
client_version = ch.version ;
server_random = sh.random ;
ciphersuite = cipher ;
session_id ;
extended_ms ;
}
in
Ciphersuite.(match ciphersuite_kex cipher with
Expand Down
19 changes: 14 additions & 5 deletions lib/handshake_server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ let server_hello session version reneg =
and secren = match reneg with
| None -> SecureRenegotiation (Cstruct.create 0)
| Some (cvd, svd) -> SecureRenegotiation (cvd <+> svd)
and ems = if session.extended_ms then
[ExtendedMasterSecret]
else
[]
and session_id =
match Cstruct.len session.session_id with
| 0 -> Rng.generate 32
Expand All @@ -183,7 +187,7 @@ let server_hello session version reneg =
random = server_random ;
sessionid = Some session_id ;
ciphersuites = session.ciphersuite ;
extensions = secren :: host }
extensions = secren :: host @ ems }
in
(* Tracing.sexpf ~tag:"handshake-out" ~f:sexp_of_tls_handshake sh ; *)
(Writer.assemble_handshake sh,
Expand All @@ -208,6 +212,8 @@ let answer_client_hello_common state reneg ch raw =
| Some _ -> fail (`Error (`NoConfiguredCiphersuite cciphers))
| None -> fail (`Fatal (`NoCiphersuite ch.ciphersuites)) ) >|= fun cipher ->

let extended_ms = List.mem ExtendedMasterSecret ch.extensions in

(* Tracing.sexpf ~tag:"cipher" ~f:Ciphersuite.sexp_of_ciphersuite cipher ; *)

{ empty_session with
Expand All @@ -216,7 +222,8 @@ let answer_client_hello_common state reneg ch raw =
ciphersuite = cipher ;
own_certificate = chain ;
own_private_key = priv ;
own_name = host }
own_name = host ;
extended_ms = extended_ms }

and server_cert session =
match session.own_certificate with
Expand Down Expand Up @@ -314,14 +321,16 @@ let answer_client_hello state (ch : client_hello) raw =


and resume ch state =
let epoch_matches (epoch : Core.epoch_data) version ciphers =
let epoch_matches (epoch : Core.epoch_data) version ciphers extensions =
let cciphers = filter_map ~f:Ciphersuite.any_ciphersuite_to_ciphersuite ciphers in
List.mem epoch.ciphersuite cciphers &&
version = epoch.protocol_version
version = epoch.protocol_version &&
List.mem ExtendedMasterSecret extensions = epoch.extended_ms &&
epoch.extended_ms
in

match state.config.session_cache ch.sessionid with
| Some epoch when epoch_matches epoch state.protocol_version ch.ciphersuites ->
| Some epoch when epoch_matches epoch state.protocol_version ch.ciphersuites ch.extensions ->
Some { session_of_epoch epoch with
client_random = ch.random ;
client_version = ch.version ;
Expand Down

0 comments on commit 97eb00f

Please sign in to comment.