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

Support PowerPC architecture for sigv4 signature #1847

Merged
merged 37 commits into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
61835a0
Use hmac and sha2 instead of ring on powerpc
crisidev Oct 13, 2022
5100597
Enable aws-sig-auth in CI
crisidev Oct 13, 2022
da7f6e3
Merge branch 'main' into powerpc-signature
crisidev Oct 13, 2022
bae218e
Update CHANGELOG
crisidev Oct 13, 2022
ec00348
Run tests against exotic platforms
crisidev Oct 13, 2022
0495c3d
Run tests only against aws rust runtime
crisidev Oct 13, 2022
613651e
PowerPC 32 and 64 bit should be fully testable now
crisidev Oct 14, 2022
47a5cff
Maybe this time build and test will work
crisidev Oct 14, 2022
29fe967
Add licence header to hmac.rs
crisidev Oct 14, 2022
3ad7f87
Properly use finalized_fixed
crisidev Oct 14, 2022
c66627d
Revert leftover
crisidev Oct 14, 2022
f31b017
Temporary disable crc32c test on powerpc
crisidev Oct 14, 2022
fe5cf98
Temporary disable system_time_conversion_test on 32bit CPUs
crisidev Oct 14, 2022
8f72a33
Disable other 3 tests on 32bit
crisidev Oct 14, 2022
98e5674
Merge branch 'main' into powerpc-signature
crisidev Oct 14, 2022
b2ed396
Temporarily disable last test
crisidev Oct 14, 2022
078700f
Update CHANGELOG and document TODOs with issues
crisidev Oct 14, 2022
6e48a9c
Merge branch 'main' into powerpc-signature
crisidev Oct 17, 2022
3fee356
Run aws-smithy-client tests in CI with crosscompiled local openssl
crisidev Oct 17, 2022
902361f
Simplify CI script
crisidev Oct 17, 2022
570bab8
Use correct curl options
crisidev Oct 17, 2022
1b21efb
Use the right OS for i686
crisidev Oct 17, 2022
9766878
Looks like I finally foung the right os type for i686
crisidev Oct 17, 2022
0ec0f98
Merge branch 'main' into powerpc-signature
crisidev Oct 18, 2022
f12edb9
Add `tcp` feature to `hyper` to get tests compiling.
LukeMathWalker Oct 21, 2022
03a6ded
Enable verbose logging to debug CI failure in cross.
LukeMathWalker Oct 21, 2022
0d32d56
Merge branch 'main' into powerpc-signature
LukeMathWalker Oct 21, 2022
f45401b
Use pre-built openSSL on i686
LukeMathWalker Oct 21, 2022
6084fde
Fix empty spaces.
LukeMathWalker Oct 21, 2022
6df5d6e
Merge branch 'main' into powerpc-signature
crisidev Oct 21, 2022
0df6cfc
Set environment variables based on matrix.target
LukeMathWalker Oct 21, 2022
bea53b6
Remove all usages of `ring` from `aws-sigv4`. It ensures broader plat…
LukeMathWalker Oct 25, 2022
299120d
Update changelog entries.
LukeMathWalker Oct 25, 2022
0f10bbe
Merge branch 'main' into powerpc-signature
LukeMathWalker Oct 25, 2022
f6e84e8
Merge branch 'main' into powerpc-signature
LukeMathWalker Oct 25, 2022
f9e96d4
Remove redundant dev dependencies.
LukeMathWalker Oct 25, 2022
e6ab7e6
Merge branch 'main' into powerpc-signature
LukeMathWalker Oct 25, 2022
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
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ jobs:
# We also exclude all first-party crates that have a non-optional dependency on `ring`.
- target: powerpc-unknown-linux-gnu
non_aws_features: --features native-tls
aws_excludes: --exclude aws-inlineable --exclude aws-sigv4 --exclude aws-sig-auth
aws_excludes: --exclude aws-inlineable
env:
CROSS_CONFIG: Cross.toml
OPENSSL_LIB_DIR: /usr/lib/i386-linux-gnu
Expand Down Expand Up @@ -205,6 +205,12 @@ jobs:
use-cross: true
command: build
args: --target ${{ matrix.target }} --manifest-path "aws/rust-runtime/Cargo.toml" ${{ matrix.aws_excludes }} --workspace
- name: Test AWS rust-runtime crates
crisidev marked this conversation as resolved.
Show resolved Hide resolved
uses: actions-rs/cargo@v1
with:
use-cross: true
command: test
args: --target ${{ matrix.target }} --manifest-path "aws/rust-runtime/Cargo.toml" ${{ matrix.aws_excludes }} --workspace

# This job is split out from the rest since it is not required to pass for merge
check-sdk-examples:
Expand Down
8 changes: 7 additions & 1 deletion CHANGELOG.next.toml
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,10 @@ author = "hlbarber"
message = "Update aws-types zeroize to flexible version to prevent downstream version conflicts."
references = ["smithy-rs#1817"]
meta = { "breaking" = false, "tada" = false, "bug" = true }
author = "ethyi"
author = "ethyi"

[[aws-sdk-rust]]
message = "Support Sigv4 signature generation on PowerPC."
references = ["smithy-rs#1847"]
meta = { "breaking" = false, "tada" = false, "bug" = true }
crisidev marked this conversation as resolved.
Show resolved Hide resolved
author = "crisidev"
9 changes: 8 additions & 1 deletion aws/rust-runtime/aws-sigv4/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,17 @@ http = { version = "0.2", optional = true }
once_cell = "1.8"
percent-encoding = { version = "2.1", optional = true }
regex = "1.5"
ring = "0.16"
time = "0.3.5"
tracing = "0.1"

[target.'cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))'.dependencies]
ring = "0.16"

# ring does not compile on powerpc (https://github.com/briansmith/ring/issues/389) so we use hmac and sha2.
[target.'cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))'.dependencies]
hmac = "0.12"
sha2 = "0.10"
crisidev marked this conversation as resolved.
Show resolved Hide resolved

[dev-dependencies]
bytes = "1"
httparse = "1.5"
Expand Down
74 changes: 70 additions & 4 deletions aws/rust-runtime/aws-sigv4/src/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,99 @@
//! Functions to create signing keys and calculate signatures.

use crate::date_time::format_date;
#[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))]
use hmac::{Hmac, Mac};
#[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))]
use sha2::{Digest, Sha256};

#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
use ring::{
digest::{self},
hmac::{self, Key, Tag},
digest,
hmac::{self, Key},
};
use std::time::SystemTime;

#[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))]
/// HashedPayload = Lowercase(HexEncode(Hash(requestPayload)))
#[allow(dead_code)] // Unused when compiling without certain features
pub(crate) fn sha256_hex_string(bytes: impl AsRef<[u8]>) -> String {
let mut hasher = Sha256::new();
hasher.update(bytes);
hex::encode(hasher.finalize())
}

#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
/// HashedPayload = Lowercase(HexEncode(Hash(requestPayload)))
#[allow(dead_code)] // Unused when compiling without certain features
pub(crate) fn sha256_hex_string(bytes: impl AsRef<[u8]>) -> String {
// hex::encode returns a lowercase string
hex::encode(digest::digest(&digest::SHA256, bytes.as_ref()))
}

#[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))]
/// Calculates a Sigv4 signature
pub fn calculate_signature(signing_key: Tag, string_to_sign: &[u8]) -> String {
pub fn calculate_signature(signing_key: impl AsRef<[u8]>, string_to_sign: &[u8]) -> String {
let mut mac = Hmac::<Sha256>::new_from_slice(signing_key.as_ref())
.expect("HMAC can take key of any size");
mac.update(string_to_sign);
hex::encode(mac.finalize().into_bytes())
}

#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
/// Calculates a Sigv4 signature
pub fn calculate_signature(signing_key: impl AsRef<[u8]>, string_to_sign: &[u8]) -> String {
let s_key = Key::new(hmac::HMAC_SHA256, signing_key.as_ref());
let tag = hmac::sign(&s_key, string_to_sign);
hex::encode(tag)
}

#[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))]
/// Generates a signing key for Sigv4
pub fn generate_signing_key(
secret: &str,
time: SystemTime,
region: &str,
service: &str,
) -> impl AsRef<[u8]> {
// kSecret = your secret access key
// kDate = HMAC("AWS4" + kSecret, Date)
// kRegion = HMAC(kDate, Region)
// kService = HMAC(kRegion, Service)
// kSigning = HMAC(kService, "aws4_request")

let secret = format!("AWS4{}", secret);
let mut mac =
Hmac::<Sha256>::new_from_slice(secret.as_ref()).expect("HMAC can take key of any size");
mac.update(format_date(time).as_bytes());
let tag = mac.finalize();

// sign region
let mut mac =
Hmac::<Sha256>::new_from_slice(&tag.into_bytes()).expect("HMAC can take key of any size");
mac.update(region.as_bytes());
let tag = mac.finalize();

// sign service
let mut mac =
Hmac::<Sha256>::new_from_slice(&tag.into_bytes()).expect("HMAC can take key of any size");
mac.update(service.as_bytes());
let tag = mac.finalize();

// sign request
let mut mac =
Hmac::<Sha256>::new_from_slice(&tag.into_bytes()).expect("HMAC can take key of any size");
mac.update("aws4_request".as_bytes());
mac.finalize().into_bytes()
}

#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
/// Generates a signing key for Sigv4
pub fn generate_signing_key(
secret: &str,
time: SystemTime,
region: &str,
service: &str,
) -> hmac::Tag {
) -> impl AsRef<[u8]> {
// kSecret = your secret access key
// kDate = HMAC("AWS4" + kSecret, Date)
// kRegion = HMAC(kDate, Region)
Expand Down