#jwt #crypto #ed25519 #security #webassembly

wascap

Wascap - WebAssembly Standard Capabilities. Library for extracting, embedding, and validating claims

19 releases

0.6.1 Jul 1, 2021
0.6.0 Feb 8, 2021
0.5.2 Jan 25, 2021
0.5.1 Oct 8, 2020
0.0.1 Jun 20, 2019

#113 in Cryptography

Download history 99/week @ 2021-06-06 185/week @ 2021-06-13 266/week @ 2021-06-20 453/week @ 2021-06-27 132/week @ 2021-07-04 355/week @ 2021-07-11 416/week @ 2021-07-18 336/week @ 2021-07-25 263/week @ 2021-08-01 297/week @ 2021-08-08 481/week @ 2021-08-15 198/week @ 2021-08-22 248/week @ 2021-08-29 394/week @ 2021-09-05 537/week @ 2021-09-12 542/week @ 2021-09-19

708 downloads per month
Used in 23 crates (12 directly)

Apache-2.0

63KB
1.5K SLoC

crates.io  Rust  license

WASCAP

In the wasmCloud host runtime, each actor securely declares the set of capabilities it requires. This library is 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 want to use the CLI that lets you sign and examine module claims, then you can install the wash CLI and use the wash claims set of commands. Note that earlier versions of wascap came with a CLI. This is no longer available and has been supercede by the wash CLI.

While there are some standard, well-known claims already defined in the library (such as wasmcloud:messaging and wasmcloud: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 wash CLI allows you to examine and sign WebAssembly files from a terminal prompt:

 $ wash claims inspect 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

~13MB
~334K SLoC