Expand description
§ASH Core
ASH (Anti-tamper Security Hash) is a request integrity and anti-replay protection library
§Safety
This crate uses #![forbid(unsafe_code)] to guarantee 100% safe Rust.
that ensures HTTP requests have not been tampered with in transit.
§What ASH Does
ASH provides cryptographic proof that:
- The payload has not been modified
- The request is for the correct endpoint (method + path + query)
- The request is not a replay of a previous request
- Optionally, only specific fields are protected (scoping)
§What ASH Does NOT Do
ASH verifies what is being submitted, not who is submitting it. Use alongside authentication systems (JWT, OAuth, API keys, etc.).
§Quick Start
use ash_core::{
ash_canonicalize_json, ash_derive_client_secret,
ash_build_proof, ash_verify_proof, ash_hash_body,
};
// 1. Server provides nonce and context_id to client
let nonce = "0123456789abcdef0123456789abcdef"; // 32+ hex chars
let context_id = "ctx_abc123";
let binding = "POST|/api/transfer|";
// 2. Client canonicalizes payload
let payload = r#"{"amount":100,"recipient":"alice"}"#;
let canonical = ash_canonicalize_json(payload).unwrap();
// 3. Client derives secret and builds proof
let client_secret = ash_derive_client_secret(nonce, context_id, binding).unwrap();
let body_hash = ash_hash_body(&canonical);
let timestamp = "1704067200";
let proof = ash_build_proof(&client_secret, timestamp, binding, &body_hash).unwrap();
// 4. Server verifies proof (re-derives secret from nonce internally)
let valid = ash_verify_proof(nonce, context_id, binding, timestamp, &body_hash, &proof).unwrap();
assert!(valid);§Features
| Feature | Description |
|---|---|
| Tamper Detection | HMAC-SHA256 proof ensures payload integrity |
| Replay Prevention | One-time contexts prevent request replay |
| Deterministic | Byte-identical output across all platforms |
| Field Scoping | Protect specific fields while allowing others to change |
| Request Chaining | Link sequential requests cryptographically |
| WASM Compatible | Works in browsers and server environments |
§Module Overview
| Module | Purpose |
|---|---|
proof | Core proof generation and verification |
canonicalize | Deterministic JSON/URL-encoded serialization |
compare | Constant-time comparison functions |
config | Scope policy configuration |
errors | Error types and codes |
§Security Considerations
- Nonce entropy: Use 32+ hex characters (128+ bits) for nonces
- Timestamp validation: Reject requests older than 5 minutes
- HTTPS required: ASH does not encrypt data, only signs it
- Context isolation: Never reuse context_id across requests
§Protocol Version
This library implements ASH Protocol v2.1 with extensions:
- v2.2: Field-level scoping
- v2.3: Request chaining
- v2.3.2: Binding normalization (METHOD|PATH|QUERY format)
- v2.3.4: Bug fixes (BUG-020 through BUG-034)
- v2.3.5: Security hardening (SEC-AUDIT-005 through SEC-AUDIT-007)
Re-exports§
pub use headers::HeaderMapView;pub use headers::HeaderBundle;pub use headers::ash_extract_headers;pub use binding::ash_normalize_binding_value;pub use binding::BindingType;pub use binding::NormalizedBindingValue;pub use binding::MAX_BINDING_VALUE_LENGTH;pub use build::build_request_proof;pub use build::BuildRequestInput;pub use build::BuildRequestResult;pub use build::BuildMeta;pub use enriched::ash_canonicalize_query_enriched;pub use enriched::CanonicalQueryResult;pub use enriched::ash_hash_body_enriched;pub use enriched::BodyHashResult;pub use enriched::ash_normalize_binding_enriched;pub use enriched::ash_parse_binding;pub use enriched::NormalizedBinding;pub use testkit::load_vectors;pub use testkit::load_vectors_from_file;pub use testkit::run_vectors;pub use testkit::AshAdapter;pub use testkit::AdapterResult;pub use testkit::TestReport;pub use testkit::VectorResult;pub use testkit::Vector;pub use testkit::VectorFile;pub use verify::verify_incoming_request;pub use verify::VerifyRequestInput;pub use verify::VerifyResult;pub use verify::VerifyMeta;
Modules§
- binding
- Generic binding normalizer.
- build
- High-level request proof building (Phase 3-B).
- config
- ASH Configuration Module.
- enriched
- Enriched API variants (Phase 2).
- headers
- Canonical header extraction for ASH protocol.
- testkit
- Testkit — Conformance adapter runner.
- verify
- High-level request verification (Phase 3-A).
Structs§
- AshError
- Main error type for ASH operations.
- Build
Proof Input - Input for building a proof.
- Unified
Proof Result - Result from unified proof generation.
- Verify
Input - Input for verifying a proof.
Enums§
- AshError
Code - Error codes for ASH protocol.
- AshMode
- Security mode for ASH verification.
- Internal
Reason - Internal diagnostic reason for errors.
Constants§
- ASH_
SDK_ VERSION - ASH SDK version (library version).
- ASH_
VERSION_ PREFIX - ASH protocol version prefix.
- DEFAULT_
CLOCK_ SKEW_ SECONDS - Default clock skew tolerance (60 seconds).
- DEFAULT_
MAX_ TIMESTAMP_ AGE_ SECONDS - Default maximum age for timestamps (5 minutes).
Functions§
- ash_
build_ proof - Build cryptographic proof (client-side).
- ash_
build_ proof_ scoped - Build v2.2 cryptographic proof with scoped fields.
- ash_
build_ proof_ unified - Build unified v2.3 cryptographic proof (client-side).
- ash_
canonicalize_ json - Canonicalize a JSON string to deterministic form.
- ash_
canonicalize_ json_ value - Canonicalize a JSON Value to a deterministic string.
- ash_
canonicalize_ json_ value_ with_ size_ check - Canonicalize a JSON Value with size validation.
- ash_
canonicalize_ query - Canonicalize a URL query string according to ASH v2.3.1 specification.
- ash_
canonicalize_ urlencoded - Canonicalize URL-encoded form data.
- ash_
derive_ client_ secret - Derive client secret from server nonce.
- ash_
extract_ scoped_ fields - Extract scoped fields from a JSON value.
- ash_
extract_ scoped_ fields_ strict - Extract scoped fields from a JSON value with strict mode.
- ash_
generate_ context_ id - Generate a unique context ID with “ash_” prefix.
- ash_
generate_ context_ id_ 256 - Generate a unique context ID with 256 bits of entropy.
- ash_
generate_ nonce - Generate a cryptographically secure random nonce.
- ash_
generate_ nonce_ or_ panic - Generate a cryptographically secure random nonce (convenience wrapper).
- ash_
hash_ body - Compute SHA-256 hash of canonical body.
- ash_
hash_ proof - Hash a proof for chaining purposes.
- ash_
hash_ scope - Compute SHA-256 hash of scope fields. Uses unit separator (‘\x1F’) to prevent collision with field names containing commas.
- ash_
hash_ scoped_ body - Hash scoped payload for client-side use.
- ash_
hash_ scoped_ body_ strict - Hash scoped payload with strict mode.
- ash_
normalize_ binding - Normalize a binding string to canonical form (v2.3.2+ format).
- ash_
normalize_ binding_ from_ url - Normalize a binding from a full URL path (including query string).
- ash_
timing_ safe_ compare - Compare two strings in constant time.
- ash_
timing_ safe_ equal - Perform a constant-time comparison of two byte slices.
- ash_
validate_ nonce - Validate a nonce string (format and length only, not uniqueness).
- ash_
validate_ timestamp - Validate a timestamp string.
- ash_
validate_ timestamp_ format - Validate timestamp format only (not freshness).
- ash_
verify_ proof - Verify proof (server-side).
- ash_
verify_ proof_ scoped - Verify v2.2 proof with scoped fields.
- ash_
verify_ proof_ unified - Verify unified v2.3 proof (server-side).
- ash_
verify_ proof_ with_ freshness - Verify proof with timestamp freshness check (server-side).