Enhance encryption security with additional safeguards.

This commit is contained in:
glay
2024-12-08 23:28:59 +08:00
parent 26b9fa97cd
commit f5ae086d3c
6 changed files with 245 additions and 141 deletions

View File

@@ -32,14 +32,20 @@ async function getBedrockCredentials(
const [encryptedRegion, encryptedAccessKey, encryptedSecretKey] =
credentials.split(":");
// console.log("===========encryptedRegion",encryptedRegion);
// console.log("===========encryptedAccessKey",encryptedAccessKey);
// console.log("===========encryptedSecretKey",encryptedSecretKey);
if (!encryptedRegion || !encryptedAccessKey || !encryptedSecretKey) {
throw new Error("Invalid Authorization header format");
}
const encryptionKey = req.headers.get("XEncryptionKey") || "";
// console.log("===========encryptionKey",encryptionKey);
// Decrypt the credentials
awsRegion = decrypt(encryptedRegion, encryptionKey);
awsAccessKey = decrypt(encryptedAccessKey, encryptionKey);
awsSecretKey = decrypt(encryptedSecretKey, encryptionKey);
[awsRegion, awsAccessKey, awsSecretKey] = await Promise.all([
decrypt(encryptedRegion, encryptionKey),
decrypt(encryptedAccessKey, encryptionKey),
decrypt(encryptedSecretKey, encryptionKey),
]);
if (!awsRegion || !awsAccessKey || !awsSecretKey) {
throw new Error(