@ -20,27 +20,29 @@ function loadKeyFromLocalStorage(callback) {
}
$ ( "#lockstatus" ) . css ( "display" , "none" ) ;
if ( ! inStorage ( "signingkey" ) || getStorage ( "signingkey" ) == "undefined" ) {
var pass = prompt ( "Generating a new signing key (might take a while, be patient). Enter a password to protect it. You'll need to save this password somewhere safe; it cannot be recovered." ) ;
generatePrivateKey ( getStorage ( "notary_name" ) + " <null@null.com>" , pass , function ( key ) {
if ( typeof key == "undefined" ) {
callback ( "Could not generate key." , false ) ;
return ;
}
keymgr = key ;
keyring . add _key _manager ( keymgr ) ;
setStorage ( "signingkey" , keymgr . armored _pgp _private ) ;
callback ( "Signing key generated." , true ) ;
showPasswordPrompt ( "Generating a new signing key (might take a while, be patient). Enter a password to protect it. You'll need to save this password somewhere safe; it cannot be recovered." , function ( pass ) {
generatePrivateKey ( getStorage ( "notary_name" ) + " <null@null.com>" , pass , function ( key ) {
if ( typeof key == "undefined" ) {
callback ( "Could not generate key." , false ) ;
return ;
}
keymgr = key ;
keyring . add _key _manager ( keymgr ) ;
setStorage ( "signingkey" , keymgr . armored _pgp _private ) ;
callback ( "Signing key generated." , true ) ;
} ) ;
} ) ;
} else {
var pass = prompt ( "Enter password to unlock signing key:" ) ;
loadPrivateKey ( getStorage ( "signingkey" ) , pass , function ( key ) {
if ( typeof key == "undefined" ) {
callback ( "Could not unlock key. Password is probably incorrect." , false ) ;
return ;
}
keymgr = key ;
keyring . add _key _manager ( keymgr ) ;
callback ( "Signing key unlocked." , true ) ;
showPasswordPrompt ( "Enter password to unlock signing key:" , function ( pass ) {
loadPrivateKey ( getStorage ( "signingkey" ) , pass , function ( key ) {
if ( typeof key == "undefined" ) {
callback ( "Could not unlock key. Password is probably incorrect." , false ) ;
return ;
}
keymgr = key ;
keyring . add _key _manager ( keymgr ) ;
callback ( "Signing key unlocked." , true ) ;
} ) ;
} ) ;
}
}
@ -201,42 +203,44 @@ function exportPublicKey() {
}
function exportPrivateKey ( ) {
var pass = prompt ( "Enter password for private key:" ) ;
const savepriv = function ( key ) {
var pass2 = prompt ( "Enter a password to protect the key backup:" ) ;
openSaveFileDialog ( function ( path ) {
key . export _pgp _private ( {
passphrase : pass2
} , function ( err , pgp _private ) {
if ( err ) {
showAlert ( "Something went wrong." ) ;
showPasswordPrompt ( "Enter password for private key:" , function ( pass ) {
const savepriv = function ( key ) {
showPasswordPrompt ( "Enter a password to protect the key backup:" , function ( pass2 ) {
openSaveFileDialog ( function ( path ) {
key . export _pgp _private ( {
passphrase : pass2
} , function ( err , pgp _private ) {
if ( err ) {
showAlert ( "Something went wrong." ) ;
} else {
writeToFile ( path , pgp _private ) ;
}
} ) ;
} , "private-key.asc" , ".asc" ) ;
} ) ;
}
kbpgp . KeyManager . import _from _armored _pgp ( {
armored : getStorage ( "signingkey" )
} , function ( err , key ) {
if ( ! err ) {
if ( key . is _pgp _locked ( ) ) {
key . unlock _pgp ( {
passphrase : pass
} , function ( err ) {
if ( ! err ) {
savepriv ( key ) ;
} else {
showAlert ( "Could not unlock key. Password is probably incorrect." ) ;
}
} ) ;
} else {
writeToFile ( path , pgp _private ) ;
console . log ( "Loaded private key w/o passphrase" ) ;
savepriv ( key ) ;
}
} ) ;
} , "private-key.asc" , ".asc" ) ;
}
kbpgp . KeyManager . import _from _armored _pgp ( {
armored : getStorage ( "signingkey" )
} , function ( err , key ) {
if ( ! err ) {
if ( key . is _pgp _locked ( ) ) {
key . unlock _pgp ( {
passphrase : pass
} , function ( err ) {
if ( ! err ) {
savepriv ( key ) ;
} else {
showAlert ( "Could not unlock key. Password is probably incorrect." ) ;
}
} ) ;
} else {
console . log ( "Loaded private key w/o passphrase" ) ;
savepriv ( key ) ;
showAlert ( "Could not unlock key: " + err ) ;
}
} else {
showAlert ( "Could not unlock key: " + err ) ;
}
} ) ;
} ) ;
}
@ -249,15 +253,16 @@ function importPrivateKey() {
keymgr = null ;
openFileDialog ( function ( path ) {
var keyfile = getFileAsString ( path ) ;
var pass = prompt ( "Enter password for imported key (password was set when exported):" ) ;
loadPrivateKey ( keyfile , pass , function ( key ) {
if ( typeof key == "undefined" ) {
showAlert ( "Could not import key. Password is probably incorrect." ) ;
return ;
}
keymgr = key ;
setStorage ( "signingkey" , keymgr . armored _pgp _private ) ;
showAlert ( "Private key imported." ) ;
showPasswordPrompt ( "Enter password for imported key (password was set when exported):" , function ( pass ) {
loadPrivateKey ( keyfile , pass , function ( key ) {
if ( typeof key == "undefined" ) {
showAlert ( "Could not import key. Password is probably incorrect." ) ;
return ;
}
keymgr = key ;
setStorage ( "signingkey" , keymgr . armored _pgp _private ) ;
showAlert ( "Private key imported." ) ;
} ) ;
} ) ;
} , ".asc" ) ;
}