|
7 | 7 | (defn git/slurp [& args] (sh/exec-slurp "git" "-C" (dyn :repo-path) ;args))
|
8 | 8 | (defn git/slurp-all [& args] (sh/exec-slurp-all "git" "-C" (dyn :repo-path) ;args))
|
9 | 9 |
|
10 |
| -# TODO |
11 |
| -# pre-receive hook |
12 |
| - |
13 | 10 | (defn is-in-dir [child parent]
|
14 | 11 | (not (deep= (first (path/parts (path/relpath parent child))) "..")))
|
15 | 12 |
|
|
41 | 38 |
|
42 | 39 | (defn git-dir [&opt repo]
|
43 | 40 | (default repo (dyn :repo-path))
|
44 |
| - (def opts @[]) |
45 |
| - (if repo (array/concat opts ["-C" repo])) |
46 | 41 | (if (dyn :git-dir)
|
47 | 42 | (dyn :git-dir)
|
48 |
| - (let [git-dir (path/join repo (sh/exec-slurp "git" ;opts "rev-parse" "--git-dir"))] |
| 43 | + (let [git-dir (path/join repo (sh/exec-slurp "git" "-C" repo "rev-parse" "--git-dir"))] |
49 | 44 | (setdyn :git-dir git-dir)
|
50 | 45 | git-dir)))
|
51 | 46 |
|
52 |
| -(defn repo-top-level [&opt repo] |
53 |
| - (default repo (dyn :repo-path)) |
54 |
| - (def opts @[]) |
55 |
| - (if repo (array/concat opts ["-C" repo])) |
56 |
| - (if (dyn :repo-top-level) |
57 |
| - (dyn :repo-top-level) |
58 |
| - (let [repo-top-level (sh/exec-slurp "git" ;opts "rev-parse" "--show-toplevel")] |
59 |
| - (setdyn :repo-top-level repo-top-level) |
60 |
| - repo-top-level))) |
61 |
| - |
62 |
| -(defn allowed-signers-absolute-path [&opt repo] |
63 |
| - (default repo (dyn :repo-path)) |
64 |
| - (def opts @[]) |
65 |
| - (if repo (array/concat opts ["-C" repo])) |
66 |
| - (if (dyn :allowed-signers-absolute-path) |
67 |
| - (dyn :allowed-signers-absolute-path) |
68 |
| - (try |
69 |
| - (let [allowed-signers-absolute-path (sh/exec-slurp "git" ;opts "config" "--local" "skm.allowedSignersFile")] |
70 |
| - (let [stat (os/stat allowed-signers-absolute-path)] |
71 |
| - (if (or (not stat) (not= (stat :mode) :file)) |
72 |
| - (error "allowedSignersFile does not exist or is not a file"))) |
73 |
| - (setdyn :allowed-signers-absolute-path allowed-signers-absolute-path)) |
74 |
| - ([err] |
75 |
| - (do |
76 |
| - (setdyn :allowed-signers-absolute-path (path/join (repo-top-level) ".allowed_signers")) |
77 |
| - (sh/exec-slurp "git" ;opts "config" "--local" "skm.allowedSignersFile" (dyn :allowed-signers-absolute-path))))))) |
78 |
| - |
79 | 47 | (defn allowed-signers-relative-path [&opt repo]
|
80 | 48 | (default repo (dyn :repo-path))
|
81 | 49 | (if (dyn :allowed-signers-relative-path)
|
82 | 50 | (dyn :allowed-signers-relative-path)
|
83 |
| - (path/relpath (repo-top-level repo) (allowed-signers-absolute-path repo)))) |
| 51 | + (let [result (sh/exec-slurp-all "git" "-C" repo "config" "--local" "skm.allowedSignersFile")] |
| 52 | + (if (and (= (result :status) 0) |
| 53 | + (result :out) |
| 54 | + (not= (result :out) "")) |
| 55 | + (setdyn :allowed-signers-relative-path (result :out)) |
| 56 | + (setdyn :allowed-signers-relative-path ".allowed_signers"))))) |
84 | 57 |
|
85 | 58 | (defn trust
|
86 | 59 | "set trust anchor"
|
|
141 | 114 | "generate the allowed_signers file using a previously set trust anchor"
|
142 | 115 | [commit]
|
143 | 116 | (check-allowed-signers)
|
144 |
| - (def allowed-signers-absolute-path (allowed-signers-absolute-path)) |
145 |
| - (var last-verified-commit (git/slurp "config" "skm.last-verified-commit")) |
| 117 | + (var last-verified-commit "") |
| 118 | + (try |
| 119 | + (set last-verified-commit (git/slurp "config" "skm.last-verified-commit")) |
| 120 | + ([err] (error (string "could not get trust anchor: " err)))) |
146 | 121 | (if (or (not last-verified-commit) (= last-verified-commit "")) (error "No last verified commit set"))
|
147 |
| - (def all_commits (string/split "\n" (git/slurp "log" "--pretty=format:%H" (allowed-signers-relative-path)))) |
| 122 | + (def all_commits (string/split "\n" (git/slurp "rev-list" commit "--" (allowed-signers-relative-path)))) |
148 | 123 | (def commits-to-verify @[])
|
149 | 124 | (var found_commit false)
|
150 | 125 | (each commit all_commits
|
|
158 | 133 | (set last-verified-commit commit))
|
159 | 134 | (trust last-verified-commit)
|
160 | 135 | (def allowed-signers-cache-file (path/join (git-dir) "allowed_signers"))
|
161 |
| - (sh/copy-file allowed-signers-absolute-path allowed-signers-cache-file) |
| 136 | + (spit allowed-signers-cache-file (git/slurp "show" (string commit ":" (allowed-signers-relative-path)))) |
162 | 137 | (git/fail "config" "gpg.ssh.allowedSignersFile" allowed-signers-cache-file)
|
163 | 138 | (print "allowed_signers was verified and copied into git_dir"))
|
164 | 139 |
|
165 | 140 | (defn verify-commit
|
166 | 141 | [commit]
|
167 |
| - (def allowed-signers-cache-file (path/join (git-dir) "allowed_signers")) |
168 |
| - (unless (deep= (slurp allowed-signers-cache-file) (slurp (allowed-signers-absolute-path))) |
169 |
| - (generate-allowed-signers (git/slurp "rev-parse" commit))) |
| 142 | + (generate-allowed-signers (git/slurp "rev-parse" commit)) |
170 | 143 | (git/loud "verify-commit" commit))
|
0 commit comments