feat(master_key): download master key file

This commit is contained in:
charlesgauthereau
2026-02-18 19:07:14 +01:00
parent ebe5c63a7b
commit 833872603a
6 changed files with 74 additions and 67 deletions
+21 -2
View File
@@ -1,3 +1,4 @@
"use server"
import fs from "node:fs";
import {env} from "@/env.mjs";
import path from "path";
@@ -6,7 +7,7 @@ import path from "path";
/**
* Get Public server key content
*/
export function getPublicServerKeyContent() {
export async function getPublicServerKeyContent() {
try {
const keyPath = path.join(env.PRIVATE_PATH, '/keys/server_public.pem')
return fs.readFileSync(keyPath, "utf8");
@@ -23,7 +24,7 @@ export function getPublicServerKeyContent() {
/**
* Get Master server key
*/
export function getMasterServerKeyContent() {
export async function getMasterServerKeyContent() {
try {
const keyPath = path.join(env.PRIVATE_PATH, '/keys/master_key.bin')
return fs.readFileSync(keyPath);
@@ -35,3 +36,21 @@ export function getMasterServerKeyContent() {
};
}
}
export async function downloadMasterKeyAction() {
try {
const keyPath = path.join(env.PRIVATE_PATH, "keys/master_key.bin");
const fileBuffer = fs.readFileSync(keyPath);
return {
success: true,
data: fileBuffer.toString("base64"),
};
} catch (error) {
return {
success: false,
message: "Unable to download master key",
};
}
}