Skip to content

Commit

Permalink
Merge pull request #138 from TrustNXT/bugfix/single-certificate-chain
Browse files Browse the repository at this point in the history
COSE: Support single-certificate x5chain
  • Loading branch information
cyraxx authored Oct 16, 2024
2 parents dcced04 + 33e0541 commit 28dfeaa
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/silly-candles-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@trustnxt/c2pa-ts': minor
---

Fix COSE deserilization failing for single-certificate chains
3 changes: 2 additions & 1 deletion src/cose/Signature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ export class Signature {

if (x5chainCandidates.length !== 1) throw new MalformedContentError('Malformed credentials');
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
const x5chain = x5chainCandidates[0]!;
let x5chain = x5chainCandidates[0]!;
if (!Array.isArray(x5chain)) x5chain = [x5chain];

try {
signature.certificate = new X509Certificate(x5chain[0]);
Expand Down
4 changes: 2 additions & 2 deletions src/cose/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export interface HeaderBucket {
[key: string]: unknown;
'1'?: number; // alg
'33'?: Uint8Array[]; // x5chain
x5chain?: Uint8Array[]; // legacy named x5chain
'33'?: Uint8Array[] | Uint8Array; // x5chain
x5chain?: Uint8Array[] | Uint8Array; // legacy named x5chain
sigTst?: {
tstTokens: {
val: Uint8Array;
Expand Down

0 comments on commit 28dfeaa

Please sign in to comment.