Skip to content

Commit

Permalink
Merged PR 826036: TPM challenge in DPS flow
Browse files Browse the repository at this point in the history
PR contains the following:
- First roundtrip to DPS. It calls register on DPS, gets the TPM authentication challenge, uses the challenge to sign a token and reissues the registration call
- Moved http client from iothubservice to edgelet-http crate. This is because both iothubservice and dps use the http client to talk to their respective services.
  • Loading branch information
dsajanice committed May 10, 2018
1 parent 09747ea commit 7ce71ae
Show file tree
Hide file tree
Showing 23 changed files with 932 additions and 209 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -313,4 +313,5 @@ backup.json

# linux dev files
*.swp
*.swo
*.vi
27 changes: 27 additions & 0 deletions edgelet/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions edgelet/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[workspace]
members = [
"docker-rs",
"dps",
"edgelet-core",
"edgelet-docker",
"edgelet-hsm",
Expand Down
24 changes: 24 additions & 0 deletions edgelet/dps/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "dps"
version = "0.1.0"
authors = ["Janice D'Sa <[email protected]>"]

[dependencies]
base64 = "0.9"
chrono = { version = "0.4", features = ["serde"] }
failure = "0.1"
futures = "0.1"
hyper = "0.11"
log = "0.4"
percent-encoding = "1.0"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
url = "1.7"

edgelet-core = { path = "../edgelet-core" }
edgelet-http = { path = "../edgelet-http" }
edgelet-utils = { path = "../edgelet-utils" }

[dev_dependencies]
tokio-core = "0.1"
95 changes: 95 additions & 0 deletions edgelet/dps/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Copyright (c) Microsoft. All rights reserved.

use std::fmt;
use std::fmt::Display;

use failure::{Backtrace, Context, Fail};
use serde_json::Error as SerdeError;

use edgelet_core::Error as CoreError;
use edgelet_http::{Error as HttpError, ErrorKind as HttpErrorKind};

#[derive(Debug)]
pub struct Error {
inner: Context<ErrorKind>,
}

#[derive(Debug, Fail)]
pub enum ErrorKind {
#[fail(display = "Core error")]
Core,
#[fail(display = "Http error")]
Http,
#[fail(display = "Serde error")]
Serde,
#[fail(display = "DPS returned an empty response when a value was expected")]
EmptyResponse,
#[fail(display = "Invalid Tpm token")]
InvalidTpmToken,
}

impl Fail for Error {
fn cause(&self) -> Option<&Fail> {
self.inner.cause()
}

fn backtrace(&self) -> Option<&Backtrace> {
self.inner.backtrace()
}
}

impl Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Display::fmt(&self.inner, f)
}
}

impl Error {
pub fn kind(&self) -> &ErrorKind {
self.inner.get_context()
}
}

impl From<ErrorKind> for Error {
fn from(kind: ErrorKind) -> Error {
Error {
inner: Context::new(kind),
}
}
}

impl From<Context<ErrorKind>> for Error {
fn from(inner: Context<ErrorKind>) -> Error {
Error { inner }
}
}

impl From<CoreError> for Error {
fn from(error: CoreError) -> Error {
Error {
inner: error.context(ErrorKind::Core),
}
}
}

impl From<HttpError> for Error {
fn from(error: HttpError) -> Error {
Error {
inner: error.context(ErrorKind::Http),
}
}
}

impl From<SerdeError> for Error {
fn from(error: SerdeError) -> Error {
Error {
inner: error.context(ErrorKind::Serde),
}
}
}

impl From<Error> for HttpError {
fn from(err: Error) -> HttpError {
HttpError::from(err.context(HttpErrorKind::TokenSource))
}
}
29 changes: 29 additions & 0 deletions edgelet/dps/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) Microsoft. All rights reserved.

#![deny(warnings)]

extern crate base64;
extern crate chrono;
#[macro_use]
extern crate failure;
extern crate futures;
extern crate hyper;
extern crate log;
extern crate percent_encoding;
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
#[cfg(test)]
extern crate tokio_core;
extern crate url;

extern crate edgelet_core;
extern crate edgelet_http;
extern crate edgelet_utils;

pub mod error;
mod model;
pub mod registration;

pub use model::{DeviceRegistration, TpmRegistrationResult};
Loading

0 comments on commit 7ce71ae

Please sign in to comment.