Skip to content

Commit c366d94

Browse files
committed
wip the sandbox script is read from HEAD:.hooks/pre-receive.js
1 parent 7220b29 commit c366d94

File tree

12 files changed

+113
-41
lines changed

12 files changed

+113
-41
lines changed

demo.git/index

119 Bytes
Binary file not shown.

demo.git/logs/HEAD

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
0000000000000000000000000000000000000000 71c666705d861b556d73f2badddaca0cfcf5e930 William Hilton <[email protected]> 1574741587 -0500 commit (initial): Initial commit
22
0000000000000000000000000000000000000000 b1f9a9a2689e95d8aaf9d2ed5513fe78f4c53901 William Hilton <[email protected]> 1575084779 -0500 commit (initial): Initial commit
3+
b1f9a9a2689e95d8aaf9d2ed5513fe78f4c53901 d76ea2f1501e44ac5c29a091e17903b6a33fc57f William Hilton <[email protected]> 1575685262 -0500 commit: add pre-receive hook
4+
d76ea2f1501e44ac5c29a091e17903b6a33fc57f ee27a42768a70831127fca08ccc9df7b13f0f81e William Hilton <[email protected]> 1575686304 -0500 commit (amend): add pre-receive hook
5+
ee27a42768a70831127fca08ccc9df7b13f0f81e 59eabecab1988d343a2cc8c054a56d5e6cb3bd89 William Hilton <[email protected]> 1575686347 -0500 commit (amend): add pre-receive hook

demo.git/logs/refs/heads/master

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
0000000000000000000000000000000000000000 71c666705d861b556d73f2badddaca0cfcf5e930 William Hilton <[email protected]> 1574741587 -0500 commit (initial): Initial commit
22
0000000000000000000000000000000000000000 b1f9a9a2689e95d8aaf9d2ed5513fe78f4c53901 William Hilton <[email protected]> 1575084779 -0500 commit (initial): Initial commit
3+
b1f9a9a2689e95d8aaf9d2ed5513fe78f4c53901 d76ea2f1501e44ac5c29a091e17903b6a33fc57f William Hilton <[email protected]> 1575685262 -0500 commit: add pre-receive hook
4+
d76ea2f1501e44ac5c29a091e17903b6a33fc57f ee27a42768a70831127fca08ccc9df7b13f0f81e William Hilton <[email protected]> 1575686304 -0500 commit (amend): add pre-receive hook
5+
ee27a42768a70831127fca08ccc9df7b13f0f81e 59eabecab1988d343a2cc8c054a56d5e6cb3bd89 William Hilton <[email protected]> 1575686347 -0500 commit (amend): add pre-receive hook
Binary file not shown.
Binary file not shown.

demo.git/packed-refs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# pack-refs with: peeled fully-peeled sorted
2+
59eabecab1988d343a2cc8c054a56d5e6cb3bd89 refs/heads/master

demo.git/refs/heads/master

Lines changed: 0 additions & 1 deletion
This file was deleted.

demo/.hooks/pre-receive.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
(async () => {
2+
function abbr (oid) {
3+
return oid.slice(0, 7)
4+
}
5+
6+
// Verify objects (ideally we'd do this _before_ moving it into the repo... but I think we'd need a custom 'fs' implementation with overlays)
7+
console.log('\nVerifying objects...\n')
8+
let i = 0
9+
10+
for (const oid of oids) {
11+
i++
12+
console.log(`\rVerifying object ${i}/${oids.length}`)
13+
const { type, object } = await git.readObject({ oid })
14+
if (type === 'commit' || type === 'tag') {
15+
const email = type === 'commit' ? object.author.email : object.tagger.email
16+
console.log(`\nVerifying ${type} ${abbr(oid)} by ${email}: `)
17+
let keys
18+
try {
19+
keys = await pgp.lookup(email)
20+
} catch (e) {
21+
console.log(`no keys found 👎\n`)
22+
console.error(`\nSignature verification failed for ${type} ${abbr(oid)}. Key lookup for ${email} threw an error.\n`)
23+
return
24+
}
25+
if (keys.length === 0) {
26+
console.log(`no keys found 👎\n`)
27+
console.error(`\nSignature verification failed for ${type} ${abbr(oid)}. No PGP keys could be found for ${email}.\n`)
28+
return
29+
}
30+
let ok = false
31+
for (const key of keys) {
32+
let result
33+
try {
34+
result = await git.verify({ ref: oid, publicKeys: key })
35+
} catch (e) {
36+
if (e.code && e.code === git.E.NoSignatureError) {
37+
console.log(`no signature 👎\n`)
38+
console.error(e.message + `
39+
40+
This server's policy is to only accept GPG-signed commits.
41+
Learn how you can create a GPG key and configure git to sign commits here:
42+
https://help.github.com/en/github/authenticating-to-github/managing-commit-signature-verification
43+
`)
44+
return
45+
} else {
46+
console.error(e.message + '\n' + e.stack)
47+
return
48+
}
49+
}
50+
if (result === false) {
51+
pgp.demote(email, key)
52+
} else {
53+
console.log(`signed with ${result[0]} 👍\n`)
54+
ok = true
55+
break
56+
}
57+
}
58+
if (!ok) {
59+
console.log(`no keys matched 👎\n`)
60+
console.error(`\nSignature verification failed for ${type} ${abbr(oid)}. It was not signed with a key publicly associated with the email address "${email}".
61+
62+
Learn how you can associate your GPG key with your email account using GitHub here:
63+
https://help.github.com/en/github/authenticating-to-github/adding-a-new-gpg-key-to-your-github-account
64+
`)
65+
return
66+
}
67+
}
68+
}
69+
70+
console.log(`\nVerification complete`)
71+
done()
72+
})()

http-server.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env node
2-
// Standalone server for use without karma!
32
var http = require('http')
43
var factory = require('./middleware')
54
var cors = require('./cors')
@@ -8,3 +7,5 @@ var config = {}
87

98
var server = http.createServer(cors(factory(config)))
109
server.listen(process.env.GIT_HTTP_MOCK_SERVER_PORT || 8174)
10+
11+
console.log(require('./logo.js'))

logo.js

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,3 @@
11
var figlet = require('figlet');
22

33
module.exports = figlet.textSync('GitServer', { font: 'Cyberlarge' })
4-
5-
if (!module.parent) {
6-
console.log(module.exports)
7-
}
8-
9-
console.log(`
10-
@@@@@@@@@@@@@@@@@@
11-
@@@ @@@
12-
@@ @@ @@
13-
@@ @@ @@
14-
@@@@@@@@@@ @@ @@ @@@@@@@@@
15-
@@ @@@ @@ @@ @@
16-
@@ @@ @@ @@ @@
17-
@@ @@@ @@ @@ @@
18-
@@@@@@@@ @@ @@ @@
19-
@@ @@ @@ @@
20-
@@@@@@@@@ @@ @@ @@
21-
@@ @@@ @@ @@ @@
22-
@@@ @@ @@ @@ @@@
23-
@@@@@@@@@ @@ @@ @@@@
24-
@@@ @@@
25-
@@@@@@@@@@@@@@@@@@
26-
27-
`)

0 commit comments

Comments
 (0)