Ejemplo n.º 1
0
func (w *Worker) lookupKeyidUuids(keyId string) (uuids []string, err error) {
	keyId = strings.ToLower(keyId)
	raw, err := hex.DecodeString(keyId)
	if err != nil {
		return nil, ErrInvalidKeyId
	}
	rKeyId := util.Reverse(keyId)
	var compareOp string
	switch len(raw) {
	case 4:
		compareOp = "LIKE $1 || '________________________________'"
	case 8:
		compareOp = "LIKE $1 || '________________________'"
	case 16:
		return []string{rKeyId}, nil
	case 20:
		return []string{rKeyId}, nil
	default:
		return nil, ErrInvalidKeyId
	}
	rows, err := w.db.Queryx(fmt.Sprintf(`
SELECT uuid FROM openpgp_pubkey WHERE uuid %s
UNION
SELECT pubkey_uuid FROM openpgp_subkey WHERE uuid %s`, compareOp, compareOp), rKeyId)
	if err == sql.ErrNoRows {
		return nil, ErrKeyNotFound
	} else if err != nil {
		return
	}
	return flattenUuidRows(rows)
}
Ejemplo n.º 2
0
func (pubkey *Pubkey) initV3() error {
	var buf bytes.Buffer
	err := pubkey.PublicKeyV3.Serialize(&buf)
	if err != nil {
		return err
	}
	fingerprint := FingerprintV3(pubkey.PublicKeyV3)
	bitLen, err := pubkey.PublicKeyV3.BitLength()
	if err != nil {
		return err
	}
	if pubkey.PublicKeyV3.IsSubkey {
		log.Println("Expected primary public key packet, got sub-key")
		return ErrInvalidPacketType
	}
	pubkey.RFingerprint = util.Reverse(fingerprint)
	pubkey.Creation = pubkey.PublicKeyV3.CreationTime
	pubkey.Expiration = NeverExpires
	if pubkey.PublicKeyV3.DaysToExpire > 0 {
		pubkey.Expiration = pubkey.Creation.Add(time.Duration(pubkey.PublicKeyV3.DaysToExpire) * time.Hour * 24)
	}
	pubkey.Algorithm = int(pubkey.PublicKeyV3.PubKeyAlgo)
	pubkey.BitLen = int(bitLen)
	return nil
}
Ejemplo n.º 3
0
func (pubkey *Pubkey) initUnsupported(op *packet.OpaquePacket) (err error) {
	pubkey.State = PacketStateUnsuppPubkey
	// Calculate opaque fingerprint on unsupported public key packet
	h := sha1.New()
	h.Write([]byte{0x99, byte(len(op.Contents) >> 8), byte(len(op.Contents))})
	h.Write(op.Contents)
	fpr := hex.EncodeToString(h.Sum(nil))
	pubkey.RFingerprint = util.Reverse(fpr)
	return
}
Ejemplo n.º 4
0
func (sig *Signature) initV3() (err error) {
	sig.Creation = sig.SignatureV3.CreationTime
	// V3 packets do not have an expiration time
	sig.Expiration = NeverExpires
	sig.SigType = int(sig.SignatureV3.SigType)
	// Extract the issuer key id
	var issuerKeyId [8]byte
	binary.BigEndian.PutUint64(issuerKeyId[:], sig.SignatureV3.IssuerKeyId)
	sigKeyId := hex.EncodeToString(issuerKeyId[:])
	sig.RIssuerKeyId = util.Reverse(sigKeyId)
	return
}
Ejemplo n.º 5
0
func (subkey *Subkey) initV4() error {
	fingerprint := Fingerprint(subkey.PublicKey)
	bitLen, err := subkey.PublicKey.BitLength()
	if err != nil {
		return err
	}
	if !subkey.PublicKey.IsSubkey {
		log.Println("Expected sub-key packet, got primary public key")
		return ErrInvalidPacketType
	}
	subkey.RFingerprint = util.Reverse(fingerprint)
	subkey.Creation = subkey.PublicKey.CreationTime
	subkey.Expiration = NeverExpires
	subkey.Algorithm = int(subkey.PublicKey.PubKeyAlgo)
	subkey.BitLen = int(bitLen)
	return nil
}
Ejemplo n.º 6
0
func (subkey *Subkey) initV3() error {
	fingerprint := FingerprintV3(subkey.PublicKeyV3)
	bitLen, err := subkey.PublicKeyV3.BitLength()
	if err != nil {
		return err
	}
	if subkey.PublicKeyV3.IsSubkey {
		log.Println("Expected primary public key packet, got sub-key")
		return ErrInvalidPacketType
	}
	subkey.RFingerprint = util.Reverse(fingerprint)
	subkey.Creation = subkey.PublicKeyV3.CreationTime
	subkey.Expiration = NeverExpires
	if subkey.PublicKeyV3.DaysToExpire > 0 {
		subkey.Expiration = subkey.Creation.Add(time.Duration(subkey.PublicKeyV3.DaysToExpire) * time.Hour * 24)
	}
	subkey.Algorithm = int(subkey.PublicKeyV3.PubKeyAlgo)
	subkey.BitLen = int(bitLen)
	return nil
}
Ejemplo n.º 7
0
func (sig *Signature) initV4() (err error) {
	if sig.Signature.IssuerKeyId == nil {
		return errors.New("Signature missing issuer key ID")
	}
	sig.Creation = sig.Signature.CreationTime
	sig.Expiration = NeverExpires
	sig.SigType = int(sig.Signature.SigType)
	// Extract the issuer key id
	var issuerKeyId [8]byte
	if sig.Signature.IssuerKeyId != nil {
		binary.BigEndian.PutUint64(issuerKeyId[:], *sig.Signature.IssuerKeyId)
		sigKeyId := hex.EncodeToString(issuerKeyId[:])
		sig.RIssuerKeyId = util.Reverse(sigKeyId)
	}
	// Expiration time
	if sig.Signature.SigLifetimeSecs != nil {
		sig.Expiration = sig.Signature.CreationTime.Add(
			time.Duration(*sig.Signature.SigLifetimeSecs) * time.Second)
	}
	return
}
Ejemplo n.º 8
0
func (pubkey *Pubkey) initV4() error {
	buf := bytes.NewBuffer(nil)
	err := pubkey.PublicKey.Serialize(buf)
	if err != nil {
		return err
	}
	fingerprint := Fingerprint(pubkey.PublicKey)
	bitLen, err := pubkey.PublicKey.BitLength()
	if err != nil {
		return err
	}
	if pubkey.PublicKey.IsSubkey {
		log.Println("Expected primary public key packet, got sub-key")
		return ErrInvalidPacketType
	}
	pubkey.RFingerprint = util.Reverse(fingerprint)
	pubkey.Creation = pubkey.PublicKey.CreationTime
	pubkey.Expiration = NeverExpires
	pubkey.Algorithm = int(pubkey.PublicKey.PubKeyAlgo)
	pubkey.BitLen = int(bitLen)
	return nil
}
Ejemplo n.º 9
0
func (pubkey *Pubkey) ShortId() string {
	if pubkey.PublicKeyV3 != nil {
		return fmt.Sprintf("%08x", uint32(pubkey.PublicKeyV3.KeyId))
	}
	return util.Reverse(pubkey.RFingerprint[:8])
}
Ejemplo n.º 10
0
func (pubkey *Pubkey) KeyId() string {
	if pubkey.PublicKeyV3 != nil {
		return fmt.Sprintf("%016x", pubkey.PublicKeyV3.KeyId)
	}
	return util.Reverse(pubkey.RFingerprint[:16])
}
Ejemplo n.º 11
0
func (pubkey *Pubkey) Fingerprint() string {
	return util.Reverse(pubkey.RFingerprint)
}
Ejemplo n.º 12
0
func (subkey *Subkey) ShortId() string {
	return util.Reverse(subkey.RFingerprint[:8])
}
Ejemplo n.º 13
0
func (subkey *Subkey) KeyId() string {
	return util.Reverse(subkey.RFingerprint[:16])
}
Ejemplo n.º 14
0
func (subkey *Subkey) Fingerprint() string {
	return util.Reverse(subkey.RFingerprint)
}
Ejemplo n.º 15
0
func (sig *Signature) IssuerFingerprint() string {
	return util.Reverse(sig.RIssuerFingerprint.String)
}
Ejemplo n.º 16
0
func (sig *Signature) IssuerKeyId() string {
	return util.Reverse(sig.RIssuerKeyId)
}