Browse Source

Working eth sale importer.

cl-refactor
Gav Wood 10 years ago
parent
commit
f3512a0562
  1. 2
      alethzero/Main.ui
  2. 35
      alethzero/MainWin.cpp
  3. 3
      alethzero/MainWin.h
  4. 14
      libdevcrypto/SHA3.cpp

2
alethzero/Main.ui

@ -1756,7 +1756,7 @@ font-size: 14pt</string>
</action> </action>
<action name="importKeyFile"> <action name="importKeyFile">
<property name="text"> <property name="text">
<string>Import Key &amp;File...</string> <string>Claim Ether Presale &amp;Wallet...</string>
</property> </property>
</action> </action>
<action name="go"> <action name="go">

35
alethzero/MainWin.cpp

@ -564,8 +564,7 @@ void Main::on_importKey_triggered()
if (std::find(m_myKeys.begin(), m_myKeys.end(), k) == m_myKeys.end()) if (std::find(m_myKeys.begin(), m_myKeys.end(), k) == m_myKeys.end())
{ {
m_myKeys.append(k); m_myKeys.append(k);
m_keysChanged = true; keysChanged();
update();
} }
else else
QMessageBox::warning(this, "Already Have Key", "Could not import the secret key: we already own this account."); QMessageBox::warning(this, "Already Have Key", "Could not import the secret key: we already own this account.");
@ -585,20 +584,29 @@ void Main::on_importKeyFile_triggered()
if (obj["encseed"].type() == js::str_type) if (obj["encseed"].type() == js::str_type)
{ {
auto encseed = fromHex(obj["encseed"].get_str()); auto encseed = fromHex(obj["encseed"].get_str());
KeyPair k = KeyPair::fromEncryptedSeed(&encseed, QInputDialog::getText(this, "Enter Password", "Enter the wallet's passphrase", QLineEdit::Password).toStdString()); KeyPair k;
if (obj["ethaddr"].type() == js::str_type) for (bool gotit = false; !gotit;)
{ {
Address a(obj["ethaddr"].get_str()); gotit = true;
Address b = k.address(); k = KeyPair::fromEncryptedSeed(&encseed, QInputDialog::getText(this, "Enter Password", "Enter the wallet's passphrase", QLineEdit::Password).toStdString());
if (a != b && QMessageBox::warning(this, "Key File Invalid", "Could not import the secret key: it doesn't agree with the given address.\nWould you like to attempt to import anyway?", QMessageBox::Yes | QMessageBox::No) == QMessageBox::No) if (obj["ethaddr"].type() == js::str_type)
return; {
Address a(obj["ethaddr"].get_str());
Address b = k.address();
if (a != b)
{
if (QMessageBox::warning(this, "Password Wrong", "Could not import the secret key: the password you gave appears to be wrong.", QMessageBox::Retry, QMessageBox::Cancel) == QMessageBox::Cancel)
return;
else
gotit = false;
}
}
} }
if (std::find(m_myKeys.begin(), m_myKeys.end(), k) == m_myKeys.end()) if (std::find(m_myKeys.begin(), m_myKeys.end(), k) == m_myKeys.end())
{ {
m_myKeys.append(k); m_myKeys.append(k);
m_keysChanged = true; keysChanged();
update();
} }
else else
QMessageBox::warning(this, "Already Have Key", "Could not import the secret key: we already own this account."); QMessageBox::warning(this, "Already Have Key", "Could not import the secret key: we already own this account.");
@ -1587,6 +1595,11 @@ void Main::on_send_clicked()
statusBar()->showMessage("Couldn't make transaction: no single account contains at least the required amount."); statusBar()->showMessage("Couldn't make transaction: no single account contains at least the required amount.");
} }
void Main::keysChanged()
{
onBalancesChange();
}
void Main::on_debug_clicked() void Main::on_debug_clicked()
{ {
debugFinished(); debugFinished();
@ -1623,7 +1636,7 @@ void Main::on_debug_clicked()
void Main::on_create_triggered() void Main::on_create_triggered()
{ {
m_myKeys.append(KeyPair::create()); m_myKeys.append(KeyPair::create());
m_keysChanged = true; keysChanged();
} }
void Main::on_debugStep_triggered() void Main::on_debugStep_triggered()

3
alethzero/MainWin.h

@ -184,6 +184,8 @@ private:
unsigned installWatch(dev::eth::MessageFilter const& _tf, std::function<void()> const& _f); unsigned installWatch(dev::eth::MessageFilter const& _tf, std::function<void()> const& _f);
unsigned installWatch(dev::h256 _tf, std::function<void()> const& _f); unsigned installWatch(dev::h256 _tf, std::function<void()> const& _f);
void keysChanged();
void onNewPending(); void onNewPending();
void onNewBlock(); void onNewBlock();
void onNameRegChange(); void onNameRegChange();
@ -221,7 +223,6 @@ private:
QStringList m_servers; QStringList m_servers;
QList<dev::KeyPair> m_myKeys; QList<dev::KeyPair> m_myKeys;
QString m_privateChain; QString m_privateChain;
bool m_keysChanged = false;
dev::bytes m_data; dev::bytes m_data;
dev::Address m_nameReg; dev::Address m_nameReg;

14
libdevcrypto/SHA3.cpp

@ -72,21 +72,25 @@ h256 sha3(bytesConstRef _input)
return ret; return ret;
} }
bytes aesDecrypt(bytesConstRef _cipher, std::string const& _password, unsigned _rounds, bytesConstRef _salt) bytes aesDecrypt(bytesConstRef _ivCipher, std::string const& _password, unsigned _rounds, bytesConstRef _salt)
{ {
bytes pw = asBytes(_password); bytes pw = asBytes(_password);
bytes target(CryptoPP::AES::DEFAULT_KEYLENGTH);
if (!_salt.size())
_salt = &pw;
bytes target(64);
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHA256>().DeriveKey(target.data(), target.size(), 0, pw.data(), pw.size(), _salt.data(), _salt.size(), _rounds); CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHA256>().DeriveKey(target.data(), target.size(), 0, pw.data(), pw.size(), _salt.data(), _salt.size(), _rounds);
try try
{ {
CryptoPP::AES::Decryption aesDecryption(target.data(), target.size()); CryptoPP::AES::Decryption aesDecryption(target.data(), 16);
bytes iv(CryptoPP::AES::BLOCKSIZE); auto cipher = _ivCipher.cropped(16);
auto iv = _ivCipher.cropped(0, 16);
CryptoPP::CBC_Mode_ExternalCipher::Decryption cbcDecryption(aesDecryption, iv.data()); CryptoPP::CBC_Mode_ExternalCipher::Decryption cbcDecryption(aesDecryption, iv.data());
std::string decrypted; std::string decrypted;
CryptoPP::StreamTransformationFilter stfDecryptor(cbcDecryption, new CryptoPP::StringSink(decrypted)); CryptoPP::StreamTransformationFilter stfDecryptor(cbcDecryption, new CryptoPP::StringSink(decrypted));
stfDecryptor.Put(_cipher.data(), _cipher.size()); stfDecryptor.Put(cipher.data(), cipher.size());
stfDecryptor.MessageEnd(); stfDecryptor.MessageEnd();
return asBytes(decrypted); return asBytes(decrypted);
} }

Loading…
Cancel
Save