Skip to content

Commit

Permalink
feat: add encrypted qrcode in certificate
Browse files Browse the repository at this point in the history
Signed-off-by: Sai Ranjit Tummalapalli <[email protected]>
  • Loading branch information
sairanjit committed Jul 25, 2024
1 parent 1c0a530 commit aabb054
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 11 deletions.
5 changes: 4 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ PROOF_TEMPLATE_URL=

# Google Signin
GOOGLE_WEB_CLIENT_ID=CLIENT_ID
GOOGLE_IOS_CLIENT_ID=CLIENT_ID
GOOGLE_IOS_CLIENT_ID=CLIENT_ID

# DATA ENCYPTION KEY
DATA_ENCRYPTION_KEY=DATA_ENCRYPTION_KEY
20 changes: 13 additions & 7 deletions app/screens/CredentialDetailsW3C.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import {
deleteCredentialExchangeRecordById,
useCredentialByState,
CredentialState,
createInvitation,
} from '@adeya/ssi'
import { BrandingOverlay } from '@hyperledger/aries-oca'
import { CredentialOverlay } from '@hyperledger/aries-oca/build/legacy'
import * as CryptoJS from 'crypto-js'
import { toString as toQRCodeString } from 'qrcode'
import React, { useCallback, useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
Expand Down Expand Up @@ -330,19 +330,25 @@ const CredentialDetailsW3C: React.FC<CredentialDetailsProps> = ({ navigation, ro
try {
setIsGeneratingPdf(true)

const invitation = await createInvitation(agent, 'https://adeya.com')
const certificateAttributes = w3cCredential?.credential.credentialSubject.claims

const dataToEncrypt = JSON.stringify({
email: certificateAttributes['email'] ?? 'email',
schemaUrl: w3cCredential?.credential.type[1],
})

const qrCodeSvg = await generateQRCodeString(invitation.invitationUrl)
// eslint-disable-next-line import/namespace
const encryptedToken = CryptoJS.AES.encrypt(dataToEncrypt, 'dataEncryptionKey').toString()

Check failure

Code scanning / CodeQL

Hard-coded credentials Critical

The hard-coded value "dataEncryptionKey" is used as
key
.

const certificateAttributes = w3cCredential?.credential.credentialSubject.claims
const qrCodeSvg = await generateQRCodeString(encryptedToken)

const prettyVc = w3cCredential?.credential.prettyVc
let content = prettyVc.certificate

const invitationUrlPlaceholder = '{{invitationUrl}}'
const invitationUrlEscapedPlaceholder = invitationUrlPlaceholder.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
const contactDetailsPlaceholder = '{{qrcode}}'
const contactDetailsEscapedPlaceholder = contactDetailsPlaceholder.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')

content = content.replace(new RegExp(invitationUrlEscapedPlaceholder, 'g'), qrCodeSvg)
content = content.replace(new RegExp(contactDetailsEscapedPlaceholder, 'g'), qrCodeSvg)

Object.keys(certificateAttributes).forEach(key => {
// Statically picking the value of placeholder
Expand Down
4 changes: 2 additions & 2 deletions ios/AdeyaWallet.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = NO;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = AdeyaWallet/AdeyaWallet.entitlements;
CURRENT_PROJECT_VERSION = 33;
CURRENT_PROJECT_VERSION = 34;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = Z5W7KRPGHZ;
ENABLE_BITCODE = NO;
Expand Down Expand Up @@ -545,7 +545,7 @@
CODE_SIGN_ENTITLEMENTS = AdeyaWallet/AdeyaWallet.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 33;
CURRENT_PROJECT_VERSION = 34;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = Z5W7KRPGHZ;
INFOPLIST_FILE = AdeyaWallet/Info.plist;
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@robinbobin/react-native-google-drive-api-wrapper": "^1.2.4",
"axios": "^1.6.0",
"bip39": "^3.1.0",
"crypto-js": "^4.2.0",
"events": "^1.1.1",
"expo-modules-core": "^1.2.7",
"i18next": "^23.4.1",
Expand Down Expand Up @@ -106,6 +107,7 @@
"@react-native/eslint-config": "^0.72.2",
"@react-native/metro-config": "^0.72.9",
"@tsconfig/react-native": "^3.0.0",
"@types/crypto-js": "^4.2.2",
"@types/lodash.flatten": "^4.4.7",
"@types/lodash.merge": "^4.6.7",
"@types/lodash.shuffle": "^4.2.7",
Expand Down
7 changes: 6 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3505,6 +3505,11 @@
dependencies:
"@babel/types" "^7.20.7"

"@types/crypto-js@^4.2.2":
version "4.2.2"
resolved "https://registry.yarnpkg.com/@types/crypto-js/-/crypto-js-4.2.2.tgz#771c4a768d94eb5922cc202a3009558204df0cea"
integrity sha512-sDOLlVbHhXpAUAL0YHDUUwDZf3iN4Bwi4W6a0W0b+QcAezUbRtH4FVb+9J4h+XFPW7l/gQ9F8qC7P+Ec4k8QVQ==

"@types/graceful-fs@^4.1.3":
version "4.1.6"
resolved "https://registry.npmjs.org/@types/graceful-fs/-/graceful-fs-4.1.6.tgz"
Expand Down Expand Up @@ -5182,7 +5187,7 @@ cross-spawn@^7.0.0, cross-spawn@^7.0.2, cross-spawn@^7.0.3:
shebang-command "^2.0.0"
which "^2.0.1"

[email protected]:
[email protected], crypto-js@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/crypto-js/-/crypto-js-4.2.0.tgz#4d931639ecdfd12ff80e8186dba6af2c2e856631"
integrity sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q==
Expand Down

0 comments on commit aabb054

Please sign in to comment.