2016-05-10 01:42:19 +00:00
|
|
|
package scans
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/s-rah/onionscan/report"
|
2016-05-27 15:03:42 +00:00
|
|
|
"golang.org/x/crypto/openpgp"
|
2016-05-10 01:42:19 +00:00
|
|
|
"regexp"
|
2016-05-27 15:03:42 +00:00
|
|
|
"strings"
|
2016-05-10 01:42:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type PGPContentScan struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cs *PGPContentScan) ScanContent(content string, report *report.OnionScanReport) {
|
2016-07-31 00:00:42 +00:00
|
|
|
//log.Printf("Scanning for PGP Key\n")
|
2016-05-10 01:42:19 +00:00
|
|
|
pgpRegexp := regexp.MustCompile("-----BEGIN PGP PUBLIC KEY BLOCK-----((?s).*)-----END PGP PUBLIC KEY BLOCK-----")
|
|
|
|
foundPGP := pgpRegexp.FindAllString(content, -1)
|
2016-05-27 15:03:42 +00:00
|
|
|
for _, keyString := range foundPGP {
|
|
|
|
keys, err := openpgp.ReadArmoredKeyRing(strings.NewReader(keyString))
|
|
|
|
if err != nil {
|
2016-07-31 00:00:42 +00:00
|
|
|
// log.Printf("ERROR: %s\n", err)
|
2016-05-27 15:03:42 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
if len(keys) < 1 || len(keys[0].Subkeys) < 1 || len(keys[0].Identities) < 1 {
|
2016-07-31 00:00:42 +00:00
|
|
|
// log.Printf("ERROR: failed to accept key\n")
|
2016-05-27 15:03:42 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
var identity string
|
|
|
|
for identity = range keys[0].Identities {
|
|
|
|
break
|
|
|
|
}
|
2016-07-31 00:00:42 +00:00
|
|
|
// log.Printf("\tFound PGP Key fingerprint: %s belonging to %s", keys[0].Subkeys[0].PublicKey.KeyIdShortString(), identity)
|
2016-05-27 15:03:42 +00:00
|
|
|
|
2016-06-06 02:52:56 +00:00
|
|
|
report.AddPGPKey(keyString, identity, keys[0].Subkeys[0].PublicKey.KeyIdShortString())
|
2016-05-10 01:42:19 +00:00
|
|
|
}
|
|
|
|
}
|