45 Commits

Author SHA1 Message Date
tlimoncelli@stackexchange.com
225d38ee11 BACKWARDS INCOMPATIBLE CHANGES:
* Using $BASEDIR to pass the location of the repo hasn't worked for a
  while. It has been removed.  Simply cd into the vcs repo before
  running a command.
BUG FIXES:
* .gitignore was being created in subdirectories instead of VCS root.
MINOR CHANGES
* _blackbox_common.sh: Replace change_to_root with change_to_vcs_root
* confidence_test.sh: Added more assertions and tests.
2015-03-10 21:16:27 +00:00
Tom Limoncelli
ccba841cd8 Merge pull request #56 from jw35/avoid-needing-path
Avoid needing blackbox scripts on $PATH
2015-03-09 07:59:09 -04:00
Tom Limoncelli
6817724205 Merge pull request #54 from enricopulatzo/patch-1
docs: correct typo in example
2015-03-09 07:58:41 -04:00
tlimoncelli@stackexchange.com
fcaceab817 'make confidence' assumes source in ~/gitwork/blackbox. Fixes #58 2015-03-09 07:56:37 -04:00
Jon Warbrick
b35c09609b Avoid needing blackbox scripts on $PATH
blackbox_edit and blackbox_cat use other blackbox scripts internally,
but assume that they will be found on $PATH. In testing it's useful to
be able to run these scripts by pathname without first putting them on
$PATH, and all the other scripts work just fine in these circumstances.

This edit fixes this by prefixing all references to other scripts in
blackbox_edit and blackbox_cat with ${blackbox_home}, which is conveniently
set as part of sourcing _blackbox_common.sh.
2015-03-08 19:59:55 +00:00
Josh Peters
e2defec756 docs: correct typo in example
the example flow used blackbox_edit (which uses the $EDITOR) but the author meant blackbox_edit_start (since the next step is editing the file in an external editor)
2015-03-06 20:29:50 -06:00
Tom Limoncelli
65a1c938ab Merge pull request #53 from Gnouc/master
Register new file now work with space in filename.
2015-03-06 08:57:49 -05:00
tlimoncelli@stackexchange.com
faa40c71c7 Add Debian instructions 2015-03-06 13:51:53 +00:00
LE Manh Cuong
90dc874d56 Register new file now work with space in filename. 2015-03-06 11:33:39 +07:00
tlimoncelli@stackexchange.com
c474e1f0a8 rename 2015-03-05 22:20:13 +00:00
tlimoncelli@stackexchange.com
8d1d09b454 Remove irrelevant error check 2015-03-04 18:23:12 -05:00
Tom Limoncelli
d7a3c791e9 Merge pull request #49 from law/master
adding rudimentary debian package building support
2015-03-04 16:18:34 -05:00
tlimoncelli@stackexchange.com
f505eb96dc Merge branch 'Gnouc-master' 2015-03-04 15:27:56 -05:00
LE Manh Cuong
19532b82d5 Issue 50:
- Fix forgetting unquotes command substitution in function vcs_relative_path.
 - Using old test instead of new test in Makefile.
 - Fix some variables for Bob in "confidence_test.sh".
2015-03-03 09:31:09 +07:00
Lee Whalen
6e32500adc Mangling Makefile to make better sense - generates .deb inputfile list from the RPM list, and does so for each run of 'make packages-deb' 2015-03-01 14:58:09 -08:00
Lee Whalen
2591c768e7 Fixing issues with Makefile per PR feedback 2015-03-01 14:37:07 -08:00
Lee Whalen
b183931cf5 adding rudimentary debian package building support 2015-02-28 20:44:28 -08:00
tlimoncelli@stackexchange.com
9c9691c5d6 BUG: "make confidence" should work on Mac OS X 2015-02-28 08:18:26 -06:00
tlimoncelli@stackexchange.com
a9562e73d6 "make confidence" should work on mac (partial implementation) 2015-02-28 07:58:30 -06:00
Tom Limoncelli
5baec75e4b Merge pull request #47 from Gnouc/master
Fix many bugs for unquote variables.
2015-02-28 07:56:57 -06:00
LE Manh Cuong
5428aed2d7 Fix many bugs for unquote variables. 2015-02-27 01:09:59 +07:00
Tom Limoncelli
971b6bf63a Merge pull request #45 from unixorn/add-antigen-zgen-instructions
Add antigen and zgen instructions
2015-02-24 14:33:38 -05:00
Joe Block
f8016871f5 Add antigen and zgen instructions 2015-02-24 11:27:13 -08:00
Tom Limoncelli
65d11ff6d5 Merge pull request #44 from jpluscplusm/patch-1
Fix typo in Readme
2015-02-24 11:45:35 -05:00
JCM
d380b43ab7 Fix typo in Readme 2015-02-24 16:29:11 +00:00
tlimoncelli@stackexchange.com
d6fc4b1dac NEWS: Blackbox is now available via MacPorts! 2015-02-24 11:06:57 -05:00
tlimoncelli@stackexchange.com
b8881d7bff Refine the upgrade procedure 2015-02-22 13:31:27 -05:00
tlimoncelli@stackexchange.com
19facd35da Better MacPorts release flow. 2015-02-22 11:25:42 -05:00
tlimoncelli@stackexchange.com
ee3b6612ff - Add blackbox_list_files to RPM and MacPorts packages.
- Makefile should not require DESTDIR variable.
2015-02-16 16:17:30 +00:00
tlimoncelli@stackexchange.com
7cfb47c09b blackbox_list_files: Only list files. No extra text. (Makes it easier to work with grep and other utilities) 2015-02-16 16:16:40 +00:00
tlimoncelli@stackexchange.com
f18a6a0a8a README.md: Add list of commands. 2015-02-16 11:09:58 -05:00
tlimoncelli@stackexchange.com
503b26d354 blackbox_update_all_files: Clarify comment. 2015-02-16 11:09:58 -05:00
Tom Limoncelli
27df8eadf0 Merge pull request #42 from jrodriguezjr/master
List files that BlackBox is tracking
2015-02-16 10:59:28 -05:00
Tom Limoncelli
79ae5d33ab Merge pull request #43 from cyberbob25/master
Added EDITOR default to _blackbox_common.sh
2015-02-16 10:56:39 -05:00
Bryan Roberts
63b5dc9de4 Fixed parameter expansion in _blackbox_common.sh for EDITOR 2015-02-15 11:52:34 -05:00
Bryan Roberts
d4fd6cf8ed Removed check for EDITOR from blackbox_edit 2015-02-15 11:40:00 -05:00
Bryan Roberts
e5028b0fdb Removed blackbox_view since blackbox_cat already exists 2015-02-15 02:36:11 -05:00
Bryan Roberts
9b5af9f85c Added EDITOR default to _blackbox_common.sh 2015-02-15 02:35:03 -05:00
Bryan Roberts
a95a5ef629 Fixed argument for deletion 2015-02-15 02:22:41 -05:00
Bryan Roberts
0e5fdf6fa3 Added EDITOR default to blackbox_edit; Created blackbox_view 2015-02-14 20:00:34 -05:00
Joe Rodriguez Jr
1c69a11cdf Changing default umask. 2015-02-11 13:47:00 -06:00
Joe Rodriguez Jr
28b8c413c0 Make file executable. 2015-02-11 08:40:16 -06:00
tlimoncelli@stackexchange.com
86fe5ae352 More securely quote $BB_FILES 2015-02-10 18:54:47 -05:00
Joe Rodriguez Jr
bb6e7e3451 List files that BlackBox is tracking 2015-02-10 16:08:19 -06:00
tlimoncelli@stackexchange.com
de3ec22655 mk_rpm_fpmdir: Many improvements: configurable epoch, description, vendor 2015-02-04 20:19:09 +00:00
26 changed files with 510 additions and 152 deletions

View File

@@ -5,6 +5,7 @@ PKGNAME=stack_blackbox
all: all:
@echo 'Menu:' @echo 'Menu:'
@echo ' make packages Make RPM packages' @echo ' make packages Make RPM packages'
@echo ' make packages-deb Make DEB packages'
@echo ' make install (incomplete)' @echo ' make install (incomplete)'
install: install:
@@ -24,13 +25,12 @@ packages: packages-rpm
tools/mk_macports.vcs_blackbox.txt: tools/mk_rpm_fpmdir.stack_blackbox.txt tools/mk_macports.vcs_blackbox.txt: tools/mk_rpm_fpmdir.stack_blackbox.txt
sed -e 's@/usr/blackbox/bin/@bin/@g' -e '/profile.d-usrblackbox.sh/d' <tools/mk_rpm_fpmdir.stack_blackbox.txt >$@ sed -e 's@/usr/blackbox/bin/@bin/@g' -e '/profile.d-usrblackbox.sh/d' <tools/mk_rpm_fpmdir.stack_blackbox.txt >$@
check-destdir: # Make mk_deb_fpmdir.vcs_blackbox.txt from mk_rpm_fpmdir.stack_blackbox.txt:
ifndef DESTDIR tools/mk_deb_fpmdir.stack_blackbox.txt: tools/mk_rpm_fpmdir.stack_blackbox.txt
$(error DESTDIR is undefined) sed -e 's@/usr/blackbox/bin/@/usr/bin/@g' -e '/profile.d-usrblackbox.sh/d' <tools/mk_deb_fpmdir.stack_blackbox.txt >$@
endif
# MacPorts expects to run: make packages-macports DESTDIR=${destroot} # MacPorts expects to run: make packages-macports DESTDIR=${destroot}
packages-macports: tools/mk_macports.vcs_blackbox.txt check-destdir packages-macports: tools/mk_macports.vcs_blackbox.txt
mkdir -p $(DESTDIR)/bin mkdir -p $(DESTDIR)/bin
cd tools && ./mk_macports mk_macports.vcs_blackbox.txt cd tools && ./mk_macports mk_macports.vcs_blackbox.txt
@@ -60,16 +60,35 @@ lock-rpm:
unlock-rpm: unlock-rpm:
sudo yum versionlock clear sudo yum versionlock clear
#
# DEB builds
#
packages-deb: tools/mk_deb_fpmdir.stack_blackbox.txt
cd tools && PKGRELEASE="$${PKGRELEASE}" PKGDESCRIPTION="Safely store secrets in git/hg/svn repos using GPG encryption" ./mk_deb_fpmdir stack_blackbox mk_deb_fpmdir.stack_blackbox.txt
packages-deb-debug: tools/mk_deb_fpmdir.stack_blackbox.txt
@echo BUILD:
@PKGRELEASE=99 make packages-deb
@echo ITEMS TO BE PACKAGED:
find ~/debbuild-$(PKGNAME)/installroot -type f
@echo ITEMS ACTUALLY IN PACKAGE:
@dpkg --contents $$(cat ~/debbuild-$(PKGNAME)/bin-packages.txt)
local-deb:
@PKGRELEASE=1 make packages
-@sudo dpkg -e $(PKGNAME)
sudo dpkg -i $$(cat ~/rpmbuild-$(PKGNAME)/bin-packages.txt)
# Add other package types here. # Add other package types here.
# #
# System Test: # System Test:
# #
confidence: confidence:
@if [[ -e ~/.gnupg ]]; then echo ERROR: '~/.gnupg should not exist. If it does, bugs may polute your .gnupg configuration. If the code has no bugs everything will be fine. Do you feel lucky?'; false ; fi @if [ -e ~/.gnupg ]; then echo ERROR: '~/.gnupg should not exist. If it does, bugs may polute your .gnupg configuration. If the code has no bugs everything will be fine. Do you feel lucky?'; false ; fi
@if which >/dev/null gpg-agent ; then pkill gpg-agent ; rm -rf /tmp/tmp.* ; fi @if which >/dev/null gpg-agent ; then pkill gpg-agent ; rm -rf /tmp/tmp.* ; fi
@export PATH=~/gitwork/blackbox/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin ; @export PATH="$(PWD)/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/local/bin:$(PATH)" ; tools/confidence_test.sh
cd ~/gitwork/blackbox && tools/confidence_test.sh tools/confidence_test.sh
@if which >/dev/null gpg-agent ; then pkill gpg-agent ; fi @if which >/dev/null gpg-agent ; then pkill gpg-agent ; fi
@if [[ -e ~/.gnupg ]]; then echo ERROR: '~/.gnupg was created which means the scripts might be poluting GnuPG configuration. Fix this bug.'; false ; fi @if [ -e ~/.gnupg ]; then echo ERROR: '~/.gnupg was created which means the scripts might be poluting GnuPG configuration. Fix this bug.'; false ; fi

View File

@@ -74,6 +74,35 @@ exception of a few specific files, is key to the kind of
collaboration that DevOps and modern IT practitioniers collaboration that DevOps and modern IT practitioniers
need to do. need to do.
Installation Instructions:
==========================
* *The MacPorts Way*: `sudo port install vcs_blackbox`
* *The RPM way*: `make packages-rpm` and now you have an RPM you can install.
* *The Debian/Ubuntu way*: `make packages-deb` and now you have a DEB you can install.
* *The hard way*: Copy all the files in "bin" to your "bin".
* *The Antigen Way*: Add `antigen bundle StackExchange/blackbox` to your .zshrc
* *The Zgen Way*: Add `zgen load StackExchange/blackbox` to your .zshrc where you're loading your other plugins.
Commands:
============================
| Name: | Description: |
| --- | --- |
| `blackbox_addadmin` | Add someone to the list of people that can encrypt/decrypt secrets |
| `blackbox_cat` | Decrypt and view the contents of a file |
| `blackbox_edit` | Decrypt, run $EDITOR, re-encrypt a file |
| `blackbox_edit_start` | Decrypt a file so it can be updated |
| `blackbox_edit_end` | Encrypt a file after blackbox_edit_start was used |
| `blackbox_initialize` | Enable blackbox for a GIT or HG repo |
| `blackbox_postdeploy` | Decrypt all managed files |
| `blackbox_register_new_file` | Encrypt a file for the first time |
| `blackbox_removeadmin` | Remove someone from the list of people that can encrypt/decrypt secrets |
| `blackbox_shred_all_files` | Safely delete any decrypted files |
| `blackbox_update_all_files` | Decrypt then re-encrypt all files. Useful after keys are changed |
Compatibility: Compatibility:
============================ ============================
@@ -87,7 +116,7 @@ It has been tested to work with many operating systems.
* `hg` -- Mercurial * `hg` -- Mercurial
* `svn` -- SubVersion (Thanks, Ben Drasin!) * `svn` -- SubVersion (Thanks, Ben Drasin!)
* Operating system * Operating system
* CentOS * CentOS / RedHat
* MacOS X * MacOS X
* Cygwin (Thanks, Ben Drasin!) * Cygwin (Thanks, Ben Drasin!)
@@ -167,7 +196,7 @@ What does this look like to the typical user?
================================ ================================
* If you need to, start the GPG Agent: `eval $(gpg-agent --daemon)` * If you need to, start the GPG Agent: `eval $(gpg-agent --daemon)`
* Decrypt the file so it is editable: `blackbox_edit FILENAME` * Decrypt the file so it is editable: `blackbox_edit_start FILENAME`
* (You will need to enter your GPG passphrase.) * (You will need to enter your GPG passphrase.)
* Edit FILENAME as you desire: `vim FILENAME` * Edit FILENAME as you desire: `vim FILENAME`
* Re-encrypt the file: `blackbox_edit_end FILENAME` * Re-encrypt the file: `blackbox_edit_end FILENAME`

View File

@@ -1,45 +0,0 @@
# Branches and Tags:
There are 3 branches/tags:
* **HEAD:** The cutting edge of development.
* **tag stable:** Stable enough for use by most people.
* **tag production:** Burned in long enough that we are confident it can be widely adopted.
If you are packaging Blackbox for distribution, you should track the *tag production*. You might also want to provide a separate package that tracks *tag stable:* for early adopters.
# Build Tasks
# Stable Releases
Marking the software to be "stable":
Step 1. Tag it.
```
git pull
git tag -d stable
git push origin :stable
git tag stable
git push origin tag stable
```
Step 2. Mark your calendar 1 week from today to check
to see if this should be promoted to production.
# Production Releases
If no bugs have been reported a full week after a stable tag has been pushed, mark the release to be "production".
```
git fetch
git checkout stable
git tag -d production
git push origin :production
git tag production
git push origin tag production
R="v1.$(date +%Y%m%d)"
git tag "$R"
git push origin tag "$R"
```

119
RELEASE_ENGINEERING.txt Normal file
View File

@@ -0,0 +1,119 @@
# Branches and Tags:
There are 3 branches/tags:
* **HEAD:** The cutting edge of development.
* **tag stable:** Stable enough for use by most people.
* **tag production:** Burned in long enough that we are confident it can be widely adopted.
If you are packaging Blackbox for distribution, you should track the *tag production*. You might also want to provide a separate package that tracks *tag stable:* for early adopters.
# Build Tasks
# Stable Releases
Marking the software to be "stable":
Step 1. Tag it.
```
git pull
git tag -d stable
git push origin :stable
git tag stable
git push origin tag stable
```
Step 2. Mark your calendar 1 week from today to check
to see if this should be promoted to production.
# Production Releases
If no bugs have been reported a full week after a stable tag has been pushed, mark the release to be "production".
```
git fetch
git checkout stable
git tag -d production
git push origin :production
git tag production
git push origin tag production
R="v1.$(date +%Y%m%d)"
git tag "$R"
git push origin tag "$R"
```
# Updating MacPorts (automatic)
Step 1: Generate the Portfile
```
tools/macports_report_upgrade.sh 1.20150222
```
This script will generate a file called `Portfile-vcs_blackbox.diff` and instructions on how to submit it as a update request.
Step 2: Submit the update request.
Submit the diff file as a bug as instructed. The instructions should look like this:
* PLEASE OPEN A TICKET WITH THIS INFORMATION:
https://trac.macports.org/newticket
* Summary: `vcs_blackbox @1.20150222 Update to latest upstream`
* Description: ```New upstream of vcs_blackbox.
github.setup and checksums updated.```
* Type: `update`
* Component: `ports`
* Port: `vcs_blackbox`
* Keywords: `maintainer`
* Attach this file: `Portfile-vcs_blackbox.diff`
Step 3: Watch for the update to happen.
# Updating MacPorts (manual)
This is the old, manual, procedure. If the automated procedure work, these notes may or may not be helpful.
The ultimate result of the script should be a `diff -u Portfile.orig Portfile`. The new `Portfile` should have these changes:
1. The `github.setup` line should have a new version number.
2. The `checksums` line(s) should have updated checksums.
How to generate the checksums?
The easiest way is to to make a Portfile with incorrect checksums, then run `sudo port -v checksum vcs_blackbox` to see what they should have been. Fix the file, and try again.
When the the checksum command works, run `port lint vcs_blackbox` and make sure it has no errors.
Some useful commands:
Change repos in sources.conf:
```
sudo vi /opt/local/etc/macports/sources.conf
Add this line early in the file:
file:///var/tmp/ports
```
Add a local repo in an automated manner:
```
fgrep >/dev/null -x 'file:///var/tmp/ports' /opt/local/etc/macports/sources.conf || sudo sed -i -e '1s@^@file:///var/tmp/ports\'$'\n@' /opt/local/etc/macports/sources.conf
```
Remove the local repo in an automated manner:
```
sudo sed -i -e '\@^file:///var/tmp/ports@d' /opt/local/etc/macports/sources.conf
```
Test a Portfile:
```
sudo port uninstall vcs_blackbox
sudo port clean --all vcs_blackbox
rm -rf ~/.macports/opt/local/var/macports/sources/rsync.macports.org/release/tarballs/ports/security/vcs_blackbox/
rm -rf /var/tmp/ports
mkdir -p /var/tmp/ports/security/vcs_blackbox
cp Portfile /var/tmp/ports/security/vcs_blackbox
cd /var/tmp/ports && portindex
sudo port -v checksum vcs_blackbox
sudo port install vcs_blackbox
```

View File

@@ -10,8 +10,13 @@
# . _blackbox_common.sh # . _blackbox_common.sh
# Where in the VCS repo should the blackbox data be found? # Where in the VCS repo should the blackbox data be found?
: ${BLACKBOXDATA:=keyrings/live} ; # If BLACKBOXDATA not set, set it. : "${BLACKBOXDATA:=keyrings/live}" ; # If BLACKBOXDATA not set, set it.
# If $EDITOR is not set, set it to "vi":
: "${EDITOR:=vi}" ;
# Outputs a string that is the base directory of this VCS repo. # Outputs a string that is the base directory of this VCS repo.
# By side-effect, sets the variable VCS_TYPE to either 'git', 'hg', # By side-effect, sets the variable VCS_TYPE to either 'git', 'hg',
# 'svn' or 'unknown'. # 'svn' or 'unknown'.
@@ -22,19 +27,19 @@ function _determine_vcs_base_and_type() {
#find topmost dir with .svn sub-dir #find topmost dir with .svn sub-dir
parent="" parent=""
grandparent="." grandparent="."
mydir=`pwd` mydir="$(pwd)"
while [ -d "$grandparent/.svn" ]; do while [ -d "$grandparent/.svn" ]; do
parent=$grandparent parent=$grandparent
grandparent="$parent/.." grandparent="$parent/.."
done done
if [ ! -z "$parent" ]; then if [ ! -z "$parent" ]; then
cd $parent cd "$parent"
echo `pwd` pwd
else else
exit 1 exit 1
fi fi
cd $mydir cd "$mydir"
VCS_TYPE=svn VCS_TYPE=svn
elif hg root 2>/dev/null ; then elif hg root 2>/dev/null ; then
# NOTE: hg has to be tested last because it always "succeeds". # NOTE: hg has to be tested last because it always "succeeds".
@@ -56,7 +61,8 @@ BB_FILES_FILE="blackbox-files.txt"
BB_FILES="${KEYRINGDIR}/${BB_FILES_FILE}" BB_FILES="${KEYRINGDIR}/${BB_FILES_FILE}"
SECRING="${KEYRINGDIR}/secring.gpg" SECRING="${KEYRINGDIR}/secring.gpg"
PUBRING="${KEYRINGDIR}/pubring.gpg" PUBRING="${KEYRINGDIR}/pubring.gpg"
: ${DECRYPT_UMASK:=o=} ; : "${DECRYPT_UMASK:=0022}" ;
# : ${DECRYPT_UMASK:=o=} ;
# Return error if not on cryptlist. # Return error if not on cryptlist.
function is_on_cryptlist() { function is_on_cryptlist() {
@@ -178,9 +184,9 @@ function decrypt_file() {
echo "========== EXTRACTING $unencrypted" echo "========== EXTRACTING $unencrypted"
old_umask=$(umask) old_umask=$(umask)
umask $DECRYPT_UMASK umask "$DECRYPT_UMASK"
gpg -q --decrypt -o "$unencrypted" "$encrypted" gpg -q --decrypt -o "$unencrypted" "$encrypted"
umask $old_umask umask "$old_umask"
} }
# Decrypt .gpg file, overwriting unencrypted file if it exists. # Decrypt .gpg file, overwriting unencrypted file if it exists.
@@ -200,12 +206,12 @@ function decrypt_file_overwrite() {
fi fi
old_umask=$(umask) old_umask=$(umask)
umask $DECRYPT_UMASK umask "$DECRYPT_UMASK"
gpg --yes -q --decrypt -o "$unencrypted" "$encrypted" gpg --yes -q --decrypt -o "$unencrypted" "$encrypted"
umask $old_umask umask "$old_umask"
new_hash=$(md5sum_file "$unencrypted") new_hash=$(md5sum_file "$unencrypted")
if [[ $old_hash != $new_hash ]]; then if [[ "$old_hash" != "$new_hash" ]]; then
echo "========== EXTRACTED $unencrypted" echo "========== EXTRACTED $unencrypted"
fi fi
} }
@@ -244,17 +250,26 @@ function enumerate_subdirs() {
while read filename; do while read filename; do
dir=$(dirname "$filename") dir=$(dirname "$filename")
while [[ $dir != '.' && $dir != '/' ]]; do while [[ $dir != '.' && $dir != '/' ]]; do
echo $dir echo "$dir"
dir=$(dirname $dir) dir=$(dirname "$dir")
done done
done <"$listfile" | sort -u done <"$listfile" | sort -u
} }
# chdir to the base of the repo.
function change_to_vcs_root() {
if [[ $REPOBASE = '' ]]; then
echo 'ERROR: _determine_vcs_base_and_type failed to set REPOBASE.'
exit 1
fi
cd "$REPOBASE"
}
# Output the path of a file relative to the repo base # Output the path of a file relative to the repo base
function vcs_relative_path() { function vcs_relative_path() {
# Usage: vcs_relative_path file # Usage: vcs_relative_path file
local name="$1" local name="$1"
python -c 'import os ; print(os.path.relpath("'$(pwd -P)'/'"$name"'", "'"$REPOBASE"'"))' python -c 'import os ; print(os.path.relpath("'"$(pwd -P)"'/'"$name"'", "'"$REPOBASE"'"))'
} }
# #
@@ -332,7 +347,7 @@ function is_in_svn() {
echo true echo true
else else
echo false echo false
fi fi
} }
@@ -372,7 +387,6 @@ function vcs_commit_svn() {
} }
# Remove file from repo, even if it was deleted locally already. # Remove file from repo, even if it was deleted locally already.
# If it doesn't exist yet in the repo, it should be a no-op. # If it doesn't exist yet in the repo, it should be a no-op.
function vcs_remove() { function vcs_remove() {
@@ -390,17 +404,3 @@ function vcs_remove_git() {
function vcs_remove_svn() { function vcs_remove_svn() {
svn delete """$@""" svn delete """$@"""
} }
function change_to_root() {
# If BASEDIR is not set, use REPOBASE.
if [[ "$BASEDIR" = "" ]]; then
BASEDIR="$REPOBASE"
fi
if [[ "$BASEDIR" = "/dev/null" ]]; then
echo 'WARNING: Not in a VCS repo. Not changing directory.'
else
echo "CDing to $BASEDIR"
cd "$BASEDIR"
fi
}

View File

@@ -79,7 +79,7 @@ function make_tempdir() {
case $(uname -s) in case $(uname -s) in
Darwin ) Darwin )
: ${TMPDIR:=/tmp} ; : "${TMPDIR:=/tmp}" ;
name=$(mktemp -d -t _stacklib_ ) name=$(mktemp -d -t _stacklib_ )
;; ;;
Linux ) Linux )

View File

@@ -16,17 +16,7 @@ source ${blackbox_home}/_stack_lib.sh
fail_if_not_in_repo fail_if_not_in_repo
KEYNAME="$1" KEYNAME="$1"
: ${KEYNAME:?ERROR: First argument must be a keyname (email address)} ; : "${KEYNAME:?ERROR: First argument must be a keyname (email address)}" ;
# The second argument, if present, is the directory to find the GPG keys to be imported.
if [[ "$2" == "" ]]; then
GPGEXPORTOPTIONS=""
else
GPGEXPORTOPTIONS=--homedir="${2}"
fi
# TODO(tlim): This could probably be done with GNUPGHOME
# but that affects all commands; we just want it to affect the key export.
# Add the email address to the BB_ADMINS file. Remove any duplicates. # Add the email address to the BB_ADMINS file. Remove any duplicates.
# The file must exist for sort to act as we expect. # The file must exist for sort to act as we expect.
@@ -38,7 +28,16 @@ sort -fdu -o "$BB_ADMINS" <(echo "$1") "$BB_ADMINS"
# Extract it: # Extract it:
make_self_deleting_tempfile pubkeyfile make_self_deleting_tempfile pubkeyfile
gpg $GPGEXPORTOPTIONS --export -a "$KEYNAME" >"$pubkeyfile"
# The second argument, if present, is the directory to find the GPG keys to be imported.
if [[ -z $2 ]]; then
gpg --export -a "$KEYNAME" >"$pubkeyfile"
else
# TODO(tlim): This could probably be done with GNUPGHOME
# but that affects all commands; we just want it to affect the key export.
gpg --homedir="$2" --export -a "$KEYNAME" >"$pubkeyfile"
fi
if [[ $(wc -l < "$pubkeyfile") = 0 ]]; then if [[ $(wc -l < "$pubkeyfile") = 0 ]]; then
fail_out "GPG key '$KEYNAME' not found. Please create it with: gpg --gen-key" fail_out "GPG key '$KEYNAME' not found. Please create it with: gpg --gen-key"
exit 1 exit 1

View File

@@ -5,13 +5,13 @@
# #
set -e set -e
blackbox_home=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) blackbox_home=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source ${blackbox_home}/_blackbox_common.sh source "${blackbox_home}/_blackbox_common.sh"
for param in """$@""" ; do for param in """$@""" ; do
shreddable=0 shreddable=0
unencrypted_file=$(get_unencrypted_filename "$param") unencrypted_file=$(get_unencrypted_filename "$param")
if [[ ! -e "$unencrypted_file" ]]; then if [[ ! -e "$unencrypted_file" ]]; then
blackbox_edit_start "$param" "${blackbox_home}/blackbox_edit_start" "$param"
shreddable=1 shreddable=1
fi fi
cat "$unencrypted_file" cat "$unencrypted_file"

View File

@@ -5,7 +5,7 @@
# #
set -e set -e
blackbox_home=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) blackbox_home=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source ${blackbox_home}/_blackbox_common.sh source "${blackbox_home}/_blackbox_common.sh"
for param in """$@""" ; do for param in """$@""" ; do
unencrypted_file=$(get_unencrypted_filename "$param") unencrypted_file=$(get_unencrypted_filename "$param")
@@ -13,7 +13,7 @@ for param in """$@""" ; do
read -r -p "Encrypt file $param? (y/n) " ans read -r -p "Encrypt file $param? (y/n) " ans
case "$ans" in case "$ans" in
y* | Y*) y* | Y*)
blackbox_register_new_file "$param" "${blackbox_home}/blackbox_register_new_file" "$param"
;; ;;
*) *)
echo 'Skipping...' echo 'Skipping...'
@@ -21,7 +21,7 @@ for param in """$@""" ; do
;; ;;
esac esac
fi fi
blackbox_edit_start "$param" "${blackbox_home}/blackbox_edit_start" "$param"
$EDITOR $(get_unencrypted_filename $param) "$EDITOR" "$(get_unencrypted_filename "$param")"
blackbox_edit_end "$param" "${blackbox_home}/blackbox_edit_end" "$param"
done done

View File

@@ -6,7 +6,7 @@
set -e set -e
blackbox_home=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) blackbox_home=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source ${blackbox_home}/_blackbox_common.sh source "${blackbox_home}/_blackbox_common.sh"
unencrypted_file=$(get_unencrypted_filename "$1") unencrypted_file=$(get_unencrypted_filename "$1")
encrypted_file=$(get_encrypted_filename "$1") encrypted_file=$(get_encrypted_filename "$1")

View File

@@ -6,7 +6,7 @@
set -e set -e
blackbox_home=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) blackbox_home=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source ${blackbox_home}/_blackbox_common.sh source "${blackbox_home}/_blackbox_common.sh"
for param in """$@""" ; do for param in """$@""" ; do
unencrypted_file=$(get_unencrypted_filename "$param") unencrypted_file=$(get_unencrypted_filename "$param")

View File

@@ -10,7 +10,7 @@
set -e set -e
blackbox_home=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) blackbox_home=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source ${blackbox_home}/_blackbox_common.sh source "${blackbox_home}/_blackbox_common.sh"
_determine_vcs_base_and_type # Sets VCS_TYPE _determine_vcs_base_and_type # Sets VCS_TYPE
@@ -22,15 +22,14 @@ if [[ $1 != 'yes' ]]; then
fi fi
fi fi
echo cd "$REPOBASE" change_to_vcs_root
cd "$REPOBASE"
echo VCS_TYPE: $VCS_TYPE echo VCS_TYPE: $VCS_TYPE
if [[ $VCS_TYPE = "git" || $VCS_TYPE = "hg" ]]; then if [[ $VCS_TYPE = "git" || $VCS_TYPE = "hg" ]]; then
# Update .gitignore or .hgignore # Update .gitignore or .hgignore
IGNOREFILE=".${VCS_TYPE}ignore" IGNOREFILE="${REPOBASE}/.${VCS_TYPE}ignore"
if ! grep -sx >/dev/null 'pubring.gpg~' "$IGNOREFILE" ; then if ! grep -sx >/dev/null 'pubring.gpg~' "$IGNOREFILE" ; then
echo 'pubring.gpg~' >>"$IGNOREFILE" echo 'pubring.gpg~' >>"$IGNOREFILE"
fi fi

9
bin/blackbox_list_files Executable file
View File

@@ -0,0 +1,9 @@
#!/usr/bin/env bash
#
# blackbox_list_files.sh -- List files that black box is tracking
#
set -e
blackbox_home=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source "${blackbox_home}/_blackbox_common.sh"
cat "$BB_FILES"

View File

@@ -15,7 +15,7 @@ export PATH=/usr/bin:/bin:"$PATH"
set -e set -e
blackbox_home=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) blackbox_home=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source ${blackbox_home}/_blackbox_common.sh source "${blackbox_home}/_blackbox_common.sh"
if [[ "$1" == "" ]]; then if [[ "$1" == "" ]]; then
FILE_GROUP="" FILE_GROUP=""
@@ -23,7 +23,7 @@ else
FILE_GROUP="$1" FILE_GROUP="$1"
fi fi
change_to_root change_to_vcs_root
prepare_keychain prepare_keychain
# Decrypt: # Decrypt:
@@ -33,7 +33,7 @@ while IFS= read <&99 -r unencrypted_file; do
decrypt_file_overwrite "$encrypted_file" "$unencrypted_file" decrypt_file_overwrite "$encrypted_file" "$unencrypted_file"
chmod g+r "$unencrypted_file" chmod g+r "$unencrypted_file"
if [[ ! -z "$FILE_GROUP" ]]; then if [[ ! -z "$FILE_GROUP" ]]; then
chgrp $FILE_GROUP "$unencrypted_file" chgrp "$FILE_GROUP" "$unencrypted_file"
fi fi
done 99<"$BB_FILES" done 99<"$BB_FILES"
echo '========== Decrypting new/changed files: DONE' echo '========== Decrypting new/changed files: DONE'

View File

@@ -12,13 +12,13 @@
set -e set -e
blackbox_home=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) blackbox_home=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source ${blackbox_home}/_blackbox_common.sh source "${blackbox_home}/_blackbox_common.sh"
_determine_vcs_base_and_type _determine_vcs_base_and_type
unencrypted_file=$(get_unencrypted_filename "$1") unencrypted_file=$(get_unencrypted_filename "$1")
encrypted_file=$(get_encrypted_filename "$1") encrypted_file=$(get_encrypted_filename "$1")
if [[ $1 == $encrypted_file ]]; then if [[ "$1" == "$encrypted_file" ]]; then
echo ERROR: Please only register unencrypted files. echo ERROR: Please only register unencrypted files.
exit 1 exit 1
fi fi
@@ -34,35 +34,37 @@ encrypt_file "$unencrypted_file" "$encrypted_file"
add_filename_to_cryptlist "$unencrypted_file" add_filename_to_cryptlist "$unencrypted_file"
# Is the unencrypted file already in HG? (ie. are we correcting a bad situation) # Is the unencrypted file already in HG? (ie. are we correcting a bad situation)
SECRETSEXPOSED=$(is_in_vcs ${unencrypted_file}) SECRETSEXPOSED=$(is_in_vcs "${unencrypted_file}")
echo "========== CREATED: ${encrypted_file}" echo "========== CREATED: ${encrypted_file}"
echo "========== UPDATING REPO:" echo "========== UPDATING REPO:"
shred_file "$unencrypted_file" shred_file "$unencrypted_file"
VCSCMD=$(which_vcs) VCSCMD=$(which_vcs)
if $SECRETSEXPOSED ; then if "$SECRETSEXPOSED" ; then
vcs_remove "$unencrypted_file" vcs_remove "$unencrypted_file"
vcs_add "$encrypted_file" vcs_add "$encrypted_file"
COMMIT_FILES="$BB_FILES $encrypted_file $unencrypted_file" COMMIT_FILES=("$BB_FILES" "$encrypted_file" "$unencrypted_file")
else else
COMMIT_FILES="$BB_FILES $encrypted_file" COMMIT_FILES=("$BB_FILES" "$encrypted_file")
fi fi
# TODO(tlim): This should be moved to _blackbox_common.sh in a # TODO(tlim): This should be moved to _blackbox_common.sh in a
# VCS-independent way. # VCS-independent way.
IGNOREFILE=".${VCS_TYPE}ignore" IGNOREFILE="${REPOBASE}/.${VCS_TYPE}ignore"
if [[ $VCS_TYPE = 'git' ]]; then if [[ $VCS_TYPE = 'git' ]]; then
ignored_file="$(echo "$unencrypted_file" | sed 's/\([\*\?]\)/\\\1/g' | sed 's/^\([!#]\)/\\\1/')" relfile="$(vcs_relative_path "$unencrypted_file")"
relfileb="${relfile/\$\//}"
ignored_file="$(echo "${relfileb}" | sed 's/\([\*\?]\)/\\\1/g' | sed 's/^\([!#]\)/\\\1/')"
if ! grep -Fsx >/dev/null "$ignored_file" "$IGNOREFILE"; then if ! grep -Fsx >/dev/null "$ignored_file" "$IGNOREFILE"; then
echo "$ignored_file" >>"$IGNOREFILE" echo "$ignored_file" >>"$IGNOREFILE"
COMMIT_FILES="$COMMIT_FILES $IGNOREFILE" COMMIT_FILES+=("$IGNOREFILE")
fi fi
vcs_add "$IGNOREFILE" vcs_add "$IGNOREFILE"
fi fi
echo 'NOTE: "already tracked!" messages are safe to ignore.' echo 'NOTE: "already tracked!" messages are safe to ignore.'
vcs_add $BB_FILES $encrypted_file vcs_add "$BB_FILES" "$encrypted_file"
vcs_commit "registered in blackbox: ${unencrypted_file}" $COMMIT_FILES vcs_commit "registered in blackbox: ${unencrypted_file}" "${COMMIT_FILES[@]}"
echo "========== UPDATING VCS: DONE" echo "========== UPDATING VCS: DONE"
echo "Local repo updated. Please push when ready." echo "Local repo updated. Please push when ready."
echo " $VCSCMD push" echo " $VCSCMD push"

View File

@@ -11,13 +11,13 @@
set -e set -e
blackbox_home=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) blackbox_home=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source ${blackbox_home}/_blackbox_common.sh source "${blackbox_home}/_blackbox_common.sh"
source ${blackbox_home}/_stack_lib.sh source "${blackbox_home}/_stack_lib.sh"
fail_if_not_in_repo fail_if_not_in_repo
KEYNAME="$1" KEYNAME="$1"
: ${KEYNAME:?ERROR: First argument must be a keyname (email address)} ; : "${KEYNAME:?ERROR: First argument must be a keyname (email address)}" ;
# Remove the email address from the BB_ADMINS file. # Remove the email address from the BB_ADMINS file.
make_self_deleting_tempfile bbtemp make_self_deleting_tempfile bbtemp

View File

@@ -17,12 +17,12 @@
set -e set -e
blackbox_home=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) blackbox_home=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source ${blackbox_home}/_blackbox_common.sh source "${blackbox_home}/_blackbox_common.sh"
change_to_root change_to_vcs_root
echo '========== FILES BEING SHREDDED:' echo '========== FILES BEING SHREDDED:'
for i in $(<$BB_FILES) ; do for i in $(<"$BB_FILES") ; do
unencrypted_file=$(get_unencrypted_filename "$i") unencrypted_file=$(get_unencrypted_filename "$i")
encrypted_file=$(get_encrypted_filename "$i") encrypted_file=$(get_encrypted_filename "$i")
if [[ -f "$unencrypted_file" ]]; then if [[ -f "$unencrypted_file" ]]; then

View File

@@ -1,12 +1,12 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# #
# blackbox_update_all_files -- Re-encrypt file after edits. # blackbox_update_all_files -- Decrypt then re-encrypt all files. Useful after keys are changed.
# #
set -e set -e
blackbox_home=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) blackbox_home=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source ${blackbox_home}/_blackbox_common.sh source "${blackbox_home}/_blackbox_common.sh"
if [[ -z $GPG_AGENT_INFO ]]; then if [[ -z $GPG_AGENT_INFO ]]; then
echo 'WARNING: You probably want to run gpg-agent as' echo 'WARNING: You probably want to run gpg-agent as'
@@ -23,7 +23,7 @@ awk <"$BB_FILES" '{ print " " $1 ".gpg" }'
echo '========== FILES IN THE WAY:' echo '========== FILES IN THE WAY:'
need_warning=false need_warning=false
for i in $(<$BB_FILES) ; do for i in $(<"$BB_FILES") ; do
unencrypted_file=$(get_unencrypted_filename "$i") unencrypted_file=$(get_unencrypted_filename "$i")
encrypted_file=$(get_encrypted_filename "$i") encrypted_file=$(get_encrypted_filename "$i")
if [[ -f "$unencrypted_file" ]]; then if [[ -f "$unencrypted_file" ]]; then
@@ -31,7 +31,7 @@ for i in $(<$BB_FILES) ; do
echo " $unencrypted_file" echo " $unencrypted_file"
fi fi
done done
if $need_warning ; then if "$need_warning" ; then
echo echo
echo 'WARNING: This will overwrite any unencrypted files laying about.' echo 'WARNING: This will overwrite any unencrypted files laying about.'
read -r -p 'Press CTRL-C now to stop. ENTER to continue: ' read -r -p 'Press CTRL-C now to stop. ENTER to continue: '
@@ -40,7 +40,7 @@ else
fi fi
echo '========== RE-ENCRYPTING FILES:' echo '========== RE-ENCRYPTING FILES:'
for i in $(<$BB_FILES) ; do for i in $(<"$BB_FILES") ; do
unencrypted_file=$(get_unencrypted_filename "$i") unencrypted_file=$(get_unencrypted_filename "$i")
encrypted_file=$(get_encrypted_filename "$i") encrypted_file=$(get_encrypted_filename "$i")
echo ========== PROCESSING "$unencrypted_file" echo ========== PROCESSING "$unencrypted_file"
@@ -53,7 +53,7 @@ done
fail_if_keychain_has_secrets fail_if_keychain_has_secrets
echo '========== COMMITING TO VCS:' echo '========== COMMITING TO VCS:'
vcs_commit 'Re-encrypted keys' $(awk <$BB_FILES '{ print $1 ".gpg" }' ) vcs_commit 'Re-encrypted keys' $(awk <"$BB_FILES" '{ print $1 ".gpg" }' )
VCSCMD=$(which_vcs) VCSCMD=$(which_vcs)
echo '========== DONE.' echo '========== DONE.'

31
tools/Portfile.template Normal file
View File

@@ -0,0 +1,31 @@
# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
# $Id: Portfile 132962 2015-02-16 10:33:02Z ryandesign@macports.org $
PortSystem 1.0
PortGroup github 1.0
github.setup StackExchange blackbox @@VERSION@@ v
name vcs_blackbox
categories security
platforms darwin
maintainers whatexit.org:tal openmaintainer
license BSD
supported_archs noarch
description Safely store secrets in git/hg/svn repos using GPG encryption
long_description Storing secrets such as passwords, certificates and private keys \
in Git/Mercurial/SubVersion is dangerous. Blackbox makes it easy \
to store secrets safely using GPG encryption. They can be easily \
decrypted for editing or use in production.
checksums rmd160 @@RMD160@@ \
sha256 @@SHA256@@
use_configure no
build {}
# This project's Makefile uses DESTDIR incorrectly.
destroot.destdir DESTDIR=${destroot}${prefix}
destroot.target packages-macports

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
blackbox_home=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/../bin blackbox_home=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/../bin
export PATH=${blackbox_home}:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin export PATH="${blackbox_home}:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/local/bin"
. _stack_lib.sh . _stack_lib.sh
@@ -15,6 +15,25 @@ function PHASE() {
echo '********************' echo '********************'
} }
function md5sum_file() {
# Portably generate the MD5 hash of file $1.
case $(uname -s) in
Darwin )
md5 -r "$1" | awk '{ print $1 }'
;;
Linux )
md5sum "$1" | awk '{ print $1 }'
;;
CYGWIN* )
md5sum "$1" | awk '{ print $1 }'
;;
* )
echo 'ERROR: Unknown OS. Exiting.'
exit 1
;;
esac
}
function assert_file_missing() { function assert_file_missing() {
if [[ -e "$1" ]]; then if [[ -e "$1" ]]; then
echo "ASSERT FAILED: ${1} should not exist." echo "ASSERT FAILED: ${1} should not exist."
@@ -36,7 +55,7 @@ function assert_file_md5hash() {
local file="$1" local file="$1"
local wanted="$2" local wanted="$2"
assert_file_exists "$file" assert_file_exists "$file"
local found=$(md5sum <"$file" | cut -d' ' -f1 ) local found=$(md5sum_file "$file")
if [[ "$wanted" != "$found" ]]; then if [[ "$wanted" != "$found" ]]; then
echo "ASSERT FAILED: $file hash wanted=$wanted found=$found" echo "ASSERT FAILED: $file hash wanted=$wanted found=$found"
exit 1 exit 1
@@ -54,7 +73,7 @@ function assert_file_group() {
;; ;;
esac esac
local found=$(ls -l "$file" | awk '{ print $4 }') local found=$(ls -lg "$file" | awk '{ print $3 }')
# NB(tlim): We could do this with 'stat' but it would break on BSD-style OSs. # NB(tlim): We could do this with 'stat' but it would break on BSD-style OSs.
if [[ "$wanted" != "$found" ]]; then if [[ "$wanted" != "$found" ]]; then
echo "ASSERT FAILED: $file chgrp wanted=$wanted found=$found" echo "ASSERT FAILED: $file chgrp wanted=$wanted found=$found"
@@ -96,7 +115,7 @@ eval $(gpg-agent --homedir "$fake_alice_home" --daemon)
GPG_AGENT_INFO_ALICE="$GPG_AGENT_INFO" GPG_AGENT_INFO_ALICE="$GPG_AGENT_INFO"
export GNUPGHOME="$fake_bob_home" export GNUPGHOME="$fake_bob_home"
eval $(gpg-agent --homedir "$fake_alice_home" --daemon) eval $(gpg-agent --homedir "$fake_bob_home" --daemon)
GPG_AGENT_INFO_BOB="$GPG_AGENT_INFO" GPG_AGENT_INFO_BOB="$GPG_AGENT_INFO"
function become_alice() { function become_alice() {
@@ -108,8 +127,8 @@ function become_alice() {
} }
function become_bob() { function become_bob() {
export GNUPGHOME="$fake_alice_home" export GNUPGHOME="$fake_bob_home"
export GPG_AGENT_INFO="$GPG_AGENT_INFO_ALICE" export GPG_AGENT_INFO="$GPG_AGENT_INFO_BOB"
git config --global user.name "Bob Example" git config --global user.name "Bob Example"
git config --global user.email bob@example.com git config --global user.email bob@example.com
} }
@@ -195,6 +214,7 @@ PHASE 'She enrolls secrets.txt.'
blackbox_register_new_file secret.txt blackbox_register_new_file secret.txt
assert_file_missing secret.txt assert_file_missing secret.txt
assert_file_exists secret.txt.gpg assert_file_exists secret.txt.gpg
assert_line_exists 'secret.txt' .gitignore
PHASE 'She decrypts secrets.txt.' PHASE 'She decrypts secrets.txt.'
blackbox_edit_start secret.txt blackbox_edit_start secret.txt
@@ -217,12 +237,14 @@ PHASE 'Bob makes sure he has all new keys.'
gpg --import keyrings/live/pubring.gpg gpg --import keyrings/live/pubring.gpg
# Pick a GID to use: # Pick a GID to use:
# This users's default group:
DEFAULT_GID_NAME=$(id -gn)
# Pick a group that is not the default group:
TEST_GID_NUM=$(id -G | fmt -1 | tail -n +2 | grep -xv $(id -u) | head -n 1) TEST_GID_NUM=$(id -G | fmt -1 | tail -n +2 | grep -xv $(id -u) | head -n 1)
TEST_GID_NAME=$(getent group "$TEST_GID_NUM" | cut -d: -f1) TEST_GID_NAME=$(python -c 'import grp; print grp.getgrgid('"$TEST_GID_NUM"').gr_name')
DEFAULT_GID_NAME=$(getent group $(id -u) | cut -d: -f1) echo DEFAULT_GID_NAME=$DEFAULT_GID_NAME
echo TEST_GID_NUM=$TEST_GID_NUM echo TEST_GID_NUM=$TEST_GID_NUM
echo TEST_GID_NAME=$TEST_GID_NAME echo TEST_GID_NAME=$TEST_GID_NAME
echo DEFAULT_GID_NAME=$DEFAULT_GID_NAME
PHASE 'Bob postdeploys... default.' PHASE 'Bob postdeploys... default.'
blackbox_postdeploy blackbox_postdeploy
@@ -276,6 +298,7 @@ blackbox_register_new_file mistake.txt
assert_file_missing mistake.txt assert_file_missing mistake.txt
assert_file_exists mistake.txt.gpg assert_file_exists mistake.txt.gpg
# NOTE: It is still in the history. That should be corrected someday. # NOTE: It is still in the history. That should be corrected someday.
assert_line_exists 'mistake.txt' .gitignore
PHASE 'Bob enrolls my/path/to/relsecrets.txt.' PHASE 'Bob enrolls my/path/to/relsecrets.txt.'
mkdir my my/path my/path/to mkdir my my/path my/path/to
@@ -284,6 +307,9 @@ cd my/path/to
blackbox_register_new_file relsecrets.txt blackbox_register_new_file relsecrets.txt
assert_file_missing relsecrets.txt assert_file_missing relsecrets.txt
assert_file_exists relsecrets.txt.gpg assert_file_exists relsecrets.txt.gpg
assert_file_missing .gitignore
assert_file_exists ../../../.gitignore
assert_line_exists 'my/path/to/relsecrets.txt' ../../../.gitignore
PHASE 'Bob decrypts relsecrets.txt.' PHASE 'Bob decrypts relsecrets.txt.'
cd .. cd ..
@@ -314,6 +340,13 @@ assert_file_missing 'stars*bars?.txt'
assert_file_exists 'stars*bars?.txt'.gpg assert_file_exists 'stars*bars?.txt'.gpg
assert_line_exists 'stars\*bars\?.txt' .gitignore assert_line_exists 'stars\*bars\?.txt' .gitignore
PHASE 'Bob enrolls stars bars.txt'
echo A very commented file >'stars bars.txt'
blackbox_register_new_file 'stars bars.txt'
assert_file_missing 'stars bars.txt'
assert_file_exists 'stars bars.txt'.gpg
assert_line_exists 'stars bars.txt' .gitignore
# TODO(tlim): Add test to make sure that now alice can NOT decrypt. # TODO(tlim): Add test to make sure that now alice can NOT decrypt.
# #
@@ -327,5 +360,5 @@ fi
find .git?* * -type f -ls find .git?* * -type f -ls
echo cd "$test_repository" echo cd "$test_repository"
echo rm "$test_repository" echo rm -rf "$test_repository"
echo DONE. echo DONE.

View File

@@ -0,0 +1,67 @@
#!/usr/bin/env bash
# Turn the Portfile.template into a Portfile.
# Usage:
# mk_portfile.sh TEMPLATE OUTPUTFILE VERSION
set -e
blackbox_home=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source ${blackbox_home}/../bin/_stack_lib.sh
TEMPLATEFILE=tools/Portfile.template
OUTPUTFILE=Portfile
PORTVERSION=${1?"Arg 1 must be a version number like 1.20150222 (with no v)"} ; shift
# Add the version number to the template.
sed <"$TEMPLATEFILE" >"$OUTPUTFILE" -e 's/@@VERSION@@/'"$PORTVERSION"'/g'
# Test it. Record the failure in $checksumout
fgrep >/dev/null -x 'file:///var/tmp/ports' /opt/local/etc/macports/sources.conf || sudo sed -i -e '1s@^@file:///var/tmp/ports\'$'\n@' /opt/local/etc/macports/sources.conf
rm -rf /var/tmp/ports
mkdir -p /var/tmp/ports/security/vcs_blackbox
cp Portfile /var/tmp/ports/security/vcs_blackbox
( cd /var/tmp/ports && sudo portindex )
make_self_deleting_tempfile checksumout
set +e
sudo port -v checksum vcs_blackbox > "$checksumout" 2>/dev/null
ret=$?
# If it failed, grab the checksums. Then re-process the template with them.
if [[ $ret != 0 ]]; then
RMD160=$(awk <"$checksumout" '/^Distfile checksum: .*rmd160/ { print $NF }')
SHA256=$(awk <"$checksumout" '/^Distfile checksum: .*sha256/ { print $NF }')
echo RMD160=$RMD160
echo SHA256=$SHA256
echo
if [[ $RMD160 != '' && $SHA256 != '' ]]; then
sed <"$TEMPLATEFILE" >"$OUTPUTFILE" -e 's/@@VERSION@@/'"$PORTVERSION"'/g' -e 's/@@RMD160@@/'"$RMD160"'/g' -e 's/@@SHA256@@/'"$SHA256"'/g'
cp Portfile /var/tmp/ports/security/vcs_blackbox
( cd /var/tmp/ports && sudo portindex )
sudo port -v checksum vcs_blackbox
fi
fi
# Generate the diff
cp /opt/local/var/macports/sources/rsync.macports.org/release/tarballs/ports/security/vcs_blackbox/Portfile /var/tmp/ports/security/vcs_blackbox/Portfile.orig
( cd /var/tmp/ports/security/vcs_blackbox && diff -u Portfile.orig Portfile ) > Portfile-vcs_blackbox.diff
open -R Portfile-vcs_blackbox.diff
echo
echo 'portfile is in:'
echo ' /var/tmp/ports/security/vcs_blackbox/Portfile'
echo 'cleanup:'
echo ' sudo vi /opt/local/etc/macports/sources.conf'
echo "
PLEASE OPEN A TICKET WITH THIS INFORMATION:
https://trac.macports.org/newticket
Summary: vcs_blackbox @$PORTVERSION Update to latest upstream
Description:
New upstream of vcs_blackbox.
github.setup and checksums updated.
Type: update
Component: ports
Port: vcs_blackbox
Keywords: maintainer
"
echo 'Attach: Portfile-vcs_blackbox.diff'

76
tools/mk_deb_fpmdir Executable file
View File

@@ -0,0 +1,76 @@
#! /usr/bin/env bash
# Use fpm to package up files into a DEB .
# Usage:
# mk_deb_fpmdir PACKAGENAME MANIFEST1 MANIFEST2 ...
# Example:
# Make a package foopkg manifest.txt
# Where "manifest.txt" contains:
# exec /usr/bin/stack_makefqdn misc/stack_makefqdn.py
# exec /usr/bin/bar bar/bar.sh
# read /usr/man/man1/bar.1 bar/bar.1.man
# 0444 /etc/foo.conf bar/foo.conf
set -e
# Parameters for this DEB:
PACKAGENAME=${1?"First arg must be the package name."}
shift
# Defaults that can be overridden:
# All packages are 1.0 unless otherwise specifed:
: ${PKGVERSION:=1.0} ;
# If there is no iteration setting, assume "1":
: ${PKGRELEASE:=1}
# If there is no epoch, assume 0
: ${PKGEPOCH:=0}
# The DEB is output here: (should be a place that can be wiped)
OUTPUTDIR="${HOME}/debbuild-$PACKAGENAME"
# The TeamCity templates expect to find the list of artifacts here:
DEB_BIN_LIST="${OUTPUTDIR}/bin-packages.txt"
# -- Now the real work can be done.
# Clean the output dir.
rm -rf "$OUTPUTDIR"
mkdir -p "$OUTPUTDIR/installroot"
# Copy the files into place:
set -o pipefail # Error out if any manifest is not found.
cat """$@""" | while read -a arr ; do
PERM="${arr[0]}"
case $PERM in
\#*) continue ;; # Skip comments.
exec) PERM=0755 ;;
read) PERM=0744 ;;
*) ;;
esac
DST="$OUTPUTDIR/installroot/${arr[1]}"
SRC="${arr[2]}"
if [[ $SRC == "cmd/"* || $SRC == *"/cmd/"* ]]; then
( cd $(dirname "$SRC" ) && go build -a -v )
fi
install -D -T -b -m "$PERM" -T "$SRC" "$DST"
done
# Build the DEB:
cd "$OUTPUTDIR" && fpm -s dir -t deb \
-a x86_64 \
-n "${PACKAGENAME}" \
--epoch "${PKGEPOCH}" \
--version "${PKGVERSION}" \
--iteration "${PKGRELEASE}" \
${PKGDESCRIPTION:+ --description="${PKGDESCRIPTION}"} \
${PKGVENDOR:+ --vendor="${PKGVENDOR}"} \
-C "$OUTPUTDIR/installroot" \
.
# TeamCity templates for DEBS expect to find
# the list of all packages created in bin-packages.txt.
# Generate that list:
find "$OUTPUTDIR" -maxdepth 1 -name '*.deb' >"$DEB_BIN_LIST"
# Output it for debugging purposes:
cat "$DEB_BIN_LIST"

View File

@@ -0,0 +1,14 @@
exec /usr/bin/_blackbox_common.sh ../bin/_blackbox_common.sh
exec /usr/bin/_stack_lib.sh ../bin/_stack_lib.sh
exec /usr/bin/blackbox_addadmin ../bin/blackbox_addadmin
exec /usr/bin/blackbox_cat ../bin/blackbox_cat
exec /usr/bin/blackbox_edit ../bin/blackbox_edit
exec /usr/bin/blackbox_edit_end ../bin/blackbox_edit_end
exec /usr/bin/blackbox_edit_start ../bin/blackbox_edit_start
exec /usr/bin/blackbox_initialize ../bin/blackbox_initialize
exec /usr/bin/blackbox_postdeploy ../bin/blackbox_postdeploy
exec /usr/bin/blackbox_register_new_file ../bin/blackbox_register_new_file
exec /usr/bin/blackbox_removeadmin ../bin/blackbox_removeadmin
exec /usr/bin/blackbox_shred_all_files ../bin/blackbox_shred_all_files
exec /usr/bin/blackbox_update_all_files ../bin/blackbox_update_all_files
exec /usr/bin/blackbox_list_files ../bin/blackbox_list_files

View File

@@ -11,3 +11,4 @@ exec bin/blackbox_register_new_file ../bin/blackbox_register_new_file
exec bin/blackbox_removeadmin ../bin/blackbox_removeadmin exec bin/blackbox_removeadmin ../bin/blackbox_removeadmin
exec bin/blackbox_shred_all_files ../bin/blackbox_shred_all_files exec bin/blackbox_shred_all_files ../bin/blackbox_shred_all_files
exec bin/blackbox_update_all_files ../bin/blackbox_update_all_files exec bin/blackbox_update_all_files ../bin/blackbox_update_all_files
exec bin/blackbox_list_files ../bin/blackbox_list_files

View File

@@ -24,6 +24,8 @@ shift
: ${PKGVERSION:=1.0} ; : ${PKGVERSION:=1.0} ;
# If there is no iteration setting, assume "1": # If there is no iteration setting, assume "1":
: ${PKGRELEASE:=1} : ${PKGRELEASE:=1}
# If there is no epoch, assume 0
: ${PKGEPOCH:=0}
# The RPM is output here: (should be a place that can be wiped) # The RPM is output here: (should be a place that can be wiped)
OUTPUTDIR="${HOME}/rpmbuild-$PACKAGENAME" OUTPUTDIR="${HOME}/rpmbuild-$PACKAGENAME"
@@ -37,6 +39,7 @@ rm -rf "$OUTPUTDIR"
mkdir -p "$OUTPUTDIR/installroot" mkdir -p "$OUTPUTDIR/installroot"
# Copy the files into place: # Copy the files into place:
set -o pipefail # Error out if any manifest is not found.
cat """$@""" | while read -a arr ; do cat """$@""" | while read -a arr ; do
PERM="${arr[0]}" PERM="${arr[0]}"
case $PERM in case $PERM in
@@ -56,12 +59,13 @@ done
# Build the RPM: # Build the RPM:
cd "$OUTPUTDIR" && fpm -s dir -t rpm \ cd "$OUTPUTDIR" && fpm -s dir -t rpm \
-a x86_64 \ -a x86_64 \
--epoch '0' \
-n "${PACKAGENAME}" \ -n "${PACKAGENAME}" \
--epoch "${PKGEPOCH}" \
--version "${PKGVERSION}" \ --version "${PKGVERSION}" \
--iteration "${PKGRELEASE}" \ --iteration "${PKGRELEASE}" \
${PKGDESCRIPTION:+ --description="${PKGDESCRIPTION}"} \
${PKGVENDOR:+ --vendor="${PKGVENDOR}"} \
-C "$OUTPUTDIR/installroot" \ -C "$OUTPUTDIR/installroot" \
--description="$PKGDESCRIPTION" \
. .
# TeamCity templates for RPMS expect to find # TeamCity templates for RPMS expect to find

View File

@@ -12,3 +12,4 @@ exec /usr/blackbox/bin/blackbox_register_new_file ../bin/blackbox_register_new_f
exec /usr/blackbox/bin/blackbox_removeadmin ../bin/blackbox_removeadmin exec /usr/blackbox/bin/blackbox_removeadmin ../bin/blackbox_removeadmin
exec /usr/blackbox/bin/blackbox_shred_all_files ../bin/blackbox_shred_all_files exec /usr/blackbox/bin/blackbox_shred_all_files ../bin/blackbox_shred_all_files
exec /usr/blackbox/bin/blackbox_update_all_files ../bin/blackbox_update_all_files exec /usr/blackbox/bin/blackbox_update_all_files ../bin/blackbox_update_all_files
exec /usr/blackbox/bin/blackbox_list_files ../bin/blackbox_list_files