Mailspring/internal_packages/keybase/lib/key-manager.cjsx
Logan Davis 40f9e5172a pgp-plugin update (#2534)
* Fix private key email-adder, add "no private key" error

The decrypt UI is seriously confusing some people. This commit
adds an error message that should at least stop them from trying
to decrypt a message without a private key to speak of. Also,
there was a dumb hardcoded true in validAddress.

* Adds incorrect passphrase notification; enables carriage return for popover

The passphrase popover was woefully inadequate. It didn't tell users
when they had the wrong password - it just closed without saying anything -
and you couldn't even use carriage return to submit the password.
This commit fixes those mistakes by buffing out passphrase-popover.cjsx.

* Adds private key popover to decrypt button

The decrypt UI was confusing and didn't provide the user with
an option to get a key imported from the message view. This
mondo commit adds an entirely new popover so that the user
never again will be forced to go to the preferences page.

* Adds more forgiving encrypted block parsing

* Overhauls decryption error handling

The decrypt UI didn't clearly communicate error messages from the
failure in PGPKeyStore.decrypt up to the user. This commit adds
nice error surfacing as well as some pretty colors.

* Fix encrypt modal key miscount error via getKeyContents coercion

On Linux and Windows, fs.watch double-triggers on some actions in
the key folder, for reasons that aren't super clear. This was causing
issues where the encrypt modal would report not having a key loaded
even though the key was totally loaded and saved. This commit sort
of kludgily forces the modal to run getKeyContents for every key
it has saved right before it returns them all. This would probably
be better fixed with a refactor the the PGP Keystore.

* remember to close popover, d'oh

* patch key picker modal styling for Linux and Windows

* response to review
2016-07-08 11:29:10 -07:00

98 lines
3.1 KiB
CoffeeScript
Executable file

{Utils, React, Actions} = require 'nylas-exports'
PGPKeyStore = require './pgp-key-store'
KeybaseUser = require './keybase-user'
PassphrasePopover = require './passphrase-popover'
kb = require './keybase'
_ = require 'underscore'
pgp = require 'kbpgp'
fs = require 'fs'
module.exports =
class KeyManager extends React.Component
@displayName: 'KeyManager'
@propTypes:
pubKeys: React.PropTypes.array.isRequired
privKeys: React.PropTypes.array.isRequired
constructor: (props) ->
super(props)
_exportPopoverDone: (passphrase, identity) =>
# check the passphrase before opening the save dialog
fs.readFile(identity.keyPath, (err, data) =>
pgp.KeyManager.import_from_armored_pgp {
armored: data
}, (err, km) =>
if err
console.warn err
else
km.unlock_pgp { passphrase: passphrase }, (err) =>
if err
PGPKeyStore._displayError(err)
else
PGPKeyStore.exportKey({identity: identity, passphrase: passphrase})
)
_exportPrivateKey: (identity, event) =>
popoverTarget = event.target.getBoundingClientRect()
Actions.openPopover(
<PassphrasePopover identity={identity} addresses={identity.addresses} onPopoverDone={ @_exportPopoverDone } />,
{originRect: popoverTarget, direction: 'left'}
)
render: ->
{pubKeys, privKeys} = @props
pubKeys = pubKeys.map (identity) =>
deleteButton = (<button title="Delete Public" className="btn btn-toolbar btn-danger" onClick={ => PGPKeyStore.deleteKey(identity) } ref="button">
Delete Key
</button>
)
exportButton = (<button title="Export Public" className="btn btn-toolbar" onClick={ => PGPKeyStore.exportKey({identity: identity}) } ref="button">
Export Key
</button>
)
actionButton = (<div className="key-actions">
{exportButton}
{deleteButton}
</div>
)
return <KeybaseUser profile={identity} key={identity.clientId} actionButton={actionButton}/>
privKeys = privKeys.map (identity) =>
deleteButton = (<button title="Delete Private" className="btn btn-toolbar btn-danger" onClick={ => PGPKeyStore.deleteKey(identity) } ref="button">
Delete Key
</button>
)
exportButton = (<button title="Export Private" className="btn btn-toolbar" onClick={ (event) => @_exportPrivateKey(identity, event) } ref="button">
Export Key
</button>
)
actionButton = (<div className="key-actions">
{exportButton}
{deleteButton}
</div>
)
return <KeybaseUser profile={identity} key={identity.clientId} actionButton={actionButton}/>
<div className="key-manager">
<div className="line-w-label">
<div className="border"></div>
<div className="title-text">Saved Public Keys</div>
<div className="border"></div>
</div>
<div>
{ pubKeys }
</div>
<div className="line-w-label">
<div className="border"></div>
<div className="title-text">Saved Private Keys</div>
<div className="border"></div>
</div>
<div>
{ privKeys }
</div>
</div>