Skip to content

Commit

Permalink
SecurePrint interface on import private keys
Browse files Browse the repository at this point in the history
  • Loading branch information
goatpig committed Mar 18, 2014
1 parent 3d05d91 commit e4c45fe
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 6 deletions.
2 changes: 1 addition & 1 deletion armoryengine/ArmoryUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2962,7 +2962,7 @@ def hardcodeMask(secret, passphrase=None, ekey=None):

def hardcodeUnmask(secret, passphrase=None, ekey=None):
if not ekey:
ekey = applyKdf(passphrase)
ekey = hardcodeApplyKdf(passphrase)
return CryptoAES().DecryptCBC(secret, ekey, paramMap['IV'])

paramMap['FUNC_PWD'] = hardcodeCreateSecurePrintPassphrase
Expand Down
72 changes: 67 additions & 5 deletions qtdialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2576,7 +2576,34 @@ def __init__(self, wlt, parent=None, main=None):
stkMany = makeVertFrame([HLINE(), lblDescrMany, frmMid])
self.stackedImport.addWidget(stkMany)

lblSecurePrint = QLabel('<b>SecurePrint</b><br>' \
'When saving imported private keys with our paper backup system, ' \
'you have the option to encrypt them with SecurePrint.<br>If you backed ' \
'up keys come with a SecurePrint passphrase, input it below.')

self.chkUseSP = QCheckBox('Use SecurePrint')
self.edtSecurePrint = QLineEdit()
self.edtSecurePrint.setEnabled(False)
w, h = tightSizeStr(self.edtSecurePrint, 'X' * 10)
self.edtSecurePrint.setMaximumWidth(w)

def toggleSP():
if self.chkUseSP.isChecked():
self.edtSecurePrint.setEnabled(True)
else:
self.edtSecurePrint.setEnabled(False)

self.chkUseSP.stateChanged.connect(toggleSP)

loSP = QGridLayout()
loSP.setColumnStretch(0, 0)
loSP.addWidget(lblSecurePrint, 0, 0, 3, 60)
loSP.addWidget(self.chkUseSP, 4, 4, 1, 1)
loSP.addWidget(self.edtSecurePrint, 4, 5, 1, 1)

frmSP = QFrame()
frmSP.setFrameStyle(STYLE_SUNKEN)
frmSP.setLayout(loSP)


# Set up the Import/Sweep select frame
Expand Down Expand Up @@ -2647,6 +2674,7 @@ def __init__(self, wlt, parent=None, main=None):
layout = QVBoxLayout()
layout.addWidget(frmTop)
layout.addWidget(self.stackedImport)
layout.addWidget(frmSP)
layout.addWidget(frmWarn)
layout.addWidget(buttonbox)

Expand All @@ -2667,19 +2695,48 @@ def clickImportCount(self):

#############################################################################
def okayClicked(self):
pwd = None
if self.chkUseSP.isChecked():
SECPRINT = HardcodedKeyMaskParams()
pwd = str(self.edtSecurePrint.text()).strip()
self.edtSecurePrint.setText("")

if len(pwd) < 9:
QMessageBox.critical(self, 'Invalid Code', tr("""
You didn't enter a full SecurePrint\xe2\x84\xa2 code. This
code is needed to decrypt your backup. If this backup is
actually unencrypted and there is no code, then choose the
appropriate backup type from the drop-down box"""), QMessageBox.Ok)
return

if not SECPRINT['FUNC_CHKPWD'](pwd):
QMessageBox.critical(self, 'Bad Encryption Code', tr("""
The SecurePrint\xe2\x84\xa2 code you entered has an error
in it. Note that the code is case-sensitive. Please verify
you entered it correctly and try again."""), QMessageBox.Ok)
return

if self.radioImportOne.isChecked():
self.processUserString()
self.processUserString(pwd)
else:
self.processMultiKey()
self.processMultiKey(pwd)


#############################################################################
def processUserString(self):
def processUserString(self, pwd=None):
theStr = str(self.edtPrivData.text()).strip().replace(' ', '')
binKeyData, addr160, addrStr = '', '', ''

try:
binKeyData, keyType = parsePrivateKeyData(theStr)

if pwd:
SECPRINT = HardcodedKeyMaskParams()
maskKey = SECPRINT['FUNC_KDF'](pwd)
SBDbinKeyData = SECPRINT['FUNC_UNMASK'](SecureBinaryData(binKeyData), ekey=maskKey)
binKeyData = SBDbinKeyData.toBinStr()
SBDbinKeyData.destroy()

if binary_to_int(binKeyData, BIGENDIAN) >= SECP256K1_ORDER:
QMessageBox.critical(self, 'Invalid Private Key', \
'The private key you have entered is actually not valid '
Expand Down Expand Up @@ -2902,12 +2959,16 @@ def processUserString(self):


#############################################################################
def processMultiKey(self):
def processMultiKey(self, pwd=None):
thisWltID = self.wlt.uniqueIDB58

inputText = str(self.txtPrivBulk.toPlainText())
inputLines = [s.strip().replace(' ', '') for s in inputText.split('\n')]
binKeyData, addr160, addrStr = '', '', ''

if pwd:
SECPRINT = HardcodedKeyMaskParams()
maskKey = SECPRINT['FUNC_KDF'](pwd)

privKeyList = []
addrSet = set()
Expand All @@ -2919,6 +2980,8 @@ def processMultiKey(self):
try:
nLines += 1
binKeyData = SecureBinaryData(parsePrivateKeyData(lineend)[0])
if pwd: binKeyData = SECPRINT['FUNC_UNMASK'](binKeyData, ekey=maskKey)

addr160 = convertKeyDataToAddress(privKey=binKeyData.toBinStr())
if not addr160 in addrSet:
addrSet.add(addr160)
Expand Down Expand Up @@ -12397,7 +12460,6 @@ def doWltSelect():
wltSltQF.setLayout(layoutWltSelect)

layoutMgmt.addWidget(makeHorizFrame([lblDesc], STYLE_SUNKEN), 0,0, 2,4)
#layoutMgmt.addLayout(layoutWltSelect, 2, 0, 3, 4)
layoutMgmt.addWidget(wltSltQF, 2, 0, 3, 4)

self.rdbtnStripped = QRadioButton('')
Expand Down

0 comments on commit e4c45fe

Please sign in to comment.