#jwt #crypto #ed25519 #security #webassembly

bin+lib wascap

Extracting, embedding, and validating WebAssembly Standard Capabilities tokens

15 releases (5 breaking)

0.5.0 Jul 24, 2020
0.4.7 Jun 24, 2020
0.4.5 Mar 24, 2020
0.4.2 Feb 28, 2020
0.0.1 Jun 20, 2019

#8 in #ed25519

Download history 124/week @ 2020-05-30 95/week @ 2020-06-06 127/week @ 2020-06-13 140/week @ 2020-06-20 128/week @ 2020-06-27 176/week @ 2020-07-04 151/week @ 2020-07-11 179/week @ 2020-07-18 132/week @ 2020-07-25 310/week @ 2020-08-01 180/week @ 2020-08-08 265/week @ 2020-08-15 110/week @ 2020-08-22 295/week @ 2020-08-29 239/week @ 2020-09-05 142/week @ 2020-09-12

595 downloads per month
Used in 3 crates

Apache-2.0

78KB
1.5K SLoC

crates.io  travis  license

WASCAP

In the waSCC runtime, each actor securely declares the set of capabilities it requires. This library and its associated binary are used to embed, extract, and validate JSON Web Tokens (JWT) containing these capability attestations, as well as the hash of the wasm file and a provable issuer for verifying module provenance.

If you just want the CLI that signs and examines capabilities claims, then you can install it with cargo:

$ cargo install wascap --features "cli"

While there are some standard, well-known claims already defined in the library (such as wascc:messaging and wascc:keyvalue), you can add custom claims in your own namespaces.

The following example illustrates embedding a new set of claims into a WebAssembly module, then extracting, validating, and examining those claims:

use wascap::prelude::*;

let unsigned = read_unsigned_wasm(); // Read a Wasm file into a byte vector
let issuer = KeyPair::new_account(); // Create an Ed25519 key pair to sign the module
let module = KeyPair::new_module(); // Create a key pair for the module itself

// Grant the module some basic capabilities, with no date limits
let claims = ClaimsBuilder::new()
    .with_capability(caps::MESSAGING)
    .with_capability(caps::KEY_VALUE)
    .issuer(&issuer.public_key())
    .subject(&module.public_key())
    .build();

// Sign the JWT and embed it into the WebAssembly module, returning the signed bytes
let embedded = wasm::embed_claims(&unsigned, &claims, &issuer)?;

// Extract a signed JWT from a WebAssembly module's bytes (performs a check on
// the signed module hash)
let extracted = wasm::extract_claims(&embedded)?.unwrap();

// Validate dates, signature, JWT structure, etc.
let v = validate_token(&extracted.jwt)?;

assert_eq!(v.expired, false);
assert_eq!(v.cannot_use_yet, false);
assert_eq!(v.expires_human, "never");
assert_eq!(v.not_before_human, "immediately");
assert_eq!(extracted.claims.issuer, issuer.public_key());

The Ed25519 key functionality is provided by the nkeys crate.

The wascap CLI allows you to examine and sign WebAssembly files from a terminal prompt:

 $ wascap caps examples/signed_loop.wasm
 ╔════════════════════════════════════════════════════════════════════════╗
                           Secure Actor - Module                         ║
 ╠═════════════╦══════════════════════════════════════════════════════════╣
  Account     ║ ACCHS57D3P2VEON5MQCJM4YA34GYBDFZR3IBG5EQNUONIHBO5X4NIURC ║
 ╠═════════════╬══════════════════════════════════════════════════════════╣
  Module      ║ MBQ2RC3BARXFWTBFW5UJ6J3QSAVYJ7D64Z5LRCPR3UI44F65Q3OMNGYM ║
 ╠═════════════╬══════════════════════════════════════════════════════════╣
  Expires     ║                                                    never ║
 ╠═════════════╬══════════════════════════════════════════════════════════╣
  Can Be Used ║                                              immediately ║
 ╠═════════════╬══════════════════════════════════════════════════════════╣
  Version     ║                                                1.0.0 (0) 
 ╠═════════════╩══════════════════════════════════════════════════════════╣
                               Capabilities                              ║
 ╠════════════════════════════════════════════════════════════════════════╣
  K/V Store                                                              ║
  Messaging                                                              ║
  HTTP Client                                                            ║
  HTTP Server                                                            ║
 ╠════════════════════════════════════════════════════════════════════════╣
                                   Tags                                  ║
 ╠════════════════════════════════════════════════════════════════════════╣
  None                                                                   ║
 ╚════════════════════════════════════════════════════════════════════════╝

Dependencies

~14MB
~351K SLoC