Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Full re-write of SDK #22

Merged
merged 34 commits into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
d48e51f
feat: Created trait and implementation for low-level crypto operations
Feb 4, 2024
df7dca8
feat: Added aes functionality to at_crypto crate
Feb 5, 2024
549cac5
refactor: moved cryto_functions_trait into at_chops crate as a form o…
Feb 5, 2024
28ffa58
feat: created at_chops methods
Feb 6, 2024
b963803
feat: Added at_chops functionality
Feb 9, 2024
6b72ddf
feat: Created tls client and trait for creating a connection
Feb 11, 2024
8e8c5dc
feat: Added at_errors crate
Feb 12, 2024
0568df0
feat: Added at_records and at_sign crates
Feb 13, 2024
ae76646
feat: created at_secrets crate
Feb 13, 2024
23c3aad
feat: started implementation of verbs crate
Feb 14, 2024
094d55d
refactor: updated tls client to use trait object instead of generics
Feb 14, 2024
d2b47bb
refactor: updated at_chops crypto trait to use concrete types so that…
Feb 17, 2024
3335af5
feat: added from verb implementation
Feb 17, 2024
abf1836
refactor: split up pkam verb from from verb
Feb 17, 2024
a940371
feat: added scan verb
Feb 18, 2024
0acf71c
feat: updated parse_server_response to remove given prefix from result
Feb 18, 2024
29029e3
feat: partial implementation of lookup verb
Feb 18, 2024
0a5adb0
feat: created new at_client and implemented at_server dns lookup and …
Feb 19, 2024
64fa84d
test: Added new test for from verb
Feb 20, 2024
a9d115f
Added trace level logging to at_chops
Feb 21, 2024
aa2b8c3
feat: Added scan to client and as an example
Feb 22, 2024
da8a4dd
feat: Updated AtId to be an AtKey and added associated methods for co…
Feb 24, 2024
e6d1517
feat: finished implementing lookup verb
Feb 24, 2024
37cd8c9
feat: Added llookup, plookup and update verbs
Feb 25, 2024
42a96b2
refactor: update verb has 2 different constructors to make using it e…
Feb 25, 2024
4bd7e77
feat: full implementation of reading text data complete
Feb 27, 2024
dba0401
Added functionality to be able to send data
Mar 14, 2024
7dc31d2
chore: Updated examples and readme to be clearer
Mar 23, 2024
45985d6
Merge remote-tracking branch 'upstream/trunk' into trunk
Mar 23, 2024
5163a46
chore: Updated readme to fix error
Mar 23, 2024
6b31592
docs: Added information about how to run tests in the README
Mar 23, 2024
e09436d
refactor: fixed clippy errors
Mar 25, 2024
b069a02
Merge branch 'trunk' into trunk
cpswan Jun 29, 2024
bbf6321
Merge branch 'trunk' into trunk
cpswan Jul 13, 2024
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
33 changes: 20 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
workspace = { members = [
"at_chops",
"at_errors",
"at_records",
"at_secrets",
"at_sign",
"at_tls",
"at_verbs",
] }
[package]
name = "at_rust"
version = "0.2.1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please bump the version to 0.3.0

Expand All @@ -6,19 +15,17 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
serde_json = "1.0.96"
regex = "1.8.3"
rsa = { version = "0.9.2", features = ["sha2"] }
rust-crypto = "0.2.36"
rand = "0.8.5"
base64 = "0.21.0"
der = "0.7.6"
hex = "0.4.3"
block-padding = "0.3.3"
generic-array = "0.14.7"
sha256 = "1.1.3"
log = "0.4.19"
at_chops = { path = "at_chops" }
at_errors = { path = "at_errors" }
at_records = { path = "at_records" }
at_secrets = { path = "at_secrets" }
at_sign = { path = "at_sign" }
at_tls = { path = "at_tls" }
at_verbs = { path = "at_verbs" }
anyhow = "1.0.79"
log = "0.4.20"


[dev-dependencies]
clap = { version = "4.5.1", features = ["derive"] }
env_logger = "0.10.0"
native-tls = "0.2.11"
65 changes: 36 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,52 +11,59 @@ It currently has limited functionality with minimal tests.
## Requirements
The following need to be installed:
- `rust` - [Installation instructions](https://doc.rust-lang.org/book/ch01-01-installation.html)
- `openssl`
- `libssl-dev`
- `pkg-config`

## Tests
Run `cargo test --workspace` to run all tests in the different workspaces.
Add `-- --nocapture` to see the logs during the tests.
Run `cargo test -p <workspace_name>` to run tests for a specific workspace.

## Run examples
### Send data
Send data to an atSign - `cargo run --example send_data_example <path-to-at-keys> <message> <atSign-of-sender> <atSign-of-receiver>`
- `path-to-at-keys` - Absolute path to the `.atKeys` of the sender
- `message` - Text data to send to receiver
- `atSign-of-sender` - The name of the atSign (without `@`) who is sending the data
- `atSign-of-receiver` - The name of the atSign (without `@`) who is receiving the data
#### E.g.
```sh
RUST_LOG=info cargo run --example send_data_example ~/.atsign/keys/@aliens12_key.atKeys hello_there aliens12 virgogigantic64
```

### Fetch data
Fetch data from an atSign - `cargo run --example fetch_data_example <path-to-at-keys> <atSign-of-receiver> <atSign-of-sender>`
- `path-to-at-keys` - Absolute path to the `.atKeys` of the receiver
- `atSign-of-receiver` - The name of the atSign (without `@`) who is receiving the data
- `atSign-of-sender` - The name of the atSign (without `@`) who is sending the data
#### E.g.
```sh
RUST_LOG=info cargo run --example fetch_data_example ~/.atsign/keys/@virgogigantic64_key.atKeys virgogigantic64 aliens12
```
Prefix all commands with `RUST_LOG=info` (or `debug` or `trace`) to see logs.
### Scan
Get the keys currently in the @sign's server.
Run `cargo run --example scan_example -- --help` for more information.

### Put data
Put data into the @sign's server.
Run `cargo run --example put_data_example -- --help` for more information.

### Get data
Get data from the @sign's server.
Run `cargo run --example get_data_example -- --help` for more information.


## Structure
- `at_client` - What consumers of the library will mostly interact with
- `at_secrets` - Struct for constructing secrets from a file
- `at_chops` (Cryptographic and Hashing Operations (CHOPS))
- `utils.rs` - Contains the generic, low level crypto operations
- `at_chops.rs` - Contains the specific combination of crypto operations that the client and verbs can use
- `verbs` - Contains a trait that all verbs have to implement. Verbs execute the atProtocol verbs by taking in arguments from the client.
This repo is broken down into workspaces to help with organization and separation of concerns. It will also make adding implementations for specific harware easier. The workspaces are:
- `at_chops` (Cryptographic and Hashing Operations (CHOPS)).
- `lib.rs` - Contains the specific combination of crypto operations required by the `AtProtocol`.
- `crypto_functions_trait.rs` - A trait which defines the methods that `AtChops` requires.
- `default_crypto_functions.rs` - Contains an implementation of the `CryptoFunctions` trait using [RustCrypto](https://github.com/RustCrypto), a pure Rust implementation of cryptographic algorithms.
- `at_errors` - Contains the error types that the library can return including associated functions for creating them.
- `at_records` - Contains the `AtRecord` struct which is used to store the data that is sent and received.
- `at_secrets` - Contains the `AtSecrets` struct which is used to store the secrets required by the `AtClient` as well as associated functions for creating them from a file.
- `at_sign` - Contains the `AtSign` struct which is used for working with AtSigns.
- `at_tls` - Contains the `TlsClient` struct which is used to establish a TLS connection with the atServer and send and receive data.
- `lib.rs` - Contains the `TlsClient` struct and methods for TLS related operations.
- `tls_connection_trait.rs` - A trait which defines the signature for creating a connection.
- `rustls_connection.rs` - Contains an implementation of the `TlsConnection` trait using [Rustls](https://github.com/rustls/)
- `at_verbs` - Contains a trait that all verbs have to implement. Also contains implementations for the verbs.
- `src` - Contains the main library code.
- `at_client.rs` - Contains the `AtClient` struct which is used to interact with the atPlatform.

## Logging
This library uses the `log` crate. This means implementors of this library can use something like `env_logger` and get info from the library.

## Contributions welcome!

All of our software is open with intent. We welcome contributions - we want pull requests, and we want to hear about issues. See also [CONTRIBUTING.md](CONTRIBUTING.md).

## Steps to Beta
- [ ] Notifications using the `monitor` verb
- [x] Interoperability with other SDKs

## Future goals
- [ ] Full test coverage
- [ ] Ability to implement different cryptographic and TLS libraries
- [ ] `no_std` implementation
- [ ] Distribute to `crates.io`
- [ ] Support for `async` runtime
Expand Down
Binary file added at_chops/.DS_Store
Binary file not shown.
17 changes: 17 additions & 0 deletions at_chops/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "at_chops"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
aes = "0.8.3"
anyhow = "1.0.79"
base64 = "0.21.0"
cipher = "0.4.4"
crypto = "0.5.1"
ctr = "0.9.2"
log = "0.4.20"
rand = "0.8.5"
rsa = { version = "0.9.2", features = ["sha2"] }
49 changes: 49 additions & 0 deletions at_chops/src/crypto_functions_trait.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use aes::cipher::StreamCipher;
use anyhow::Result;
use rsa::{RsaPrivateKey, RsaPublicKey};

/// A trait for cryptographic functions needed within the atSign library.
pub trait CryptoFunctions {
// ----- Base64 -----
/// Encode a byte array to base64 String.
fn base64_encode(&self, data: &[u8]) -> String;

/// Decode a base64 encoded string.
fn base64_decode(&self, data: &[u8]) -> Result<Vec<u8>>;

// ----- RSA -----
/// Construct an RSA private key from a byte array.
fn construct_rsa_private_key(&self, key: &[u8]) -> Result<RsaPrivateKey>;

/// Construct an RSA public key from a byte array.
fn construct_rsa_public_key(&self, key: &[u8]) -> Result<RsaPublicKey>;

/// Generate a new RSA key pair.
fn generate_rsa_key_pair(&self) -> Result<(RsaPrivateKey, RsaPublicKey)>;

/// Verify a signature using an RSA public key.
fn rsa_verify(&self, data: &[u8], signature: &[u8], key: &RsaPublicKey) -> Result<bool>;

/// Sign data (given as a byte array) using an RSA private key.
/// The signature is returned as a byte array.
fn rsa_sign(&self, data: &[u8], key: &RsaPrivateKey) -> Result<Vec<u8>>;

/// Encrypt some data using an RSA public key.
fn rsa_encrypt(&self, plaintext: &[u8], key: &RsaPublicKey) -> Result<Vec<u8>>;

/// Decrypt some data using an RSA private key.
fn rsa_decrypt(&self, ciphertext: &[u8], key: &RsaPrivateKey) -> Result<Vec<u8>>;

// ----- AES -----
/// Construct an AES-256 cipher from a byte array and IV.
fn construct_aes_cipher(&self, key: &[u8], iv: &[u8; 16]) -> Result<Box<dyn StreamCipher>>;

/// Create a new AES-256 key from scratch.
fn create_new_aes_key(&self) -> Result<[u8; 32]>;

/// Encrypt some data using an AES key.
fn aes_encrypt(&self, cipher: &mut dyn StreamCipher, plaintext: &[u8]) -> Result<Vec<u8>>;

/// Decrypt some data using an AES key.
fn aes_decrypt(&self, cipher: &mut dyn StreamCipher, ciphertext: &[u8]) -> Result<Vec<u8>>;
}
Loading