Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:Communication Layer #50

Open
wants to merge 46 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
49daaee
Added key to crypto predicates along the usages
fabian-hk Dec 5, 2024
134c6a6
Proof optimization
fabian-hk Dec 6, 2024
b137b35
Improve proofs and code cleanup
fabian-hk Dec 6, 2024
17b31e3
Make key in crypto predicates not dependent on the key usage
fabian-hk Dec 20, 2024
88cf697
Simplified Sign bytes_invariant
fabian-hk Dec 20, 2024
a277cb6
First draft of a confidential send function
fabian-hk Jul 20, 2024
38f9cdf
Confidential send and receive function and example protocol
fabian-hk Jul 29, 2024
e11ad00
Authenticated send and receive function; first draft of events that c…
fabian-hk Aug 5, 2024
13188db
Improved events that can be extended by a higher layer
fabian-hk Aug 7, 2024
106c001
Cleanup code; documentation
fabian-hk Aug 9, 2024
03eddb2
Fixed issue with initialization method for debug run; Code cleanup
fabian-hk Aug 10, 2024
31f0379
Introduced comm_higher_layer_event_preds_later function to improve co…
fabian-hk Aug 19, 2024
93f1747
First draft of confidential and authenticated send and receive functions
fabian-hk Aug 20, 2024
0719149
Updated version of the confidential and authenticated send and receiv…
fabian-hk Oct 24, 2024
8c1efed
Cleanup decrypt_message_proof post condition and signature predicate
fabian-hk Oct 28, 2024
85a711e
Updated communication layer to be compatible with label changes
fabian-hk Oct 30, 2024
eadbb82
Conf-auth proof with pk_enc extract function
fabian-hk Nov 7, 2024
8faf365
Cleanup
fabian-hk Nov 11, 2024
c8282c1
Cleanup; Separate file for core extension
fabian-hk Nov 12, 2024
7d9e3a8
Define later for comm_higher_layer_event_preds
fabian-hk Nov 14, 2024
96f2e30
First draft of request-response functions
fabian-hk Nov 20, 2024
f8644a4
Request-response functions with state on the server side
fabian-hk Nov 27, 2024
b605ff9
Use comm_meta_data for the request-response functions; Added last pro…
fabian-hk Nov 29, 2024
261d091
Clean up states and events
fabian-hk Dec 5, 2024
57a3500
Removed id and client from request response pairs
fabian-hk Dec 5, 2024
3271ca2
Updated com layer README
fabian-hk Dec 5, 2024
cfe081c
Tried to replace reveal by showing the property with pkenc_input but …
fabian-hk Nov 5, 2024
db61f53
Conf auth proof without reveal but with pk_receiver in message
fabian-hk Nov 8, 2024
5167191
Only encrypt payload
fabian-hk Nov 10, 2024
94ac9aa
Cleanup
fabian-hk Nov 10, 2024
4f9becd
Sign predicate cleanup
fabian-hk Dec 6, 2024
18f4c4f
Fixed issues after rebase on feature/add-key-to-crypto-preds
fabian-hk Dec 10, 2024
a2f4d14
Automatically serialize and parse messages
fabian-hk Dec 16, 2024
7492439
Cleanup
fabian-hk Dec 16, 2024
28e6207
Added SMTPats to request response lemmas
fabian-hk Dec 17, 2024
5033826
Changed post condition of receive_request_proof
fabian-hk Dec 18, 2024
11e0d2a
Removed communication_keys_sess_ids from send response and receive re…
fabian-hk Dec 20, 2024
23b45cb
Add function to generate a communication layer response nonce with an…
fabian-hk Jan 8, 2025
b625d4a
Add trace printing functions; Cleanup
fabian-hk Jan 9, 2025
a3539be
Encapsulate all com messages in com_message_t type. This is needed fo…
fabian-hk Jan 10, 2025
8d4f779
Improve printing of communication messages
fabian-hk Jan 22, 2025
7deb02c
Feedback
fabian-hk Jan 22, 2025
3d927a0
Feedback
fabian-hk Jan 28, 2025
7499ea7
Using False as default in event predicates extension by higher layer;…
fabian-hk Jan 30, 2025
40ba5f5
Update URL to communication layer examples
fabian-hk Jan 30, 2025
14504c8
Adjust request/confidential message postconditions (#101)
qaphla Feb 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .fst.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"src/lib/hpke",
"src/lib/state",
"src/lib/utils",
"src/lib/communication",
"examples/nsl_pk",
"examples/iso_dh"
]
Expand Down
2 changes: 1 addition & 1 deletion Makefile
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FSTAR_EXE ?= $(shell which fstar.exe)
Z3 ?= $(shell which z3)
COMPARSE_HOME ?= $(DY_HOME)/../comparse

INNER_SOURCE_DIRS = core lib lib/comparse lib/crypto lib/event lib/hpke lib/state lib/utils
INNER_SOURCE_DIRS = core lib lib/comparse lib/crypto lib/event lib/hpke lib/state lib/utils lib/communication
SOURCE_DIRS = $(addprefix $(DY_HOME)/src/, $(INNER_SOURCE_DIRS))
INNER_EXAMPLE_DIRS = nsl_pk iso_dh
EXAMPLE_DIRS ?= $(addprefix $(DY_HOME)/examples/, $(INNER_EXAMPLE_DIRS))
TWal marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
3 changes: 3 additions & 0 deletions src/lib/DY.Lib.fst
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ include DY.Lib.Printing

/// Functions and lemmas for HPKE, built on top of kem, kdf and aead
include DY.Lib.HPKE

/// Functions and lemmas to securely send messages over the network
include DY.Lib.Communication
204 changes: 204 additions & 0 deletions src/lib/communication/DY.Lib.Communication.Core.Invariants.fst
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
module DY.Lib.Communication.Core.Invariants

open Comparse
open DY.Core
open DY.Lib.Crypto.PKE.Split
open DY.Lib.Crypto.Signature.Split
open DY.Lib.Crypto.AEAD.Split
open DY.Lib.Event.Typed
open DY.Lib.State.PrivateKeys
open DY.Lib.State.Tagged

open DY.Lib.Communication.Data
open DY.Lib.Communication.Core

#set-options "--fuel 0 --ifuel 0 --z3cliopt 'smt.qi.eager_threshold=100'"

(*** PkEnc Predicates ***)

val pke_crypto_predicates_communication_layer: {|cusages:crypto_usages|} -> pke_crypto_predicate
let pke_crypto_predicates_communication_layer #cusages = {
pred = (fun tr sk_usage pk msg ->
(exists sender receiver.
sk_usage == long_term_key_type_to_usage (LongTermPkeKey comm_layer_pkenc_tag) receiver /\
(get_label tr msg) `can_flow tr` (comm_label sender receiver) /\
event_triggered tr sender (CommConfSendMsg sender receiver msg)
)
);
pred_later = (fun tr1 tr2 sk_usage pk msg -> ());
}

val pke_crypto_predicates_communication_layer_and_tag:
{|cusages:crypto_usages|} ->
(string & pke_crypto_predicate)
let pke_crypto_predicates_communication_layer_and_tag #cusages =
(comm_layer_pkenc_tag, pke_crypto_predicates_communication_layer)

(*** Sign Predicates ***)

#push-options "--ifuel 3 --fuel 0"
val sign_crypto_predicates_communication_layer: {|cusages:crypto_usages|} -> sign_crypto_predicate
let sign_crypto_predicates_communication_layer #cusages = {
pred = (fun tr sk_usage vk sig_msg ->
(match parse signature_input sig_msg with
| Some (Plain sender receiver payload_bytes) -> (
sk_usage == long_term_key_type_to_usage (LongTermSigKey comm_layer_sign_tag) sender /\
get_label tr payload_bytes `can_flow tr` public /\
event_triggered tr sender (CommAuthSendMsg sender payload_bytes)
)
| Some (Encrypted sender receiver payload_bytes pk_receiver) -> (
match parse com_send_byte payload_bytes with
| None -> False
| Some payload -> (
get_label tr payload_bytes `can_flow tr` public /\
(exists plain_payload nonce.
sk_usage == long_term_key_type_to_usage (LongTermSigKey comm_layer_sign_tag) sender /\
payload.b == pke_enc pk_receiver nonce plain_payload /\
event_triggered tr sender (CommConfAuthSendMsg sender receiver plain_payload)
qaphla marked this conversation as resolved.
Show resolved Hide resolved
)
)
)
| None -> False)
);
pred_later = (fun tr1 tr2 sk_usage vk msg -> parse_wf_lemma signature_input (bytes_well_formed tr1) msg);
}
#pop-options

val sign_crypto_predicates_communication_layer_and_tag:
{|cusages:crypto_usages|} ->
(string & sign_crypto_predicate)
let sign_crypto_predicates_communication_layer_and_tag #cusages =
(comm_layer_sign_tag, sign_crypto_predicates_communication_layer)

val has_communication_layer_crypto_predicates:
{|crypto_invariants|} ->
prop
let has_communication_layer_crypto_predicates #cinvs =
has_pke_predicate pke_crypto_predicates_communication_layer_and_tag /\
has_sign_predicate sign_crypto_predicates_communication_layer_and_tag

(*** Event Predicates ***)

noeq
type comm_higher_layer_event_preds (a:Type) {| parseable_serializeable bytes a |} = {
send_conf: tr:trace -> sender:principal -> receiver:principal -> payload:a -> prop;
send_conf_later:
tr1:trace -> tr2:trace ->
sender:principal -> receiver:principal -> payload:a ->
Lemma
(requires
send_conf tr1 sender receiver payload /\
bytes_well_formed tr1 (serialize a payload) /\
tr1 <$ tr2
)
(ensures send_conf tr2 sender receiver payload)
;
send_auth: tr:trace -> sender:principal -> payload:a -> prop;
send_auth_later:
tr1:trace -> tr2:trace ->
sender:principal -> payload:a ->
Lemma
(requires
send_auth tr1 sender payload /\
bytes_well_formed tr1 (serialize a payload) /\
tr1 <$ tr2
)
(ensures send_auth tr2 sender payload)
;
send_conf_auth: tr:trace -> sender:principal -> receiver:principal -> payload:a -> prop;
send_conf_auth_later:
tr1:trace -> tr2:trace ->
sender:principal -> receiver:principal -> payload:a ->
Lemma
(requires
send_conf_auth tr1 sender receiver payload /\
bytes_well_formed tr1 (serialize a payload) /\
tr1 <$ tr2
)
(ensures send_conf_auth tr2 sender receiver payload)
}

let default_comm_higher_layer_event_preds (a:Type) {| parseable_serializeable bytes a |} : comm_higher_layer_event_preds a = {
send_conf = (fun tr sender receiver payload -> True);
send_conf_later = (fun tr1 tr2 sender receiver payload -> ());
send_auth = (fun tr sender payload -> True);
send_auth_later = (fun tr1 tr2 sender payload -> ());
send_conf_auth = (fun tr sender receiver payload -> True);
send_conf_auth_later = (fun tr1 tr2 sender receiver payload -> ())
}

#push-options "--ifuel 1 --fuel 0"
let event_predicate_communication_layer
{|cinvs:crypto_invariants|}
(#a:Type) {| parseable_serializeable bytes a |}
(higher_layer_preds:comm_higher_layer_event_preds a) :
event_predicate communication_event =
fun tr prin e ->
(match e with
| CommConfSendMsg sender receiver payload -> (
is_knowable_by (comm_label sender receiver) tr payload /\
(match parse a payload with
| None -> False
| Some payload_p -> higher_layer_preds.send_conf tr sender receiver payload_p
)
)
| CommConfReceiveMsg receiver payload -> (
exists sender.
//is_knowable_by (comm_label sender receiver) tr payload /\
fabian-hk marked this conversation as resolved.
Show resolved Hide resolved
(
event_triggered tr sender (CommConfSendMsg sender receiver payload) \/
is_publishable tr payload
)
)
| CommAuthSendMsg sender payload -> (
(match parse a payload with
| None -> False
| Some payload_p -> higher_layer_preds.send_auth tr sender payload_p
)
)
| CommAuthReceiveMsg sender receiver payload -> (
is_publishable tr payload /\
(
event_triggered tr sender (CommAuthSendMsg sender payload) \/
is_corrupt tr (long_term_key_label sender)
)
)
| CommConfAuthSendMsg sender receiver payload -> (
is_knowable_by (comm_label sender receiver) tr payload /\
(match parse a payload with
| None -> False
| Some payload_p -> higher_layer_preds.send_conf_auth tr sender receiver payload_p
)
)
| CommConfAuthReceiveMsg sender receiver payload -> (
// We can only show the following about the decrypted ciphertext (payload):
// is_knowable_by (comm_label sender receiver) tr payload \/
// is_corrupt tr (principal_label sender)
// There are two cases how the ciphertext is created:
// 1. The corrupted sender created the ciphertext. This means that the
// payload flows to public. This would also mean that it flows to the
// sender and receiver. The problem is the second case.
// 2. The corrupted sender takes a ciphertext from an honest principal.
// Since the crypto predicates apply to this ciphertext, the
// decrypted payload flows to the receiver and some unknown sender'.
event_triggered tr sender (CommConfAuthSendMsg sender receiver payload) \/
is_corrupt tr (long_term_key_label sender)
)
)
#pop-options

val event_predicate_communication_layer_and_tag:
{|cinvs:crypto_invariants|} ->
#a:Type -> {| parseable_serializeable bytes a |} ->
comm_higher_layer_event_preds a ->
(string & compiled_event_predicate)
let event_predicate_communication_layer_and_tag #cinvs higher_layer_preds =
(event_communication_event.tag, compile_event_pred (event_predicate_communication_layer #cinvs higher_layer_preds))

val has_communication_layer_event_predicates:
{|protocol_invariants|} ->
#a:Type -> {| parseable_serializeable bytes a |} ->
comm_higher_layer_event_preds a ->
prop
let has_communication_layer_event_predicates #invs higher_layer_preds =
has_event_pred (event_predicate_communication_layer #invs.crypto_invs higher_layer_preds)
Loading