forked from s-rah/onionscan
/
pgp_content_scan.go
43 lines (36 loc) · 1.45 KB
/
pgp_content_scan.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
package deanonymization
import (
"github.com/s-rah/onionscan/config"
"github.com/s-rah/onionscan/report"
"golang.org/x/crypto/openpgp"
"regexp"
"strings"
)
// PGPContentScan extracts any PGP public key blobs that may exist in the current
// scan.
func PGPContentScan(osreport *report.OnionScanReport, anonreport *report.AnonymityReport, osc *config.OnionScanConfig) {
pgpRegexp := regexp.MustCompile("-----BEGIN PGP PUBLIC KEY BLOCK-----((?s).*)-----END PGP PUBLIC KEY BLOCK-----")
for _, id := range osreport.Crawls {
crawlRecord, _ := osc.Database.GetCrawlRecord(id)
if strings.Contains(crawlRecord.Page.Headers.Get("Content-Type"), "text/html") {
foundPGP := pgpRegexp.FindAllString(crawlRecord.Page.Snapshot, -1)
for _, keyString := range foundPGP {
keys, err := openpgp.ReadArmoredKeyRing(strings.NewReader(keyString))
if err != nil {
continue
}
if len(keys) < 1 || len(keys[0].Subkeys) < 1 || len(keys[0].Identities) < 1 {
continue
}
var identity string
for identity = range keys[0].Identities {
anonreport.EmailAddresses = append(anonreport.EmailAddresses, identity)
osc.Database.InsertRelationship(osreport.HiddenService, "pgp", "email-address", identity)
break
}
osreport.AddPGPKey(keyString, identity, keys[0].Subkeys[0].PublicKey.KeyIdShortString())
osc.Database.InsertRelationship(osreport.HiddenService, "pgp", "identity", keys[0].Subkeys[0].PublicKey.KeyIdShortString())
}
}
}
}