Exemplo n.º 1
0
// GetPublicKeyInit gets a public key init from keydb.
// If no such KeyInit could be found, sql.ErrNoRows is returned.
func (keyDB *KeyDB) GetPublicKeyInit(sigKeyHash string) (*uid.KeyInit, error) {
	var json string
	err := keyDB.getPublicKeyInitQuery.QueryRow(sigKeyHash).Scan(&json)
	switch {
	case err != nil:
		return nil, log.Error(err)
	default:
		ki, err := uid.NewJSONKeyInit([]byte(json))
		if err != nil {
			return nil, err
		}
		return ki, nil
	}
}
Exemplo n.º 2
0
// GetPrivateKeyInit returns the private KeyInit for the given pubKeyHash.
func (keyDB *KeyDB) GetPrivateKeyInit(
	pubKeyHash string,
) (ki *uid.KeyInit, sigPubKey, privKey string, err error) {
	var json string
	err = keyDB.getPrivateKeyInitQuery.QueryRow(pubKeyHash).Scan(&json, &sigPubKey, &privKey)
	switch {
	case err != nil:
		return nil, "", "", log.Error(err)
	default:
		ki, err = uid.NewJSONKeyInit([]byte(json))
		if err != nil {
			return nil, "", "", err
		}
		return
	}
}
Exemplo n.º 3
0
func (ce *CryptEngine) fetchKeyInit(pseudonym string) error {
	// map pseudonym
	id, domain, err := identity.MapPlus(pseudonym)
	if err != nil {
		return err
	}
	// get corresponding public ID
	msg, _, found, err := ce.keyDB.GetPublicUID(id, math.MaxInt64) // TODO: use simpler API
	if err != nil {
		return err
	}
	if !found {
		return log.Errorf("not UID for '%s' found", id)
	}
	// get SIGKEYHASH
	sigKeyHash, err := msg.SigKeyHash()
	if err != nil {
		return err
	}
	// get JSON-RPC client and capabilities
	client, _, err := ce.cache.Get(domain, ce.keydPort, ce.keydHost,
		ce.homedir, "KeyInitRepository.FetchKeyInit")
	if err != nil {
		return err
	}
	// call server
	content := make(map[string]interface{})
	content["SigKeyHash"] = sigKeyHash
	reply, err := client.JSONRPCRequest("KeyInitRepository.FetchKeyInit", content)
	if err != nil {
		return err
	}
	rep, ok := reply["KeyInit"].(string)
	if !ok {
		return log.Errorf("cryptengine: could not fetch key init for '%s'", sigKeyHash)
	}
	ki, err := uid.NewJSONKeyInit([]byte(rep))
	if err != nil {
		return err
	}
	// store public key init message
	if err := ce.keyDB.AddPublicKeyInit(ki); err != nil {
		return err
	}
	return nil
}