-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblacklist.go
59 lines (46 loc) · 971 Bytes
/
blacklist.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"bufio"
"io/ioutil"
"log"
"os"
"path/filepath"
"strings"
"golang.org/x/crypto/ssh"
)
const blacklistPath = "blacklist"
var blacklist = make(map[string]bool)
func loadBlacklistedKeys() {
files, err := ioutil.ReadDir(blacklistPath)
if err != nil {
log.Fatal(err)
}
for _, f := range files {
if f.IsDir() {
log.Fatalf("Subdirectories not supported in %q directory\n", blacklistPath)
}
file, err := os.Open(filepath.Join(blacklistPath, f.Name()))
if err != nil {
log.Fatal(err)
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
key := strings.TrimSpace(scanner.Text())
blacklist[key] = true
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
}
return
}
func markBlacklistedKeys(keys []*publicKey) {
for _, k := range keys {
key := strings.TrimSpace(string(ssh.MarshalAuthorizedKey(k.key)))
if blacklist[key] {
k.blacklisted = true
}
}
return
}