Browse Source

Initial commit of first working version.

master
Chris McCormick 8 years ago
commit
6d78861634
6 changed files with 242 additions and 0 deletions
  1. 71
    0
      README.md
  2. 6
    0
      config
  3. 3
    0
      git-proxy-command
  4. 3
    0
      git-ssh-wrap
  5. 121
    0
      gitnonymous
  6. 38
    0
      gitnonymous-setup

+ 71
- 0
README.md View File

@@ -0,0 +1,71 @@
1
+Contribute anonymously to Git repositories over Tor.
2
+
3
+## tl;dr ##
4
+
5
+	yourname@yourbox:~$ . gitnonymous somename
6
+	somename⚔ yourname@yourbox:~$ git commit_
7
+
8
+## Setup ##
9
+
10
+Before you start, you'll probably want to:
11
+
12
+ * Set up an anonymous email account with some provider.
13
+ * Sign up to the Git hosting service you use with that anonymous email address.
14
+
15
+To configure a new anonymous identity on your machine:
16
+
17
+	$ ./gitnonymous-setup KEYNAME
18
+
19
+Where `KEYNAME` is some memorable string that you will use to identify your anonymous ID like `baby-protector` or `elite-freedom-defender`. You can create multiple anonymous identities.
20
+
21
+Be aware that `KEYNAME` is stored in the SSH public key's comment field so don't make it personally identifiable.
22
+
23
+Then you should edit the new file in `~/.gitnonymous-KEYNAME/config` to set the email address and name of your anonymous identity:
24
+
25
+	export GIT_COMMITTER_NAME="Baby Protector"
26
+	export GIT_COMMITTER_EMAIL="protect-all-babies@anonymous-mail-provider.com"
27
+	export GIT_AUTHOR_NAME="Baby Protector"
28
+	export GIT_AUTHOR_EMAIL="protect-all-babies@anonymous-mail-provider.com"
29
+
30
+## Use ##
31
+
32
+You can symlink the `gitnonymous` and `gitnonymous-setup` commands into your `~/bin` folder or somewhere else on your `PATH` to execute them without typing the full path.
33
+
34
+Each time you want make anonymous commits in the current shell:
35
+
36
+	$ . gitnonymous KEYNAME
37
+
38
+After that when you commit and push you will do so with the anonymous identity you have created, over the tor network, using the new SSH key that was created.
39
+
40
+This command:
41
+
42
+ * Spawns an `ssh-agent` that is limited to the current shell.
43
+ * Adds the anonymous SSH key to `ssh-agent`.
44
+ * Sets the `GIT_COMMITTER` and `GIT_AUTHOR` environment variables.
45
+ * Sets the `GIT_SSH` environment variable to point at a configured `git-ssh-wrap` script.
46
+ * Sets the `GIT_PROXY_COMMAND` environment variable to proxy network requests through tor.
47
+
48
+Your prompt will be updated to reflect the configured environment:
49
+
50
+	KEYNAME⚔ yourname@yourbox:~$
51
+
52
+To deactivate the gitnonymous environment run the same command again:
53
+
54
+	KEYNAME⚔ yourname@yourbox:~$ . gitnonymous KEYNAME
55
+	yourname@yourbox:~$ _
56
+
57
+Or just exit the current shell.
58
+
59
+## Dependencies ##
60
+
61
+ * `git`
62
+ * `tor` (install `tor` package)
63
+ * `nc` (install `netcat-openbsd` package)
64
+ * `ssh`
65
+ * `bash`
66
+
67
+## Tested ##
68
+
69
+ * With `git` 1.9.1 on Xubuntu 14.04.
70
+
71
+Patches welcome!

+ 6
- 0
config View File

@@ -0,0 +1,6 @@
1
+#!/usr/bin/env bash
2
+
3
+export GIT_COMMITTER_NAME="YOUR NAME"
4
+export GIT_COMMITTER_EMAIL="your.email@your-anonymous-provider.com"
5
+export GIT_AUTHOR_NAME="YOUR NAME"
6
+export GIT_AUTHOR_EMAIL="your.email@your-anonymous-provider.com"

+ 3
- 0
git-proxy-command View File

@@ -0,0 +1,3 @@
1
+#!/usr/bin/env sh
2
+
3
+nc -X 5 -x 127.0.0.1:9050 $*

+ 3
- 0
git-ssh-wrap View File

@@ -0,0 +1,3 @@
1
+#!/usr/bin/env sh
2
+
3
+ssh -i "${HOME}/.gitnonymous-KEYNAME/ssh/id_rsa" -o ProxyCommand="nc -X 5 -x localhost:9050 %h %p" $@

+ 121
- 0
gitnonymous View File

@@ -0,0 +1,121 @@
1
+#!/usr/bin/env bash
2
+
3
+# See the README for instructions setting up.
4
+# ./make-anonymous-key KEYNAME
5
+
6
+# figure out which directory we are stored in
7
+# https://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in
8
+_GITNONYMOUS_SRC="${BASH_SOURCE[0]}"
9
+# resolve $_GITNONYMOUS_SRC until the file is no longer a symlink
10
+while [ -h "$_GITNONYMOUS_SRC" ]; do
11
+  dir="$( cd -P "$( dirname "$_GITNONYMOUS_SRC" )" && pwd )"
12
+  _GITNONYMOUS_SRC="$(readlink "$_GITNONYMOUS_SRC")"
13
+  # if $_GITNONYMOUS_SRC was a relative symlink, we need to resolve it
14
+  # relative to the path where the symlink file was located
15
+  [[ $_GITNONYMOUS_SRC != /* ]] && _GITNONYMOUS_SRC="$DIR/$_GITNONYMOUS_SRC"
16
+done
17
+dir="$( cd -P "$( dirname "$_GITNONYMOUS_SRC" )" && pwd )"
18
+unset _GITNONYMOUS_SRC
19
+
20
+gitnonymous_usage () {
21
+  if [ "$1" != "" ]
22
+  then
23
+    gitnonymous_error "Don't call this script directly. 'Source' it instead."
24
+  fi
25
+  echo "Usage:"
26
+  echo ". ${BASH_SOURCE[0]} KEYNAME"
27
+}
28
+
29
+# function to throw error messages
30
+gitnonymous_error () {
31
+  >&2 echo $@
32
+}
33
+
34
+# when we are missing a config file call this
35
+gitnonymous_error_missing () {
36
+  gitnonymous_error $@
37
+  gitnonymous_error "To create it run: ${dir}/gitnonymous-setup ${keyname}"
38
+}
39
+
40
+# Make sure we were called with 'source' instead of directly
41
+if [[ "${BASH_SOURCE[0]}" != "$0" ]]
42
+then
43
+  # check for the keyname parameter
44
+  if [ "$1" = "" ]
45
+  then
46
+    gitnonymous_usage
47
+    return 1
48
+  else
49
+    # set the key and the config file
50
+    keyname="${1}"
51
+    rootdir="${HOME}/.gitnonymous-${keyname}"
52
+    configfile="${rootdir}/config"
53
+    sshdir="${rootdir}/ssh"
54
+    oldenvfile="${rootdir}/previous-environment"
55
+    
56
+    if [ "$_GITNONYMOUS" != "" ]
57
+    # toggle everything off again
58
+    then
59
+      echo "Unsetting gitnonymous environment ${keyname}"
60
+      # kill our special ssh agent
61
+      ssh-agent -k
62
+      # restore the command prompt
63
+      export PS1="${_GITNONYMOUS_OLDPS1}"
64
+      unset GIT_COMMITTER_EMAIL
65
+      unset GIT_COMMITTER_NAME
66
+      unset GIT_AUTHOR_EMAIL
67
+      unset GIT_AUTHOR_NAME
68
+      unset GIT_SSH
69
+      unset GIT_PROXY_COMMAND
70
+      unset ALL_PROXY
71
+      # restore any GIT_ environment variables set before
72
+      . "${oldenvfile}"
73
+      # unset our environment variables we set
74
+      unset _GITNONYMOUS_OLDPS1
75
+      unset _GITNONYMOUS
76
+      echo "Done unsetting ${keyname}."
77
+    else
78
+      # add our custom local SSH key (make the key with ./make-anonymous-key)
79
+      if [ -f ${sshdir}/id_rsa ]
80
+      then
81
+        # start a new SSH agent just for this session
82
+        eval $(ssh-agent -a "${sshdir}/.ssh-agent")
83
+        # add the key
84
+        ssh-add ${sshdir}/id_rsa
85
+      else
86
+        gitnonymous_error_missing "SSH config in ${sshdir} not found!"
87
+        return 3
88
+      fi
89
+      
90
+      # load the user's anonymous GIT settings and environment
91
+      if [ -f "${configfile}" ]
92
+      then
93
+        # save the old GIT values
94
+        export | grep -E "GIT_|ALL_PROXY" > ${oldenvfile}
95
+        # source the config file
96
+        .  "${configfile}"
97
+      else
98
+        gitnonymous_error_missing "GIT config in ${configfile} not found!"
99
+        return 4
100
+      fi
101
+      
102
+      # trap exit of this shell and kill ssh-agent
103
+      trap 'ssh-agent -k' EXIT
104
+      
105
+      # tell GIT to use our customised anonymous SSH wrapper
106
+      export GIT_SSH="${rootdir}/git-ssh-wrap"
107
+      
108
+      # tell GIT to use the tor proxy for all other traffic
109
+      export GIT_PROXY_COMMAND="${dir}/git-proxy-command"
110
+      export ALL_PROXY="socks5://127.0.0.1:9050"
111
+      
112
+      # make it obvious we're in a special environment
113
+      _GITNONYMOUS_OLDPS1="${PS1}"
114
+      export PS1="${keyname}⚔ ${PS1}"
115
+      export _GITNONYMOUS="${keyname}"
116
+    fi
117
+  fi
118
+else
119
+  gitnonymous_usage true
120
+  exit 2
121
+fi

+ 38
- 0
gitnonymous-setup View File

@@ -0,0 +1,38 @@
1
+#!/usr/bin/env bash
2
+
3
+# figure out which directory we are stored in
4
+# https://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in
5
+_GITNONYMOUS_SRC="${BASH_SOURCE[0]}"
6
+# resolve $_GITNONYMOUS_SRC until the file is no longer a symlink
7
+while [ -h "$_GITNONYMOUS_SRC" ]; do
8
+  dir="$( cd -P "$( dirname "$_GITNONYMOUS_SRC" )" && pwd )"
9
+  _GITNONYMOUS_SRC="$(readlink "$_GITNONYMOUS_SRC")"
10
+  # if $_GITNONYMOUS_SRC was a relative symlink, we need to resolve it
11
+  # relative to the path where the symlink file was located
12
+  [[ $_GITNONYMOUS_SRC != /* ]] && _GITNONYMOUS_SRC="$DIR/$_GITNONYMOUS_SRC"
13
+done
14
+dir="$( cd -P "$( dirname "$_GITNONYMOUS_SRC" )" && pwd )"
15
+unset _GITNONYMOUS_SRC
16
+
17
+# set up our other variables
18
+confdir="${HOME}/.gitnonymous-${1}"
19
+sshfile="${confdir}/ssh/id_rsa"
20
+configfile="${confdir}/config"
21
+sshwrapperfile="${confdir}/git-ssh-wrap"
22
+
23
+if [ "$1" = "" ]
24
+then
25
+  echo "Usage: $0 KEYNAME"
26
+else
27
+  comment="${1}@anonymous"
28
+  echo "-> Creating ${confdir}."
29
+  mkdir -p "${confdir}/ssh"
30
+  echo "-> Creating SSH key '${sshfile}'."
31
+  echo "SSH key comment (public) is '${comment}'."
32
+  ssh-keygen -C "${comment}" -f "${sshfile}"
33
+  echo "-> Creating SSH wrapper '${sshwrapperfile}'."
34
+  cat "${dir}/git-ssh-wrap" | sed "s/KEYNAME/${1}/" > "${sshwrapperfile}"
35
+  chmod 755 "${sshwrapperfile}"
36
+  echo "-> Creating config file '${configfile}'."
37
+  cp ${dir}/config "${configfile}"
38
+fi

Loading…
Cancel
Save