65 lines
1.7 KiB
Go
65 lines
1.7 KiB
Go
package scans
|
|
|
|
import (
|
|
"github.com/s-rah/onionscan/report"
|
|
"golang.org/x/crypto/openpgp"
|
|
"golang.org/x/crypto/openpgp/armor"
|
|
//pgpPacket "golang.org/x/crypto/openpgp/packet"
|
|
"log"
|
|
"regexp"
|
|
"strings"
|
|
"bytes"
|
|
)
|
|
|
|
type PGPContentScan struct {
|
|
}
|
|
|
|
func (cs *PGPContentScan) ScanContent(content string, report *report.OnionScanReport) {
|
|
log.Printf("Scanning for PGP Key\n")
|
|
pgpRegexp := regexp.MustCompile("-----BEGIN PGP PUBLIC KEY BLOCK-----((?s).*)-----END PGP PUBLIC KEY BLOCK-----")
|
|
foundPGP := pgpRegexp.FindAllString(content, -1)
|
|
for _, keyString := range foundPGP {
|
|
log.Printf("\tFound key: %s\n", keyString)
|
|
|
|
buf := bytes.NewBuffer([]byte(keyString))
|
|
block, err := armor.Decode(buf)
|
|
if err != nil {
|
|
log.Printf("error decoding: %s\n", err)
|
|
} else {
|
|
log.Printf("Block: %s\n", block)
|
|
log.Printf("body: %s\n", block.Body)
|
|
|
|
|
|
//packet, err := pgpPacket.Read(block.Body)
|
|
/*if err != nil {
|
|
log.Printf("Read error: %s", err)
|
|
}*/
|
|
/*pk, ok := packet.(*pgpPacket.PublicKeyV3)
|
|
if !ok {
|
|
log.Printf("failed to parse, got: %s", packet)
|
|
}*/
|
|
//log.Printf("fingerprint: %s\n", pk.Fingerprint)
|
|
}
|
|
|
|
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)
|
|
//pk3 := pubkey.(*pgpPacket.PublicKeyV3)
|
|
|
|
report.AddPGPKey(keyString)
|
|
}
|
|
}
|