Пример #1
0
// GetVerifyKeys loads the verification keys from the keylookup server and
// adds them to the keypool and wallet.
func (c *Client) GetVerifyKeys() error {
	var verifyKeys [][ed25519.PublicKeySize]byte
	var err error
	if c.online {
		onlineGroup.Add(1)
		defer onlineGroup.Done()
		// Online!!! Load from keylookup service
		lookupClient := keylookupClient.New(nil, c.cacert, TrustRoot)
		verifyKeys, err = lookupClient.GetVerifyList()
		if err != nil {
			c.LastError = err
			err = ErrRetry
		}
		if verifyKeys != nil {
			c.walletStore.SetVerifyKeys(verifyKeys)
		}
	}
	if verifyKeys == nil {
		// We need keys anyways
		verifyKeys = c.walletStore.GetVerifyKeys()
	}
	for _, vKey := range verifyKeys {
		c.packetClient.AddVerifyKey(&vKey)
	}
	return err
}
Пример #2
0
// getPubKey looks up a public key from the keypool and tries to fetch it from
// keylookup if necessary.
func (c *Client) getPubKey(keyid [signkeys.KeyIDSize]byte) (pubkey *signkeys.PublicKey, err error) {
	pubkey, err = c.packetClient.Keypool.Lookup(keyid)
	if err != nil {
		if err != keypool.ErrNotFound {
			c.LastError = err
			return nil, ErrFatal
		}
		if !c.IsOnline() {
			c.LastError = err
			return nil, ErrOffline
		}
		onlineGroup.Add(1)
		defer onlineGroup.Done()
		lookupClient := keylookupClient.New(nil, c.cacert, TrustRoot)
		pubkey, err = lookupClient.GetKey(&keyid)
		if err != nil {
			_, fatal, err := lookupError(err)
			c.LastError = err
			if fatal {
				return nil, ErrFinal
			}
			return nil, ErrRetry
		}
		_, err = c.packetClient.Keypool.LoadKey(pubkey)
		if err != nil && err != keypool.ErrExists {
			c.LastError = err
			return nil, ErrFatal
		}
	}
	return pubkey, nil
}