| 1 |
//////////////////////////////////////////////////////////////// |
| 2 |
// Copyright 2019 Galois, Inc. All Rights Reserved |
| 3 |
// |
| 4 |
// Licensed under the Apache License, Version 2.0 (the "License"). |
| 5 |
// You may not use this file except in compliance with the License. |
| 6 |
// A copy of the License is located at |
| 7 |
// |
| 8 |
// http://aws.amazon.com/apache2.0 |
| 9 |
// |
| 10 |
// or in the "license" file accompanying this file. This file is distributed |
| 11 |
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 12 |
// express or implied. See the License for the specific language governing |
| 13 |
// permissions and limitations under the License. |
| 14 |
// |
| 15 |
//////////////////////////////////////////////////////////////// |
| 16 |
// |
| 17 |
// This file describes the correspondence between the Cryptol |
| 18 |
// specification of the TLS handshake and the C code in |
| 19 |
// tls/s2n_handshake_io.c, allowing SAW to prove that the code |
| 20 |
// corresponds to the specification. |
| 21 |
// |
| 22 |
//////////////////////////////////////////////////////////////// |
| 23 |
|
| 24 |
|
| 25 |
enable_experimental; |
| 26 |
// lax_loads_and_stores is needed to support the uses of |
| 27 |
// llvm_points_to_bitfield in the specifications below. As a result, SAW will |
| 28 |
// return fresh, symbolic values when it reads from uninitialized memory. Make |
| 29 |
// sure all of the arguments are initialized in the preconditions of a |
| 30 |
// specification, or else SAW will fill them in with underconstrained symbolic |
| 31 |
// values! |
| 32 |
enable_lax_loads_and_stores; |
| 33 |
|
| 34 |
// Low level specifications for some of the functions and constants declared in |
| 35 |
// tls/s2n_handshake_io.c |
| 36 |
import "s2n_handshake_io.cry"; |
| 37 |
|
| 38 |
llvm <- llvm_load_module "../../bitcode/all_llvm.bc"; |
| 39 |
print "Loaded bitcode via Crucible"; |
| 40 |
|
| 41 |
//////////////////////////////////////////////////////////////// |
| 42 |
// References to various components of the connection state: |
| 43 |
// The Cryptol definitions are located in the s2n_handshake_io.cry file. |
| 44 |
// Those Cryptol definitions will be compared against the actual C |
| 45 |
// definitions by this SAW script. |
| 46 |
//////////////////////////////////////////////////////////////// |
| 47 |
|
| 48 |
//conn->mode |
| 49 |
let conn_mode pconn = crucible_field pconn "mode"; |
| 50 |
|
| 51 |
let secure_crypto_params pconn = crucible_field pconn "secure"; |
| 52 |
|
| 53 |
//conn->secure->cipher_suite->key_exchange_alg->flags |
| 54 |
let conn_secure_cipher_suite crypto_params = crucible_field crypto_params "cipher_suite"; |
| 55 |
|
| 56 |
//let key_exchange_algorithm csuite = crucible_elem csuite 3; |
| 57 |
let key_exchange_algorithm csuite = crucible_field csuite "key_exchange_alg"; |
| 58 |
|
| 59 |
let kea_is_ephemeral kea = crucible_elem kea 0; |
| 60 |
//let kea_is_ephemeral kea = crucible_field kea "is_ephemeral"; |
| 61 |
|
| 62 |
//conn->status_type |
| 63 |
let conn_status_type pconn = crucible_field pconn "status_type"; |
| 64 |
|
| 65 |
//conn->config |
| 66 |
let conn_config pconn = crucible_field pconn "config"; |
| 67 |
|
| 68 |
//conn->config -> client_cert_auth_type |
| 69 |
let config_cca_type config = (crucible_field config "client_cert_auth_type"); |
| 70 |
|
| 71 |
//conn->handshake_params.our_chain_and_key->ocsp_status.size |
| 72 |
let ocsp_status_size cert_and_key = |
| 73 |
crucible_field (crucible_field (cert_and_key) "ocsp_status") "size"; |
| 74 |
|
| 75 |
let {{ |
| 76 |
// Convert a Bit to a length-1 bitvector. |
| 77 |
bit_to_bv1 : Bit -> [1] |
| 78 |
bit_to_bv1 b = [b] |
| 79 |
|
| 80 |
// Convert a length-1 bitvector to a Bit. |
| 81 |
bv1_to_bit : [1] -> Bit |
| 82 |
bv1_to_bit bv1 = bv1 @ 0 |
| 83 |
}}; |
| 84 |
|
| 85 |
//conn->session_ticket_status |
| 86 |
let conn_session_ticket_status pconn = (crucible_field pconn "session_ticket_status"); |
| 87 |
|
| 88 |
//conn->client_cert_auth_type |
| 89 |
let cca_type pconn = crucible_field pconn "client_cert_auth_type"; |
| 90 |
|
| 91 |
//conn->client_cert_auth_type_overridden |
| 92 |
let cca_type_ov pconn = crucible_field pconn "client_cert_auth_type_overridden"; |
| 93 |
|
| 94 |
//conn->handshake.handshake_type |
| 95 |
let conn_handshake_handshake_type pconn = |
| 96 |
crucible_field (crucible_field pconn "handshake") "handshake_type"; |
| 97 |
|
| 98 |
//conn->handshake.message_number |
| 99 |
let conn_handshake_message_number pconn = |
| 100 |
crucible_field (crucible_field pconn "handshake") "message_number"; |
| 101 |
|
| 102 |
//conn->handshake.state_machine |
| 103 |
let conn_handshake_state_machine pconn = |
| 104 |
crucible_field (crucible_field pconn "handshake") "state_machine"; |
| 105 |
|
| 106 |
//conn->handshake_params.our_chain_and_key |
| 107 |
let conn_chain_and_key pconn = |
| 108 |
crucible_field (crucible_field pconn "handshake_params") "our_chain_and_key"; |
| 109 |
|
| 110 |
//conn->psk_params.chosen_psk |
| 111 |
let conn_chosen_psk pconn = |
| 112 |
crucible_field (crucible_field pconn "psk_params") "chosen_psk"; |
| 113 |
|
| 114 |
//conn->early_data_state |
| 115 |
let conn_early_data_state pconn = crucible_field pconn "early_data_state"; |
| 116 |
|
| 117 |
// Ghost state that represents the number of times the connection write socket |
| 118 |
// has been corked/uncorked. |
| 119 |
corked <- crucible_declare_ghost_state "corked"; |
| 120 |
crucible_ghost_value corked {{ 0 : [2] }}; |
| 121 |
|
| 122 |
// setup_handshake_common de-serializes parts of the s2n_handshake and |
| 123 |
// s2n_connection structs into a Cryptol record. It also deserializes the ghost |
| 124 |
// state. We use the suffix "_common" since it captures the properties shared |
| 125 |
// in common between setup_connection and setup_psk_connection. |
| 126 |
// |
| 127 |
// The chosen_psk_null argument is true if conn->psk_params.chosen_psk should |
| 128 |
// be set to NULL, which enables the use of FULL_HANDSHAKE if TLS 1.3 is used. |
| 129 |
// If false, then chosen_psk is set to a non-NULL value, disabling |
| 130 |
// FULL_HANDSHAKE if TLS 1.3 is used. The value of conn->psk_params.chosen_psk |
| 131 |
// has no effect if TLS 1.2 is used. |
| 132 |
let setup_connection_common chosen_psk_null = do { |
| 133 |
pconn <- crucible_alloc (llvm_struct "struct.s2n_connection"); |
| 134 |
|
| 135 |
version <- crucible_fresh_var "version" (llvm_int 8); |
| 136 |
crucible_precond {{ version != S2N_UNKNOWN_PROTOCOL_VERSION /\ version <= S2N_TLS13 }}; |
| 137 |
crucible_points_to (crucible_field pconn "actual_protocol_version") (crucible_term version); |
| 138 |
|
| 139 |
mode <- crucible_fresh_var "mode" (llvm_int 32); |
| 140 |
crucible_points_to (conn_mode pconn) (crucible_term mode); |
| 141 |
|
| 142 |
handshake_type <- crucible_fresh_var "handshake_type" (llvm_int 32); |
| 143 |
crucible_points_to (conn_handshake_handshake_type pconn) |
| 144 |
(crucible_term handshake_type); |
| 145 |
|
| 146 |
message_number <- crucible_fresh_var "message_number" (llvm_int 32); |
| 147 |
crucible_points_to (conn_handshake_message_number pconn) |
| 148 |
(crucible_term message_number); |
| 149 |
|
| 150 |
state_machine <- crucible_fresh_var "state_machine" (llvm_int 32); |
| 151 |
crucible_points_to (conn_handshake_state_machine pconn) |
| 152 |
(crucible_term state_machine); |
| 153 |
|
| 154 |
cork_val <- crucible_fresh_var "corked" (llvm_int 2); |
| 155 |
crucible_ghost_value corked cork_val; |
| 156 |
|
| 157 |
// We assume that the client_cert_auth_type_overridden flag in s2n_connection is set. |
| 158 |
// If that flag is not set, auth_type / "cca_type" could be determined by the config |
| 159 |
// or just set to a default value. Since we're primarily interested in the handshake |
| 160 |
// here and the end result is the same, just consider the connection auth_type. |
| 161 |
cca_ov <- crucible_fresh_var "cca_ov" (llvm_int 8); |
| 162 |
crucible_points_to (cca_type_ov pconn) (crucible_term cca_ov); |
| 163 |
crucible_equal (crucible_term cca_ov) (crucible_term {{1 : [8]}}); |
| 164 |
|
| 165 |
cca <- crucible_fresh_var "cca" (llvm_int 32); |
| 166 |
crucible_points_to (cca_type pconn) (crucible_term cca); |
| 167 |
|
| 168 |
secure <- crucible_alloc (llvm_struct "struct.s2n_crypto_parameters"); |
| 169 |
crucible_points_to (secure_crypto_params pconn) secure; |
| 170 |
|
| 171 |
cipher_suite <- crucible_alloc (llvm_struct "struct.s2n_cipher_suite"); |
| 172 |
crucible_points_to (conn_secure_cipher_suite secure) cipher_suite; |
| 173 |
|
| 174 |
kea <- crucible_alloc (llvm_struct "struct.s2n_kex"); |
| 175 |
crucible_points_to (key_exchange_algorithm cipher_suite) kea; |
| 176 |
|
| 177 |
eph_flag <- crucible_fresh_var "eph_flag" (llvm_int 8); |
| 178 |
crucible_points_to (kea_is_ephemeral kea) (crucible_term eph_flag); |
| 179 |
|
| 180 |
config <- crucible_alloc (llvm_struct "struct.s2n_config"); |
| 181 |
crucible_points_to (conn_config pconn) config; |
| 182 |
|
| 183 |
cak <- crucible_alloc (llvm_struct "struct.s2n_cert_chain_and_key"); |
| 184 |
crucible_points_to (conn_chain_and_key pconn) cak; |
| 185 |
|
| 186 |
status_size <- crucible_fresh_var "status_size" (llvm_int 32); |
| 187 |
crucible_points_to (ocsp_status_size cak) (crucible_term status_size); |
| 188 |
crucible_equal (crucible_term status_size) (crucible_term {{zero : [32]}}); |
| 189 |
|
| 190 |
// We assume that corking/uncorking is managed by s2n, so set the corked_io |
| 191 |
// bit in s2n_connection to one... |
| 192 |
let corked_io = {{ True }}; |
| 193 |
llvm_points_to_bitfield pconn "corked_io" (llvm_term {{ bit_to_bv1 corked_io }}); |
| 194 |
|
| 195 |
// ...we assume that the client_session_resumed bit in s2n_connection must |
| 196 |
// be zero... |
| 197 |
llvm_points_to_bitfield pconn "client_session_resumed" (llvm_term {{ 0 : [1] }}); |
| 198 |
|
| 199 |
// ...we currently require that the use_tickets bit in s2n_config must be |
| 200 |
// zero... |
| 201 |
llvm_points_to_bitfield config "use_tickets" (llvm_term {{ 0 : [1] }}); |
| 202 |
|
| 203 |
// ...on the other hand, the quic_enabled bits in both s2n_connection and |
| 204 |
// s2n_config are allowed to be either 0 or 1. As such, we don't need to |
| 205 |
// impose any direct constraints on them. We simply query which values |
| 206 |
// they have taken on during simulation and remember them for later. |
| 207 |
conn_quic_enabled <- llvm_fresh_var "conn_quic_enabled" (llvm_int 1); |
| 208 |
llvm_points_to_bitfield pconn "quic_enabled" (llvm_term conn_quic_enabled); |
| 209 |
config_quic_enabled <- llvm_fresh_var "config_quic_enabled" (llvm_int 1); |
| 210 |
llvm_points_to_bitfield config "quic_enabled" (llvm_term config_quic_enabled); |
| 211 |
let quic_enabled_bit = {{ bv1_to_bit conn_quic_enabled \/ bv1_to_bit config_quic_enabled }}; |
| 212 |
|
| 213 |
session_ticket_status <- crucible_fresh_var "session_ticket_status" (llvm_int 32); |
| 214 |
crucible_points_to (conn_session_ticket_status pconn) (crucible_term session_ticket_status); |
| 215 |
|
| 216 |
ocsp_flag <- crucible_fresh_var "ocsp_flag" (llvm_int 32); |
| 217 |
crucible_points_to (conn_status_type pconn) (crucible_term ocsp_flag); |
| 218 |
|
| 219 |
if chosen_psk_null |
| 220 |
then crucible_points_to (conn_chosen_psk pconn) crucible_null |
| 221 |
else do { chosen_psk <- crucible_alloc (llvm_struct "struct.s2n_psk"); |
| 222 |
crucible_points_to (conn_chosen_psk pconn) chosen_psk; |
| 223 |
}; |
| 224 |
let chosen_psk_null_bit = if chosen_psk_null then {{ True }} else {{ False }}; |
| 225 |
|
| 226 |
early_data_state <- crucible_fresh_var "early_data_state" (llvm_int 32); |
| 227 |
crucible_points_to (conn_early_data_state pconn) (crucible_term early_data_state); |
| 228 |
|
| 229 |
no_client_cert <- crucible_fresh_var "no_client_cert" (llvm_int 8); |
| 230 |
|
| 231 |
npn_negotiated <- llvm_fresh_var "npn_negotiated" (llvm_int 1); |
| 232 |
llvm_points_to_bitfield pconn "npn_negotiated" (llvm_term npn_negotiated); |
| 233 |
let npn_negotiated_bit = {{ bv1_to_bit npn_negotiated }}; |
| 234 |
|
| 235 |
// This returns a connection containing a handshake. If the connection or the handshake |
| 236 |
// definitions are changed, they must also be changed here. |
| 237 |
return (pconn, {{ {corked_io = corked_io |
| 238 |
,mode = mode |
| 239 |
,handshake = {message_number = message_number |
| 240 |
,handshake_type = handshake_type |
| 241 |
,state_machine = state_machine } |
| 242 |
,corked = cork_val |
| 243 |
,is_caching_enabled = False |
| 244 |
,key_exchange_eph = eph_flag != zero |
| 245 |
,server_can_send_ocsp = |
| 246 |
((ocsp_flag == 1) && (status_size > 0)) || |
| 247 |
((mode == 1) && (ocsp_flag == 1)) |
| 248 |
,resume_from_cache = False |
| 249 |
,client_auth_flag = if mode == S2N_CLIENT then cca == S2N_CERT_AUTH_REQUIRED else |
| 250 |
if mode == S2N_SERVER then cca != S2N_CERT_AUTH_NONE else False |
| 251 |
,no_client_cert = no_client_cert != zero |
| 252 |
,actual_protocol_version = version |
| 253 |
,early_data_state = early_data_state |
| 254 |
,chosen_psk_null = chosen_psk_null_bit |
| 255 |
,quic_enabled = quic_enabled_bit |
| 256 |
,npn_negotiated = npn_negotiated_bit |
| 257 |
} |
| 258 |
}}); |
| 259 |
}; |
| 260 |
|
| 261 |
// Set conn->psk_params.chosen_psk to NULL, which enables the use of FULL_HANDSHAKE |
| 262 |
// if TLS 1.3 is used. Note that if TLS 1.2 is used, there is no difference between |
| 263 |
// this function and setup_psk_connection. |
| 264 |
let setup_connection = setup_connection_common true; |
| 265 |
|
| 266 |
// Set conn->psk_params.chosen_psk to a non-NULL value, which disables the use of FULL_HANDSHAKE |
| 267 |
// if TLS 1.3 is used. Note that if TLS 1.2 is used, there is no difference between |
| 268 |
// this function and setup_connection. |
| 269 |
let setup_psk_connection = setup_connection_common false; |
| 270 |
|
| 271 |
|
| 272 |
// This function checks that the values of the state_machine array are what we |
| 273 |
// expect. 'state_machine' is the pointer to the beginning of the array, 'index_term' |
| 274 |
// is the term representing the index in the array. |
| 275 |
let verify_state_machine_elem state_machine state_machine_model index_term = do { |
| 276 |
let index = eval_int index_term; |
| 277 |
let abstract = {{ state_machine_model @ index_term }}; |
| 278 |
|
| 279 |
crucible_points_to (crucible_elem (crucible_elem state_machine index) 0) (crucible_term {{ abstract.record_type }}); |
| 280 |
|
| 281 |
crucible_points_to (crucible_elem (crucible_elem state_machine index) 1) (crucible_term {{ abstract.message_type }}); |
| 282 |
|
| 283 |
crucible_points_to (crucible_elem (crucible_elem state_machine index) 2) (crucible_term {{ abstract.writer }}); |
| 284 |
|
| 285 |
}; |
| 286 |
|
| 287 |
// For now axiomitize this is always false and see if we can prove something |
| 288 |
let s2n_allowed_to_cache_connection_spec = do { |
| 289 |
pconf <- crucible_alloc_readonly (llvm_struct "struct.s2n_connection"); |
| 290 |
|
| 291 |
crucible_execute_func [pconf]; |
| 292 |
crucible_return (crucible_term {{ 0 : [32] }}); |
| 293 |
}; |
| 294 |
|
| 295 |
let s2n_connection_get_client_auth_type_spec = do { |
| 296 |
pconn <- crucible_alloc_readonly (llvm_struct "struct.s2n_connection"); |
| 297 |
auth_type <- crucible_alloc (llvm_int 32); |
| 298 |
|
| 299 |
cca_ov <- crucible_fresh_var "cca_ov" (llvm_int 8); |
| 300 |
crucible_points_to (cca_type_ov pconn) (crucible_term cca_ov); |
| 301 |
|
| 302 |
config <- crucible_alloc_readonly (llvm_struct "struct.s2n_config"); |
| 303 |
crucible_points_to (conn_config pconn) config; |
| 304 |
|
| 305 |
config_cca_ov <- llvm_fresh_var "config_cca_ov" (llvm_int 8); |
| 306 |
crucible_points_to (crucible_field config "client_cert_auth_type_overridden") (crucible_term config_cca_ov); |
| 307 |
|
| 308 |
config_cca <- crucible_fresh_var "config_cca" (llvm_int 32); |
| 309 |
crucible_points_to (config_cca_type config) (crucible_term config_cca); |
| 310 |
|
| 311 |
cca <- crucible_fresh_var "cca" (llvm_int 32); |
| 312 |
crucible_points_to (cca_type pconn) (crucible_term cca); |
| 313 |
|
| 314 |
mode <- crucible_fresh_var "mode" (llvm_int 32); |
| 315 |
crucible_points_to (conn_mode pconn) (crucible_term mode); |
| 316 |
|
| 317 |
crucible_execute_func [pconn, auth_type]; |
| 318 |
|
| 319 |
crucible_points_to (auth_type) (crucible_term {{ |
| 320 |
if cca_ov != zero then cca else |
| 321 |
if config_cca_ov != zero then config_cca else |
| 322 |
if mode == S2N_CLIENT then S2N_CERT_AUTH_OPTIONAL else |
| 323 |
S2N_CERT_AUTH_NONE |
| 324 |
}}); |
| 325 |
|
| 326 |
crucible_return (crucible_term {{ 0 : [32] }}); |
| 327 |
}; |
| 328 |
|
| 329 |
// Specification for s2n_conn_set_handshake_type that sets up simulation of it |
| 330 |
// by conn_set_handshake_type (low-level model function) |
| 331 |
let s2n_conn_set_handshake_type_spec chosen_psk_null = do { |
| 332 |
(pconn, conn) <- setup_connection_common chosen_psk_null; |
| 333 |
// We assume that the connection struct denotes a valid connection state |
| 334 |
crucible_precond {{ valid_connection conn }}; |
| 335 |
|
| 336 |
// symbolically execute s2n_conn_set_handshake_type |
| 337 |
crucible_execute_func [pconn]; |
| 338 |
|
| 339 |
// Next we check that the changes to s2n_connection fields are |
| 340 |
// simulated by the low-level specification of the function. We do |
| 341 |
// this by running the model function conn_set_handshake_type on the |
| 342 |
// deserealized pre-state of the s2n_connection struct and checking |
| 343 |
// that values of the fields of the resulting struct match the fields |
| 344 |
// of the post-state of the s2n_connection struct. In this case only handshake |
| 345 |
// type should change |
| 346 |
let conn' = {{ conn_set_handshake_type conn }}; |
| 347 |
crucible_ghost_value corked {{ conn'.corked }}; |
| 348 |
crucible_points_to (conn_handshake_handshake_type pconn) (crucible_term {{ conn'.handshake.handshake_type }}); |
| 349 |
|
| 350 |
// assert that s2n_conn_set_handshake_type returns 0 (true if the 4 |
| 351 |
// functions it calls don't fail) |
| 352 |
crucible_return (crucible_term {{ 0 : [32] }}); |
| 353 |
}; |
| 354 |
|
| 355 |
// specification for s2n_advance_message that sets up simulation of it |
| 356 |
// by advance_message (low-level model function) |
| 357 |
let s2n_advance_message_spec = do { |
| 358 |
// Note that s2n_advance_message() doesn't actually care about the value of |
| 359 |
// chosen_psk, so we arbitrarily set it to NULL here by using |
| 360 |
// setup_connection. Using setup_psk_connection would work just as well. |
| 361 |
(pconn, conn) <- setup_connection; |
| 362 |
// We assume that the connection struct denotes a valid connection state |
| 363 |
crucible_precond {{ valid_connection conn }}; |
| 364 |
|
| 365 |
// symbolically execute s2n_advance_message |
| 366 |
crucible_execute_func [pconn]; |
| 367 |
|
| 368 |
// Next we check that the changes to s2n_connection fields are |
| 369 |
// simulated by the low-level specification of the function. We do |
| 370 |
// this by running the model function advance_message on the |
| 371 |
// deserealized pre-state of the s2n_connection struct and checking |
| 372 |
// that values of the fields of the resulting struct match the fields |
| 373 |
// of the post-state of the s2n_connection struct. |
| 374 |
let conn' = {{ advance_message conn }}; |
| 375 |
crucible_ghost_value corked {{ conn'.corked }}; |
| 376 |
llvm_points_to_bitfield pconn "corked_io" (llvm_term {{ bit_to_bv1 (conn'.corked_io) }}); |
| 377 |
crucible_points_to (conn_mode pconn) (crucible_term {{ conn'.mode }}); |
| 378 |
crucible_points_to (conn_handshake_handshake_type pconn) (crucible_term {{ conn'.handshake.handshake_type }}); |
| 379 |
crucible_points_to (conn_handshake_message_number pconn) (crucible_term {{ conn'.handshake.message_number }}); |
| 380 |
|
| 381 |
// make sure the low-level spec representation of the declarative |
| 382 |
// handshake/cork-uncork state machine is equivalent to the one in |
| 383 |
// s2n |
| 384 |
// The Cryptol representations are defined here: tests/saw/spec/handshake/s2n_handshake_io.cry |
| 385 |
// |
| 386 |
// Note that we use crucible_points_to_untyped here rather than |
| 387 |
// crucible_points_to because LLVM 7 and later represent static arrays that |
| 388 |
// are partially initialized with zeroes as packed structs. For more |
| 389 |
// information, see |
| 390 |
// https://llvm.discourse.group/t/array-layout-changed-by-clang-llvm-starting-from-version-7/2271 |
| 391 |
// |
| 392 |
// Changing the Cryptol definitions of the state machines to match these |
| 393 |
// new types would be annoying, and moreover, it isn't guaranteed that |
| 394 |
// future versions of LLVM won't change the types further. Fortunately, the |
| 395 |
// in-memory representation of the arrays hasn't changed, just the types. |
| 396 |
// As a result, we can use crucible_points_to_untyped to check if the two |
| 397 |
// state machines are bitwise equivalent without checking the types. |
| 398 |
crucible_points_to_untyped (crucible_global "handshakes") (crucible_term {{ handshakes }}); |
| 399 |
crucible_points_to_untyped (crucible_global "tls13_handshakes") (crucible_term {{ tls13_handshakes }}); |
| 400 |
|
| 401 |
let messages = [ {{CLIENT_HELLO : [5]}} |
| 402 |
, {{SERVER_HELLO : [5]}} |
| 403 |
, {{SERVER_NEW_SESSION_TICKET : [5]}} |
| 404 |
, {{SERVER_CERT : [5]}} |
| 405 |
, {{SERVER_CERT_STATUS : [5]}} |
| 406 |
, {{SERVER_KEY : [5]}} |
| 407 |
, {{SERVER_CERT_REQ : [5]}} |
| 408 |
, {{SERVER_HELLO_DONE : [5]}} |
| 409 |
, {{CLIENT_CERT : [5]}} |
| 410 |
, {{CLIENT_KEY : [5]}} |
| 411 |
, {{CLIENT_CERT_VERIFY : [5]}} |
| 412 |
, {{CLIENT_CHANGE_CIPHER_SPEC : [5]}} |
| 413 |
, {{CLIENT_NPN : [5]}} |
| 414 |
, {{CLIENT_FINISHED : [5]}} |
| 415 |
, {{SERVER_CHANGE_CIPHER_SPEC : [5]}} |
| 416 |
, {{SERVER_FINISHED : [5]}} |
| 417 |
, {{ENCRYPTED_EXTENSIONS : [5]}} |
| 418 |
, {{SERVER_CERT_VERIFY : [5]}} |
| 419 |
, {{HELLO_RETRY_MSG : [5]}} |
| 420 |
, {{END_OF_EARLY_DATA : [5]}} |
| 421 |
, {{APPLICATION_DATA : [5]}} |
| 422 |
]; |
| 423 |
|
| 424 |
for messages (verify_state_machine_elem (crucible_global "state_machine") {{ state_machine }} ); |
| 425 |
for messages (verify_state_machine_elem (crucible_global "tls13_state_machine") {{ tls13_state_machine }} ); |
| 426 |
|
| 427 |
// assert that s2n_advance_message returns 0 (true if the 4 |
| 428 |
// functions it calls don't fail) |
| 429 |
crucible_return (crucible_term {{ 0 : [32] }}); |
| 430 |
}; |
| 431 |
|
| 432 |
// Specs for the 5 functions that s2n_advance_message calls. Right now |
| 433 |
// we just assume the specs and don't verify them. That's because we |
| 434 |
// don't model the state that they depend on, instead, making assumptions |
| 435 |
// about it: we use managed corking and the socket was initially uncorked. |
| 436 |
|
| 437 |
// Specification for s2n_socket_write_uncork. The relevant part is |
| 438 |
// that it decrements the 'corked' ghost variable to indicate that the socket |
| 439 |
// has been uncorked. |
| 440 |
let s2n_socket_write_uncork_spec = do { |
| 441 |
pconn <- crucible_alloc_readonly (llvm_struct "struct.s2n_connection"); |
| 442 |
cork_val <- crucible_fresh_var "corked" (llvm_int 2); |
| 443 |
crucible_ghost_value corked cork_val; |
| 444 |
|
| 445 |
crucible_execute_func [pconn]; |
| 446 |
|
| 447 |
crucible_ghost_value corked {{ cork_val - 1 }}; |
| 448 |
|
| 449 |
crucible_return (crucible_term {{ 0 : [32] }}); |
| 450 |
}; |
| 451 |
|
| 452 |
// Specification for s2n_generate_new_client_session_id. This is essentially |
| 453 |
// a noop function that returns 0 from the perspective of our current proof |
| 454 |
let s2n_generate_new_client_session_id_spec = do { |
| 455 |
pconn <- crucible_alloc_readonly (llvm_struct "struct.s2n_connection"); |
| 456 |
|
| 457 |
crucible_execute_func [pconn]; |
| 458 |
|
| 459 |
crucible_return (crucible_term {{ 0 : [32] }}); |
| 460 |
}; |
| 461 |
|
| 462 |
// Specification for s2n_resume_decrypt_session_spec. This is essentially |
| 463 |
// a noop function that returns 0 from the perspective of our current proof |
| 464 |
let s2n_resume_decrypt_session_spec = do { |
| 465 |
pconn <- crucible_alloc_readonly (llvm_struct "struct.s2n_connection"); |
| 466 |
from <- crucible_alloc_readonly (llvm_struct "struct.s2n_stuffer"); |
| 467 |
|
| 468 |
crucible_execute_func [pconn, from]; |
| 469 |
crucible_return (crucible_term {{ 0 : [32] }}); |
| 470 |
}; |
| 471 |
|
| 472 |
// Specification for s2n_socket_write_cork. The relevant part is |
| 473 |
// that it increments the 'corked' ghost variable to 1 to |
| 474 |
// indicate that the socket has been corked. |
| 475 |
let s2n_socket_write_cork_spec = do { |
| 476 |
pconn <- crucible_alloc_readonly (llvm_struct "struct.s2n_connection"); |
| 477 |
|
| 478 |
cork_val <- crucible_fresh_var "corked" (llvm_int 2); |
| 479 |
crucible_ghost_value corked cork_val; |
| 480 |
|
| 481 |
crucible_execute_func [pconn]; |
| 482 |
|
| 483 |
crucible_ghost_value corked {{ cork_val + 1 }}; |
| 484 |
|
| 485 |
crucible_return (crucible_term {{ 0 : [32] }}); |
| 486 |
}; |
| 487 |
|
| 488 |
// Specification for s2n_socket_was_corked. We assume this function |
| 489 |
// always returns 0 to indicate our assumption that the socket was |
| 490 |
// uncorked initially. If it was corked, then the cork/uncork state |
| 491 |
// machine would be bypassed, making verification moot. |
| 492 |
let s2n_socket_was_corked_spec = do { |
| 493 |
pconn <- crucible_alloc_readonly (llvm_struct "struct.s2n_connection"); |
| 494 |
|
| 495 |
crucible_execute_func [pconn]; |
| 496 |
|
| 497 |
crucible_return (crucible_term {{ 0 : [32] }}); |
| 498 |
}; |
| 499 |
|
| 500 |
|
| 501 |
// Specification for s2n_socket_quickack. This is essentially |
| 502 |
// a noop function that returns 0 from the perspective of our current proof |
| 503 |
let s2n_socket_quickack_spec = do { |
| 504 |
pconn <- crucible_alloc_readonly (llvm_struct "struct.s2n_connection"); |
| 505 |
|
| 506 |
crucible_execute_func [pconn]; |
| 507 |
|
| 508 |
crucible_return (crucible_term {{ 0 : [32] }}); |
| 509 |
}; |
| 510 |
|
| 511 |
|
| 512 |
// Specification for s2n_connection_is_managed_corked. We assume it |
| 513 |
// always returns 1 to reflect our assumption that the library is |
| 514 |
// managing the corking and uncorking of the socket. Otherwise, the |
| 515 |
//cork/uncork state machine would be bypassed making verification moot. |
| 516 |
let s2n_connection_is_managed_corked_spec = do { |
| 517 |
pconn <- crucible_alloc_readonly (llvm_struct "struct.s2n_connection"); |
| 518 |
|
| 519 |
crucible_execute_func [pconn]; |
| 520 |
|
| 521 |
crucible_return (crucible_term {{ 1 : [32] }}); |
| 522 |
}; |