Skip to content

Commit ac708c0

Browse files
committed
Add NEDB support
1 parent 2451eed commit ac708c0

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

src/datastore/NedbDataStore.ts

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ export class NeDBDataStore implements DataStore {
8787
}
8888
}
8989

90-
9190
public async runMigrations() {
9291
const config = await this.userStore.getRemoteUser("config");
9392
if (!config) {
@@ -579,6 +578,17 @@ export class NeDBDataStore implements DataStore {
579578
log.warn(`Failed to decrypt password for ${userId} ${domain}`, ex);
580579
}
581580
}
581+
if (configData.certificate && this.cryptoStore) {
582+
try {
583+
clientConfig.setCertificate({
584+
cert: configData.certificate.cert,
585+
key: this.cryptoStore.decryptLargeString(configData.certificate.key),
586+
})
587+
}
588+
catch (ex) {
589+
log.warn(`Failed to decrypt TLS key for ${userId} ${domain}`, ex);
590+
}
591+
}
582592
return clientConfig;
583593
}
584594

@@ -608,7 +618,24 @@ export class NeDBDataStore implements DataStore {
608618
// Store the encrypted password, ready for the db
609619
config.setPassword(encryptedPass);
610620
}
611-
userConfig[config.getDomain().replace(/\./g, "_")] = config.serialize();
621+
const domainCfg = userConfig[config.getDomain().replace(/\./g, "_")] = config.serialize();
622+
if (config.certificate) {
623+
if (!this.cryptoStore) {
624+
throw new Error(
625+
'Cannot store certificate'
626+
);
627+
}
628+
try {
629+
domainCfg.certificate = {
630+
cert: config.certificate.cert,
631+
key: this.cryptoStore.encryptLargeString(config.certificate.key),
632+
};
633+
}
634+
catch (ex) {
635+
log.warn(`Failed to encrypt TLS key for ${userId} ${config.getDomain()}`, ex);
636+
}
637+
}
638+
612639
user.set("client_config", userConfig);
613640
await this.userStore.setMatrixUser(user);
614641
}
@@ -675,6 +702,14 @@ export class NeDBDataStore implements DataStore {
675702
}
676703
}
677704

705+
public async removeClientCert(userId: string, domain: string): Promise<void> {
706+
const config = await this.getIrcClientConfig(userId, domain);
707+
if (config) {
708+
config.setCertificate();
709+
await this.storeIrcClientConfig(config);
710+
}
711+
}
712+
678713
public async getMatrixUserByUsername(domain: string, username: string): Promise<MatrixUser|undefined> {
679714
const domainKey = domain.replace(/\./g, "_");
680715
const matrixUsers = await this.userStore.getByMatrixData({

src/models/IrcClientConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export class IrcClientConfig {
7272
return this.config.password;
7373
}
7474

75-
public setCertificate(keypair: IrcClientCertKeypair) {
75+
public setCertificate(keypair?: IrcClientCertKeypair) {
7676
this.config.certificate = keypair;
7777
}
7878

0 commit comments

Comments
 (0)