@@ -13,6 +13,8 @@ import { Url } from '../../js/common/core/common.js';
1313import { View } from '../../js/common/view.js' ;
1414import { Xss } from '../../js/common/platform/xss.js' ;
1515import { ContactStore } from '../../js/common/platform/store/contact-store.js' ;
16+ import { Buf } from '../../js/common/core/buf.js' ;
17+ import { OpenPGPKey } from '../../js/common/core/crypto/pgp/openpgp-key.js' ;
1618
1719// todo - this should use KeyImportUI for consistency.
1820View . run (
@@ -71,7 +73,7 @@ View.run(
7173 ! this . firstParsedPublicKey . usableForEncryption &&
7274 ! this . firstParsedPublicKey . usableForSigning
7375 ) {
74- this . showKeyNotUsableError ( ) ;
76+ await this . showKeyNotUsableError ( ) ;
7577 } else {
7678 let emailText = '' ;
7779 if ( this . parsedPublicKeys . length === 1 ) {
@@ -116,7 +118,7 @@ View.run(
116118 frameId : this . frameId ,
117119 } ) ;
118120 } else {
119- this . showKeyNotUsableError ( ) ;
121+ await this . showKeyNotUsableError ( ) ;
120122 }
121123 }
122124 this . sendResizeMsg ( ) ;
@@ -137,6 +139,25 @@ View.run(
137139 ) ;
138140 } ;
139141
142+ private getErrorText = async ( ) => {
143+ let errorStr = '' ;
144+ const { keys, errs } = await KeyUtil . readMany ( Buf . fromUtfStr ( this . armoredPubkey ) ) ;
145+ errorStr = errs . join ( '\n' ) ;
146+ for ( const key of keys ) {
147+ const errorMessage = await OpenPGPKey . checkPublicKeyError ( key ) ;
148+ if ( errorMessage ) {
149+ const match = new RegExp ( / E r r o r e n c r y p t i n g m e s s a g e : ( .+ ) $ / ) . exec ( errorMessage ) ;
150+ // remove `error: error encrypting message: part`, so error message will begin directly from error reason
151+ if ( match ) {
152+ errorStr += match [ 1 ] ;
153+ } else {
154+ errorStr += errorMessage ;
155+ }
156+ }
157+ }
158+ return errorStr ;
159+ } ;
160+
140161 private sendResizeMsg = ( ) => {
141162 const origHeight = $ ( '#pgp_block' ) . height ( ) ;
142163 if ( ! origHeight ) {
@@ -167,8 +188,9 @@ View.run(
167188 }
168189 } ;
169190
170- private showKeyNotUsableError = ( ) => {
191+ private showKeyNotUsableError = async ( ) => {
171192 $ ( '.error_container' ) . removeClass ( 'hidden' ) ;
193+ $ ( '.error_introduce_label' ) . html ( `This OpenPGP key is not usable.<br/><small>(${ await this . getErrorText ( ) } )</small>` ) ; // xss-escaped
172194 $ ( '.hide_if_error' ) . hide ( ) ;
173195 $ ( '.fingerprints, .add_contact, #manual_import_warning' ) . remove ( ) ;
174196 const email = this . firstParsedPublicKey ?. emails [ 0 ] ;
0 commit comments