Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
52 changes: 25 additions & 27 deletions .github/workflows/eaa_kbc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ on:
paths:
- 'src/kbc_modules/eaa_kbc/**'

env:
RATS_TLS_LIBDIR: /usr/local/lib/rats-tls

jobs:
eaa_kbc_ci:
if: github.event_name == 'pull_request'
name: Check
runs-on: ubuntu18.04
runs-on: ubuntu-18.04
strategy:
fail-fast: false
matrix:
Expand All @@ -23,36 +26,31 @@ jobs:
- beta
- nightly
steps:
- name: Install rats-tls dependencies
run: |
apt-get update && apt-get install -y autoconf gcc g++ make wget git cmake \
libseccomp-dev binutils-dev libprotoc-dev protobuf-compiler \
pkg-config libssl-dev openssl libtool file curl gnupg;

wget https://github.com/protobuf-c/protobuf-c/archive/v1.3.1.tar.gz &&\
tar -zxvf v1.3.1.tar.gz && cd protobuf-c-1.3.1 && ./autogen.sh && \
./configure && make && make install
- name: Set up docker
use: docker-practice/actions-setup-docker@master

wget https://download.01.org/intel-sgx/sgx-linux/2.14/as.ld.objdump.gold.r3.tar.gz && \
tar -zxvf as.ld.objdump.gold.r3.tar.gz && cp -rf external/toolset/ubuntu18.04/* /usr/local/bin/ && \
rm -rf external && rm -rf as.ld.objdump.gold.r3.tar.gz
- name: Install Rust toolchain (${{ matrix.rust }})
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
override: true

wget https://download.01.org/intel-sgx/sgx-linux/2.14/distro/ubuntu18.04-server/sgx_linux_x64_sdk_2.14.100.2.bin;
chmod +x sgx_linux_x64_sdk_2.14.100.2.bin && echo -e 'no\n/opt/intel\n' | ./sgx_linux_x64_sdk_2.14.100.2.bin;
rm -rf sgx_linux_x64_sdk_2.14.100.2.bin;

source /opt/intel/sgxsdk/environment;

echo 'deb [arch=amd64] https://download.01.org/intel-sgx/sgx_repo/ubuntu bionic main' | tee /etc/apt/sources.list.d/intel-sgx.list && \
wget -qO - https://download.01.org/intel-sgx/sgx_repo/ubuntu/intel-sgx-deb.key | apt-key add -;

apt-get update -y && apt-get install -y libsgx-dcap-quote-verify libsgx-dcap-default-qpl libsgx-dcap-ql-dev libsgx-uae-service libsgx-dcap-quote-verify-dev;
- name: Create rats-tls compiling container
run: |
rats_compile_env=$(docker run -itd --privileged --rm --net host -v /usr/local/lib:/root/target inclavarecontainers/test:compile-check-ubuntu18.04);
echo "rats_compile_env=$rats_compile_env" >> $GITHUB_ENV

- name: Install rats-tls
- name: Build and install rats-tls
run: |
git clone https://github.com/alibaba/inclavare-containers && cd inclavare-containers/rats-tls;
cmake -DBUILD_SAMPLES=on -H. -Bbuild && make -C build install;
docker exec $rats_compile_env bash -c 'git clone https://github.com/alibaba/inclavare-containers;
cd inclavare-containers/rats-tls;
cmake -DBUILD_SAMPLES=on -H. -Bbuild;
make -C build install;
cd /root/target;
mkdir rats-tls;
cp -rf ${{ env.RATS_TLS_LIBDIR }} /root/target/rats-tls'

- name: Build AA with EAA KBC
run: |
make KBC=eaa_kbc && make install;
make KBC=eaa_kbc && make install;
8 changes: 4 additions & 4 deletions src/grpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@ fn parse_input(input_byte: Vec<u8>) -> Result<InputPayload> {
let kbc_name: String = kbc_kbs_pair[..index].to_string();
let kbs_uri: String = kbc_kbs_pair[(index + 2)..].to_string();
debug!("Get KBC_NAME:{}, KBS_URI:{}", kbc_name, kbs_uri);
return Ok(InputPayload {
kbc_name: kbc_name,
kbs_uri: kbs_uri,
Ok(InputPayload {
kbc_name,
kbs_uri,
annotation: jsonstring_annotation.to_string(),
});
})
} else {
return Err(anyhow!(
"Invalid parameters: invalid {} pair format!",
Expand Down
1 change: 1 addition & 0 deletions src/kbc_modules/eaa_kbc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@ e.g: EAA KBS address is 127.0.0.1:1122 :
eaa_kbc::127.0.0.1:1122
```

### test


16 changes: 8 additions & 8 deletions src/kbc_modules/eaa_kbc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl KbcInterface for EAAKbc {
"protocol_version".to_string(),
self.protocol_version.clone(),
);
Ok(KbcCheckInfo { kbs_info: kbs_info })
Ok(KbcCheckInfo { kbs_info })
}

fn decrypt_payload(&mut self, annotation: &str) -> Result<Vec<u8>> {
Expand Down Expand Up @@ -69,7 +69,7 @@ impl KbcInterface for EAAKbc {
impl EAAKbc {
pub fn new(kbs_uri: String) -> EAAKbc {
EAAKbc {
kbs_uri: kbs_uri,
kbs_uri,
protocol_version: String::new(),
algorithm: String::new(),
key_length: 0,
Expand Down Expand Up @@ -99,17 +99,17 @@ impl EAAKbc {
}

fn kbs_query_version(&mut self) -> Result<String> {
let request = VersionRequest::new();
let request = VersionRequest::default();
let trans_json = serde_json::to_string(&request)?;
let trans_data: &[u8] = trans_json.as_bytes();
let recv_string: String = self.kbs_trans_and_recv(trans_data, "Version")?;
let response: VersionResponse =
serde_json::from_str::<VersionResponse>(recv_string.as_str())?;

match response.status.as_str() {
"OK" => return Ok(response.version),
"OK" => Ok(response.version),
"Fail" => return Err(anyhow!("The VersionResponse status is 'Fail'!")),
_ => return Err(anyhow!("Can't understand the VersionResponse status!")),
_ => return Err(anyhow!("Can't understand the VersionResponse status!hahahahahahaha")),
}
}

Expand All @@ -120,7 +120,7 @@ impl EAAKbc {
iv: Vec<u8>,
) -> Result<Vec<u8>> {
let blob = Blob {
kid: key_id.clone(),
kid: key_id,
encrypted_data: base64::encode(&encrypted_payload),
algorithm: "AES".to_string(),
key_length: 256,
Expand All @@ -146,7 +146,7 @@ impl EAAKbc {
"There is no field matching the encrypted payload in the data field of DecryptionResponse"
))?;
let decrypted_payload = base64::decode(decrypted_payload_string)?;
return Ok(decrypted_payload);
Ok(decrypted_payload)
} else {
return Err(anyhow!(
"DecryptionResponse status is OK but the data is null!"
Expand Down Expand Up @@ -180,7 +180,7 @@ impl EAAKbc {
})?;

let recv_string: String = String::from_utf8(buffer[..len_recv].to_vec())?;
debug!("Recieved: {}", recv_string);
debug!("Recieved: {}! hahahaha", recv_string);

Ok(recv_string)
}
Expand Down
6 changes: 6 additions & 0 deletions src/kbc_modules/eaa_kbc/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ impl VersionRequest {
}
}

impl Default for VersionRequest {
fn default() -> Self {
Self::new()
}
}

#[derive(Serialize, Deserialize, Debug)]
pub struct VersionResponse {
pub status: String,
Expand Down
17 changes: 8 additions & 9 deletions src/kbc_modules/eaa_kbc/rats_tls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ unsafe impl ForeignTypeRef for RatsTlsRef {
#[derive(Clone)]
pub struct RatsTls(NonNull<rats_tls_handle>);

unsafe impl Send for RatsTlsRef {}
unsafe impl Sync for RatsTlsRef {}
unsafe impl Send for RatsTls {}
unsafe impl Sync for RatsTls {}

Expand Down Expand Up @@ -69,12 +67,13 @@ impl DerefMut for RatsTls {

impl RatsTls {
pub fn new() -> Result<RatsTls, RatsTlsErrT> {
let mut conf: rats_tls_conf_t = Default::default();
conf.api_version = RATS_TLS_API_VERSION_DEFAULT;
conf.log_level = RATS_TLS_LOG_LEVEL_DEBUG;

conf.cert_algo = RATS_TLS_CERT_ALGO_DEFAULT;
conf.enclave_id = 0;
let mut conf = rats_tls_conf_t {
api_version: RATS_TLS_API_VERSION_DEFAULT,
log_level: RATS_TLS_LOG_LEVEL_DEBUG,
cert_algo: RATS_TLS_CERT_ALGO_DEFAULT,
enclave_id: 0,
..Default::default()
};
conf.flags |= RATS_TLS_CONF_FLAGS_MUTUAL;

let mut handle: rats_tls_handle = unsafe { std::mem::zeroed() };
Expand Down Expand Up @@ -137,6 +136,6 @@ impl RatsTls {
#[no_mangle]
extern "C" fn callback(_evidence: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int {
info!("EAA KBC Rats-TLS callback function is unimplement!.");
return 0;
0
}
}
2 changes: 1 addition & 1 deletion src/kbc_modules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl KbcModuleList {
mod_list.insert("offline_sev_kbc".to_string(), instantiate_func);
}

KbcModuleList { mod_list: mod_list }
KbcModuleList { mod_list }
}

pub fn get_func(&self, kbc_name: &str) -> Result<&KbcInstantiateFunc> {
Expand Down
2 changes: 1 addition & 1 deletion src/kbc_modules/offline_fs_kbc/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub mod tests {
);

fs::write(keyfile_path.clone(), "foo").unwrap();
assert!(load_keys(keyfile_name.clone()).is_err());
assert!(load_keys(&keyfile_name.to_string()).is_err());

fs::remove_file(keyfile_name).unwrap();
}
Expand Down
4 changes: 2 additions & 2 deletions src/kbc_modules/sample_kbc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use anyhow::*;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

const HARDCODED_KEY: &'static [u8] = &[
const HARDCODED_KEY: &[u8] = &[
217, 155, 119, 5, 176, 186, 122, 22, 130, 149, 179, 163, 54, 114, 112, 176, 221, 155, 55, 27,
245, 20, 202, 139, 155, 167, 240, 163, 55, 17, 218, 234,
];
Expand Down Expand Up @@ -53,7 +53,7 @@ impl SampleKbc {
pub fn new(kbs_uri: String) -> SampleKbc {
let mut kbs_info: HashMap<String, String> = HashMap::new();
kbs_info.insert("kbs_uri".to_string(), kbs_uri);
SampleKbc { kbs_info: kbs_info }
SampleKbc { kbs_info }
}
}

Expand Down