HTTP Signatures
This crate is used to create and verify HTTP Signatures, defined here. It has support for Actix Web, Hyper, Rocket, and Reqwest types. In the future, I might also support Iron middleware for verification.
Running the examples
Each example is hosted within it's own crate in the examples folder
The hyper examples are configured to talk to eachother by default. The server runs on port 3000, and the client POSTs on port 3000. They also use the Signature
header to sign and verify the request.
The actix-web server and client examples listens and post to port 5000, and can be tested with the each other. They use the Signature
header to sign and verify the request.
The rocket 4 server listen on port 8000, and the reqwest client can be used to interact with it. These examples use the Authorization
header to sign and verify the request.
Usage
With Actix Web
Add this to your Cargo.toml
[]
= "0.7"
= ["use_actix_web"]
Server Usage
Use it in your application like this.
const PHRASE: &str = "Hewwo, Mr. Obama???";
;
= open?;
let mut key_file_vec = Vec new;
key_file.read_to_end?;
let key_arc = new;
let state = MyState ;
new
.bind
.expect
.run;
Ok
}
Client Usage
let key_id = "some-username-or-something";
let json = r#"{"library":"actix-web"}"#;
let mut req = post
.content_length
.content_type
.body?;
req.with_signature_header?;
run;
With Hyper
Add this to your Cargo.toml
[]
= "0.7"
= ["use_hyper"]
Client
Use it when building a request as follows.
let client = new;
let json = r#"{"library":"hyper"}"#;
let mut req = post
.body?;
req.headers_mut.insert;
req.headers_mut.insert;
let key_id = "some-username-or-something";
// Add the HTTP Signature
req.with_signature_header?;
let post = client.request.and_then;
run;
Server
This is a very basic example server outline that should give you a general idea of how to set up a Hyper server that verifies HTTP Signatures. This is not meant to be code that actually works.
const PHRASE: &str = "Hewwo, Mr. Obama???";
= open?;
let mut key_file_vec = Vec new;
key_file.read_to_end?;
let key_arc = new;
let service = move || ;
let addr = "127.0.0.1:3000".parse?;
let server = bind
.serve
.map_err;
run;
Ok
}
With Reqwest
Add this to your Cargo.toml
[]
= "0.7"
= false
= ["use_reqwest"]
In your code, use it when building a request as follows.
let key_id = "some-username-or-something".into;
let client = new;
let mut req = client.get.build?;
req.with_authorization_header?;
let res = client.execute?;
With Rocket
Add this to your Cargo.toml
[]
= "0.7"
= false
= ["use_rocket"]
In your code, use it in a route like so
;
= open?;
let mut key_vec = Vec new;
key_file.read_to_end?;
ignite
.mount
.manage
.launch;
Ok
}
Contributing
Please be aware that all code contributed to this project will be licensed under the GPL version 3.
License
HTTP Signatures is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
HTTP Signatures is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. This file is part of HTTP Signatures
You should have received a copy of the GNU General Public License along with HTTP Signatures If not, see http://www.gnu.org/licenses/.