Skip to content

Commit

Permalink
Update access.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
dmihalcik-virtru committed Dec 4, 2024
1 parent 4016252 commit ebf24bc
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions lib/src/access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,24 @@ export async function fetchKasPubKey(
}
// Logs insecure KAS. Secure is enforced in constructor
validateSecureUrl(kasEndpoint);
const infoStatic = { url: kasEndpoint, algorithm: algorithm || 'rsa:2048' };

const pkUrlV2 = new URL('/v2/kas_public_key?v=2', kasEndpoint);
if (!pkUrlV2) {
throw new ConfigurationError(`KAS definition invalid: [${kasEndpoint}]`);
// Parse kasEndpoint to URL, then append to its path and update its query parameters
let pkUrlV2: URL;
try {
pkUrlV2 = new URL(kasEndpoint);
} catch (e) {
throw new ConfigurationError(`KAS definition invalid: [${kasEndpoint}]`, e);
}
if (!pkUrlV2.pathname.endsWith('kas_public_key')) {
if (!pkUrlV2.pathname.endsWith('/')) {
pkUrlV2.pathname += '/';
}
pkUrlV2.pathname += 'v2/kas_public_key';
}
pkUrlV2.searchParams.set('algorithm', algorithm || 'rsa:2048');
if (!pkUrlV2.searchParams.get('v')) {
pkUrlV2.searchParams.set('v', '2');
}
pkUrlV2.searchParams.set('algorithm', infoStatic.algorithm);

let kasPubKeyResponseV2: Response;
try {
Expand Down

0 comments on commit ebf24bc

Please sign in to comment.