|
@@ -3,6 +3,7 @@
|
|
mod tpm;
|
|
mod tpm;
|
|
|
|
|
|
use super::*;
|
|
use super::*;
|
|
|
|
+
|
|
use openssl::{
|
|
use openssl::{
|
|
error::ErrorStack,
|
|
error::ErrorStack,
|
|
encrypt::{Encrypter, Decrypter},
|
|
encrypt::{Encrypter, Decrypter},
|
|
@@ -43,6 +44,7 @@ pub(crate) enum Error {
|
|
InvalidHashFormat,
|
|
InvalidHashFormat,
|
|
Message(String),
|
|
Message(String),
|
|
Serde(serde_block_tree::Error),
|
|
Serde(serde_block_tree::Error),
|
|
|
|
+ Io(std::io::Error),
|
|
}
|
|
}
|
|
|
|
|
|
impl Display for Error {
|
|
impl Display for Error {
|
|
@@ -56,6 +58,7 @@ impl Display for Error {
|
|
Error::InvalidHashFormat => write!(f, "invalid format"),
|
|
Error::InvalidHashFormat => write!(f, "invalid format"),
|
|
Error::Message(message) => f.write_str(message.as_str()),
|
|
Error::Message(message) => f.write_str(message.as_str()),
|
|
Error::Serde(serde_err) => serde_err.fmt(f),
|
|
Error::Serde(serde_err) => serde_err.fmt(f),
|
|
|
|
+ Error::Io(io_err) => io_err.fmt(f),
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -72,6 +75,12 @@ impl From<serde_block_tree::Error> for Error {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+impl From<std::io::Error> for Error {
|
|
|
|
+ fn from(error: std::io::Error) -> Error {
|
|
|
|
+ Error::Io(error)
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
pub(crate) type Result<T> = std::result::Result<T, Error>;
|
|
pub(crate) type Result<T> = std::result::Result<T, Error>;
|
|
|
|
|
|
/// A cryptographic hash.
|
|
/// A cryptographic hash.
|
|
@@ -543,6 +552,21 @@ pub(crate) trait Creds: CredsPriv + CredsPub {
|
|
fn public(&self) -> &AsymKeyPub;
|
|
fn public(&self) -> &AsymKeyPub;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/// A trait for types which store credentials.
|
|
|
|
+pub(crate) trait CredStore {
|
|
|
|
+ type CredHandle: Creds;
|
|
|
|
+
|
|
|
|
+ /// Returns the node credentials. If credentials haven't been generated, they are generated
|
|
|
|
+ /// stored and returned.
|
|
|
|
+ fn node_creds(&self) -> Result<&Self::CredHandle>;
|
|
|
|
+ /// Returns the root credentials. If no root credentials have been generated, or the provided
|
|
|
|
+ /// password is incorrect, then an error is returned.
|
|
|
|
+ fn root_creds(&self, password: &str) -> Result<&Self::CredHandle>;
|
|
|
|
+ /// Generates the root crednetials and protects them using the given password. If the root
|
|
|
|
+ /// credentials have already been generated then an error is returned.
|
|
|
|
+ fn gen_root_creds(&self, password: &str) -> Result<&Self::CredHandle>;
|
|
|
|
+}
|
|
|
|
+
|
|
pub(crate) fn encrypt_block<C: Creds>(
|
|
pub(crate) fn encrypt_block<C: Creds>(
|
|
mut block: Block, principal: &Principal, creds: &C
|
|
mut block: Block, principal: &Principal, creds: &C
|
|
) -> Result<Block> {
|
|
) -> Result<Block> {
|