Skip to content

Commit

Permalink
fail better
Browse files Browse the repository at this point in the history
  • Loading branch information
dmihalcik-virtru committed Jan 22, 2025
1 parent b820265 commit c880c6b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
7 changes: 2 additions & 5 deletions cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,11 +562,8 @@ export const handleArgs = (args: string[]) => {
log('DEBUG', `About to TDF3 decrypt [${argv.file}]`);
const ct = await client.read(await parseReadOptions(argv));
const destination = argv.output ? createWriteStream(argv.output) : process.stdout;
try {
await ct.pipeTo(Writable.toWeb(destination));
} catch (e) {
log('ERROR', `Failed to pipe to destination stream: ${e}`);
}
await ct.pipeTo(Writable.toWeb(destination));

const lastRequest = authProvider.requestLog[authProvider.requestLog.length - 1];
log('SILLY', `last request is ${JSON.stringify(lastRequest)}`);
let accessToken = null;
Expand Down
16 changes: 8 additions & 8 deletions lib/tdf3/src/tdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -922,14 +922,6 @@ export async function readStream(cfg: DecryptConfiguration) {
integrityAlgorithm
);

const rootSig = isLegacyTDF
? base64.encode(hex.encodeArrayBuffer(payloadSig))
: base64.encodeArrayBuffer(payloadSig);

if (manifest.encryptionInformation.integrityInformation.rootSignature.sig !== rootSig) {
throw new IntegrityError('Failed integrity check on root signature');
}

if (!cfg.noVerifyAssertions) {
for (const assertion of manifest.assertions || []) {
// Create a default assertion key
Expand All @@ -948,6 +940,14 @@ export async function readStream(cfg: DecryptConfiguration) {
}
}

const rootSig = isLegacyTDF
? base64.encode(hex.encodeArrayBuffer(payloadSig))
: base64.encodeArrayBuffer(payloadSig);

if (manifest.encryptionInformation.integrityInformation.rootSignature.sig !== rootSig) {
throw new IntegrityError('Failed integrity check on root signature');
}

let mapOfRequestsOffset = 0;
const chunkMap = new Map(
segments.map(({ hash, encryptedSegmentSize = encryptedSegmentSizeDefault, segmentSize = segmentSizeDefault }) => {
Expand Down

0 comments on commit c880c6b

Please sign in to comment.