Skip to content

Commit

Permalink
fix: Hmac Fixes (#196)
Browse files Browse the repository at this point in the history
Updated handling of hmac to use hkdf keys

Co-authored-by: Alex Risch <[email protected]>
  • Loading branch information
alexrisch and Alex Risch authored Mar 11, 2024
1 parent c67dfd2 commit 3ce9a4c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.xmtp.android.library

import android.util.Log
import com.google.protobuf.kotlin.toByteString
import com.google.protobuf.kotlin.toByteStringUtf8
import io.grpc.StatusException
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.channels.awaitClose
Expand Down Expand Up @@ -327,7 +326,7 @@ data class Conversations(
Crypto.deriveKey(
conversation.keyMaterial!!,
ByteArray(0),
info.toByteStringUtf8().toByteArray()
info.toByteArray(Charsets.UTF_8),
)
val hmacKeyData = HmacKeyData.newBuilder()
hmacKeyData.hmacKey = hmacKey.toByteString()
Expand Down
7 changes: 1 addition & 6 deletions library/src/main/java/org/xmtp/android/library/Crypto.kt
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,7 @@ class Crypto {
salt: ByteArray,
info: ByteArray,
): ByteArray {
val keySpec = SecretKeySpec(secret, "HmacSHA256")
val hmac = Mac.getInstance("HmacSHA256")
hmac.init(keySpec)
val derivedKey = hmac.doFinal(salt + info)

return derivedKey.copyOfRange(0, 32)
return Hkdf.computeHkdf("HMACSHA256", secret, salt, info, 32)
}

fun verifyHmacSignature(
Expand Down

0 comments on commit 3ce9a4c

Please sign in to comment.