mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-15 09:11:21 +10:00
ability to fetch client certs for p2p
This commit is contained in:
@ -5,9 +5,13 @@ import { CertificateBundle } from "./ca";
|
||||
export type CertificateStore = {
|
||||
store(name: string, data: CertificateBundle): Promise<void>;
|
||||
fetch(name: string): Promise<CertificateBundle | undefined>;
|
||||
blacklistCertificate(name: string): Promise<void>;
|
||||
checkBlacklistCertificate(name: string): Promise<boolean>;
|
||||
};
|
||||
|
||||
export const fsCertificateStore = (base: string) => {
|
||||
const blacklist = path.join(base, ".blacklist");
|
||||
fs.mkdirSync(blacklist, { recursive: true });
|
||||
const store: CertificateStore = {
|
||||
async store(name: string, data: CertificateBundle) {
|
||||
const filepath = path.join(base, name);
|
||||
@ -18,6 +22,14 @@ export const fsCertificateStore = (base: string) => {
|
||||
if (!fs.existsSync(filepath)) return undefined;
|
||||
return JSON.parse(fs.readFileSync(filepath, "utf-8"));
|
||||
},
|
||||
async blacklistCertificate(name: string) {
|
||||
const filepath = path.join(blacklist, name);
|
||||
fs.writeFileSync(filepath, Buffer.from([]));
|
||||
},
|
||||
async checkBlacklistCertificate(name: string): Promise<boolean> {
|
||||
const filepath = path.join(blacklist, name);
|
||||
return fs.existsSync(filepath);
|
||||
},
|
||||
};
|
||||
return store;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user