initial import of pgp libs

This commit is contained in:
Dan Ballard 2016-05-27 08:03:42 -07:00
parent 4874bee930
commit aa8f8aff57
1 changed files with 23 additions and 3 deletions

View File

@ -2,18 +2,38 @@ package scans
import ( import (
"github.com/s-rah/onionscan/report" "github.com/s-rah/onionscan/report"
"golang.org/x/crypto/openpgp"
"log" "log"
"regexp" "regexp"
"strings"
) )
type PGPContentScan struct { type PGPContentScan struct {
} }
func (cs *PGPContentScan) ScanContent(content string, report *report.OnionScanReport) { func (cs *PGPContentScan) ScanContent(content string, report *report.OnionScanReport) {
log.Printf("\tScanning for PGP Key\n") log.Printf("Scanning for PGP Key\n")
pgpRegexp := regexp.MustCompile("-----BEGIN PGP PUBLIC KEY BLOCK-----((?s).*)-----END PGP PUBLIC KEY BLOCK-----") pgpRegexp := regexp.MustCompile("-----BEGIN PGP PUBLIC KEY BLOCK-----((?s).*)-----END PGP PUBLIC KEY BLOCK-----")
foundPGP := pgpRegexp.FindAllString(content, -1) foundPGP := pgpRegexp.FindAllString(content, -1)
for _, key := range foundPGP { for _, keyString := range foundPGP {
report.AddPGPKey(key) log.Printf("\tFound key: %s\n", keyString)
keys, err := openpgp.ReadArmoredKeyRing(strings.NewReader(keyString));
if err != nil {
log.Printf("ERROR: %s\n", err)
continue
}
if len(keys) != 1 || len(keys[0].Subkeys) != 1 {
log.Printf("ERROR: failed to accept key\n")
continue
}
for name, identity := range keys[0].Identities {
log.Printf("identity: %s,%s,%s\n", name, identity.Name, identity.UserId)
}
pubkey := keys[0].Subkeys[0].PublicKey
log.Printf("pubkey: %X", pubkey.Fingerprint)
report.AddPGPKey(keyString)
} }
} }