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

synchronous challange-response verification #4

Merged
merged 12 commits into from
Sep 9, 2022
4 changes: 4 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Formatting checks
run: cargo fmt --all -- --check
- name: Clippy checks
run: cargo clippy --all-targets -- -D clippy::all -D clippy::cargo
- name: Build
run: cargo build --verbose
- name: Run tests
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target
Cargo.lock
27 changes: 27 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[package]
name = "veraison-apiclient"
version = "0.0.1"
edition = "2021"
repository = "https://github.com/veraison/rust-apiclient"
description = "client API for Veraison"
license = "Apache-2.0"
keywords = ["attestation", "verification", "veraison"]
categories = ["web-programming"]

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

[dependencies]
reqwest = { version = "0.11", features = ["json", "rustls-tls", "blocking"] }
url = { version = "2", features = ["serde"] }
base64 = "0.13.0"
thiserror = "1"
serde = "1.0.144"
chrono = "0.4"

[dependencies.serde_with]
version = "1.14.0"
features = ["base64", "chrono"]

[dev-dependencies]
wiremock = "0.5"
async-std = { version = "1.6.5", features = ["attributes"] }
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]
Copyright 2022 Contributors to the Veraison project.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# `Veraison API client`

The `veraison_apiclient` crate provides a client implementation of the [Veraison API](https://github.com/veraison/docs/tree/main/api) in Rust.
37 changes: 37 additions & 0 deletions examples/challenge_response.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2022 Contributors to the Veraison project.
// SPDX-License-Identifier: Apache-2.0

extern crate veraison_apiclient;

use veraison_apiclient::*;

fn my_evidence_builder(nonce: &[u8], accept: &[String]) -> Result<(Vec<u8>, String), Error> {
println!("server challenge: {:?}", nonce);
println!("acceptable media types: {:#?}", accept);

Ok((
// some very fake evidence
vec![0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff],
// the first acceptable evidence type
accept[0].to_string(),
))
}

fn main() {
let api_endpoint = "http://127.0.0.1:8080/challenge-response/v1/".to_string();

// create a ChallengeResponse object
let cr = ChallengeResponseBuilder::new()
.with_base_url(api_endpoint)
.with_evidence_creation_cb(my_evidence_builder)
.build()
.unwrap();

let nonce = Nonce::Value(vec![0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef]);
// alternatively, to let Veraison pick the challenge: "let nonce = Nonce::Size(32);"

match cr.run(nonce) {
Err(e) => println!("Error: {}", e),
Ok(attestation_result) => println!("Attestation Result: {}", attestation_result),
}
}
Loading