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

Verify message-header serialization and deserialization #47

Merged
merged 25 commits into from
Oct 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
31e4e7e
Enhance Makefile
RustanLeino Sep 26, 2019
e3595d8
Use `Result` type instead of `Either`
RustanLeino Sep 26, 2019
bfca9c7
Reformat code according to Dafny style guide
RustanLeino Sep 27, 2019
8a53935
Use `:-` error-handling assignment
RustanLeino Sep 27, 2019
5915688
Make serialization and deserialization verify
RustanLeino Sep 28, 2019
a73b6dd
Remove special data structure for an empty AAD
RustanLeino Sep 28, 2019
d71dbcd
Include MessageHeader and some Util in build
RustanLeino Sep 26, 2019
8080e8a
Change MessageHeader to use seq instead of array
RustanLeino Sep 26, 2019
3997d30
Revise according to @MatthewBennington's comments
RustanLeino Oct 1, 2019
737ff25
Specify validity of authentication header
RustanLeino Oct 1, 2019
d99a241
Implement serialization of header authentication
RustanLeino Oct 1, 2019
4ab103d
Fail deserialization on duplicate keys, not on unsorted input
RustanLeino Oct 2, 2019
1973310
Minor renamings and changes
RustanLeino Oct 2, 2019
68580be
Eliminate import opened
RustanLeino Oct 2, 2019
f67780a
Act on review comments
RustanLeino Oct 2, 2019
781ca5c
Name magic constants
RustanLeino Oct 2, 2019
083c80f
Make StandardLibrary conform to Dafny style guide
RustanLeino Oct 2, 2019
9554fee
Improve streams
RustanLeino Oct 3, 2019
a7d33ea
Rename variables that hold String{Reader,Writer} to rd, wr
RustanLeino Oct 3, 2019
548facd
Combine MessageHeader files
RustanLeino Oct 3, 2019
7c2036b
Combine MessageHeader submodules
RustanLeino Oct 3, 2019
9381a96
Respond to PR comments
RustanLeino Oct 5, 2019
d218053
Refactor as per PR comments
RustanLeino Oct 5, 2019
c3f5847
Refactor as per PR comments
RustanLeino Oct 5, 2019
8e6bef0
Act on more PR review comments
RustanLeino Oct 8, 2019
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
15 changes: 11 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@ SRCS = \
src/SDK/AlgorithmSuite.dfy \
src/SDK/CMM/DefaultCMM.dfy \
src/SDK/CMM/Defs.dfy \
src/SDK/Deserialize.dfy \
src/SDK/Keyring/AESKeyring.dfy \
src/SDK/Keyring/Defs.dfy \
src/SDK/Keyring/RSAKeyring.dfy \
src/SDK/Materials.dfy \
src/SDK/MessageHeader.dfy \
src/SDK/Serialize.dfy \
src/SDK/ToyClient.dfy \
src/StandardLibrary/Base64.dfy \
src/StandardLibrary/StandardLibrary.dfy \
src/StandardLibrary/UInt.dfy \
src/Util/Streams.dfy \
src/Util/UTF8.dfy \

SRCV = $(patsubst src/%.dfy, build/%.dfy.verified, $(SRCS))

Expand All @@ -37,7 +42,9 @@ SRCDIRS = $(dir $(SRCS))
DEPS = $(foreach dir, $(SRCDIRS), $(wildcard $(dir)/*.cs)) \
$(BCDLL)

.PHONY: all hkdf test noverif clean-build clean
DEPS_CS = $(foreach dir, src/Crypto/ src/ src/SDK/ src/SDK/CMM src/SDK/Keyring src/StandardLibrary src/Util, $(wildcard $(dir)/*.cs))

.PHONY: all release build verify buildcs hkdf test clean-build clean

all: verify build test

Expand All @@ -53,6 +60,9 @@ build/%.dfy.verified: src/%.dfy
build/Main.exe: $(SRCS) $(DEPS)
$(DAFNY) /out:build/Main $(SRCS) $(DEPS) /compile:2 /noVerify /noIncludes && cp $(BCDLL) build/

buildcs: build/Main.cs
csc /r:System.Numerics.dll /r:$(BCDLL) /target:exe /debug /nowarn:0164 /nowarn:0219 /nowarn:1717 /nowarn:0162 /nowarn:0168 build/Main.cs $(DEPS_CS) /out:build/Main.exe

# TODO: HKDF.dfy hasn't been reviewed yet.
# Once it is, re-add:
#
Expand All @@ -68,9 +78,6 @@ lib/%.dll:
test: $(DEPS)
lit test -q -v

noverif: $(DEPS)
$(DAFNY) /out:build/Main $(SRCS) $(DEPS) /compile:2 /noVerify /noIncludes && cp $(BCDLL) build/

clean-build:
$(RM) -r build/*

Expand Down
34 changes: 32 additions & 2 deletions src/SDK/AlgorithmSuite.dfy
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,22 @@ module AlgorithmSuite {
import C = Cipher
import Digests

const validIDs: set<uint16> := {0x0378, 0x0346, 0x0214, 0x0178, 0x0146, 0x0114, 0x0078, 0x0046, 0x0014};
const VALID_IDS: set<uint16> := {0x0378, 0x0346, 0x0214, 0x0178, 0x0146, 0x0114, 0x0078, 0x0046, 0x0014};

newtype ID = x | x in validIDs witness 0x0014
newtype ID = x | x in VALID_IDS witness 0x0014
{
function method KeyLength(): nat {
Suite[this].params.keyLen as nat
}

function method IVLength(): nat {
Suite[this].params.ivLen as nat
}

function method TagLength(): nat {
Suite[this].params.tagLen as nat
}

function method SignatureType(): Option<S.ECDSAParams> {
Suite[this].sign
}
Expand Down Expand Up @@ -46,4 +54,26 @@ module AlgorithmSuite {
AES_192_GCM_IV12_TAG16_KDFNONE_SIGNONE := AlgSuite(C.AES_GCM_192, Digests.HmacNOSHA, None),
AES_128_GCM_IV12_TAG16_KDFNONE_SIGNONE := AlgSuite(C.AES_GCM_128, Digests.HmacNOSHA, None)
]

/* Suite is intended to have an entry for each possible value of ID. This is stated and checked in three ways.
* - lemma SuiteIsCompletes states and proves the connection between type ID and Suite.Keys
* - lemma ValidIDsAreSuiteKeys states and proves the connected between predicate ValidIDs and Suite.Keys
* - the member functions of ID use the expression `Suite[this]`, whose well-formedness relies on every
* ID being in Suite.Keys
*/

lemma SuiteIsComplete(id: ID)
ensures id in Suite.Keys
{
}

lemma ValidIDsAreSuiteKeys()
ensures VALID_IDS == set id | id in Suite.Keys :: id as uint16
{
forall x | x in VALID_IDS
ensures exists id :: id in Suite.Keys && id as uint16 == x
{
assert x as ID in Suite.Keys;
}
}
}
4 changes: 2 additions & 2 deletions src/SDK/CMM/DefaultCMM.dfy
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ module DefaultCMMDef {
{
return Failure("Could not retrieve materials required for encryption");
}
res := Success(em);
return Success(em);
}

method DecryptMaterials(alg_id: AlgorithmSuite.ID, edks: seq<Materials.EncryptedDataKey>, enc_ctx: Materials.EncryptionContext) returns (res: Result<Materials.DecryptionMaterials>)
Expand Down Expand Up @@ -104,7 +104,7 @@ module DefaultCMMDef {
return Failure("Could not get materials required for decryption.");
}

res := Success(dm);
return Success(dm);
}
}
}
Expand Down
Loading