(armored, keyringId)
| 134 | } |
| 135 | |
| 136 | async decrypt(armored, keyringId) { |
| 137 | this.ports.dDialog.emit('waiting', {waiting: true}); |
| 138 | try { |
| 139 | const {data, signatures} = await model.decryptMessage({ |
| 140 | message: this.message, |
| 141 | armored, |
| 142 | keyringId, |
| 143 | unlockKey: this.unlockKey.bind(this), |
| 144 | senderAddress: this.sender, |
| 145 | uiLogSource: 'security_log_viewer', |
| 146 | lookupKey: keyringId ? rotation => lookupKey({keyringId, email: this.sender, rotation}) : undefined |
| 147 | }); |
| 148 | this.signatures = signatures; |
| 149 | if (this.ports.dDialog && signatures) { |
| 150 | this.ports.dDialog.emit('signature-verification', {signers: signatures}); |
| 151 | } |
| 152 | const {message, attachments} = await parseMessage(data, 'html'); |
| 153 | this.ports.dDialog.emit('decrypted-message', {message}); |
| 154 | for (const attachment of attachments) { |
| 155 | this.ports.dDialog.emit('add-decrypted-attachment', {attachment}); |
| 156 | } |
| 157 | if (this.ports.decryptCont) { |
| 158 | this.ports.decryptCont.emit('decrypt-done'); |
| 159 | } |
| 160 | this.ports.dDialog.emit('waiting', {waiting: false, unlock: true}); |
| 161 | } catch (error) { |
| 162 | if (error.code === 'PWD_DIALOG_CANCEL') { |
| 163 | if (this.hasPort('Frame')) { |
| 164 | return this.dialogCancel(); |
| 165 | } |
| 166 | } |
| 167 | if (this.ports.dDialog) { |
| 168 | this.ports.dDialog.emit('error-message', {error: error.message}); |
| 169 | } |
| 170 | if (this.ports.decryptCont) { |
| 171 | let err = error; |
| 172 | switch (error.code) { |
| 173 | case 'ARMOR_PARSE_ERROR': |
| 174 | case 'PWD_DIALOG_CANCEL': |
| 175 | case 'NO_KEY_FOUND': |
| 176 | err = mapError(err); |
| 177 | break; |
| 178 | default: |
| 179 | err = { |
| 180 | // don't expose internal errors to API |
| 181 | code: 'DECRYPT_ERROR', |
| 182 | message: 'Generic decrypt error' |
| 183 | }; |
| 184 | } |
| 185 | this.ports.decryptCont.emit('error-message', {error: err}); |
| 186 | } |
| 187 | this.ports.dDialog.emit('waiting', {waiting: false}); |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | async unlockKey({key, message}) { |
| 192 | const pwdControl = await createController('pwdDialog'); |
no test coverage detected