Skip to content

Commit 8aa8dea

Browse files
agokarnjyao1
authored andcommitted
Refactor src/migtd/src/ratls/server_client.rs.
1 parent 1d6e245 commit 8aa8dea

File tree

1 file changed

+40
-14
lines changed

1 file changed

+40
-14
lines changed

src/migtd/src/ratls/server_client.rs

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,41 +23,67 @@ use verify::*;
2323

2424
type Result<T> = core::result::Result<T, RatlsError>;
2525

26+
#[cfg(not(feature = "policy_v2"))]
27+
pub fn server<T: AsyncRead + AsyncWrite + Unpin>(stream: T) -> Result<SecureChannel<T>> {
28+
let signing_key = EcdsaPk::new()?;
29+
let (certs, quote) = gen_cert(&signing_key)?;
30+
let certs = vec![certs];
31+
32+
// Server verifies certificate of client
33+
let config = TlsConfig::new(certs, signing_key, verify_client_cert, quote)?;
34+
35+
config.tls_server(stream).map_err(|e| e.into())
36+
}
37+
38+
#[cfg(feature = "policy_v2")]
2639
pub fn server<T: AsyncRead + AsyncWrite + Unpin>(
2740
stream: T,
28-
#[cfg(feature = "policy_v2")] remote_policy: Vec<u8>,
41+
remote_policy: Vec<u8>,
2942
) -> Result<SecureChannel<T>> {
3043
let signing_key = EcdsaPk::new()?;
31-
let (certs, quote) = gen_cert(&signing_key)?;
44+
let (certs, _quote) = gen_cert(&signing_key)?;
3245
let certs = vec![certs];
3346

34-
#[cfg(feature = "policy_v2")]
35-
let _ = &quote; // mark as intentionally unused
36-
3747
// Server verifies certificate of client
38-
#[cfg(not(feature = "policy_v2"))]
39-
let config = TlsConfig::new(certs, signing_key, verify_client_cert, quote)?;
40-
#[cfg(feature = "policy_v2")]
4148
let config = TlsConfig::new(certs, signing_key, verify_client_cert, remote_policy)?;
4249
config.tls_server(stream).map_err(|e| e.into())
4350
}
4451

52+
#[cfg(not(feature = "policy_v2"))]
4553
pub fn client<T: AsyncRead + AsyncWrite + Unpin>(
4654
stream: T,
47-
#[cfg(feature = "policy_v2")] remote_policy: Vec<u8>,
4855
#[cfg(feature = "vmcall-raw")] data: &mut Vec<u8>,
4956
) -> Result<SecureChannel<T>> {
5057
let signing_key = EcdsaPk::new()?;
5158
let (certs, quote) = gen_cert(&signing_key)?;
5259
let certs = vec![certs];
5360

54-
#[cfg(feature = "policy_v2")]
55-
let _ = &quote; // mark as intentionally unused
56-
5761
// Client verifies certificate of server
58-
#[cfg(not(feature = "policy_v2"))]
5962
let config = TlsConfig::new(certs, signing_key, verify_server_cert, quote)?;
60-
#[cfg(feature = "policy_v2")]
63+
config.tls_client(stream).map_err(|e| {
64+
#[cfg(feature = "vmcall-raw")]
65+
data.extend_from_slice(
66+
&format!(
67+
"Error: server_client client(): Failure in tls_client() error: {:?}\n",
68+
e
69+
)
70+
.into_bytes(),
71+
);
72+
e.into()
73+
})
74+
}
75+
76+
#[cfg(feature = "policy_v2")]
77+
pub fn client<T: AsyncRead + AsyncWrite + Unpin>(
78+
stream: T,
79+
remote_policy: Vec<u8>,
80+
#[cfg(feature = "vmcall-raw")] data: &mut Vec<u8>,
81+
) -> Result<SecureChannel<T>> {
82+
let signing_key = EcdsaPk::new()?;
83+
let (certs, _quote) = gen_cert(&signing_key)?;
84+
let certs = vec![certs];
85+
86+
// Client verifies certificate of server
6187
let config = TlsConfig::new(certs, signing_key, verify_server_cert, remote_policy)?;
6288
config.tls_client(stream).map_err(|e| {
6389
#[cfg(feature = "vmcall-raw")]

0 commit comments

Comments
 (0)