forked from martinthomson/ohttp
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlib.rs
More file actions
executable file
·42 lines (35 loc) · 1.14 KB
/
lib.rs
File metadata and controls
executable file
·42 lines (35 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
pub mod err;
use err::AttestError;
use libc::{c_char, c_int, size_t};
use std::ffi::CString;
type Res<T> = Result<T, Box<dyn std::error::Error>>;
#[link(name = "azguestattestation")]
extern "C" {
fn get_attestation_token(
app_data: *const u8,
pcr_sel: u32,
jwt: *mut u8,
jwt_len: *mut size_t,
endpoint_url: *const c_char,
) -> c_int;
}
pub fn attest(data: &[u8], pcrs: u32, endpoint_url: &str) -> Res<Vec<u8>> {
match CString::new(endpoint_url) {
Ok(endpoint_url_cstring) => unsafe {
let mut dstlen = 32 * 1024;
let mut dst = Vec::with_capacity(dstlen);
let pdst = dst.as_mut_ptr();
let url_ptr = endpoint_url_cstring.as_ptr();
let ret = get_attestation_token(data.as_ptr(), pcrs, pdst, &mut dstlen, url_ptr);
if ret == 0 {
dst.set_len(dstlen);
Ok(dst)
} else {
Err(Box::new(AttestError::MAAToken(ret)))
}
},
_e => Err(Box::new(AttestError::Convertion)),
}
}