@@ -417,7 +417,7 @@ private static byte[] calculateSignature(byte[] data, byte[] secret, Config.Inte
417417 public TDFObject createTDF (InputStream payload ,
418418 OutputStream outputStream ,
419419 Config .TDFConfig tdfConfig , SDK .KAS kas , AttributesServiceFutureStub attrService )
420- throws IOException , JOSEException , AutoConfigureException , InterruptedException , ExecutionException {
420+ throws IOException , JOSEException , AutoConfigureException , InterruptedException , ExecutionException , DecoderException {
421421
422422 if (tdfConfig .autoconfigure ) {
423423 Autoconfigure .Granter granter = new Autoconfigure .Granter (new ArrayList <>());
@@ -532,7 +532,8 @@ public TDFObject createTDF(InputStream payload,
532532 assertion .statement = assertionConfig .statement ;
533533 assertion .appliesToState = assertionConfig .appliesToState .toString ();
534534
535- var assertionHash = assertion .hash ();
535+ var assertionHashAsHex = assertion .hash ();
536+ var assertionHash = Hex .decodeHex (assertionHashAsHex );
536537 byte [] completeHash = new byte [aggregateHash .size () + assertionHash .length ];
537538 System .arraycopy (aggregateHash .toByteArray (), 0 , completeHash , 0 , aggregateHash .size ());
538539 System .arraycopy (assertionHash , 0 , completeHash , aggregateHash .size (), assertionHash .length );
@@ -545,7 +546,7 @@ public TDFObject createTDF(InputStream payload,
545546 assertionSigningKey = assertionConfig .assertionKey ;
546547 }
547548 var hashValues = new Manifest .Assertion .HashValues (
548- Base64 . getEncoder (). encodeToString ( assertionHash ) ,
549+ assertionHashAsHex ,
549550 encodedHash
550551 );
551552 assertion .sign (hashValues , assertionSigningKey );
@@ -707,7 +708,7 @@ public Reader loadTDF(SeekableByteChannel tdf, SDK.KAS kas,
707708 throw new SegmentSizeMismatch ("mismatch encrypted segment size in manifest" );
708709 }
709710
710- var aggregateSignatureBytes = aggregateHash .toByteArray ();
711+ var aggregateHashByteArrayBytes = aggregateHash .toByteArray ();
711712 // Validate assertions
712713 for (var assertion : manifest .assertions ) {
713714 // Skip assertion verification if disabled
@@ -726,22 +727,17 @@ public Reader loadTDF(SeekableByteChannel tdf, SDK.KAS kas,
726727 }
727728
728729 var hashValues = assertion .verify (assertionKey );
729- var assertionAsJson = gson .toJson (assertion );
730- JsonCanonicalizer jc = new JsonCanonicalizer (assertionAsJson );
731- var hashOfAssertion = digest .digest (jc .getEncodedUTF8 ());
732- var assertionCompare = isLegacyTdf ? Hex .encodeHexString (hashOfAssertion ) : Base64 .getEncoder ().encodeToString (hashOfAssertion );
730+ var hashOfAssertionAsHex = assertion .hash ();
733731
734- if (!Objects .equals (assertionCompare , hashValues .getAssertionHash ())) {
732+ if (!Objects .equals (hashOfAssertionAsHex , hashValues .getAssertionHash ())) {
735733 throw new AssertionException ("assertion hash mismatch" , assertion .id );
736734 }
737735
738- if (isLegacyTdf ) {
739- hashOfAssertion = Hex .encodeHexString (hashOfAssertion ).getBytes ();
740- }
736+ var hashOfAssertion = Hex .decodeHex (hashOfAssertionAsHex );
741737
742- var signature = new byte [aggregateSignatureBytes .length + hashOfAssertion .length ];
743- System .arraycopy (aggregateSignatureBytes , 0 , signature , 0 , aggregateSignatureBytes .length );
744- System .arraycopy (hashOfAssertion , 0 , signature , aggregateSignatureBytes .length , hashOfAssertion .length );
738+ var signature = new byte [aggregateHashByteArrayBytes .length + hashOfAssertion .length ];
739+ System .arraycopy (aggregateHashByteArrayBytes , 0 , signature , 0 , aggregateHashByteArrayBytes .length );
740+ System .arraycopy (hashOfAssertion , 0 , signature , aggregateHashByteArrayBytes .length , hashOfAssertion .length );
745741 var encodeSignature = Base64 .getEncoder ().encodeToString (signature );
746742
747743 if (!Objects .equals (encodeSignature , hashValues .getSignature ())) {
0 commit comments