Skip to content
This repository was archived by the owner on May 9, 2022. It is now read-only.

Commit 0bd520c

Browse files
longtomjrPiDelport
authored andcommitted
feat(auth): add messages used to set access key, use rtc_types in protected channel
1 parent 69d8e01 commit 0bd520c

File tree

3 files changed

+75
-10
lines changed

3 files changed

+75
-10
lines changed

rtc_tenclave/src/dh/protected_channel.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use secrecy::{ExposeSecret, Secret};
44
use sgx_tcrypto::{rsgx_rijndael128GCM_decrypt, rsgx_rijndael128GCM_encrypt};
55
use sgx_types::*;
66

7+
use rtc_types::enclave_messages::{EncryptedEnclaveMessage, RecommendedAesGcmIv};
8+
79
use super::types::AlignedKey;
810
use crate::util::concat_u8;
911

@@ -12,9 +14,6 @@ use super::enclave;
1214
#[cfg(not(test))]
1315
use sgx_tstd::enclave;
1416

15-
// NIST AES-GCM recommended IV size
16-
type RecommendedAesGcmIv = [u8; 12];
17-
1817
pub struct ProtectedChannel {
1918
iv_constructor: DeterministicAesGcmIvConstructor,
2019
key: Secret<AlignedKey>,
@@ -70,13 +69,6 @@ impl ProtectedChannel {
7069
}
7170
}
7271

73-
pub struct EncryptedEnclaveMessage<const MESSAGE_SIZE: usize, const AAD_SIZE: usize> {
74-
tag: sgx_aes_gcm_128bit_tag_t,
75-
ciphertext: [u8; MESSAGE_SIZE],
76-
aad: [u8; AAD_SIZE],
77-
nonce: RecommendedAesGcmIv,
78-
}
79-
8072
/// Implement the deterministic construction of AES-GCM IVs, as described in section 8.2.1 of [NIST SP 800-38D],
8173
/// "Recommendation for Block Cipher Modes of Operation: Galois/Counter Mode (GCM) and GMAC".
8274
///

rtc_types/src/enclave_messages.rs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
use sgx_types::*;
2+
use std::mem;
3+
4+
use rkyv::{Archive, Deserialize, Serialize};
5+
6+
// NIST AES-GCM recommended IV size
7+
pub type RecommendedAesGcmIv = [u8; 12];
8+
9+
#[repr(C)]
10+
pub struct EncryptedEnclaveMessage<const MESSAGE_SIZE: usize, const AAD_SIZE: usize> {
11+
pub tag: sgx_aes_gcm_128bit_tag_t,
12+
pub ciphertext: [u8; MESSAGE_SIZE],
13+
pub aad: [u8; AAD_SIZE],
14+
pub nonce: RecommendedAesGcmIv,
15+
}
16+
17+
// TODO: Macro?
18+
pub mod set_access_key {
19+
use super::*;
20+
21+
#[derive(Archive, Deserialize, Serialize, Debug, PartialEq, Clone)]
22+
pub struct Request {
23+
// XXX: Technically this only needs to be available inside of enclave contexts.
24+
// It might make sense to conditionally export this as public.
25+
pub uuid: [u8; 16], // TODO: Use UUID crate?
26+
pub access_key: [u8; 24], // [u8; ACCESS_KEY_BYTES]
27+
}
28+
29+
pub const REQUEST_SIZE: usize = mem::size_of::<<Request as Archive>::Archived>();
30+
31+
pub type EncryptedRequest = EncryptedEnclaveMessage<REQUEST_SIZE, 0>;
32+
33+
#[derive(Archive, Deserialize, Serialize, Debug, PartialEq)]
34+
pub struct Response {
35+
success: bool,
36+
}
37+
38+
pub const RESPONSE_SIZE: usize = mem::size_of::<<Response as Archive>::Archived>();
39+
40+
pub type EncryptedResponse = EncryptedEnclaveMessage<RESPONSE_SIZE, 0>;
41+
}
42+
43+
#[cfg(test)]
44+
mod test {
45+
use rkyv::{
46+
archived_root,
47+
ser::{serializers::BufferSerializer, Serializer},
48+
Aligned, Deserialize, Infallible,
49+
};
50+
51+
use super::*;
52+
53+
#[test]
54+
fn test_set_access_key_msg() {
55+
let request = set_access_key::Request {
56+
uuid: [5u8; 16],
57+
access_key: [2u8; 24],
58+
};
59+
60+
let mut serializer = BufferSerializer::new(Aligned([0u8; set_access_key::REQUEST_SIZE]));
61+
serializer.serialize_value(&request.clone()).unwrap();
62+
let buf = serializer.into_inner();
63+
let archived = unsafe { archived_root::<set_access_key::Request>(buf.as_ref()) };
64+
let deserialized = archived.deserialize(&mut Infallible).unwrap();
65+
66+
assert_eq!(
67+
request, deserialized,
68+
"Deserialized request should match initial request"
69+
);
70+
}
71+
}

rtc_types/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ pub use exec_token::*;
2525
mod ecall_result;
2626
pub use ecall_result::*;
2727

28+
pub mod enclave_messages;
29+
2830
#[repr(C)]
2931
#[derive(Clone, Debug)]
3032
pub struct EncryptedMessage {

0 commit comments

Comments
 (0)