示例#1
0
 private_keys wallet_db::get_account_private_keys( const fc::sha512& password )
 { try {
     private_keys keys;
     keys.reserve( accounts.size() );
     for( const auto& item : accounts )
     {
        auto key_rec = lookup_key(item.second.account_address);
        if( key_rec.valid() && key_rec->has_private_key() )
        {
           try {
              keys.push_back( key_rec->decrypt_private_key( password ) );
           } catch ( const fc::exception& e )
           {
              wlog( "error decrypting private key: ${e}", ("e", e.to_detail_string() ) );
              throw; // TODO... don't thtrow here, just log
           }
        }
     }
     return keys;
 } FC_RETHROW_EXCEPTIONS( warn, "" ) }
示例#2
0
/**
 * Load an encrypted private key from an ASN.1 encoded blob
 * Schemes per PKCS#5 (RFC 2898)
 */
static private_key_t *parse_encrypted_private_key(chunk_t blob)
{
	asn1_parser_t *parser;
	chunk_t object;
	int objectID;
	private_key_t *key = NULL;
	pkcs5_t *pkcs5 = NULL;

	parser = asn1_parser_create(encryptedPKIObjects, blob);

	while (parser->iterate(parser, &objectID, &object))
	{
		switch (objectID)
		{
			case EPKINFO_ENCRYPTION_ALGORITHM:
			{
				pkcs5 = pkcs5_from_algorithmIdentifier(object,
												parser->get_level(parser) + 1);
				if (!pkcs5)
				{
					goto end;
				}
				break;
			}
			case EPKINFO_ENCRYPTED_DATA:
			{
				key = decrypt_private_key(pkcs5, object);
				break;
			}
		}
	}

end:
	DESTROY_IF(pkcs5);
	parser->destroy(parser);
	return key;
}
示例#3
0
   // Only returns private keys corresponding to owner and active keys
   map<PrivateKeyType, string> WalletDb::get_account_private_keys( const fc::sha512& password )const
   { try {
       map<PublicKeyType, string> public_keys;
       for( const auto& account_item : accounts )
       {
           const auto& account = account_item.second;
           public_keys[ account.owner_key ] = account.name;
           for( const auto& active_key_item : account.active_key_history )
           {
               const auto& active_key = active_key_item.second;
               if( active_key != PublicKeyType() )
                   public_keys[ active_key ] = account.name;
           }
       }

       map<PrivateKeyType, string> private_keys;
       for( const auto& public_key_item : public_keys )
       {
           const auto& public_key = public_key_item.first;
           const auto& account_name = public_key_item.second;

           const auto key_entry = lookup_key( public_key );
           if( !key_entry.valid() || !key_entry->has_private_key() )
               continue;

           try
           {
               private_keys[ key_entry->decrypt_private_key( password ) ] = account_name;
           }
           catch( const fc::exception& e )
           {
               elog( "Error decrypting private key: ${e}", ("e",e.to_detail_string()) );
           }
       }
       return private_keys;
   } FC_CAPTURE_AND_RETHROW() }