| 440 | } |
| 441 | |
| 442 | bool CCryptoKeyStore::DecryptHDChain(CHDChain& hdChainRet) const |
| 443 | { |
| 444 | if (!IsCrypted()) |
| 445 | return true; |
| 446 | |
| 447 | if (cryptedHDChain.IsNull()) |
| 448 | return false; |
| 449 | |
| 450 | if (!cryptedHDChain.IsCrypted()) |
| 451 | return false; |
| 452 | |
| 453 | SecureVector vchSecureSeed; |
| 454 | SecureVector vchSecureCryptedSeed = cryptedHDChain.GetSeed(); |
| 455 | std::vector<unsigned char> vchCryptedSeed(vchSecureCryptedSeed.begin(), vchSecureCryptedSeed.end()); |
| 456 | if (!DecryptSecret(vMasterKey, vchCryptedSeed, cryptedHDChain.GetID(), vchSecureSeed)) |
| 457 | return false; |
| 458 | |
| 459 | hdChainRet = cryptedHDChain; |
| 460 | if (!hdChainRet.SetSeed(vchSecureSeed, false)) |
| 461 | return false; |
| 462 | |
| 463 | // hash of decrypted seed must match chain id |
| 464 | if (hdChainRet.GetSeedHash() != cryptedHDChain.GetID()) |
| 465 | return false; |
| 466 | |
| 467 | SecureVector vchSecureCryptedMnemonic; |
| 468 | SecureVector vchSecureCryptedMnemonicPassphrase; |
| 469 | |
| 470 | // it's ok to have no mnemonic if wallet was initialized via hdseed |
| 471 | if (cryptedHDChain.GetMnemonic(vchSecureCryptedMnemonic, vchSecureCryptedMnemonicPassphrase)) { |
| 472 | SecureVector vchSecureMnemonic; |
| 473 | SecureVector vchSecureMnemonicPassphrase; |
| 474 | |
| 475 | std::vector<unsigned char> vchCryptedMnemonic(vchSecureCryptedMnemonic.begin(), vchSecureCryptedMnemonic.end()); |
| 476 | std::vector<unsigned char> vchCryptedMnemonicPassphrase(vchSecureCryptedMnemonicPassphrase.begin(), vchSecureCryptedMnemonicPassphrase.end()); |
| 477 | |
| 478 | if (!vchCryptedMnemonic.empty() && !DecryptSecret(vMasterKey, vchCryptedMnemonic, cryptedHDChain.GetID(), vchSecureMnemonic)) |
| 479 | return false; |
| 480 | if (!vchCryptedMnemonicPassphrase.empty() && !DecryptSecret(vMasterKey, vchCryptedMnemonicPassphrase, cryptedHDChain.GetID(), vchSecureMnemonicPassphrase)) |
| 481 | return false; |
| 482 | |
| 483 | if (!hdChainRet.SetMnemonic(vchSecureMnemonic, vchSecureMnemonicPassphrase, false)) |
| 484 | return false; |
| 485 | } |
| 486 | |
| 487 | hdChainRet.SetCrypted(false); |
| 488 | hdChainRet.Debug(__func__); |
| 489 | |
| 490 | return true; |
| 491 | } |
| 492 | |
| 493 | bool CCryptoKeyStore::SetHDChain(const CHDChain& chain) |
| 494 | { |
nothing calls this directly
no test coverage detected