summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bin/roughenough-client.rs45
-rw-r--r--src/bin/roughenough-kms.rs4
-rw-r--r--src/bin/roughenough-server.rs2
-rw-r--r--src/config/environment.rs20
-rw-r--r--src/config/file.rs23
-rw-r--r--src/config/memory.rs12
-rw-r--r--src/config/mod.rs22
-rw-r--r--src/key/mod.rs40
-rw-r--r--src/kms/mod.rs45
-rw-r--r--src/server.rs21
10 files changed, 123 insertions, 111 deletions
diff --git a/src/bin/roughenough-client.rs b/src/bin/roughenough-client.rs
index 5d7c25c..55831e1 100644
--- a/src/bin/roughenough-client.rs
+++ b/src/bin/roughenough-client.rs
@@ -31,12 +31,14 @@ use std::collections::HashMap;
use std::fs::File;
use std::io::Write;
use std::iter::Iterator;
-use std::net::{ToSocketAddrs, UdpSocket};
+use std::net::{SocketAddr, ToSocketAddrs, UdpSocket};
use clap::{App, Arg};
use roughenough::merkle::root_from_paths;
use roughenough::sign::Verifier;
-use roughenough::{RtMessage, Tag, CERTIFICATE_CONTEXT, SIGNED_RESPONSE_CONTEXT, roughenough_version};
+use roughenough::{
+ roughenough_version, RtMessage, Tag, CERTIFICATE_CONTEXT, SIGNED_RESPONSE_CONTEXT,
+};
fn create_nonce() -> [u8; 64] {
let rng = rand::SystemRandom::new();
@@ -61,6 +63,21 @@ fn receive_response(sock: &mut UdpSocket) -> RtMessage {
RtMessage::from_bytes(&buf[0..resp_len]).unwrap()
}
+fn stress_test_forever(addr: &SocketAddr) -> ! {
+ if !addr.ip().is_loopback() {
+ panic!("Cannot use non-loopback address {} for stress testing", addr.ip());
+ }
+
+ println!("Stress testing!");
+
+ let nonce = create_nonce();
+ let socket = UdpSocket::bind("0.0.0.0:0").expect("Couldn't open UDP socket");
+ let request = make_request(&nonce);
+ loop {
+ socket.send_to(&request, addr).unwrap();
+ }
+}
+
struct ResponseHandler {
pub_key: Option<Vec<u8>>,
msg: HashMap<Tag, Vec<u8>>,
@@ -162,7 +179,10 @@ impl ResponseHandler {
let hash = root_from_paths(index as usize, &self.nonce, paths);
- assert_eq!(hash, srep[&Tag::ROOT], "Nonce is not present in the response's merkle tree");
+ assert_eq!(
+ hash, srep[&Tag::ROOT],
+ "Nonce is not present in the response's merkle tree"
+ );
}
fn validate_midpoint(&self, midpoint: u64) {
@@ -252,23 +272,7 @@ fn main() {
let addr = (host, port).to_socket_addrs().unwrap().next().unwrap();
if stress {
- if !addr.ip().is_loopback() {
- println!(
- "ERROR: Cannot use non-loopback address {} for stress testing",
- addr.ip()
- );
- return;
- }
-
- println!("Stress-testing!");
-
- let nonce = create_nonce();
- let socket = UdpSocket::bind("0.0.0.0:0").expect("Couldn't open UDP socket");
- let request = make_request(&nonce);
-
- loop {
- socket.send_to(&request, addr).unwrap();
- }
+ stress_test_forever(&addr)
}
let mut requests = Vec::with_capacity(num_requests);
@@ -317,3 +321,4 @@ fn main() {
);
}
}
+
diff --git a/src/bin/roughenough-kms.rs b/src/bin/roughenough-kms.rs
index b9099cd..d1cc4a6 100644
--- a/src/bin/roughenough-kms.rs
+++ b/src/bin/roughenough-kms.rs
@@ -36,7 +36,7 @@ fn aws_kms(kms_key: &str, plaintext_seed: &[u8]) {
match EnvelopeEncryption::encrypt_seed(&client, &plaintext_seed) {
Ok(encrypted_blob) => {
- println!("key_protection: \"{}\"", kms_key);
+ println!("kms_protection: \"{}\"", kms_key);
println!("seed: {}", hex::encode(&encrypted_blob));
}
Err(e) => {
@@ -53,7 +53,7 @@ fn gcp_kms(kms_key: &str, plaintext_seed: &[u8]) {
match EnvelopeEncryption::encrypt_seed(&client, &plaintext_seed) {
Ok(encrypted_blob) => {
- println!("key_protection: \"{}\"", kms_key);
+ println!("kms_protection: \"{}\"", kms_key);
println!("seed: {}", hex::encode(&encrypted_blob));
}
Err(e) => {
diff --git a/src/bin/roughenough-server.rs b/src/bin/roughenough-server.rs
index d541207..5893f12 100644
--- a/src/bin/roughenough-server.rs
+++ b/src/bin/roughenough-server.rs
@@ -40,8 +40,8 @@ use std::sync::atomic::Ordering;
use roughenough::config;
use roughenough::config::ServerConfig;
-use roughenough::server::Server;
use roughenough::roughenough_version;
+use roughenough::server::Server;
macro_rules! check_ctrlc {
($keep_running:expr) => {
diff --git a/src/config/environment.rs b/src/config/environment.rs
index 797f422..fa96185 100644
--- a/src/config/environment.rs
+++ b/src/config/environment.rs
@@ -19,7 +19,7 @@ use std::time::Duration;
use config::ServerConfig;
use config::{DEFAULT_BATCH_SIZE, DEFAULT_STATUS_INTERVAL};
-use key::KeyProtection;
+use key::KmsProtection;
use Error;
///
@@ -33,7 +33,7 @@ use Error;
/// seed | `ROUGHENOUGH_SEED`
/// batch_size | `ROUGHENOUGH_BATCH_SIZE`
/// status_interval | `ROUGHENOUGH_STATUS_INTERVAL`
-/// key_protection | `ROUGHENOUGH_KEY_PROTECTION`
+/// kms_protection | `ROUGHENOUGH_KMS_PROTECTION`
/// health_check_port | `ROUGHENOUGH_HEALTH_CHECK_PORT`
///
pub struct EnvironmentConfig {
@@ -42,7 +42,7 @@ pub struct EnvironmentConfig {
seed: Vec<u8>,
batch_size: u8,
status_interval: Duration,
- key_protection: KeyProtection,
+ kms_protection: KmsProtection,
health_check_port: Option<u16>,
}
@@ -51,7 +51,7 @@ const ROUGHENOUGH_INTERFACE: &str = "ROUGHENOUGH_INTERFACE";
const ROUGHENOUGH_SEED: &str = "ROUGHENOUGH_SEED";
const ROUGHENOUGH_BATCH_SIZE: &str = "ROUGHENOUGH_BATCH_SIZE";
const ROUGHENOUGH_STATUS_INTERVAL: &str = "ROUGHENOUGH_STATUS_INTERVAL";
-const ROUGHENOUGH_KEY_PROTECTION: &str = "ROUGHENOUGH_KEY_PROTECTION";
+const ROUGHENOUGH_KMS_PROTECTION: &str = "ROUGHENOUGH_KMS_PROTECTION";
const ROUGHENOUGH_HEALTH_CHECK_PORT: &str = "ROUGHENOUGH_HEALTH_CHECK_PORT";
impl EnvironmentConfig {
@@ -62,7 +62,7 @@ impl EnvironmentConfig {
seed: Vec::new(),
batch_size: DEFAULT_BATCH_SIZE,
status_interval: DEFAULT_STATUS_INTERVAL,
- key_protection: KeyProtection::Plaintext,
+ kms_protection: KmsProtection::Plaintext,
health_check_port: None,
};
@@ -95,10 +95,10 @@ impl EnvironmentConfig {
cfg.status_interval = Duration::from_secs(u64::from(val));
};
- if let Ok(key_protection) = env::var(ROUGHENOUGH_KEY_PROTECTION) {
- cfg.key_protection = key_protection
+ if let Ok(kms_protection) = env::var(ROUGHENOUGH_KMS_PROTECTION) {
+ cfg.kms_protection = kms_protection
.parse()
- .unwrap_or_else(|_| panic!("invalid key_protection value: {}", key_protection));
+ .unwrap_or_else(|_| panic!("invalid kms_protection value: {}", kms_protection));
}
if let Ok(health_check_port) = env::var(ROUGHENOUGH_HEALTH_CHECK_PORT) {
@@ -134,8 +134,8 @@ impl ServerConfig for EnvironmentConfig {
self.status_interval
}
- fn key_protection(&self) -> &KeyProtection {
- &self.key_protection
+ fn kms_protection(&self) -> &KmsProtection {
+ &self.kms_protection
}
fn health_check_port(&self) -> Option<u16> {
diff --git a/src/config/file.rs b/src/config/file.rs
index b70392d..d3ec64a 100644
--- a/src/config/file.rs
+++ b/src/config/file.rs
@@ -21,7 +21,7 @@ use yaml_rust::YamlLoader;
use config::ServerConfig;
use config::{DEFAULT_BATCH_SIZE, DEFAULT_STATUS_INTERVAL};
-use key::KeyProtection;
+use key::KmsProtection;
use Error;
///
@@ -42,7 +42,7 @@ pub struct FileConfig {
seed: Vec<u8>,
batch_size: u8,
status_interval: Duration,
- key_protection: KeyProtection,
+ kms_protection: KmsProtection,
health_check_port: Option<u16>,
}
@@ -69,7 +69,7 @@ impl FileConfig {
seed: Vec::new(),
batch_size: DEFAULT_BATCH_SIZE,
status_interval: DEFAULT_STATUS_INTERVAL,
- key_protection: KeyProtection::Plaintext,
+ kms_protection: KmsProtection::Plaintext,
health_check_port: None,
};
@@ -87,13 +87,12 @@ impl FileConfig {
let val = value.as_i64().expect("status_interval value invalid");
config.status_interval = Duration::from_secs(val as u64)
}
- "key_protection" => {
- let val = value
- .as_str()
- .unwrap()
- .parse()
- .unwrap_or_else(|_| panic!("invalid key_protection value: {:?}", value));
- config.key_protection = val
+ "kms_protection" => {
+ let val =
+ value.as_str().unwrap().parse().unwrap_or_else(|_| {
+ panic!("invalid kms_protection value: {:?}", value)
+ });
+ config.kms_protection = val
}
"health_check_port" => {
let val = value.as_i64().unwrap() as u16;
@@ -133,8 +132,8 @@ impl ServerConfig for FileConfig {
self.status_interval
}
- fn key_protection(&self) -> &KeyProtection {
- &self.key_protection
+ fn kms_protection(&self) -> &KmsProtection {
+ &self.kms_protection
}
fn health_check_port(&self) -> Option<u16> {
diff --git a/src/config/memory.rs b/src/config/memory.rs
index 47480d6..e3aae7e 100644
--- a/src/config/memory.rs
+++ b/src/config/memory.rs
@@ -14,7 +14,7 @@
use config::ServerConfig;
use config::{DEFAULT_BATCH_SIZE, DEFAULT_STATUS_INTERVAL};
-use key::KeyProtection;
+use key::KmsProtection;
use std::time::Duration;
use hex;
@@ -28,7 +28,7 @@ pub struct MemoryConfig {
pub seed: Vec<u8>,
pub batch_size: u8,
pub status_interval: Duration,
- pub key_protection: KeyProtection,
+ pub kms_protection: KmsProtection,
pub health_check_port: Option<u16>,
}
@@ -41,8 +41,8 @@ impl MemoryConfig {
.unwrap(),
batch_size: DEFAULT_BATCH_SIZE,
status_interval: DEFAULT_STATUS_INTERVAL,
- key_protection: KeyProtection::Plaintext,
- health_check_port: None
+ kms_protection: KmsProtection::Plaintext,
+ health_check_port: None,
}
}
}
@@ -68,8 +68,8 @@ impl ServerConfig for MemoryConfig {
self.status_interval
}
- fn key_protection(&self) -> &KeyProtection {
- &self.key_protection
+ fn kms_protection(&self) -> &KmsProtection {
+ &self.kms_protection
}
fn health_check_port(&self) -> Option<u16> {
diff --git a/src/config/mod.rs b/src/config/mod.rs
index b0ff9b4..b73892f 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -37,7 +37,7 @@ pub use self::environment::EnvironmentConfig;
mod memory;
pub use self::memory::MemoryConfig;
-use key::KeyProtection;
+use key::KmsProtection;
use Error;
/// Maximum number of requests to process in one batch and include the the Merkle tree.
@@ -56,17 +56,19 @@ pub const DEFAULT_STATUS_INTERVAL: Duration = Duration::from_secs(600);
/// --- | --- | --- | ---
/// `interface` | `ROUGHENOUGH_INTERFACE` | Required | IP address or interface name for listening to client requests
/// `port` | `ROUGHENOUGH_PORT` | Required | UDP port to listen for requests
-/// `seed` | `ROUGHENOUGH_SEED` | Required | A 32-byte hexadecimal value used to generate the server's long-term key pair. **This is a secret value and must be un-guessable**, treat it with care.
-/// `batch_size` | `ROUGHENOUGH_BATCH_SIZE` | Optional | The maximum number of requests to process in one batch. All nonces in a batch are used to build a Merkle tree, the root of which is signed. Defaults to [DEFAULT_BATCH_SIZE](constant.DEFAULT_BATCH_SIZE.html) requests per batch.
-/// `status_interval` | `ROUGHENOUGH_STATUS_INTERVAL` | Optional | Number of _seconds_ between each logged status update. Default value is [DEFAULT_STATUS_INTERVAL](constant.DEFAULT_STATUS_INTERVAL.html).
-/// `key_protection` | `ROUGHENOUGH_KEY_PROTECTION` | Optional | Encryption method (if any) applied to the `seed`. Defaults to "`plaintext`" (no encryption, `seed` is in the clear).
-/// `health_check_port` | `ROUGHENOUGH_HEALTH_CHECK_PORT` | Optional | If present, the TCP port to respond to Google-style HTTP "legacy health check".
+/// `seed` | `ROUGHENOUGH_SEED` | Required | A 32-byte hexadecimal value used to generate the server's long-term key pair. **This is a secret value and must be un-guessable**, treat it with care. (If compiled with KMS support, length will vary)
+/// `batch_size` | `ROUGHENOUGH_BATCH_SIZE` | Optional | The maximum number of requests to process in one batch. All nonces in a batch are used to build a Merkle tree, the root of which is signed. Default is `64` requests per batch.
+/// `status_interval` | `ROUGHENOUGH_STATUS_INTERVAL` | Optional | Number of _seconds_ between each logged status update. Default is `600` seconds (10 minutes).
+/// `health_check_port` | `ROUGHENOUGH_HEALTH_CHECK_PORT` | Optional | If present, enable an HTTP health check responder on the provided port. **Use with caution**.
+/// `kms_protection` | `ROUGHENOUGH_KMS_PROTECTION` | Optional | If compiled with KMS support, the ID of the KMS key used to protect the long-term identity.
///
/// Implementations of this trait obtain a valid configuration from different back-end
/// sources. See:
/// * [FileConfig](struct.FileConfig.html) - configure via a YAML file
/// * [EnvironmentConfig](struct.EnvironmentConfig.html) - configure via environment vars
///
+/// The health check and KMS features require
+///
pub trait ServerConfig {
/// [Required] IP address or interface name to listen for client requests
fn interface(&self) -> &str;
@@ -90,7 +92,7 @@ pub trait ServerConfig {
/// [Optional] Method used to protect the seed for the server's long-term key pair.
/// Defaults to "`plaintext`" (no encryption, seed is in the clear).
- fn key_protection(&self) -> &KeyProtection;
+ fn kms_protection(&self) -> &KmsProtection;
/// [Optional] If present, the TCP port to respond to Google-style HTTP "legacy health check".
/// This is a *very* simplistic check, it emits a fixed HTTP response to all TCP connections.
@@ -145,10 +147,14 @@ pub fn is_valid_config(cfg: &Box<ServerConfig>) -> bool {
error!("seed value is missing");
is_valid = false;
}
- if *cfg.key_protection() == KeyProtection::Plaintext && cfg.seed().len() != 32 {
+ if *cfg.kms_protection() == KmsProtection::Plaintext && cfg.seed().len() != 32 {
error!("plaintext seed value must be 32 characters long");
is_valid = false;
}
+ if *cfg.kms_protection() != KmsProtection::Plaintext && cfg.seed().len() <= 32 {
+ error!("KMS use enabled but seed value is too short to be an encrypted blob");
+ is_valid = false;
+ }
if cfg.batch_size() < 1 || cfg.batch_size() > 64 {
error!(
"batch_size {} is invalid; valid range 1-64",
diff --git a/src/key/mod.rs b/src/key/mod.rs
index 5ce0296..634d252 100644
--- a/src/key/mod.rs
+++ b/src/key/mod.rs
@@ -33,7 +33,7 @@ pub use self::online::OnlineKey;
/// Methods for protecting the server's long-term identity
#[derive(Debug, PartialEq, Eq, PartialOrd, Hash, Clone)]
-pub enum KeyProtection {
+pub enum KmsProtection {
/// No protection, seed is in plaintext
Plaintext,
@@ -44,32 +44,32 @@ pub enum KeyProtection {
GoogleKmsEnvelope(String),
}
-impl Display for KeyProtection {
+impl Display for KmsProtection {
fn fmt(&self, f: &mut Formatter) -> Result<(), std::fmt::Error> {
match self {
- KeyProtection::Plaintext => write!(f, "Plaintext"),
- KeyProtection::AwsKmsEnvelope(key_id) => write!(f, "AwsKms({})", key_id),
- KeyProtection::GoogleKmsEnvelope(key_id) => write!(f, "GoogleKms({})", key_id),
+ KmsProtection::Plaintext => write!(f, "Plaintext"),
+ KmsProtection::AwsKmsEnvelope(key_id) => write!(f, "AwsKms({})", key_id),
+ KmsProtection::GoogleKmsEnvelope(key_id) => write!(f, "GoogleKms({})", key_id),
}
}
}
-impl FromStr for KeyProtection {
+impl FromStr for KmsProtection {
type Err = String;
- fn from_str(s: &str) -> Result<KeyProtection, String> {
+ fn from_str(s: &str) -> Result<KmsProtection, String> {
match s {
- "plaintext" => Ok(KeyProtection::Plaintext),
- s if s.starts_with("arn:") => Ok(KeyProtection::AwsKmsEnvelope(s.to_string())),
- s if s.starts_with("projects/") => Ok(KeyProtection::GoogleKmsEnvelope(s.to_string())),
- s => Err(format!("unknown KeyProtection '{}'", s)),
+ "plaintext" => Ok(KmsProtection::Plaintext),
+ s if s.starts_with("arn:") => Ok(KmsProtection::AwsKmsEnvelope(s.to_string())),
+ s if s.starts_with("projects/") => Ok(KmsProtection::GoogleKmsEnvelope(s.to_string())),
+ s => Err(format!("unknown KmsProtection '{}'", s)),
}
}
}
#[cfg(test)]
mod test {
- use key::KeyProtection;
+ use key::KmsProtection;
use std::str::FromStr;
#[test]
@@ -79,20 +79,20 @@ mod test {
let resource_id =
"projects/key-project/locations/global/keyRings/key-ring/cryptoKeys/my-key";
- match KeyProtection::from_str("plaintext") {
- Ok(KeyProtection::Plaintext) => (),
+ match KmsProtection::from_str("plaintext") {
+ Ok(KmsProtection::Plaintext) => (),
e => panic!("unexpected result {:?}", e),
};
- match KeyProtection::from_str(arn) {
- Ok(KeyProtection::AwsKmsEnvelope(msg)) => assert_eq!(msg, arn),
+ match KmsProtection::from_str(arn) {
+ Ok(KmsProtection::AwsKmsEnvelope(msg)) => assert_eq!(msg, arn),
e => panic!("unexpected result {:?}", e),
}
- match KeyProtection::from_str(resource_id) {
- Ok(KeyProtection::GoogleKmsEnvelope(msg)) => assert_eq!(msg, resource_id),
+ match KmsProtection::from_str(resource_id) {
+ Ok(KmsProtection::GoogleKmsEnvelope(msg)) => assert_eq!(msg, resource_id),
e => panic!("unexpected result {:?}", e),
}
- match KeyProtection::from_str("frobble") {
- Err(msg) => assert!(msg.contains("unknown KeyProtection")),
+ match KmsProtection::from_str("frobble") {
+ Err(msg) => assert!(msg.contains("unknown KmsProtection")),
e => panic!("unexpected result {:?}", e),
}
}
diff --git a/src/kms/mod.rs b/src/kms/mod.rs
index ed3cd13..464d06a 100644
--- a/src/kms/mod.rs
+++ b/src/kms/mod.rs
@@ -15,6 +15,10 @@
//!
//! Protect the server's long-term key with envelope encryption and a key management system.
//!
+//! Note: KMS support must be enabled at compile time, see the Roughenough's [documentation
+//! on optional features](https://github.com/int08h/roughenough/blob/doc/OPTIONAL-FEATURES.md#key-management-system-kms-support)
+//! for instructions.
+//!
//! ## Motivation
//!
//! The seed for the server's [long-term key](../key/struct.LongTermKey.html) is subject to
@@ -57,7 +61,7 @@ use std;
use config::ServerConfig;
use error;
-use key::KeyProtection;
+use key::KmsProtection;
pub use self::envelope::EnvelopeEncryption;
@@ -129,13 +133,13 @@ pub use kms::awskms::inner::AwsKms;
/// Load the seed value for the long-term key.
///
-/// Loading behavior depends on the value of `config.key_protection()`:
+/// Loading behavior depends on the value of `config.kms_protection()`:
///
-/// * If `config.key_protection() == Plaintext` then the value returned from `config.seed()`
+/// * If `config.kms_protection() == Plaintext` then the value returned from `config.seed()`
/// is used as-is and assumed to be a 32-byte hexadecimal value.
///
/// * Otherwise `config.seed()` is assumed to be an encrypted opaque blob generated from
-/// a prior `EnvelopeEncryption::encrypt_seed` call. The value of `config.key_protection()`
+/// a prior `EnvelopeEncryption::encrypt_seed` call. The value of `config.kms_protection()`
/// is parsed as a KMS key id and `EnvelopeEncryption::decrypt_seed` is called to obtain
/// the plaintext seed value.
///
@@ -143,9 +147,9 @@ pub use kms::awskms::inner::AwsKms;
pub fn load_seed(config: &Box<ServerConfig>) -> Result<Vec<u8>, error::Error> {
use kms::envelope::EnvelopeEncryption;
- match config.key_protection() {
- KeyProtection::Plaintext => Ok(config.seed()),
- KeyProtection::AwsKmsEnvelope(key_id) => {
+ match config.kms_protection() {
+ KmsProtection::Plaintext => Ok(config.seed()),
+ KmsProtection::AwsKmsEnvelope(key_id) => {
info!("Unwrapping seed via AWS KMS key '{}'", key_id);
let kms = AwsKms::from_arn(key_id)?;
let seed = EnvelopeEncryption::decrypt_seed(&kms, &config.seed())?;
@@ -165,13 +169,13 @@ pub use kms::gcpkms::inner::GcpKms;
/// Load the seed value for the long-term key.
///
-/// Loading behavior depends on the value of `config.key_protection()`:
+/// Loading behavior depends on the value of `config.kms_protection()`:
///
-/// * If `config.key_protection() == Plaintext` then the value returned from `config.seed()`
+/// * If `config.kms_protection() == Plaintext` then the value returned from `config.seed()`
/// is used as-is and assumed to be a 32-byte hexadecimal value.
///
/// * Otherwise `config.seed()` is assumed to be an encrypted opaque blob generated from
-/// a prior `EnvelopeEncryption::encrypt_seed` call. The value of `config.key_protection()`
+/// a prior `EnvelopeEncryption::encrypt_seed` call. The value of `config.kms_protection()`
/// is parsed as a KMS key id and `EnvelopeEncryption::decrypt_seed` is called to obtain
/// the plaintext seed value.
///
@@ -179,9 +183,9 @@ pub use kms::gcpkms::inner::GcpKms;
pub fn load_seed(config: &Box<ServerConfig>) -> Result<Vec<u8>, error::Error> {
use kms::envelope::EnvelopeEncryption;
- match config.key_protection() {
- KeyProtection::Plaintext => Ok(config.seed()),
- KeyProtection::GoogleKmsEnvelope(resource_id) => {
+ match config.kms_protection() {
+ KmsProtection::Plaintext => Ok(config.seed()),
+ KmsProtection::GoogleKmsEnvelope(resource_id) => {
info!("Unwrapping seed via Google KMS key '{}'", resource_id);
let kms = GcpKms::from_resource_id(resource_id)?;
let seed = EnvelopeEncryption::decrypt_seed(&kms, &config.seed())?;
@@ -193,30 +197,29 @@ pub fn load_seed(config: &Box<ServerConfig>) -> Result<Vec<u8>, error::Error> {
}
}
-
/// Load the seed value for the long-term key.
///
-/// Loading behavior depends on the value of `config.key_protection()`:
+/// Loading behavior depends on the value of `config.kms_protection()`:
///
-/// * If `config.key_protection() == Plaintext` then the value returned from `config.seed()`
+/// * If `config.kms_protection() == Plaintext` then the value returned from `config.seed()`
/// is used as-is and assumed to be a 32-byte hexadecimal value.
///
/// * Otherwise `config.seed()` is assumed to be an encrypted opaque blob generated from
-/// a prior `EnvelopeEncryption::encrypt_seed` call. The value of `config.key_protection()`
+/// a prior `EnvelopeEncryption::encrypt_seed` call. The value of `config.kms_protection()`
/// is parsed as a KMS key id and `EnvelopeEncryption::decrypt_seed` is called to obtain
/// the plaintext seed value.
///
/// ## KMS Disabled
///
/// The KMS feature is *disabled* in this build of Roughenough. The only
-/// supported `key_protection` value is `plaintext`. Any other value is an error.
+/// supported `kms_protection` value is `plaintext`. Any other value is an error.
///
#[cfg(not(any(feature = "awskms", feature = "gcpkms")))]
pub fn load_seed(config: &Box<ServerConfig>) -> Result<Vec<u8>, error::Error> {
- match config.key_protection() {
- KeyProtection::Plaintext => Ok(config.seed()),
+ match config.kms_protection() {
+ KmsProtection::Plaintext => Ok(config.seed()),
v => Err(error::Error::InvalidConfiguration(format!(
- "key_protection '{}' requires KMS, but server was not compiled with KMS support",
+ "kms_protection '{}' requires KMS, but server was not compiled with KMS support",
v
))),
}
diff --git a/src/server.rs b/src/server.rs
index f851270..755fd4f 100644
--- a/src/server.rs
+++ b/src/server.rs
@@ -35,9 +35,9 @@ use config::ServerConfig;
use key::{LongTermKey, OnlineKey};
use kms;
use merkle::MerkleTree;
-use {Error, RtMessage, Tag, MIN_REQUEST_LENGTH};
-use std::io::Write;
use mio::tcp::Shutdown;
+use std::io::Write;
+use {Error, RtMessage, Tag, MIN_REQUEST_LENGTH};
macro_rules! check_ctrlc {
($keep_running:expr) => {
@@ -93,7 +93,6 @@ pub struct Server {
}
impl Server {
-
///
/// Create a new server instance from the provided
/// [`ServerConfig`](../config/trait.ServerConfig.html) trait object instance.
@@ -133,7 +132,8 @@ impl Server {
.unwrap();
let health_listener = if let Some(hc_port) = config.health_check_port() {
- let hc_sock_addr: SocketAddr = format!("{}:{}", config.interface(), hc_port).parse()
+ let hc_sock_addr: SocketAddr = format!("{}:{}", config.interface(), hc_port)
+ .parse()
.unwrap();
let tcp_listener = TcpListener::bind(&hc_sock_addr)
@@ -327,20 +327,20 @@ impl Server {
match listener.accept() {
Ok((ref mut stream, src_addr)) => {
info!("health check from {}", src_addr);
-
+
match stream.write(HTTP_RESPONSE.as_bytes()) {
Ok(_) => (),
- Err(e) => warn!("error writing health check {}", e)
+ Err(e) => warn!("error writing health check {}", e),
}
match stream.shutdown(Shutdown::Both) {
Ok(_) => (),
- Err(e) => warn!("error in health check socket shutdown {}", e)
+ Err(e) => warn!("error in health check socket shutdown {}", e),
}
}
Err(ref e) if e.kind() == ErrorKind::WouldBlock => {
debug!("blocking in TCP health check");
- },
+ }
Err(e) => {
warn!("unexpected health check error {}", e);
}
@@ -350,8 +350,7 @@ impl Server {
STATUS => {
info!(
"responses {}, invalid requests {}",
- self.response_counter,
- self.num_bad_requests
+ self.response_counter, self.num_bad_requests
);
self.timer.set_timeout(self.config.status_interval(), ());
@@ -380,7 +379,7 @@ impl Server {
#[cfg(fuzzing)]
pub fn send_to_self(&mut self, data: &[u8]) {
- self.response_counter.store(0, Ordering::SeqCst);;
+ self.response_counter = 0;
self.num_bad_requests = 0;
let res = self
.fake_client_socket