From 056d1a8385783eef6f21547392ccee898f36c472 Mon Sep 17 00:00:00 2001 From: Chris Swan <478926+cpswan@users.noreply.github.com> Date: Fri, 1 Dec 2023 15:14:34 +0000 Subject: [PATCH 01/31] docs: Add CHANGELOG --- CHANGELOG.md | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..1ba88e3 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,11 @@ +## v0.2.0 + +- Interoperability with other Atsign SDKs +- Autobug workflow +- Removed direct dependency on a specific TLS client +- OpenSSF Scorecard +- create at_secrets from values + +## v0.1.0 + +- Initial version with PKAM auth and simple data exchange From 1166232d14d83a423f78ae941822c4e330d3cd4e Mon Sep 17 00:00:00 2001 From: Chris Swan <478926+cpswan@users.noreply.github.com> Date: Fri, 1 Dec 2023 15:33:03 +0000 Subject: [PATCH 02/31] fix: Clippy warning - unused import --- src/at_chops/at_chops.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/at_chops/at_chops.rs b/src/at_chops/at_chops.rs index f6c2606..3386b0f 100644 --- a/src/at_chops/at_chops.rs +++ b/src/at_chops/at_chops.rs @@ -1,4 +1,4 @@ -use log::{info, warn}; +//use log::{info, warn}; use super::utils::{ base64_decode, base64_encode, construct_aes_key, construct_rsa_private_key, From 67399412ab404a5ff30f79bb28acbb5f6b59eb90 Mon Sep 17 00:00:00 2001 From: Chris Swan <478926+cpswan@users.noreply.github.com> Date: Fri, 1 Dec 2023 15:33:18 +0000 Subject: [PATCH 03/31] fix: Clippy warning - unused import --- src/at_chops/utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/at_chops/utils.rs b/src/at_chops/utils.rs index bbc73c3..2356961 100644 --- a/src/at_chops/utils.rs +++ b/src/at_chops/utils.rs @@ -1,4 +1,4 @@ -use std::iter::repeat; +//use std::iter::repeat; use crypto::{aes::KeySize, symmetriccipher::SynchronousStreamCipher}; From 4f0113e855c789dac45ded99ba082e58c636eb88 Mon Sep 17 00:00:00 2001 From: Chris Swan <478926+cpswan@users.noreply.github.com> Date: Fri, 1 Dec 2023 15:33:41 +0000 Subject: [PATCH 04/31] ci: Add Clippy workflow --- .github/workflows/clippy.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .github/workflows/clippy.yml diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml new file mode 100644 index 0000000..ab896b7 --- /dev/null +++ b/.github/workflows/clippy.yml @@ -0,0 +1,24 @@ +name: Clippy +on: + workflow_dispatch: + push: + branches: [trunk] + pull_request: + branches: [trunk] + +permissions: + contents: read + +jobs: + clippy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + - name: Install Rust + run: rustup update stable + + - name: Install Clippy + run: rustup component add clippy + + - name: Run Clippy + run: cargo clippy From ebcdfc28c698995d6f1eddab393bd779ed48fe95 Mon Sep 17 00:00:00 2001 From: Chris Swan <478926+cpswan@users.noreply.github.com> Date: Fri, 1 Dec 2023 15:34:52 +0000 Subject: [PATCH 05/31] fix: Clippy warning - unused import --- src/at_chops/utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/at_chops/utils.rs b/src/at_chops/utils.rs index 2356961..301011c 100644 --- a/src/at_chops/utils.rs +++ b/src/at_chops/utils.rs @@ -3,7 +3,7 @@ use crypto::{aes::KeySize, symmetriccipher::SynchronousStreamCipher}; use base64::{engine::general_purpose, Engine as _}; -use log::info; +//use log::info; use rsa::{ pkcs1v15::SigningKey, pkcs8::{DecodePrivateKey, DecodePublicKey}, From f0bff3c696134c670508c8123c9f1070389571e2 Mon Sep 17 00:00:00 2001 From: Chris Swan <478926+cpswan@users.noreply.github.com> Date: Fri, 1 Dec 2023 15:40:22 +0000 Subject: [PATCH 06/31] fix: Clippy warning - module_inception --- src/at_chops/{at_chops.rs => chops.rs} | 0 src/at_chops/mod.rs | 2 +- src/at_client.rs | 2 +- src/at_secrets.rs | 2 +- src/verbs/from.rs | 2 +- 5 files changed, 4 insertions(+), 4 deletions(-) rename src/at_chops/{at_chops.rs => chops.rs} (100%) diff --git a/src/at_chops/at_chops.rs b/src/at_chops/chops.rs similarity index 100% rename from src/at_chops/at_chops.rs rename to src/at_chops/chops.rs diff --git a/src/at_chops/mod.rs b/src/at_chops/mod.rs index f85f6c7..a17b577 100644 --- a/src/at_chops/mod.rs +++ b/src/at_chops/mod.rs @@ -1,4 +1,4 @@ -pub mod at_chops; +pub mod chops; mod b64_encoded_string; mod utils; diff --git a/src/at_client.rs b/src/at_client.rs index 7e6b124..2d9d754 100644 --- a/src/at_client.rs +++ b/src/at_client.rs @@ -1,6 +1,6 @@ use log::info; -use crate::at_chops::at_chops::{ +use crate::at_chops::chops::{ create_new_shared_symmetric_key, decrypt_data_with_shared_symmetric_key, decrypt_symmetric_key, encrypt_data_with_public_key, encrypt_data_with_shared_symmetric_key, }; diff --git a/src/at_secrets.rs b/src/at_secrets.rs index ae48f1f..5333328 100644 --- a/src/at_secrets.rs +++ b/src/at_secrets.rs @@ -1,4 +1,4 @@ -use crate::at_chops::at_chops::{decode_self_encryption_key, decrypt_private_key}; +use crate::at_chops::chops::{decode_self_encryption_key, decrypt_private_key}; use crate::at_error::Result; use log::info; use serde_json::{from_str, Value}; diff --git a/src/verbs/from.rs b/src/verbs/from.rs index bdc38b8..1a055ee 100644 --- a/src/verbs/from.rs +++ b/src/verbs/from.rs @@ -1,6 +1,6 @@ use log::info; -use crate::at_chops::at_chops::sign_challenge; +use crate::at_chops::chops::sign_challenge; use super::{prelude::*, Verb}; From c8a6296be2e6f48bc8554ad0dfb17ec7d9ad0f07 Mon Sep 17 00:00:00 2001 From: Chris Swan <478926+cpswan@users.noreply.github.com> Date: Fri, 1 Dec 2023 15:41:55 +0000 Subject: [PATCH 07/31] fix: Clippy warning - immediate dereference --- src/at_chops/chops.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/at_chops/chops.rs b/src/at_chops/chops.rs index 3386b0f..c1fcd5e 100644 --- a/src/at_chops/chops.rs +++ b/src/at_chops/chops.rs @@ -19,7 +19,7 @@ pub fn decrypt_private_key( ) -> String { let iv: [u8; 16] = [0x00; 16]; let mut cypher = construct_aes_key(decoded_self_encryption_key, &iv); - let decoded_private_key = base64_decode(&encrypted_private_key); + let decoded_private_key = base64_decode(encrypted_private_key); let mut output: Vec = vec![0; decoded_private_key.len()]; cypher.process(&decoded_private_key, &mut output); From 7b18773e325c003b158d76717c1585ff269ef5b7 Mon Sep 17 00:00:00 2001 From: Chris Swan <478926+cpswan@users.noreply.github.com> Date: Fri, 1 Dec 2023 15:42:32 +0000 Subject: [PATCH 08/31] fix: Clippy warning - immediate dereference --- src/at_chops/chops.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/at_chops/chops.rs b/src/at_chops/chops.rs index c1fcd5e..d0d8962 100644 --- a/src/at_chops/chops.rs +++ b/src/at_chops/chops.rs @@ -36,7 +36,7 @@ pub fn decrypt_private_key( /// Sign a given challenge with the decrypted private key. pub fn sign_challenge(challenge: &str, decrypted_private_key: &str) -> String { - let decoded_private_key = base64_decode(&decrypted_private_key); + let decoded_private_key = base64_decode(decrypted_private_key); let rsa_private_key = construct_rsa_private_key(&decoded_private_key); rsa_sign(rsa_private_key, &challenge.as_bytes()) } From 1e8e2f84a0a072bf86921ec390782b2cb8c1e8e7 Mon Sep 17 00:00:00 2001 From: Chris Swan <478926+cpswan@users.noreply.github.com> Date: Fri, 1 Dec 2023 15:43:10 +0000 Subject: [PATCH 09/31] fix: Clippy warning - immediate dereference --- src/at_chops/chops.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/at_chops/chops.rs b/src/at_chops/chops.rs index d0d8962..1f307ec 100644 --- a/src/at_chops/chops.rs +++ b/src/at_chops/chops.rs @@ -38,7 +38,7 @@ pub fn decrypt_private_key( pub fn sign_challenge(challenge: &str, decrypted_private_key: &str) -> String { let decoded_private_key = base64_decode(decrypted_private_key); let rsa_private_key = construct_rsa_private_key(&decoded_private_key); - rsa_sign(rsa_private_key, &challenge.as_bytes()) + rsa_sign(rsa_private_key, challenge.as_bytes()) } /// Cut a new symmetric key to be used when interacting with a new atSign. From d07f7b0bf591689ae919c2fd2345e57ad1d10a42 Mon Sep 17 00:00:00 2001 From: Chris Swan <478926+cpswan@users.noreply.github.com> Date: Fri, 1 Dec 2023 15:45:28 +0000 Subject: [PATCH 10/31] fix: Clippy warning - unnecessary let binding --- src/at_chops/chops.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/at_chops/chops.rs b/src/at_chops/chops.rs index 1f307ec..c7af344 100644 --- a/src/at_chops/chops.rs +++ b/src/at_chops/chops.rs @@ -52,9 +52,7 @@ pub fn decrypt_symmetric_key(encrypted_symmetric_key: &str, decrypted_private_ke let decoded_private_key = base64_decode(&decrypted_private_key); let rsa_private_key = construct_rsa_private_key(&decoded_private_key); let decoded_symmetric_key = base64_decode(&encrypted_symmetric_key); - let decrypted_symmetric_key = - decrypt_symm_key_with_private_key(&rsa_private_key, &decoded_symmetric_key); - decrypted_symmetric_key + decrypt_symm_key_with_private_key(&rsa_private_key, &decoded_symmetric_key) } /// Encrypt data with our RSA public key. From 77fcd10f1a16ee805847014d74fe698dd6eec175 Mon Sep 17 00:00:00 2001 From: Chris Swan <478926+cpswan@users.noreply.github.com> Date: Fri, 1 Dec 2023 15:46:52 +0000 Subject: [PATCH 11/31] fix: Clippy warning - immediate dereference --- src/at_chops/chops.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/at_chops/chops.rs b/src/at_chops/chops.rs index c7af344..8383a9b 100644 --- a/src/at_chops/chops.rs +++ b/src/at_chops/chops.rs @@ -49,7 +49,7 @@ pub fn create_new_shared_symmetric_key() -> String { /// Decrypt the symmetric key with "our" private key. pub fn decrypt_symmetric_key(encrypted_symmetric_key: &str, decrypted_private_key: &str) -> String { - let decoded_private_key = base64_decode(&decrypted_private_key); + let decoded_private_key = base64_decode(decrypted_private_key); let rsa_private_key = construct_rsa_private_key(&decoded_private_key); let decoded_symmetric_key = base64_decode(&encrypted_symmetric_key); decrypt_symm_key_with_private_key(&rsa_private_key, &decoded_symmetric_key) From 4713e31f1049d87682c802e3a3f1ae0904e49a65 Mon Sep 17 00:00:00 2001 From: Chris Swan <478926+cpswan@users.noreply.github.com> Date: Fri, 1 Dec 2023 15:47:30 +0000 Subject: [PATCH 12/31] fix: Clippy warning - immediate dereference --- src/at_chops/chops.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/at_chops/chops.rs b/src/at_chops/chops.rs index 8383a9b..6bb5a6c 100644 --- a/src/at_chops/chops.rs +++ b/src/at_chops/chops.rs @@ -51,7 +51,7 @@ pub fn create_new_shared_symmetric_key() -> String { pub fn decrypt_symmetric_key(encrypted_symmetric_key: &str, decrypted_private_key: &str) -> String { let decoded_private_key = base64_decode(decrypted_private_key); let rsa_private_key = construct_rsa_private_key(&decoded_private_key); - let decoded_symmetric_key = base64_decode(&encrypted_symmetric_key); + let decoded_symmetric_key = base64_decode(encrypted_symmetric_key); decrypt_symm_key_with_private_key(&rsa_private_key, &decoded_symmetric_key) } From 8fd32844fcf4dd4d632e540941f8e7326a5dbf7a Mon Sep 17 00:00:00 2001 From: Chris Swan <478926+cpswan@users.noreply.github.com> Date: Fri, 1 Dec 2023 15:49:08 +0000 Subject: [PATCH 13/31] fix: Clippy warning - immediate dereference --- src/at_chops/chops.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/at_chops/chops.rs b/src/at_chops/chops.rs index 6bb5a6c..83cbaf3 100644 --- a/src/at_chops/chops.rs +++ b/src/at_chops/chops.rs @@ -57,7 +57,7 @@ pub fn decrypt_symmetric_key(encrypted_symmetric_key: &str, decrypted_private_ke /// Encrypt data with our RSA public key. pub fn encrypt_data_with_public_key(encoded_public_key: &str, data: &str) -> String { - let decoded_public_key = base64_decode(&encoded_public_key); + let decoded_public_key = base64_decode(encoded_public_key); let rsa_public_key = construct_rsa_public_key(&decoded_public_key); let encrypted_data = encrypt_with_public_key(&rsa_public_key, &data.as_bytes()); encrypted_data From b045e874a834761f020e94e7a141cc94619d3c1d Mon Sep 17 00:00:00 2001 From: Chris Swan <478926+cpswan@users.noreply.github.com> Date: Fri, 1 Dec 2023 15:49:34 +0000 Subject: [PATCH 14/31] fix: Clippy warning - immediate dereference --- src/at_chops/chops.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/at_chops/chops.rs b/src/at_chops/chops.rs index 83cbaf3..d9183ad 100644 --- a/src/at_chops/chops.rs +++ b/src/at_chops/chops.rs @@ -59,7 +59,7 @@ pub fn decrypt_symmetric_key(encrypted_symmetric_key: &str, decrypted_private_ke pub fn encrypt_data_with_public_key(encoded_public_key: &str, data: &str) -> String { let decoded_public_key = base64_decode(encoded_public_key); let rsa_public_key = construct_rsa_public_key(&decoded_public_key); - let encrypted_data = encrypt_with_public_key(&rsa_public_key, &data.as_bytes()); + let encrypted_data = encrypt_with_public_key(&rsa_public_key, data.as_bytes()); encrypted_data } From ce44584f5996651081b472076317f4bfb49a2555 Mon Sep 17 00:00:00 2001 From: Chris Swan <478926+cpswan@users.noreply.github.com> Date: Fri, 1 Dec 2023 15:50:02 +0000 Subject: [PATCH 15/31] fix: Clippy warning - immediate dereference --- src/at_chops/chops.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/at_chops/chops.rs b/src/at_chops/chops.rs index d9183ad..1eb1e4a 100644 --- a/src/at_chops/chops.rs +++ b/src/at_chops/chops.rs @@ -65,7 +65,7 @@ pub fn encrypt_data_with_public_key(encoded_public_key: &str, data: &str) -> Str /// Encrypt data with AES symm key. pub fn encrypt_data_with_shared_symmetric_key(encoded_symmetric_key: &str, data: &str) -> String { - let decoded_symmetric_key = base64_decode(&encoded_symmetric_key); + let decoded_symmetric_key = base64_decode(encoded_symmetric_key); let iv: [u8; 16] = [0x00; 16]; let mut cypher = construct_aes_key(&decoded_symmetric_key, &iv); let encrypted_data = encrypt_data_with_aes_key(&mut cypher, &data.as_bytes()); From 0e022fa2309a4ab6055d8a2b23ba38a4810746ed Mon Sep 17 00:00:00 2001 From: Chris Swan <478926+cpswan@users.noreply.github.com> Date: Fri, 1 Dec 2023 15:50:39 +0000 Subject: [PATCH 16/31] fix: Clippy warning - immediate dereference --- src/at_chops/chops.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/at_chops/chops.rs b/src/at_chops/chops.rs index 1eb1e4a..43c54bd 100644 --- a/src/at_chops/chops.rs +++ b/src/at_chops/chops.rs @@ -68,7 +68,7 @@ pub fn encrypt_data_with_shared_symmetric_key(encoded_symmetric_key: &str, data: let decoded_symmetric_key = base64_decode(encoded_symmetric_key); let iv: [u8; 16] = [0x00; 16]; let mut cypher = construct_aes_key(&decoded_symmetric_key, &iv); - let encrypted_data = encrypt_data_with_aes_key(&mut cypher, &data.as_bytes()); + let encrypted_data = encrypt_data_with_aes_key(&mut cypher, data.as_bytes()); base64_encode(&encrypted_data) } From af35e7411692fab5e31106668ad001ed0dc552dc Mon Sep 17 00:00:00 2001 From: Chris Swan <478926+cpswan@users.noreply.github.com> Date: Fri, 1 Dec 2023 15:51:08 +0000 Subject: [PATCH 17/31] fix: Clippy warning - immediate dereference --- src/at_chops/chops.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/at_chops/chops.rs b/src/at_chops/chops.rs index 43c54bd..d6cd5a6 100644 --- a/src/at_chops/chops.rs +++ b/src/at_chops/chops.rs @@ -74,7 +74,7 @@ pub fn encrypt_data_with_shared_symmetric_key(encoded_symmetric_key: &str, data: /// Decrypt data with an encoded AES symm key. pub fn decrypt_data_with_shared_symmetric_key(encoded_symmetric_key: &str, data: &str) -> String { - let decoded_symmetric_key = base64_decode(&encoded_symmetric_key); + let decoded_symmetric_key = base64_decode(encoded_symmetric_key); let iv: [u8; 16] = [0x00; 16]; let mut cypher = construct_aes_key(&decoded_symmetric_key, &iv); let decoded_data = base64_decode(&data); From 07580490d40ac4db39e9bdf441719f20f321f53b Mon Sep 17 00:00:00 2001 From: Chris Swan <478926+cpswan@users.noreply.github.com> Date: Fri, 1 Dec 2023 15:51:33 +0000 Subject: [PATCH 18/31] fix: Clippy warning - immediate dereference --- src/at_chops/chops.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/at_chops/chops.rs b/src/at_chops/chops.rs index d6cd5a6..f80aa48 100644 --- a/src/at_chops/chops.rs +++ b/src/at_chops/chops.rs @@ -77,7 +77,7 @@ pub fn decrypt_data_with_shared_symmetric_key(encoded_symmetric_key: &str, data: let decoded_symmetric_key = base64_decode(encoded_symmetric_key); let iv: [u8; 16] = [0x00; 16]; let mut cypher = construct_aes_key(&decoded_symmetric_key, &iv); - let decoded_data = base64_decode(&data); + let decoded_data = base64_decode(data); let decrypted_data = decrypt_data_with_aes_key(&mut cypher, &decoded_data); String::from_utf8(decrypted_data).expect("Unable to convert to UTF-8") } From 7c78d433e07eb0f52c3f10d1eb9e1a7e74d5827e Mon Sep 17 00:00:00 2001 From: Chris Swan <478926+cpswan@users.noreply.github.com> Date: Fri, 1 Dec 2023 15:52:09 +0000 Subject: [PATCH 19/31] fix: Clippy warning - immediate dereference --- src/at_chops/utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/at_chops/utils.rs b/src/at_chops/utils.rs index 301011c..e77fdbf 100644 --- a/src/at_chops/utils.rs +++ b/src/at_chops/utils.rs @@ -33,7 +33,7 @@ pub fn construct_aes_key(data: &[u8], iv: &[u8; 16]) -> Box RsaPrivateKey { - let rsa_key = RsaPrivateKey::from_pkcs8_der(&data).expect("Unable to create RSA Private Key"); + let rsa_key = RsaPrivateKey::from_pkcs8_der(data).expect("Unable to create RSA Private Key"); rsa_key.validate().expect("Invalid RSA Private Key"); rsa_key } From 40e9961acf948c3d497573d23c1dda17d4862cd4 Mon Sep 17 00:00:00 2001 From: Chris Swan <478926+cpswan@users.noreply.github.com> Date: Fri, 1 Dec 2023 15:54:10 +0000 Subject: [PATCH 20/31] fix: Clippy warning - immediate dereference --- src/at_chops/utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/at_chops/utils.rs b/src/at_chops/utils.rs index e77fdbf..ee7578c 100644 --- a/src/at_chops/utils.rs +++ b/src/at_chops/utils.rs @@ -41,7 +41,7 @@ pub fn construct_rsa_private_key(data: &[u8]) -> RsaPrivateKey { /// Construct an RSA public key from a decoded key. pub fn construct_rsa_public_key(data: &[u8]) -> RsaPublicKey { let rsa_key = - RsaPublicKey::from_public_key_der(&data).expect("Unable to create RSA Public Key"); + RsaPublicKey::from_public_key_der(data).expect("Unable to create RSA Public Key"); rsa_key } From fb6145e66b71793bd7a34576da3e08be3a6eedb8 Mon Sep 17 00:00:00 2001 From: Chris Swan <478926+cpswan@users.noreply.github.com> Date: Fri, 1 Dec 2023 15:55:29 +0000 Subject: [PATCH 21/31] fix: Clippy warning - unnecessary let binding --- src/at_chops/utils.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/at_chops/utils.rs b/src/at_chops/utils.rs index ee7578c..5ef3845 100644 --- a/src/at_chops/utils.rs +++ b/src/at_chops/utils.rs @@ -61,8 +61,7 @@ pub fn rsa_sign(key: RsaPrivateKey, data: &[u8]) -> String { let signature_bytes = binding.as_ref(); // Encode signature - let sha256_signature_encoded = base64_encode(&signature_bytes); - sha256_signature_encoded + base64_encode(&signature_bytes) } /// Create a new AES-256 key from scratch. From 2c27e731001160de1c93b3ddf229d57a817e1fce Mon Sep 17 00:00:00 2001 From: Chris Swan <478926+cpswan@users.noreply.github.com> Date: Fri, 1 Dec 2023 15:56:06 +0000 Subject: [PATCH 22/31] fix: Clippy warning - unnecessary let binding --- src/at_chops/utils.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/at_chops/utils.rs b/src/at_chops/utils.rs index 5ef3845..16483ef 100644 --- a/src/at_chops/utils.rs +++ b/src/at_chops/utils.rs @@ -40,9 +40,7 @@ pub fn construct_rsa_private_key(data: &[u8]) -> RsaPrivateKey { /// Construct an RSA public key from a decoded key. pub fn construct_rsa_public_key(data: &[u8]) -> RsaPublicKey { - let rsa_key = - RsaPublicKey::from_public_key_der(data).expect("Unable to create RSA Public Key"); - rsa_key + RsaPublicKey::from_public_key_der(data).expect("Unable to create RSA Public Key") } /// Sign data using an RSA private key. From 0f42f91e8c80ab6b65c754ec144f3999687887bd Mon Sep 17 00:00:00 2001 From: Chris Swan <478926+cpswan@users.noreply.github.com> Date: Fri, 1 Dec 2023 15:56:49 +0000 Subject: [PATCH 23/31] fix: Clippy warning - immediate dereference --- src/at_chops/utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/at_chops/utils.rs b/src/at_chops/utils.rs index 16483ef..b5d75a9 100644 --- a/src/at_chops/utils.rs +++ b/src/at_chops/utils.rs @@ -51,7 +51,7 @@ pub fn rsa_sign(key: RsaPrivateKey, data: &[u8]) -> String { let verifying_key = signing_key.verifying_key(); // Sign - let signature = signing_key.sign_with_rng(&mut rng, &data); + let signature = signing_key.sign_with_rng(&mut rng, data); verifying_key .verify(&data, &signature) .expect("failed to verify"); From 1f6e7b1fcd2e139312b57c15b3c47f5411357c3d Mon Sep 17 00:00:00 2001 From: Chris Swan <478926+cpswan@users.noreply.github.com> Date: Fri, 1 Dec 2023 15:57:30 +0000 Subject: [PATCH 24/31] fix: Clippy warning - immediate dereference --- src/at_chops/utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/at_chops/utils.rs b/src/at_chops/utils.rs index b5d75a9..4687240 100644 --- a/src/at_chops/utils.rs +++ b/src/at_chops/utils.rs @@ -53,7 +53,7 @@ pub fn rsa_sign(key: RsaPrivateKey, data: &[u8]) -> String { // Sign let signature = signing_key.sign_with_rng(&mut rng, data); verifying_key - .verify(&data, &signature) + .verify(data, &signature) .expect("failed to verify"); let binding = signature.to_bytes(); let signature_bytes = binding.as_ref(); From f48bc78a804f2af9d57767f309aa56872af41018 Mon Sep 17 00:00:00 2001 From: Chris Swan <478926+cpswan@users.noreply.github.com> Date: Fri, 1 Dec 2023 16:00:58 +0000 Subject: [PATCH 25/31] fix: Clippy warning - immediate dereference --- src/at_chops/utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/at_chops/utils.rs b/src/at_chops/utils.rs index 4687240..84385af 100644 --- a/src/at_chops/utils.rs +++ b/src/at_chops/utils.rs @@ -59,7 +59,7 @@ pub fn rsa_sign(key: RsaPrivateKey, data: &[u8]) -> String { let signature_bytes = binding.as_ref(); // Encode signature - base64_encode(&signature_bytes) + base64_encode(signature_bytes) } /// Create a new AES-256 key from scratch. From 7a86d790e93a39305758efbf61c93f51fb62b7d6 Mon Sep 17 00:00:00 2001 From: Chris Swan <478926+cpswan@users.noreply.github.com> Date: Fri, 1 Dec 2023 16:01:53 +0000 Subject: [PATCH 26/31] fix: Clippy warning - immediate dereference --- src/at_chops/utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/at_chops/utils.rs b/src/at_chops/utils.rs index 84385af..94ecb52 100644 --- a/src/at_chops/utils.rs +++ b/src/at_chops/utils.rs @@ -113,7 +113,7 @@ pub fn decrypt_data_with_aes_key( data: &[u8], ) -> Vec { let mut output: Vec = vec![0; data.len()]; - aes_key.process(&data, &mut output); + aes_key.process(data, &mut output); // Remove padding due to PkCS#7 padding used by other SDKs let last = output.last().unwrap(); output.truncate(output.len() - usize::from(*last)); From dc922132db2ec79f02871804948a540e4b49c2f9 Mon Sep 17 00:00:00 2001 From: Chris Swan <478926+cpswan@users.noreply.github.com> Date: Fri, 1 Dec 2023 16:03:44 +0000 Subject: [PATCH 27/31] fix: Clippy --fix --- src/at_chops/chops.rs | 4 ++-- src/at_chops/utils.rs | 8 ++++---- src/at_client.rs | 20 ++++++++++---------- src/at_secrets.rs | 10 +++++----- src/verbs/from.rs | 2 +- src/verbs/lookup.rs | 2 +- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/at_chops/chops.rs b/src/at_chops/chops.rs index f80aa48..f4849db 100644 --- a/src/at_chops/chops.rs +++ b/src/at_chops/chops.rs @@ -113,13 +113,13 @@ mod test { #[test] fn decrypt_private_key_test() { let self_encryption_key = decode_self_encryption_key(SELF_ENCRYPTION_KEY_ENCODED); - let result = decrypt_private_key(&PKAM_KEY_ENCRYPTED_AND_ENCODED, &self_encryption_key); + let result = decrypt_private_key(PKAM_KEY_ENCRYPTED_AND_ENCODED, &self_encryption_key); assert_eq!(result, PKAM_KEY_DECRYPTED_AND_ENCODED); } #[test] fn sign_challenge_test() { - let result = sign_challenge(CHALLENGE_TEXT, &PKAM_KEY_DECRYPTED_AND_ENCODED); + let result = sign_challenge(CHALLENGE_TEXT, PKAM_KEY_DECRYPTED_AND_ENCODED); assert_eq!(result, CHALLENGE_RESULT); } diff --git a/src/at_chops/utils.rs b/src/at_chops/utils.rs index 94ecb52..0c3bf97 100644 --- a/src/at_chops/utils.rs +++ b/src/at_chops/utils.rs @@ -179,7 +179,7 @@ mod test { #[test] fn construct_rsa_private_key_test() { // Arrange - let private_key = base64_decode(&PKAM_KEY_DECRYPTED_AND_ENCODED); + let private_key = base64_decode(PKAM_KEY_DECRYPTED_AND_ENCODED); // Act let _ = construct_rsa_private_key(&private_key); // Assert it doesn't panic @@ -188,7 +188,7 @@ mod test { #[test] fn construct_rsa_public_key_test() { // Arrange - let public_key = base64_decode(&PUBLIC_ENCRYPTION_KEY); + let public_key = base64_decode(PUBLIC_ENCRYPTION_KEY); // Act let _ = construct_rsa_public_key(&public_key); // Assert it doesn't panic @@ -197,7 +197,7 @@ mod test { #[test] fn rsa_sign_test() { // Arrange - let private_key = base64_decode(&PKAM_KEY_DECRYPTED_AND_ENCODED); + let private_key = base64_decode(PKAM_KEY_DECRYPTED_AND_ENCODED); let rsa_key = construct_rsa_private_key(&private_key); // Act let decrypted = rsa_sign(rsa_key, CHALLENGE_TEXT.as_bytes()); @@ -213,7 +213,7 @@ mod test { #[test] fn encrypt_with_public_key_test() { - let public_key = base64_decode(&PUBLIC_ENCRYPTION_KEY); + let public_key = base64_decode(PUBLIC_ENCRYPTION_KEY); let public_key = construct_rsa_public_key(&public_key); let _ = encrypt_with_public_key(&public_key, &TEST_KEY_DECODED); // Assert it doesn't panic. diff --git a/src/at_client.rs b/src/at_client.rs index 2d9d754..573b1f5 100644 --- a/src/at_client.rs +++ b/src/at_client.rs @@ -59,7 +59,7 @@ impl AtClient { // Save for our use let encrypted_encoded_sym_key = encrypt_data_with_public_key(&self.secrets.encrypt_public_key, &new_key); - let _ = UpdateVerb::execute( + UpdateVerb::execute( &mut self.tls_client, UpdateVerbInputs::new( &self.at_sign, @@ -82,7 +82,7 @@ impl AtClient { symm_key_encrypted_with_recipient_public_key ); // Send data - let _ = UpdateVerb::execute( + UpdateVerb::execute( &mut self.tls_client, UpdateVerbInputs::new( &self.at_sign, @@ -96,9 +96,9 @@ impl AtClient { } else if response.contains("data") { info!("Already have a copy of the key"); // Decrypt symm key - let encrypted_symmetric_key = response.split(":").collect::>()[1]; + let encrypted_symmetric_key = response.split(':').collect::>()[1]; symm_key = - decrypt_symmetric_key(&encrypted_symmetric_key, &self.secrets.encrypt_private_key); + decrypt_symmetric_key(encrypted_symmetric_key, &self.secrets.encrypt_private_key); info!("Decrypted symmetric key: {}", symm_key); } else { return Err(AtError::new(String::from("Unknown response from server"))); @@ -110,7 +110,7 @@ impl AtClient { UpdateVerbInputs::new( &self.at_sign, // TODO: Pass this in as an option somewhere - &record_id, + record_id, &encrypted_data_to_send, Some(&self.namespace), None, @@ -128,7 +128,7 @@ impl AtClient { &mut self.tls_client, LookupVerbInputs::new(&from, record_id, Some(&self.namespace)), )?; - let encrypted_and_encoded_data = response.split(":").collect::>()[1]; + let encrypted_and_encoded_data = response.split(':').collect::>()[1]; info!("Fetching symmetric key"); // Fetch symm key let response = LookupVerb::execute( @@ -136,15 +136,15 @@ impl AtClient { LookupVerbInputs::new(&from, "shared_key", None), )?; info!("Decrypting symmetric key"); - let encrypted_and_encoded_symm_key = response.split(":").collect::>()[1]; + let encrypted_and_encoded_symm_key = response.split(':').collect::>()[1]; let symm_key = decrypt_symmetric_key( - &encrypted_and_encoded_symm_key, + encrypted_and_encoded_symm_key, &self.secrets.encrypt_private_key, ); info!("Decrypted symmetric key: {}", symm_key); info!("Decrypting data"); let encoded_data = - decrypt_data_with_shared_symmetric_key(&symm_key, &encrypted_and_encoded_data); + decrypt_data_with_shared_symmetric_key(&symm_key, encrypted_and_encoded_data); info!("Decrypted data: {}", encoded_data); Ok(()) @@ -183,7 +183,7 @@ fn get_at_sign_server_addr( // Trimming to remove the newline character let addr = addr.trim(); - let addr = addr.split(":").collect::>(); + let addr = addr.split(':').collect::>(); let host = addr[0].to_string(); let port = addr[1] .parse::() diff --git a/src/at_secrets.rs b/src/at_secrets.rs index 5333328..ac02247 100644 --- a/src/at_secrets.rs +++ b/src/at_secrets.rs @@ -64,17 +64,17 @@ impl AtSecrets { ) -> Result { info!("Decoding keys"); // Decode the self encrypt key from base64 - let decoded_self_encrypted_key = decode_self_encryption_key(&aes_self_encrypt_key); + let decoded_self_encrypted_key = decode_self_encryption_key(aes_self_encrypt_key); // Use the key to decrypt all the other private keys let pkam_public_key = - decrypt_private_key(&aes_pkam_public_key, &decoded_self_encrypted_key); + decrypt_private_key(aes_pkam_public_key, &decoded_self_encrypted_key); let pkam_private_key = - decrypt_private_key(&aes_pkam_private_key, &decoded_self_encrypted_key); + decrypt_private_key(aes_pkam_private_key, &decoded_self_encrypted_key); let encrypt_public_key = - decrypt_private_key(&aes_encrypt_public_key, &decoded_self_encrypted_key); + decrypt_private_key(aes_encrypt_public_key, &decoded_self_encrypted_key); let encrypt_private_key = - decrypt_private_key(&aes_encrypt_private_key, &decoded_self_encrypted_key); + decrypt_private_key(aes_encrypt_private_key, &decoded_self_encrypted_key); info!("Keys decoded and decrypted"); diff --git a/src/verbs/from.rs b/src/verbs/from.rs index 1a055ee..3213685 100644 --- a/src/verbs/from.rs +++ b/src/verbs/from.rs @@ -29,7 +29,7 @@ impl<'a> Verb<'a> for FromVerb { let (_, data) = response.split_at(6); info!("Challenge: {}", data); - let signed_challenge = sign_challenge(&data, input.priv_pkam); + let signed_challenge = sign_challenge(data, input.priv_pkam); tls_client.send(format!("pkam:{}\n", signed_challenge))?; let response = tls_client.read_line()?; diff --git a/src/verbs/lookup.rs b/src/verbs/lookup.rs index b0fcd7f..1b41fe7 100644 --- a/src/verbs/lookup.rs +++ b/src/verbs/lookup.rs @@ -32,7 +32,7 @@ impl<'a> Verb<'a> for LookupVerb { send_string.push_str(&format!(".{}", namespace)); } send_string.push_str(&format!("@{}", input.to_at_sign.get_at_sign())); - send_string.push_str(&format!("\n")); + send_string.push_str("\n"); tls_client.send(send_string)?; let response = tls_client.read_line()?; Ok(response) From 04f2880c6d568e9abfef762a965802e963de6a9c Mon Sep 17 00:00:00 2001 From: Chris Swan <478926+cpswan@users.noreply.github.com> Date: Fri, 1 Dec 2023 16:05:22 +0000 Subject: [PATCH 28/31] fix: Clippy warning - char literal --- src/verbs/lookup.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/verbs/lookup.rs b/src/verbs/lookup.rs index 1b41fe7..ae50ed7 100644 --- a/src/verbs/lookup.rs +++ b/src/verbs/lookup.rs @@ -32,7 +32,7 @@ impl<'a> Verb<'a> for LookupVerb { send_string.push_str(&format!(".{}", namespace)); } send_string.push_str(&format!("@{}", input.to_at_sign.get_at_sign())); - send_string.push_str("\n"); + send_string.push('\n'); tls_client.send(send_string)?; let response = tls_client.read_line()?; Ok(response) From a1690089ec44bb1ec8df9acc46effaea2b24a9f0 Mon Sep 17 00:00:00 2001 From: Chris Swan <478926+cpswan@users.noreply.github.com> Date: Fri, 1 Dec 2023 16:11:14 +0000 Subject: [PATCH 29/31] docs: Bump version number after linting --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 235b4ae..a591804 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "at_rust" -version = "0.2.0" +version = "0.2.1" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html From 43bc89e0db1e8a17a8c14dbced91c5754ba0f174 Mon Sep 17 00:00:00 2001 From: Chris Swan <478926+cpswan@users.noreply.github.com> Date: Fri, 1 Dec 2023 16:26:07 +0000 Subject: [PATCH 30/31] docs: Add OpenSSF Best Practices badge --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index cd4aafa..36edd7c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ [![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/atsign-foundation/at_rust/badge)](https://api.securityscorecards.dev/projects/github.com/atsign-foundation/at_rust) +[![OpenSSF Best Practices](https://www.bestpractices.dev/projects/8148/badge)](https://www.bestpractices.dev/projects/8148) # Rust SDK - (⚠️Alpha version⚠️) This repo contains libraries, tools, samples and examples for developers who wish to work with the atPlatform from Rust code. From b8329f25a4437cc8c8a60eb043ec7d99b045dd69 Mon Sep 17 00:00:00 2001 From: Chris Swan <478926+cpswan@users.noreply.github.com> Date: Fri, 1 Dec 2023 20:01:17 +0000 Subject: [PATCH 31/31] docs: Add 0.2.1 changes --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ba88e3..8023044 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v0.2.1 + +- Fix linter warnings +- Add linter workflow +- Add OpenSSF Best Practices badge + ## v0.2.0 - Interoperability with other Atsign SDKs