Skip to content

Commit

Permalink
Presentation Activity (#459)
Browse files Browse the repository at this point in the history
Adding PresentationActivity to wallet, which will appear on-screen
with related presentation UI once the NfcEngagementHandler starts the
activity. This addition allows for in-person presentation with NFC
engagement.

Tested manually with 0/1/2 active credentials in wallet.

Signed-off-by: Suzanna Jiwani <[email protected]>
Signed-off-by: Peter Sorotokin <[email protected]>
  • Loading branch information
suzannajiwani authored and sorotokin committed Feb 16, 2024
1 parent a8311ba commit e06d834
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ import com.android.identity.android.mdoc.engagement.NfcEngagementHelper
import com.android.identity.android.mdoc.transport.DataTransport
import com.android.identity.android.mdoc.transport.DataTransportOptions
import com.android.identity.internal.Util
<<<<<<< HEAD
import com.android.identity.securearea.EcCurve
=======
>>>>>>> 406e896 (Presentation Activity (#459))
import com.android.identity.securearea.SecureArea
import com.android.identity.util.Logger

Expand All @@ -38,7 +41,11 @@ class NfcEngagementHandler : HostApduService() {

private var engagementHelper: NfcEngagementHelper? = null

<<<<<<< HEAD
private val eDeviceKeyCurve = EcCurve.P256
=======
private val eDeviceKeyCurve = SecureArea.EC_CURVE_P256
>>>>>>> 406e896 (Presentation Activity (#459))
private val eDeviceKeyPair by lazy {
Util.createEphemeralKeyPair(eDeviceKeyCurve)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.MutableLiveData
import com.android.identity.android.mdoc.deviceretrieval.DeviceRetrievalHelper
import com.android.identity.android.mdoc.transport.DataTransport
<<<<<<< HEAD
import com.android.identity.credential.AuthenticationKey
=======
>>>>>>> 406e896 (Presentation Activity (#459))
import com.android.identity.credential.Credential
import com.android.identity.credential.NameSpacedData
import com.android.identity.internal.Util
Expand All @@ -54,8 +57,11 @@ import com.android.identity.mdoc.request.DeviceRequestParser
import com.android.identity.mdoc.response.DeviceResponseGenerator
import com.android.identity.mdoc.response.DocumentGenerator
import com.android.identity.mdoc.util.MdocUtil
<<<<<<< HEAD
import com.android.identity.securearea.Algorithm
import com.android.identity.securearea.EcCurve
=======
>>>>>>> 406e896 (Presentation Activity (#459))
import com.android.identity.securearea.SecureArea
import com.android.identity.util.Constants
import com.android.identity.util.Logger
Expand All @@ -70,15 +76,24 @@ import java.util.OptionalLong
class PresentationActivity : ComponentActivity() {
companion object {
private const val TAG = "PresentationActivity"
<<<<<<< HEAD
private var transport: DataTransport?
private var handover: ByteArray?
private var eDeviceKeyCurve: EcCurve?
private var eDeviceKeyPair: KeyPair?
private var deviceEngagement: ByteArray?
=======
private var mTransport: DataTransport?
private var mHandover: ByteArray?
private var mEDeviceKeyCurve: Int? = null
private var mEDeviceKeyPair: KeyPair?
private var mDeviceEngagement: ByteArray?
>>>>>>> 406e896 (Presentation Activity (#459))
private var state = MutableLiveData<State>()

init {
state.value = State.NOT_CONNECTED
<<<<<<< HEAD
transport = null
handover = null
eDeviceKeyCurve = null
Expand All @@ -94,6 +109,22 @@ class PresentationActivity : ComponentActivity() {
this.eDeviceKeyCurve = eDeviceKeyCurve
this.eDeviceKeyPair = eDeviceKeyPair
this.deviceEngagement = deviceEngagement
=======
mTransport = null
mHandover = null
mEDeviceKeyCurve = null
mEDeviceKeyPair = null
mDeviceEngagement = null
}

fun startPresentation(context: Context, transport: DataTransport, handover: ByteArray,
eDeviceKeyCurve: Int, eDeviceKeyPair: KeyPair, deviceEngagement: ByteArray) {
mTransport = transport
mHandover = handover
mEDeviceKeyCurve = eDeviceKeyCurve
mEDeviceKeyPair = eDeviceKeyPair
mDeviceEngagement = deviceEngagement
>>>>>>> 406e896 (Presentation Activity (#459))
Logger.i(TAG, "engagement info set")

val launchAppIntent = Intent(context, PresentationActivity::class.java)
Expand Down Expand Up @@ -227,9 +258,15 @@ class PresentationActivity : ComponentActivity() {

},
ContextCompat.getMainExecutor(applicationContext),
<<<<<<< HEAD
eDeviceKeyPair!!,
eDeviceKeyCurve!!)
.useForwardEngagement(transport!!, deviceEngagement!!, handover!!)
=======
mEDeviceKeyPair!!,
mEDeviceKeyCurve!!)
.useForwardEngagement(mTransport!!, mDeviceEngagement!!, mHandover!!)
>>>>>>> 406e896 (Presentation Activity (#459))
.build()
}

Expand All @@ -245,8 +282,13 @@ class PresentationActivity : ComponentActivity() {
}
deviceRetrievalHelper?.disconnect()
deviceRetrievalHelper = null
<<<<<<< HEAD
transport = null
handover = null
=======
mTransport = null
mHandover = null
>>>>>>> 406e896 (Presentation Activity (#459))
state.value = State.NOT_CONNECTED
}

Expand Down Expand Up @@ -293,7 +335,11 @@ class PresentationActivity : ComponentActivity() {
val credentialConfiguration = credential.credentialConfiguration
val now = Timestamp.now()

<<<<<<< HEAD
val authKey: AuthenticationKey
=======
val authKey: Credential.AuthenticationKey
>>>>>>> 406e896 (Presentation Activity (#459))
try {
authKey = credential.findAuthenticationKey(WalletApplication.AUTH_KEY_DOMAIN, now)!!
} catch (e: Exception) {
Expand Down Expand Up @@ -323,7 +369,11 @@ class PresentationActivity : ComponentActivity() {
authKey.secureArea,
authKey.alias,
null,
<<<<<<< HEAD
Algorithm.ES256
=======
SecureArea.ALGORITHM_ES256
>>>>>>> 406e896 (Presentation Activity (#459))
)
.generate()
)
Expand Down

0 comments on commit e06d834

Please sign in to comment.