Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for android attestation using new native module #1586

Merged
merged 2 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/android/app/gradle.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,19 @@ com.google.android.datatransport:transport-runtime:3.1.7=debugRuntimeClasspath,d
com.google.android.gms:play-services-auth-api-phone:18.0.1=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
com.google.android.gms:play-services-auth-base:18.0.4=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
com.google.android.gms:play-services-auth:20.3.0=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
com.google.android.gms:play-services-base:18.0.1=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
com.google.android.gms:play-services-base:18.2.0=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
com.google.android.gms:play-services-basement:18.1.0=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
com.google.android.gms:play-services-clearcut:16.0.0=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
com.google.android.gms:play-services-cloud-messaging:17.0.1=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
com.google.android.gms:play-services-flags:16.0.1=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
com.google.android.gms:play-services-iid:17.0.0=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
com.google.android.gms:play-services-phenotype:16.0.0=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
com.google.android.gms:play-services-stats:17.0.2=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
com.google.android.gms:play-services-tasks:18.0.1=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
com.google.android.gms:play-services-tasks:18.0.2=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
com.google.android.gms:play-services-vision-common:17.0.2=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
com.google.android.gms:play-services-vision:17.0.2=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
com.google.android.material:material:1.1.0=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
com.google.android.play:integrity:1.2.0=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
com.google.code.findbugs:jsr305:3.0.2=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
com.google.crypto.tink:tink-android:1.5.0=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
com.google.errorprone:error_prone_annotations:2.9.0=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
Expand Down
4 changes: 2 additions & 2 deletions app/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ PODS:
- React-jsinspector (0.72.5)
- React-logger (0.72.5):
- glog
- "react-native-attestation (1.0.0-alpha.99+1f2c467)":
- "react-native-attestation (1.0.0-alpha.130+374b6166)":
- RCT-Folly (= 2021.07.22.00)
- React-Core
- react-native-camera (3.44.3):
Expand Down Expand Up @@ -928,7 +928,7 @@ SPEC CHECKSUMS:
React-jsiexecutor: ff70a72027dea5cc7d71cfcc6fad7f599f63987a
React-jsinspector: aef73cbd43b70675f572214d10fa438c89bf11ba
React-logger: 2e4aee3e11b3ec4fa6cfd8004610bbb3b8d6cca4
react-native-attestation: a853896933d0b108c1444787cee81fc969fed2a1
react-native-attestation: 1934de33bee417356a58859742139c149580f286
react-native-camera: b8cc03e2feec0c04403d0998e37cf519d8fd4c6f
react-native-config: 5330c8258265c1e5fdb8c009d2cabd6badd96727
react-native-encrypted-storage: db300a3f2f0aba1e818417c1c0a6be549038deb7
Expand Down
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"@hyperledger/anoncreds-react-native": "^0.1.0",
"@hyperledger/aries-askar-react-native": "^0.1.1",
"@hyperledger/aries-oca": "1.0.0-alpha.72",
"@hyperledger/aries-react-native-attestation": "^1.0.0-alpha.96",
"@hyperledger/aries-react-native-attestation": "1.0.0-alpha.130",
"@hyperledger/indy-vdr-react-native": "^0.1.0",
"@react-native-async-storage/async-storage": "1.15.11",
"@react-native-community/masked-view": "0.1.11",
Expand Down
62 changes: 43 additions & 19 deletions app/src/services/attestation.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { Agent, BaseEvent, BasicMessageEventTypes, BasicMessageRecord, BasicMessageRole } from '@aries-framework/core'
import { useAgent } from '@aries-framework/react-hooks'
import { generateKey, appleAttestation } from '@hyperledger/aries-react-native-attestation'
import {
generateKey,
appleAttestation,
googleAttestation,
isPlayIntegrityAvailable,
} from '@hyperledger/aries-react-native-attestation'
import { Buffer } from 'buffer'
import React, { createContext, useContext, useState } from 'react'
import { Platform } from 'react-native'
// eslint-disable-next-line import/no-extraneous-dependencies
import { Subscription } from 'rxjs'

Expand All @@ -13,7 +19,7 @@ enum Action {

type InfrastructureMessage = {
type: 'attestation'
platform: 'apple'
platform?: 'apple' | 'google'
version: 1
action: Action
}
Expand All @@ -23,7 +29,7 @@ type RequestIssuanceInfrastructureMessage = InfrastructureMessage & {
}

type ChallengeResponseInfrastructureMessage = InfrastructureMessage & {
key_id: string
key_id?: string
attestation_object: string
}

Expand Down Expand Up @@ -63,27 +69,45 @@ export const AttestationProvider: React.FC<AttestationProviderParams> = ({ child
message: InfrastructureMessage
): Promise<ChallengeResponseInfrastructureMessage | null> => {
switch (message.action) {
case Action.RequestAttestation: {
case Action.RequestAttestation:
try {
const keyId = await generateKey()
const attestationAsBuffer = await appleAttestation(
keyId,
(message as RequestIssuanceInfrastructureMessage).nonce
)
const attestationResponse: ChallengeResponseInfrastructureMessage = {
type: 'attestation',
platform: 'apple',
version: 1,
action: Action.ChallengeResponse,
key_id: keyId,
attestation_object: attestationAsBuffer.toString('base64'),
if (Platform.OS === 'ios') {
const keyId = await generateKey()
const attestationAsBuffer = await appleAttestation(
keyId,
(message as RequestIssuanceInfrastructureMessage).nonce
)
const attestationResponse: ChallengeResponseInfrastructureMessage = {
type: 'attestation',
platform: 'apple',
version: 1,
action: Action.ChallengeResponse,
key_id: keyId,
attestation_object: attestationAsBuffer.toString('base64'),
}

return attestationResponse
} else if (Platform.OS === 'android') {
const available = await isPlayIntegrityAvailable()
if (!available) {
return null
}
const tokenString = await googleAttestation((message as RequestIssuanceInfrastructureMessage).nonce)
const attestationResponse: ChallengeResponseInfrastructureMessage = {
type: 'attestation',
platform: 'google',
version: 1,
action: Action.ChallengeResponse,
attestation_object: tokenString,
}

return attestationResponse
} else {
return null
}

return attestationResponse
} catch (error: unknown) {
return null
}
}

default:
return null
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3939,13 +3939,13 @@ __metadata:
languageName: node
linkType: hard

"@hyperledger/aries-react-native-attestation@npm:^1.0.0-alpha.96":
version: 1.0.0-alpha.99
resolution: "@hyperledger/aries-react-native-attestation@npm:1.0.0-alpha.99"
"@hyperledger/aries-react-native-attestation@npm:1.0.0-alpha.130":
version: 1.0.0-alpha.130
resolution: "@hyperledger/aries-react-native-attestation@npm:1.0.0-alpha.130"
peerDependencies:
react: "*"
react-native: "*"
checksum: afa44068ce67781c132499b975fa35a921f87530524c85ccba8be72161d650cb8b8705bd98f8aebecd92e9c3775aec523ae02e67c3d87f4ab40a15450b9d59bb
checksum: 1feef575fc61237d67e5f813fb487ce1c502a48101002e0da30ee9391a3c88ecfcf3315e2f75d9543ecc235e82d053a94886d1e5376be61bf4d24894dfee7cd3
languageName: node
linkType: hard

Expand Down Expand Up @@ -8694,7 +8694,7 @@ __metadata:
"@hyperledger/anoncreds-react-native": ^0.1.0
"@hyperledger/aries-askar-react-native": ^0.1.1
"@hyperledger/aries-oca": 1.0.0-alpha.72
"@hyperledger/aries-react-native-attestation": ^1.0.0-alpha.96
"@hyperledger/aries-react-native-attestation": 1.0.0-alpha.130
"@hyperledger/indy-vdr-react-native": ^0.1.0
"@react-native-async-storage/async-storage": 1.15.11
"@react-native-community/masked-view": 0.1.11
Expand Down
Loading