@@ -569,12 +569,15 @@ export class NeDBDataStore implements DataStore {
569569 }
570570 const clientConfig = new IrcClientConfig ( userId , domain , configData ) ;
571571 const encryptedPass = clientConfig . getPassword ( ) ;
572- if ( encryptedPass ) {
573- if ( ! this . cryptoStore ) {
574- throw new Error ( `Cannot decrypt password of ${ userId } - no private key` ) ;
572+ if ( encryptedPass && this . cryptoStore ) {
573+ // NOT fatal, but really worrying.
574+ try {
575+ const decryptedPass = this . cryptoStore . decrypt ( encryptedPass ) ;
576+ clientConfig . setPassword ( decryptedPass ) ;
577+ }
578+ catch ( ex ) {
579+ log . warn ( `Failed to decrypt password for ${ userId } ${ domain } ` , ex ) ;
575580 }
576- const decryptedPass = this . cryptoStore . decrypt ( encryptedPass ) ;
577- clientConfig . setPassword ( decryptedPass ) ;
578581 }
579582 return clientConfig ;
580583 }
@@ -610,6 +613,29 @@ export class NeDBDataStore implements DataStore {
610613 await this . userStore . setMatrixUser ( user ) ;
611614 }
612615
616+ public async ensurePasskeyCanDecrypt ( ) : Promise < void > {
617+ if ( ! this . cryptoStore ) {
618+ return ;
619+ }
620+ const docs = await this . userStore . select < unknown , { id : string ; data : { client_config : ClientConfigMap } } > ( {
621+ type : "matrix" ,
622+ "data.client_config" : { $exists : true } ,
623+ } ) ;
624+ for ( const { id : userId , data } of docs ) {
625+ for ( const [ domain , clientConfig ] of Object . entries ( data . client_config ) ) {
626+ if ( clientConfig . password ) {
627+ try {
628+ this . cryptoStore . decrypt ( clientConfig . password ) ;
629+ }
630+ catch ( ex ) {
631+ log . error ( `Failed to decrypt password for ${ userId } on ${ domain } ` , ex ) ;
632+ throw Error ( 'Cannot decrypt user password, refusing to continue' , { cause : ex } ) ;
633+ }
634+ }
635+ }
636+ }
637+ }
638+
613639 public async getUserFeatures ( userId : string ) : Promise < UserFeatures > {
614640 const matrixUser = await this . userStore . getMatrixUser ( userId ) ;
615641 return matrixUser ? ( matrixUser . get ( "features" ) as UserFeatures || { } ) : { } ;
0 commit comments