From 7b183ba1c25ef7e73860ffe0133bc23bf92caf7b Mon Sep 17 00:00:00 2001 From: Jiale Zhang Date: Mon, 22 Nov 2021 11:59:24 +0800 Subject: [PATCH 1/5] Fix: Rust lint check failed Signed-off-by: Jiale Zhang --- src/grpc/mod.rs | 8 ++++---- src/kbc_modules/eaa_kbc/mod.rs | 12 ++++++------ src/kbc_modules/eaa_kbc/protocol.rs | 6 ++++++ src/kbc_modules/eaa_kbc/rats_tls/mod.rs | 17 ++++++++--------- src/kbc_modules/mod.rs | 2 +- src/kbc_modules/offline_fs_kbc/common.rs | 2 +- src/kbc_modules/sample_kbc/mod.rs | 4 ++-- 7 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/grpc/mod.rs b/src/grpc/mod.rs index 5e5eea06..d6c27e41 100644 --- a/src/grpc/mod.rs +++ b/src/grpc/mod.rs @@ -143,11 +143,11 @@ fn parse_input(input_byte: Vec) -> Result { 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!", diff --git a/src/kbc_modules/eaa_kbc/mod.rs b/src/kbc_modules/eaa_kbc/mod.rs index 51bd6af7..adad00ba 100644 --- a/src/kbc_modules/eaa_kbc/mod.rs +++ b/src/kbc_modules/eaa_kbc/mod.rs @@ -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> { @@ -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, @@ -99,7 +99,7 @@ impl EAAKbc { } fn kbs_query_version(&mut self) -> Result { - 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")?; @@ -107,7 +107,7 @@ impl EAAKbc { serde_json::from_str::(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!")), } @@ -120,7 +120,7 @@ impl EAAKbc { iv: Vec, ) -> Result> { let blob = Blob { - kid: key_id.clone(), + kid: key_id, encrypted_data: base64::encode(&encrypted_payload), algorithm: "AES".to_string(), key_length: 256, @@ -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!" diff --git a/src/kbc_modules/eaa_kbc/protocol.rs b/src/kbc_modules/eaa_kbc/protocol.rs index b80a114b..ddbfbd62 100644 --- a/src/kbc_modules/eaa_kbc/protocol.rs +++ b/src/kbc_modules/eaa_kbc/protocol.rs @@ -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, diff --git a/src/kbc_modules/eaa_kbc/rats_tls/mod.rs b/src/kbc_modules/eaa_kbc/rats_tls/mod.rs index 7d2aca98..5cda9b2c 100644 --- a/src/kbc_modules/eaa_kbc/rats_tls/mod.rs +++ b/src/kbc_modules/eaa_kbc/rats_tls/mod.rs @@ -21,8 +21,6 @@ unsafe impl ForeignTypeRef for RatsTlsRef { #[derive(Clone)] pub struct RatsTls(NonNull); -unsafe impl Send for RatsTlsRef {} -unsafe impl Sync for RatsTlsRef {} unsafe impl Send for RatsTls {} unsafe impl Sync for RatsTls {} @@ -69,12 +67,13 @@ impl DerefMut for RatsTls { impl RatsTls { pub fn new() -> Result { - 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() }; @@ -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 } } diff --git a/src/kbc_modules/mod.rs b/src/kbc_modules/mod.rs index d9f10580..310ae328 100644 --- a/src/kbc_modules/mod.rs +++ b/src/kbc_modules/mod.rs @@ -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> { diff --git a/src/kbc_modules/offline_fs_kbc/common.rs b/src/kbc_modules/offline_fs_kbc/common.rs index 7fc2f1c9..f4a152ff 100644 --- a/src/kbc_modules/offline_fs_kbc/common.rs +++ b/src/kbc_modules/offline_fs_kbc/common.rs @@ -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(); } diff --git a/src/kbc_modules/sample_kbc/mod.rs b/src/kbc_modules/sample_kbc/mod.rs index 05a98754..00467860 100644 --- a/src/kbc_modules/sample_kbc/mod.rs +++ b/src/kbc_modules/sample_kbc/mod.rs @@ -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, ]; @@ -53,7 +53,7 @@ impl SampleKbc { pub fn new(kbs_uri: String) -> SampleKbc { let mut kbs_info: HashMap = HashMap::new(); kbs_info.insert("kbs_uri".to_string(), kbs_uri); - SampleKbc { kbs_info: kbs_info } + SampleKbc { kbs_info } } } From 602647e58caff54de4908b8401814e26b0f72d96 Mon Sep 17 00:00:00 2001 From: Jiale Zhang Date: Mon, 22 Nov 2021 19:32:42 +0800 Subject: [PATCH 2/5] CI/CD: fix: eaa_kbc CI run failed Signed-off-by: Jiale Zhang --- .github/workflows/eaa_kbc.yml | 52 +++++++++++++++++------------------ 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/.github/workflows/eaa_kbc.yml b/.github/workflows/eaa_kbc.yml index 1dd50164..d897bbdb 100644 --- a/.github/workflows/eaa_kbc.yml +++ b/.github/workflows/eaa_kbc.yml @@ -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: @@ -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; \ No newline at end of file From 49048f7c6790500e11b3d13b5c0c13919e059d02 Mon Sep 17 00:00:00 2001 From: Jiale Zhang Date: Tue, 23 Nov 2021 11:16:01 +0800 Subject: [PATCH 3/5] test --- src/kbc_modules/eaa_kbc/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kbc_modules/eaa_kbc/mod.rs b/src/kbc_modules/eaa_kbc/mod.rs index adad00ba..497056ce 100644 --- a/src/kbc_modules/eaa_kbc/mod.rs +++ b/src/kbc_modules/eaa_kbc/mod.rs @@ -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) } From 83874c192f7ed88cb36b7e1d49ce83999b66cf17 Mon Sep 17 00:00:00 2001 From: sleepyXuan <93501856+sleepyXuan@users.noreply.github.com> Date: Tue, 23 Nov 2021 11:24:51 +0800 Subject: [PATCH 4/5] Update README.md --- src/kbc_modules/eaa_kbc/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/kbc_modules/eaa_kbc/README.md b/src/kbc_modules/eaa_kbc/README.md index e86459b5..9cfc80e8 100644 --- a/src/kbc_modules/eaa_kbc/README.md +++ b/src/kbc_modules/eaa_kbc/README.md @@ -60,5 +60,6 @@ e.g: EAA KBS address is 127.0.0.1:1122 : eaa_kbc::127.0.0.1:1122 ``` +### test From 49ab5137d14f04d60ad17f73693b639f9d6264df Mon Sep 17 00:00:00 2001 From: sleepyXuan <429567708@qq.com> Date: Tue, 23 Nov 2021 11:40:39 +0800 Subject: [PATCH 5/5] test2 --- src/kbc_modules/eaa_kbc/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kbc_modules/eaa_kbc/mod.rs b/src/kbc_modules/eaa_kbc/mod.rs index 497056ce..d0486a95 100644 --- a/src/kbc_modules/eaa_kbc/mod.rs +++ b/src/kbc_modules/eaa_kbc/mod.rs @@ -109,7 +109,7 @@ impl EAAKbc { match response.status.as_str() { "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")), } }