Skip to content

Commit

Permalink
- anonymize COSE content according to debug mode rules; (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
MykhailoNester authored Sep 3, 2021
1 parent a32bffc commit b76bbd2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ import dgca.verifier.app.decoder.model.VerificationResult
interface CoseService {

fun decode(input: ByteArray, verificationResult: VerificationResult): CoseData?

fun anonymizeCose(input: ByteArray): ByteArray?
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package dgca.verifier.app.decoder.cose

import COSE.HeaderKeys
import com.google.common.primitives.Bytes
import com.upokecenter.cbor.CBORObject
import dgca.verifier.app.decoder.model.CoseData
import dgca.verifier.app.decoder.model.VerificationResult
Expand Down Expand Up @@ -60,4 +61,35 @@ class DefaultCoseService : CoseService {
unprotectedHeader.get(key)
}
}

override fun anonymizeCose(input: ByteArray): ByteArray? {
return try {
val messageObject = CBORObject.DecodeFromBytes(input)

val content = messageObject[2].EncodeToBytes()
val index = Bytes.indexOf(input, content)

val newArray = ByteArray(input.size)

val anonymize = ByteArray(content.size)
anonymize.forEachIndexed { i, _ ->
anonymize[i] = 0x58
}

System.arraycopy(input, 0, newArray, 0, index)
System.arraycopy(anonymize, 0, newArray, index, anonymize.size)
System.arraycopy(
input,
index + anonymize.size,
newArray,
index + anonymize.size,
input.size - (anonymize.size + index)
)

newArray

} catch (e: Throwable) {
null
}
}
}

0 comments on commit b76bbd2

Please sign in to comment.