@@ -57,7 +57,7 @@ interface RoomRecord {
5757export class PgDataStore implements DataStore , ProvisioningStore {
5858 private serverMappings : { [ domain : string ] : IrcServer } = { } ;
5959
60- public static readonly LATEST_SCHEMA = 9 ;
60+ public static readonly LATEST_SCHEMA = 10 ;
6161 private pgPool : Pool ;
6262 private hasEnded = false ;
6363 private cryptoStore ?: StringCrypto ;
@@ -505,7 +505,7 @@ export class PgDataStore implements DataStore, ProvisioningStore {
505505
506506 public async getIrcClientConfig ( userId : string , domain : string ) : Promise < IrcClientConfig | null > {
507507 const res = await this . pgPool . query (
508- "SELECT config, password FROM client_config WHERE user_id = $1 and domain = $2" ,
508+ "SELECT config, password, cert, key FROM client_config WHERE user_id = $1 and domain = $2" ,
509509 [
510510 userId ,
511511 domain
@@ -524,6 +524,23 @@ export class PgDataStore implements DataStore, ProvisioningStore {
524524 log . warn ( `Failed to decrypt password for ${ userId } ${ domain } ` , ex ) ;
525525 }
526526 }
527+ config . certificate = {
528+ cert : row . cert ,
529+ key : row . key ,
530+ } ;
531+ // TODO: Testing
532+ if ( row . cert && row . key && this . cryptoStore ) {
533+ // NOT fatal, but really worrying.
534+ try {
535+ config . certificate = {
536+ cert : this . cryptoStore . decrypt ( row . cert ) ,
537+ key : this . cryptoStore . decrypt ( row . key )
538+ } ;
539+ }
540+ catch ( ex ) {
541+ log . warn ( `Failed to decrypt certificate for ${ userId } ${ domain } ` , ex ) ;
542+ }
543+ }
527544 return new IrcClientConfig ( userId , domain , config ) ;
528545 }
529546
@@ -536,14 +553,23 @@ export class PgDataStore implements DataStore, ProvisioningStore {
536553 // We need to make sure we have a matrix user in the store.
537554 await this . pgPool . query ( "INSERT INTO matrix_users VALUES ($1, NULL) ON CONFLICT DO NOTHING" , [ userId ] ) ;
538555 let password = config . getPassword ( ) ;
556+ const cert : { cert ?: string , key ?: string } = { } ;
557+
558+ // This implies without a cryptostore these will be stored plain.
539559 if ( password && this . cryptoStore ) {
540560 password = this . cryptoStore . encrypt ( password ) ;
541561 }
562+ if ( config . certificate && this . cryptoStore ) {
563+ cert . cert = this . cryptoStore . encrypt ( config . certificate . cert ) ;
564+ cert . key = this . cryptoStore . encrypt ( config . certificate . key ) ;
565+ }
542566 const parameters = {
543567 user_id : userId ,
544568 domain : config . getDomain ( ) ,
545569 // either use the decrypted password, or whatever is stored already.
546570 password,
571+ cert : cert ?. cert ,
572+ key : cert ?. key ,
547573 config : JSON . stringify ( config . serialize ( true ) ) ,
548574 } ;
549575 const statement = PgDataStore . BuildUpsertStatement (
0 commit comments