HTTP Signatures
This crate is used to create and verify HTTP Signatures, defined here. It has support for Hyper, Rocket, and Reqwest types. In the future, I might also support Iron middleware for verification.
Running the examples
Since this crate is built to modularly require dependencies, running the examples is not as straightforward as for other projects. To run hyper_server
and hyper_client
, the proper commands are
and
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 rocket server
runs on port 8000, and the reqwest client
GETs on port 8000. These examples use the Authorization
header to sign and verify the request.
Usage
With Hyper
Add this to your Cargo.toml
[]
= "0.3"
= ["use_hyper"]
Client
Use it when building a request as follows.
let key_id = "some-username-or-something";
let private_key = from;
let client = new;
let json = r#"{"library":"hyper"}"#;
let mut req = post
.body
.unwrap;
req.headers_mut.insert;
req.headers_mut.insert;
// Add the HTTP Signature
req.with_signature_header.unwrap;
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???";
With Reqwest
Add this to your Cargo.toml
[]
= "0.3"
= false
= ["use_reqwest"]
In your code, use it when building a request as follows.
let key_id = "some-username-or-something".into;
let private_key = from;
let client = new;
let mut req = client.get.build.unwrap;
req.with_authorization_header
.unwrap;
let res = client.execute.unwrap;
With Rocket
Add this to your Cargo.toml
[]
= "0.3"
= false
= ["use_rocket"]
In your code, use it in a route like so
;
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/.