예제 #1
0
  void start(const fc::ip::endpoint& endpoint_to_probe, 
             const fc::ecc::private_key& my_node_id,
             const bts::blockchain::digest_type& chain_id)
  {
    fc::future<void> connect_task = fc::async([=](){ _connection->connect_to(endpoint_to_probe); }, "connect_task");
    try
    {
      connect_task.wait(fc::seconds(10));
    }
    catch (const fc::timeout_exception&)
    {
      ilog("timeout connecting to node ${endpoint}", ("endpoint", endpoint_to_probe));
      connect_task.cancel();
      throw;
    }

    fc::sha256::encoder shared_secret_encoder;
    fc::sha512 shared_secret = _connection->get_shared_secret();
    shared_secret_encoder.write(shared_secret.data(), sizeof(shared_secret));
    fc::ecc::compact_signature signature = my_node_id.sign_compact(shared_secret_encoder.result());

    bts::net::hello_message hello("map_bts_network", 
                                  BTS_NET_PROTOCOL_VERSION,
                                  fc::ip::address(), 0, 0,
                                  my_node_id.get_public_key(), 
                                  signature,
                                  chain_id,
                                  fc::variant_object());
    
    _connection->send_message(hello);
  }
예제 #2
0
        PublicKeyType withdraw_with_escrow::encrypt_memo_data(
            const fc::ecc::private_key& one_time_private_key,
            const fc::ecc::public_key&  to_public_key,
            const fc::ecc::private_key& from_private_key,
            const std::string& memo_message,
            const fc::ecc::public_key&  memo_pub_key,
            MemoFlagsEnum memo_type)
        {
            memo = TransferMemo();
            const auto secret = one_time_private_key.get_shared_secret(to_public_key);
            const auto ext_to_public_key = ExtendedPublicKey(to_public_key);
            const auto secret_ext_public_key = ext_to_public_key.child(fc::sha256::hash(secret));
            const auto secret_public_key = secret_ext_public_key.get_pub_key();

            sender = Address(one_time_private_key.get_public_key());
            receiver = Address(secret_public_key);

            fc::sha512 check_secret;
            if (from_private_key.get_secret() != fc::ecc::private_key().get_secret())
                check_secret = from_private_key.get_shared_secret(secret_public_key);

            MemoData memo_content;
            memo_content.set_message(memo_message);
            memo_content.from = memo_pub_key;
            memo_content.from_signature = check_secret._hash[0];
            memo_content.memo_flags = memo_type;

            memo->one_time_key = one_time_private_key.get_public_key();

            encrypt_memo_data(secret, memo_content);
            return secret_public_key;
        }
예제 #3
0
  void start(const fc::ip::endpoint& endpoint_to_probe,
             const fc::ecc::private_key& my_node_id,
             const graphene::chain::chain_id_type& chain_id)
  {
    _remote = endpoint_to_probe;
    fc::future<void> connect_task = fc::async([this](){ _connection->connect_to(_remote); }, "connect_task");
    try
    {
      connect_task.wait(fc::seconds(10));
    }
    catch (const fc::timeout_exception&)
    {
      ilog("timeout connecting to node ${endpoint}", ("endpoint", endpoint_to_probe));
      connect_task.cancel(__FUNCTION__);
      throw;
    }

    fc::sha256::encoder shared_secret_encoder;
    fc::sha512 shared_secret = _connection->get_shared_secret();
    shared_secret_encoder.write(shared_secret.data(), sizeof(shared_secret));
    fc::ecc::compact_signature signature = my_node_id.sign_compact(shared_secret_encoder.result());

    graphene::net::hello_message hello("network_mapper",
                                  GRAPHENE_NET_PROTOCOL_VERSION,
                                  fc::ip::address(), 0, 0,
                                  my_node_id.get_public_key(),
                                  signature,
				  chain_id,
                                  fc::variant_object());

    _connection->send_message(hello);
  }
예제 #4
0
    void domain_transfer_operation::titan_transfer( const fc::ecc::private_key& one_time_private_key,
                                                    const fc::ecc::public_key& to_public_key,
                                                    const fc::ecc::private_key& from_private_key,
                                                    const std::string& memo_message,
                                                    const fc::ecc::public_key& memo_pub_key,
                                                    memo_flags_enum memo_type )
    {
        memo = titan_memo();
        auto secret = one_time_private_key.get_shared_secret( to_public_key );
        auto ext_to_public_key = extended_public_key(to_public_key);
        auto secret_ext_public_key = ext_to_public_key.child( fc::sha256::hash(secret) );
        auto secret_public_key = secret_ext_public_key.get_pub_key();
        owner = address( secret_public_key );

        auto check_secret = from_private_key.get_shared_secret( secret_public_key );

        memo_data memo_content;
        memo_content.set_message( memo_message );
        memo_content.from = memo_pub_key;
        memo_content.from_signature = check_secret._hash[0];
        memo_content.memo_flags = memo_type;

        memo->one_time_key = one_time_private_key.get_public_key();

        FC_ASSERT( memo.valid() );
        memo->encrypted_memo_data = fc::aes_encrypt( secret, fc::raw::pack( memo_content ) );
    }
예제 #5
0
   public_key_type withdraw_with_signature::encrypt_memo_data(
           const fc::ecc::private_key& one_time_private_key,
           const fc::ecc::public_key&  to_public_key,
           const fc::ecc::private_key& from_private_key,
           const std::string& memo_message,
           const fc::ecc::public_key&  memo_pub_key,
           memo_flags_enum memo_type )
   {
      memo = titan_memo();
      const auto secret = one_time_private_key.get_shared_secret( to_public_key );
      const auto ext_to_public_key = extended_public_key( to_public_key );
      const auto secret_ext_public_key = ext_to_public_key.child( fc::sha256::hash( secret ) );
      const auto secret_public_key = secret_ext_public_key.get_pub_key();
      owner = address( secret_public_key );

      fc::sha512 check_secret;
      if( from_private_key.get_secret() != fc::ecc::private_key().get_secret() )
        check_secret = from_private_key.get_shared_secret( secret_public_key );

      memo_data memo_content;
      memo_content.set_message( memo_message );
      memo_content.from = memo_pub_key;
      memo_content.from_signature = check_secret._hash[0];
      memo_content.memo_flags = memo_type;

      memo->one_time_key = one_time_private_key.get_public_key();

      encrypt_memo_data( secret, memo_content );
      return secret_public_key;
   }
예제 #6
0
 encrypted_message message::encrypt( const fc::ecc::private_key& onetimekey,
                                     const fc::ecc::public_key&  receiver_public_key )const
 {
    auto shared_secret = onetimekey.get_shared_secret( receiver_public_key );
    encrypted_message result;
    result.onetimekey = onetimekey.get_public_key();
    result.data = fc::aes_encrypt( shared_secret, fc::raw::pack( *this ) );
    return  result;
 }
예제 #7
0
   omemo_status withdraw_with_signature::decrypt_memo_data( const fc::ecc::private_key& receiver_key, bool ignore_owner )const
   { try {
      try {
         FC_ASSERT( memo.valid() );
         auto secret = receiver_key.get_shared_secret( memo->one_time_key );
         extended_private_key ext_receiver_key(receiver_key);

         fc::ecc::private_key secret_private_key = ext_receiver_key.child( fc::sha256::hash(secret),
                                                                           extended_private_key::public_derivation );
         auto secret_public_key = secret_private_key.get_public_key();

         if( !ignore_owner && owner != address( secret_public_key ) )
            return omemo_status();

         auto memo = decrypt_memo_data( secret );

         bool has_valid_signature = false;
         if( memo.memo_flags == from_memo && !( memo.from == public_key_type() && memo.from_signature == 0 ) )
         {
            auto check_secret = secret_private_key.get_shared_secret( memo.from );
            has_valid_signature = check_secret._hash[0] == memo.from_signature;
         }
         else
         {
            has_valid_signature = true;
         }

         return memo_status( memo, has_valid_signature, secret_private_key );
      }
      catch ( const fc::aes_exception& e )
      {
         return omemo_status();
      }
   } FC_CAPTURE_AND_RETHROW( (ignore_owner) ) }
예제 #8
0
 void signed_block_header::sign( const fc::ecc::private_key& signer, digest_type chain_id )
 { try {
    fc::sha256::encoder enc;
    fc::raw::pack( enc, *this );
    fc::raw::pack( enc, chain_id );
    delegate_signature = signer.sign_compact( digest() );
 } FC_RETHROW_EXCEPTIONS( warn, "" ) }
예제 #9
0
void    signed_transaction::sign( const fc::ecc::private_key& k )
{
    try {
        sigs.insert( k.sign_compact( digest() ) );
    }
    FC_RETHROW_EXCEPTIONS( warn, "error signing transaction", ("trx", *this ) );
}
예제 #10
0
    omemo_status domain_transfer_operation::decrypt_memo_data( const fc::ecc::private_key& receiver_key ) const
    { try {
        FC_ASSERT( memo.valid() );
//      ilog( "receiver_key: ${r}", ("r",receiver_key) );
        auto secret = receiver_key.get_shared_secret( memo->one_time_key );
//      ilog( "secret: ${secret}", ("secret",secret) );
        extended_private_key ext_receiver_key(receiver_key);
 //     ilog( "ext_receiver_key: ${key}",("key",ext_receiver_key) );
      
        fc::ecc::private_key secret_private_key = ext_receiver_key.child( fc::sha256::hash(secret), 
                                                                          extended_private_key::public_derivation );
   //   ilog( "secret_private_key: ${k}", ("k",secret_private_key)  );
        auto secret_public_key = secret_private_key.get_public_key();
    //  ilog( "secret_public_key: ${k}", ("k",secret_public_key)  );

        if( owner != address(secret_public_key) )
            return omemo_status();

     // ilog( "owner: ${o} == ${address}", ("o",owner)("address",address(secret_public_key)) );
        auto memo = decrypt_memo_data( secret );

        bool has_valid_signature = false;
        if( memo.memo_flags == from_memo )
        {
            auto check_secret = secret_private_key.get_shared_secret( memo.from );
            has_valid_signature = check_secret._hash[0] == memo.from_signature;
        }
        else
        {
            has_valid_signature = true;
        }

        return memo_status( memo, has_valid_signature, secret_private_key );
   } FC_RETHROW_EXCEPTIONS( warn, "" ) }
예제 #11
0
   void pow::create( const fc::ecc::private_key& w, const digest_type& i ) {
      input  = i;
      signature = w.sign_compact(input,false);

      auto sig_hash            = fc::sha256::hash( signature );
      public_key_type recover  = fc::ecc::public_key( signature, sig_hash, false );

      work = fc::sha256::hash(recover);
   }
예제 #12
0
   void wallet_db::cache_memo( const memo_status& memo,
                               const fc::ecc::private_key& account_key,
                               const fc::sha512& password )
   {
      key_data data;
      data.account_address = address(account_key.get_public_key());
      //data.memo = memo_data(memo);
      data.valid_from_signature = memo.has_valid_signature;
      data.encrypt_private_key( password, memo.owner_private_key );

      store_key( data );
   }
예제 #13
0
std::string key_to_wif(const fc::ecc::private_key& key)
{
  fc::sha256 secret = key.get_secret();
  const size_t size_of_data_to_hash = sizeof(secret) + 1;
  const size_t size_of_hash_bytes = 4;
  char data[size_of_data_to_hash + size_of_hash_bytes];
  data[0] = (char)0x80;
  memcpy(&data[1], (char*)&secret, sizeof(secret));
  fc::sha256 digest = fc::sha256::hash(data, size_of_data_to_hash);
  digest = fc::sha256::hash(digest);
  memcpy(data + size_of_data_to_hash, (char*)&digest, size_of_hash_bytes);
  return fc::to_base58(data, sizeof(data));
}
bts_server_process_info_ptr launch_bts_server_process(const genesis_block_config& genesis_block,
                                                      const fc::ecc::private_key& trustee_key)
{
  bts_server_process_info_ptr server_process_info = std::make_shared<bts_server_process_info>();
  server_process_info->server_process = std::make_shared<fc::process>();
  
  std::vector<std::string> options;
  options.push_back("--trustee-address");
  options.push_back(bts::blockchain::address(trustee_key.get_public_key()));

  fc::path server_config_dir = bts_xt_client_test_config::config_directory / "BitSharesX_Server";
  fc::remove_all(server_config_dir);
  fc::create_directories(server_config_dir);

  fc::json::save_to_file(genesis_block, server_config_dir / "genesis.json", true);

  server_process_info->server_process->exec(bts_xt_client_test_config::bts_server_exe, options, server_config_dir);

  std::shared_ptr<std::ofstream> stdouterrfile = std::make_shared<std::ofstream>((server_config_dir / "stdouterr.txt").string().c_str());
  fc::buffered_istream_ptr out_stream = server_process_info->server_process->out_stream();
  fc::buffered_istream_ptr err_stream = server_process_info->server_process->err_stream();
  server_process_info->stdout_reader_done = fc::async([out_stream,stdouterrfile]()
    {
      char buf[1024];
      for (;;)
      {
        size_t bytes_read = out_stream->readsome(buf, sizeof(buf));
        if (!bytes_read)
          break;
        stdouterrfile->write(buf, bytes_read);
      }
    });
  server_process_info->stderr_reader_done = fc::async([err_stream,stdouterrfile]()
    {
      char buf[1024];
      for (;;)
      {
        size_t bytes_read = err_stream->readsome(buf, sizeof(buf));
        if (!bytes_read)
          break;
        stdouterrfile->write(buf, bytes_read);
      }
    });
  return server_process_info;
}
예제 #15
0
 void                         subscribe_message::sign( const fc::ecc::private_key& k )
 {
    sig = k.sign_compact( digest() );
 }
fc::process_ptr launch_bts_client_process(uint32_t process_number, uint16_t rpc_port, 
                                          const fc::ecc::private_key& trustee_key, 
                                          bool act_as_trustee)
{
  fc::process_ptr bts_client_process(std::make_shared<fc::process>());
  std::vector<std::string> options;

  std::ostringstream numbered_config_dir_name;
  numbered_config_dir_name << "BitSharesX_" << std::setw(3) << std::setfill('0') << process_number;
  fc::path numbered_config_dir = bts_xt_client_test_config::config_directory / numbered_config_dir_name.str();
  fc::remove_all(numbered_config_dir);
  fc::create_directories(numbered_config_dir);

  // create a wallet in that directory
  // we could (and probably should) make bts_xt_client create the wallet, 
  // but if we ask it to create the wallet
  // it will interactively prompt for passwords which is a big hassle.
  // here we explicitly create one with a blank password
  {
    bts::wallet::wallet_ptr wallet = std::make_shared<bts::wallet::wallet>();
    wallet->set_data_directory(numbered_config_dir);
    fc::path wallet_data_filename = wallet->get_wallet_file();
    wallet->create(wallet_data_filename, "", WALLET_PASPHRASE);
  }

  options.push_back("--data-dir");
  options.push_back(numbered_config_dir.string());

  options.push_back("--server");
  options.push_back("--rpcuser="******"--rpcpassword="******"--rpcport");
  options.push_back(boost::lexical_cast<std::string>(rpc_port));
  options.push_back("--trustee-address");
  options.push_back(bts::blockchain::address(trustee_key.get_public_key()));
  if (act_as_trustee)
  {
    options.push_back("--trustee-private-key");
    options.push_back(trustee_key.get_secret());
  }

  bts_client_process->exec(bts_xt_client_test_config::bts_client_exe, options, numbered_config_dir);

#if 0
  std::shared_ptr<std::ofstream> stdouterrfile = std::make_shared<std::ofstream>((numbered_config_dir / "stdouterr.txt").string().c_str());
  fc::buffered_istream_ptr out_stream = bts_client_process->out_stream();
  fc::buffered_istream_ptr err_stream = bts_client_process->err_stream();
  server_process_info->stdout_reader_done = fc::async([out_stream,stdouterrfile]()
    {
      char buf[1024];
      for (;;)
      {
        size_t bytes_read = out_stream->readsome(buf, sizeof(buf));
        if (!bytes_read)
          break;
        stdouterrfile->write(buf, bytes_read);
      }
    });
  server_process_info->stderr_reader_done = fc::async([err_stream,stdouterrfile]()
    {
      char buf[1024];
      for (;;)
      {
        size_t bytes_read = err_stream->readsome(buf, sizeof(buf));
        if (!bytes_read)
          break;
        stdouterrfile->write(buf, bytes_read);
      }
    });
#endif
  return bts_client_process;
}
예제 #17
0
 void peer_connection::signin( const fc::ecc::private_key& key )
 {
    auto sig = key.sign_compact( fc::sha256::hash( (char*)&_shared_secret, sizeof(_shared_secret) ) );
    auto self = shared_from_this();
    fc::async( [=](){ self->send_message( signin_request( sig ) ); } );
 }
예제 #18
0
 void signed_block::sign( const fc::ecc::private_key& trustee_priv_key )
 {
    trustee_signature = trustee_priv_key.sign_compact( id() );
 }
예제 #19
0
std::string key_to_wif(const fc::ecc::private_key& key)
{
  return key_to_wif( key.get_secret() );
}
예제 #20
0
signed_block database::_generate_block(
   fc::time_point_sec when,
   witness_id_type witness_id,
   const fc::ecc::private_key& block_signing_private_key
   )
{
   try {
   uint32_t skip = get_node_properties().skip_flags;
   uint32_t slot_num = get_slot_at_time( when );
   FC_ASSERT( slot_num > 0 );
   witness_id_type scheduled_witness = get_scheduled_witness( slot_num );
   FC_ASSERT( scheduled_witness == witness_id );

   const auto& witness_obj = witness_id(*this);

   if( !(skip & skip_witness_signature) )
      FC_ASSERT( witness_obj.signing_key == block_signing_private_key.get_public_key() );

   static const size_t max_block_header_size = fc::raw::pack_size( signed_block_header() ) + 4;
   auto maximum_block_size = get_global_properties().parameters.maximum_block_size;
   size_t total_block_size = max_block_header_size;

   signed_block pending_block;

   //
   // The following code throws away existing pending_tx_session and
   // rebuilds it by re-applying pending transactions.
   //
   // This rebuild is necessary because pending transactions' validity
   // and semantics may have changed since they were received, because
   // time-based semantics are evaluated based on the current block
   // time.  These changes can only be reflected in the database when
   // the value of the "when" variable is known, which means we need to
   // re-apply pending transactions in this method.
   //
   _pending_tx_session.reset();
   _pending_tx_session = _undo_db.start_undo_session();

   uint64_t postponed_tx_count = 0;
   // pop pending state (reset to head block state)
   for( const processed_transaction& tx : _pending_tx )
   {
      size_t new_total_size = total_block_size + fc::raw::pack_size( tx );

      // postpone transaction if it would make block too big
      if( new_total_size >= maximum_block_size )
      {
         postponed_tx_count++;
         continue;
      }

      try
      {
         auto temp_session = _undo_db.start_undo_session();
         processed_transaction ptx = _apply_transaction( tx );
         temp_session.merge();

         // We have to recompute pack_size(ptx) because it may be different
         // than pack_size(tx) (i.e. if one or more results increased
         // their size)
         total_block_size += fc::raw::pack_size( ptx );
         pending_block.transactions.push_back( ptx );
      }
      catch ( const fc::exception& e )
      {
         // Do nothing, transaction will not be re-applied
         wlog( "Transaction was not processed while generating block due to ${e}", ("e", e) );
         wlog( "The transaction was ${t}", ("t", tx) );
      }
   }
   if( postponed_tx_count > 0 )
   {
      wlog( "Postponed ${n} transactions due to block size limit", ("n", postponed_tx_count) );
   }

   _pending_tx_session.reset();

   // We have temporarily broken the invariant that
   // _pending_tx_session is the result of applying _pending_tx, as
   // _pending_tx now consists of the set of postponed transactions.
   // However, the push_block() call below will re-create the
   // _pending_tx_session.

   pending_block.previous = head_block_id();
   pending_block.timestamp = when;
   pending_block.transaction_merkle_root = pending_block.calculate_merkle_root();
   pending_block.witness = witness_id;

   if( !(skip & skip_witness_signature) )
      pending_block.sign( block_signing_private_key );

   // TODO:  Move this to _push_block() so session is restored.
   if( !(skip & skip_block_size_check) )
   {
      FC_ASSERT( fc::raw::pack_size(pending_block) <= get_global_properties().parameters.maximum_block_size );
   }

   push_block( pending_block, skip );

   return pending_block;
} FC_CAPTURE_AND_RETHROW( (witness_id) ) }
예제 #21
0
파일: elliptic.hpp 프로젝트: bitshares/fc
 void pack( Stream& s, const fc::ecc::private_key& pk, uint32_t _max_depth )
 {
     FC_ASSERT( _max_depth > 0 );
     fc::raw::pack( s, pk.get_secret(), _max_depth - 1 );
 }
예제 #22
0
 void signed_transaction::sign( const fc::ecc::private_key& signer )
 {
    signatures.push_back( signer.sign_compact( digest() ) );
 }
예제 #23
0
 void signed_transaction::sign( const fc::ecc::private_key& signer, const digest_type& chain_id )
 {
    signatures.push_back( signer.sign_compact( digest( chain_id ) ) );
 }
예제 #24
0
 message encrypted_message::decrypt( const fc::ecc::private_key& e )const
 {
    auto shared_secret = e.get_shared_secret(onetimekey);
    return decrypt(shared_secret);
 }
예제 #25
0
 void signed_block_header::sign( const fc::ecc::private_key& signer )
 { try {
    delegate_signature = signer.sign_compact( digest() );
 } FC_RETHROW_EXCEPTIONS( warn, "" ) }
 extended_private_key( const fc::ecc::private_key& k ):priv_key(k.get_secret()){}
예제 #27
0
 void pack( Stream& s, const fc::ecc::private_key& pk)
 {
     fc::raw::pack( s, pk.get_secret() );
 }
예제 #28
0
파일: block.cpp 프로젝트: AlexChien/steem
 void signed_block_header::sign( const fc::ecc::private_key& signer )
 {
    witness_signature = signer.sign_compact( digest() );
 }