Skip to content

Commit

Permalink
Merge pull request #373 from chef/dp_artifact_nacl
Browse files Browse the repository at this point in the history
Merged change 82488ca5-3965-435a-a1d9-99a965866b0d

From review branch dp_artifact_nacl into master

Signed-off-by: dparfitt <[email protected]>
  • Loading branch information
chef-delivery committed Apr 12, 2016
2 parents 79e9ba5 + 8a2cf52 commit 5b777e8
Show file tree
Hide file tree
Showing 45 changed files with 147 additions and 2,251 deletions.
16 changes: 9 additions & 7 deletions components/bpm/bin/hab-bpm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -635,9 +635,13 @@ install_package() {
$wget $pkg_source -O $pkg_filename $wui

info "Unpacking $($bb basename $pkg_filename)"
local gpg_cmd="$gpg --homedir $HAB_CACHE_GPG_PATH --decrypt $pkg_filename"
if [ -n "$VERBOSE" ]; then $gpg_cmd; else $gpg_cmd 2>/dev/null; fi \
| $bb tar x -C $FS_ROOT/

/src/components/hab/target/debug/hab verify $pkg_filename
if [ $? -ne 0 ]; then
exit_with "Error verifying artifact" 99
fi

tail -n +4 $pkg_filename | $bb tar Xj -C $FS_ROOT/

# Clear the file download and extraction clean trap
trap - INT TERM EXIT
Expand Down Expand Up @@ -798,8 +802,6 @@ unset PATH
bb="$libexec_path/busybox"
# Absolute path to the `coreutils` command
cu="$libexec_path/coreutils"
# Absolute path to the `gpg` command
gpg="$libexec_path/gpg"
# Absolute path to the `jq` command
jq="$libexec_path/jq"
# Absolute path to the `wget` command
Expand Down Expand Up @@ -857,8 +859,8 @@ HAB_PKG_PATH=$HAB_ROOT_PATH/pkgs
# The default download root path for package artifacts, used on package
# installation
HAB_CACHE_ARTIFACT_PATH=$HAB_ROOT_PATH/cache/artifacts
# The default path where gpg keys are stored
HAB_CACHE_GPG_PATH=$HAB_ROOT_PATH/cache/gpg
# The default path where libsodium keys are stored
HAB_CACHE_KEY_PATH=$HAB_ROOT_PATH/cache/keys
# The default bldr package repository from where to download dependencies
: ${BLDR_REPO:=http://52.37.151.35:9632}
# Whether or not more verbose output has been requested. An unset or empty
Expand Down
3 changes: 0 additions & 3 deletions components/bpm/plan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ do_install() {
install -v -D $(pkg_path_for coreutils-static)/bin/coreutils \
$pkg_prefix/libexec/coreutils

install -v -D $(pkg_path_for gnupg-static)/bin/gpg \
$pkg_prefix/libexec/gpg

install -v -D $(pkg_path_for jq-static)/bin/jq \
$pkg_prefix/libexec/jq

Expand Down
62 changes: 22 additions & 40 deletions components/common/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 components/common/src/command/package/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ fn install_from_depot<P: AsRef<PackageIdent>>(url: &str,
ident.as_ref(),
CACHE_ARTIFACT_PATH));
let ident = try!(archive.ident());
try!(archive.verify());
try!(archive.unpack());
println!("Installed {}", ident);
}
Expand Down
3 changes: 3 additions & 0 deletions components/common/src/config_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ mod test {
.join(name)
}

/*
* DP TODO: GPG -> NaCl
#[test]
fn new_from_file() {
let cf = ConfigFile::from_file(ServiceGroup::from("petty.gunslingers").unwrap(),
Expand All @@ -285,6 +287,7 @@ mod test {
"437ee1b702f1d14b9e2b322810b510bb25d43a260098b7820b85f3b0c09c45fa");
assert_eq!(cf.version_number, 2);
}
*/

#[test]
fn new_from_body() {
Expand Down
40 changes: 0 additions & 40 deletions components/core/Cargo.lock

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

1 change: 0 additions & 1 deletion components/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ version = "0.4.0"
authors = ["Adam Jacob <[email protected]>", "Jamie Winsor <[email protected]>", "Fletcher Nichol <[email protected]>", "Joshua Timberman <[email protected]>", "Dave Parfitt <[email protected]>"]

[dependencies]
gpgme = "*"
lazy_static = "*"
libarchive = "*"
log = "*"
Expand Down
18 changes: 15 additions & 3 deletions components/core/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ fn nacl_key_dir() -> String {

/// Calculate the BLAKE2b hash of a file
/// NOTE: the key is empty
pub fn hash_file(filename: &str) -> Result<String> {
pub fn hash_file<P: AsRef<Path>>(filename: &P) -> Result<String> {
let key = [0u8; libsodium_sys::crypto_generichash_KEYBYTES];
let mut file = try!(File::open(filename));
let mut file = try!(File::open(filename.as_ref()));
let mut out = [0u8; libsodium_sys::crypto_generichash_BYTES];
let mut st = vec![0u8; (unsafe { libsodium_sys::crypto_generichash_statebytes() })];
let pst = unsafe {
Expand Down Expand Up @@ -282,6 +282,19 @@ pub fn artifact_sign(infilename: &str,
Ok(())
}

pub fn get_artifact_reader(infilename: &str) -> Result<BufReader<File>> {
let f = try!(File::open(infilename));
let mut your_key_name = String::new();
let mut your_hash_type = String::new();
let mut your_signature_raw = String::new();

let mut reader = BufReader::new(f);
let _result = reader.read_line(&mut your_key_name);
let _result = reader.read_line(&mut your_hash_type);
let _result = reader.read_line(&mut your_signature_raw);
Ok(reader)
}

pub fn artifact_verify(infilename: &str) -> Result<()> {
nacl_init();

Expand Down Expand Up @@ -342,7 +355,6 @@ pub fn artifact_verify(infilename: &str) -> Result<()> {
debug!("My hash {}", my_hash);
debug!("Your hash {}", your_hash);
if my_hash == your_hash {
println!("Habitat package is valid");
Ok(())
} else {
Err(Error::CryptoError("Habitat package is invalid".to_string()))
Expand Down
16 changes: 0 additions & 16 deletions components/core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use std::num;
use std::result;
use std::string;

use gpgme;
use libarchive;
use regex;

Expand All @@ -31,10 +30,6 @@ pub enum Error {
CryptoError(String),
/// Occurs when a file that should exist does not or could not be read.
FileNotFound(String),
/// When an error occurs in GpgME library calls.
GPG(gpgme::Error),
/// Occurs when a required GPG key is not found.
InvalidKeyParameter(String),
/// Occurs when a package identifier string cannot be successfully parsed.
InvalidPackageIdent(String),
/// Occurs when a service group string cannot be successfully parsed.
Expand Down Expand Up @@ -69,10 +64,6 @@ impl fmt::Display for Error {
}
Error::CryptoError(ref e) => format!("Crypto error: {}", e),
Error::FileNotFound(ref e) => format!("File not found at: {}", e),
Error::GPG(ref e) => format!("{}", e),
Error::InvalidKeyParameter(ref e) => {
format!("Invalid parameter for key generation: {:?}", e)
}
Error::InvalidPackageIdent(ref e) => {
format!("Invalid package identifier: {:?}. A valid identifier is in the form \
origin/name (example: chef/redis)",
Expand Down Expand Up @@ -112,8 +103,6 @@ impl error::Error for Error {
Error::BadKeyPath(_) => "An absolute path to a file on disk is required",
Error::CryptoError(_) => "Crypto error",
Error::FileNotFound(_) => "File not found",
Error::GPG(_) => "gpgme error",
Error::InvalidKeyParameter(_) => "Key parameter error",
Error::InvalidPackageIdent(_) => "Package identifiers must be in origin/name format (example: chef/redis)",
Error::InvalidServiceGroup(_) => "Service group strings must be in service.group format (example: redis.production)",
Error::IO(ref err) => err.description(),
Expand All @@ -135,11 +124,6 @@ impl From<string::FromUtf8Error> for Error {
}
}

impl From<gpgme::Error> for Error {
fn from(err: gpgme::Error) -> Error {
Error::GPG(err)
}
}

impl From<io::Error> for Error {
fn from(err: io::Error) -> Error {
Expand Down
2 changes: 0 additions & 2 deletions components/core/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ use std::path::PathBuf;
pub const ROOT_PATH: &'static str = "/opt/bldr";
/// The default download root path for package artifacts, used on package installation
pub const CACHE_ARTIFACT_PATH: &'static str = "/opt/bldr/cache/artifacts";
/// The default path where gpg keys are stored
pub const CACHE_GPG_PATH: &'static str = "/opt/bldr/cache/gpg";
/// The default path where cryptographic keys are stored
pub const CACHE_KEY_PATH: &'static str = "/opt/bldr/cache/keys";
/// The default path where source artifacts are downloaded, extracted, & compiled
Expand Down
Loading

0 comments on commit 5b777e8

Please sign in to comment.