Skip to content

Commit 75f96c6

Browse files
author
Woody Gilk
committed
Merge branch 'master' of https://github.com/jaytaylor/git-encrypt into develop
2 parents af884a0 + f57dd8d commit 75f96c6

File tree

2 files changed

+155
-1
lines changed

2 files changed

+155
-1
lines changed

README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ by people much smarter than me, gitcrypt would not exist.
77
> There is [some controversy][4] over using this technique, so do your research
88
and understand the implications of using this tool before you go crazy with it.
99

10+
## Requirements
11+
Openssl must be installed and the binary must be available in your $PATH.
12+
1013
## Installation
1114

1215
Clone git-encrypt somewhere on your local machine:
@@ -20,7 +23,7 @@ The `gitcrypt` command must be executable:
2023

2124
And it must be accessible in your `$PATH`:
2225

23-
$ sudo ln -s gitcrypt /usr/bin/gitcrypt
26+
$ sudo ln -s gitcrypt /usr/local/bin/gitcrypt
2427

2528
## Configuration
2629

@@ -114,6 +117,32 @@ Once configuration is complete, reset and checkout all the files:
114117

115118
All the files in the are now decrypted and ready to be edited.
116119

120+
# Alternate method: git-encrypt-init.sh
121+
122+
Contributed by [Jay Taylor](https://jaytaylor.com "jaytaylor.com")
123+
124+
125+
The git-encrypt-init.sh shell script automatically performs all prepartion,
126+
setup and configuration for a local repository clone, prompting the user for
127+
any required information (salt and password phrases.) This method of also
128+
ensures that the git-encrypt scripts are automatically installed to
129+
`~/.gitencrypt/`. One drawback to this approach is that it only supports having
130+
1 password.
131+
132+
One reason to use this alternate approach is because it makes decrypting cloned
133+
repositories as simple as executing one script.
134+
135+
## Usage
136+
137+
Once you've cloned git-encrypt using the alternate script is straightforward:
138+
139+
$ cd /path/to/your/repository
140+
$ sh /path/to/git-encrypt/git-encrypt-init.sh
141+
142+
Then you can add the files you would like to have encrypted to the
143+
.gitattributes file contained in the root of your repository.
144+
145+
117146
# Conclusion
118147

119148
Enjoy your secure git repository! If you think gitcrypt is totally awesome,

git-encrypt-init.sh

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
#!/usr/bin/env bash
2+
3+
##
4+
# @author Jay Taylor [@jtaylor]
5+
#
6+
# @date 2012-04-09
7+
#
8+
# @description Initializes openssl encryption filter into the .git/config file
9+
# of a cloned git repository.
10+
#
11+
12+
13+
localGitConfigFile='.git/config'
14+
15+
16+
################################################################################
17+
18+
# Ensure that we are running in the root of a git repository.
19+
if ! [ -r "$localGitConfigFile" ]; then
20+
echo 'fatal: this script can only be run in the root of a git repository' 1>&2
21+
echo 'check your current directory (by running `pwd`), correct any issues you find, and then try again' 1>&2
22+
exit 1
23+
fi
24+
25+
26+
# Define filter scripts and other static executable/reference file contents.
27+
# NB: The semi-colons at the end of each line for the first 3 entries here are
28+
# due to the use of `eval` below.
29+
clean_filter_openssl='#!/usr/bin/env bash;
30+
;
31+
SALT_FIXED={{SALT}};
32+
#A1F1F8129C4FEBAB3513C174 # 24 or less hex characters;
33+
PASS_FIXED={{PASSWORD}};
34+
;
35+
openssl enc -base64 -aes-256-ecb -S $SALT_FIXED -k $PASS_FIXED'
36+
37+
smudge_filter_openssl='#!/usr/bin/env bash;
38+
;
39+
# No salt is needed for decryption.;
40+
PASS_FIXED={{PASSWORD}};
41+
;
42+
# If decryption fails, use `cat` instead.;
43+
# Error messages are redirected to /dev/null.;
44+
openssl enc -d -base64 -aes-256-ecb -k $PASS_FIXED 2> /dev/null || cat'
45+
46+
diff_filter_openssl='#!/usr/bin/env bash;
47+
;
48+
# No salt is needed for decryption.;
49+
PASS_FIXED={{PASSWORD}};
50+
;
51+
# Error messages are redirected to /dev/null.;
52+
openssl enc -d -base64 -aes-256-ecb -k $PASS_FIXED -in "$1" 2> /dev/null || cat "$1"'
53+
54+
gitattributes='*.md filter=openssl diff=openssl
55+
sensitive.txt filter=openssl diff=openssl
56+
[merge]
57+
renormalize = true'
58+
59+
gitconfig='[filter "openssl"]
60+
smudge = ~/.gitencrypt/smudge_filter_openssl
61+
clean = ~/.gitencrypt/clean_filter_openssl
62+
[diff "openssl"]
63+
textconv = ~/.gitencrypt/diff_filter_openssl'
64+
65+
66+
# Initialize .gitencrypt directory in the users $HOME if not already there.
67+
68+
if ! [ -d "$HOME/.gitencrypt" ]; then
69+
echo 'info: initializing ~/.gitencrypt'
70+
71+
# Prompt user for salt and password.
72+
while [ -z "$salt" ]; do
73+
echo 'Enter the salt phrase (16 hexadecimal characters):'
74+
read salt
75+
done
76+
77+
while [ -z "$password" ]; do
78+
echo 'Enter the encryption pass-phrase:'
79+
read password
80+
done
81+
82+
mkdir "$HOME/.gitencrypt"
83+
84+
for filter in clean_filter_openssl smudge_filter_openssl diff_filter_openssl; do
85+
echo "info: generating filter script '$filter'"
86+
filterScriptPath="$HOME/.gitencrypt/$filter"
87+
88+
# This ugliness is due to `eval` not handling newlines very nicely.
89+
# @see http://stackoverflow.com/a/3524860/293064 for more eval details.
90+
echo -e $(eval "echo \$$filter") | tr ';' '\n' | sed "s/{{SALT}}/$salt/g
91+
s/{{PASSWORD}}/$password/g
92+
s/^ *\(.*\) *$/\1/g" > "$filterScriptPath"
93+
94+
chmod a+x "$filterScriptPath"
95+
done
96+
fi
97+
98+
99+
# Initialize .gitattributes file if it doesn't exist.
100+
101+
if ! [ -e '.gitattributes' ]; then
102+
echo "info: initializing file '.gitattributes'"
103+
echo -n $gitattributes > .gitattributes
104+
fi
105+
106+
107+
# Initialize the .git/conf file for this repository clone if not already.
108+
109+
checkForPreExistingConf=$(grep '^\[\(filter\|diff\) "openssl"]$' "$localGitConfigFile")
110+
111+
if [ -n "$checkForPreExistingConf" ]; then
112+
echo 'info: openssl filter/diff already configured for this clone'
113+
else
114+
cat <<EOF >> "$localGitConfigFile"
115+
$gitconfig
116+
EOF
117+
echo 'info: openssl filter/diff successfuly applied to this clone'
118+
fi
119+
120+
121+
# Reset the HEAD to re-check out all of the files [with the encryption filters.]
122+
123+
echo 'info: re-checking out all of the files to ensure that the encryption filters are applied'
124+
git reset --hard HEAD
125+

0 commit comments

Comments
 (0)