Skip to content

Commit 1f4f0cd

Browse files
committed
DocumentGenerator: Don't include payload in DeviceSigned COSE_Sign1.
ISO/IEC 18013-5:2021 clause 9.1.3.4 specifically said to not do that. This bug was introduced in PR #482 when switching to the new CBOR and COSE libraries. Fix this. Also add a new check to Cose.coseSign1Check() for this. This check will trigger a unit-test failure if the fix mentioned in the previous paragraph isn't applied. Test: New test and all unit tests pass. Signed-off-by: David Zeuthen <zeuthen@google.com>
1 parent aafced9 commit 1f4f0cd

File tree

2 files changed

+7
-1
lines changed
  • identity/src/main/java/com/android/identity/cose
  • identity-mdoc/src/main/java/com/android/identity/mdoc/response

2 files changed

+7
-1
lines changed

identity-mdoc/src/main/java/com/android/identity/mdoc/response/DocumentGenerator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class DocumentGenerator
117117
secureArea,
118118
keyAlias,
119119
deviceAuthenticationBytes,
120-
true,
120+
false,
121121
signatureAlgorithm,
122122
mapOf(
123123
Pair(

identity/src/main/java/com/android/identity/cose/Cose.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ object Cose {
199199
* @param detachedData detached data, if any.
200200
* @param signature the COSE_Sign1 object.
201201
* @param signatureAlgorithm the signature algorithm to use.
202+
* @throws IllegalArgumentException if not exactly one of `detachedData` and
203+
* `signature.payload` are non-`null`.
202204
* @return whether the signature is valid and was made with the private key corresponding to the
203205
* given public key.
204206
*/
@@ -209,6 +211,10 @@ object Cose {
209211
signature: CoseSign1,
210212
signatureAlgorithm: Algorithm
211213
): Boolean {
214+
require(
215+
(detachedData != null && signature.payload == null) ||
216+
(detachedData == null && signature.payload != null)
217+
)
212218
val encodedProtectedHeaders =
213219
if (signature.protectedHeaders.isNotEmpty()) {
214220
val phb = CborMap.builder()

0 commit comments

Comments
 (0)