Skip to content

Commit

Permalink
[INJIMOB-1458] fallback issuers config if wellknown not available (mo…
Browse files Browse the repository at this point in the history
…sip#1507)

* [INJIMOB-1458] fallback issuers config if wellknown not available (mosip#1505)

* [INJIMOB-1458] fallback to issuers config if well known is not available

Signed-off-by: KiruthikaJeyashankar <[email protected]>

* [INJIMOB-1458] set vc metadata id as credential ID & displayId as UIN/PolicyNUmber

Co-authored-by: Swati Goel <[email protected]>
Signed-off-by: KiruthikaJeyashankar <[email protected]>

---------

Signed-off-by: KiruthikaJeyashankar <[email protected]>
Co-authored-by: Swati Goel <[email protected]>

* [INJIMOB-1458] fix QR login failure due to alias mismatch in activation and QRLogin

Signed-off-by: KiruthikaJeyashankar <[email protected]>

---------

Signed-off-by: KiruthikaJeyashankar <[email protected]>
Co-authored-by: Swati Goel <[email protected]>
  • Loading branch information
KiruthikaJeyashankar and swatigoel authored Jun 11, 2024
1 parent 3ab9c49 commit af920f2
Show file tree
Hide file tree
Showing 22 changed files with 148 additions and 108 deletions.
2 changes: 1 addition & 1 deletion .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fileignoreconfig:
- filename: shared/openId4VCI/Utils.ts
checksum: ee4db1768be8d51fac0eb876a7b16fd2ab1806abcc711f01056f672003d11f31
- filename: shared/cryptoutil/cryptoUtil.ts
checksum: 2efef1baca1eee0da60420c8d966a6d58589bc3ac74169ab1cdc19423b630dba
checksum: a8edd1047e33bfc9e37b73945b8edcd294b8e29baf380f86cb0f647b355c8e5a
- filename: shared/telemetry/TelemetryConstants.js
checksum: fd8dc3a69cdef68855dc5f0531d8e634bfa2621bb4dc22f85b8247512a349c4c
- filename: shared/telemetry/TelemetryUtils.js
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,20 @@ public String getName() {
@ReactMethod
public void requestCredential(ReadableMap issuerMetaData, String jwtProofValue, String accessToken, Promise promise) {
try {
CredentialFormat credentialFormat;
switch (issuerMetaData.getString("credentialFormat")) {
case "ldp_vc":
credentialFormat = CredentialFormat.LDP_VC;
break;
default:
credentialFormat = CredentialFormat.LDP_VC;
}
CredentialResponse response = vciClient.requestCredential(new IssuerMetaData(
issuerMetaData.getString("credentialAudience"),
issuerMetaData.getString("credentialEndpoint"),
issuerMetaData.getInt("downloadTimeoutInMilliSeconds"),
convertReadableArrayToStringArray(issuerMetaData.getArray("credentialType")),
CredentialFormat.LDP_VC), new JWTProof(jwtProofValue)
credentialFormat), new JWTProof(jwtProofValue)
, accessToken);
promise.resolve(response.toJsonString());
} catch (Exception exception) {
Expand Down
3 changes: 0 additions & 3 deletions components/ActivityLogEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export class ActivityLog {
_vcKey: string;
timestamp: number;
deviceName: string;
vcLabel: string;
type: ActivityLogType;
issuer: string;

Expand All @@ -35,7 +34,6 @@ export class ActivityLog {
type = '',
timestamp = Date.now(),
deviceName = '',
vcLabel = '',
issuer = '',
} = {}) {
this.id = id;
Expand All @@ -44,7 +42,6 @@ export class ActivityLog {
this.type = type;
this.timestamp = timestamp;
this.deviceName = deviceName;
this.vcLabel = vcLabel;
this.issuer = issuer;
}

Expand Down
3 changes: 2 additions & 1 deletion components/VC/common/VCUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {VCVerification} from '../../VCVerification';
import {MIMOTO_BASE_URL} from '../../../shared/constants';
import {VCItemDetailsProps} from '../Views/VCDetailView';
import {getSelectedCredentialTypeDetails} from '../../../shared/openId4VCI/Utils';
import {parseJSON} from '../../../shared/Utils';

export const CARD_VIEW_DEFAULT_FIELDS = ['fullName'];
export const DETAIL_VIEW_DEFAULT_FIELDS = [
Expand Down Expand Up @@ -207,7 +208,7 @@ export const getIdType = (
idType !== undefined
) {
let supportedCredentialsWellknown;
wellknown = JSON.parse(wellknown) as Object[];
wellknown = parseJSON(wellknown) as unknown as Object[];
if (!!!wellknown['credentials_supported']) {
return i18n.t('VcDetails:nationalCard');
}
Expand Down
16 changes: 9 additions & 7 deletions components/openId4VCI/CredentialType.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import {getDisplayObjectForCurrentLanguage} from '../../shared/openId4VCI/Utils'
import {CredentialTypes} from '../../machines/VerifiableCredential/VCMetaMachine/vc';

export const CredentialType: React.FC<CredentialTypeProps> = props => {
const selectedIssuerDisplayObject = getDisplayObjectForCurrentLanguage(
props.item.display,
);
const selectedIssuerDisplayObject = props.item.display
? getDisplayObjectForCurrentLanguage(props.item.display)
: {};

return (
<Pressable
accessible={false}
Expand All @@ -29,10 +30,11 @@ export const CredentialType: React.FC<CredentialTypeProps> = props => {
]
}>
<View style={Theme.IssuersScreenStyles.issuerBoxIconContainer}>
{SvgImage.IssuerIcon({
...props,
displayDetails: selectedIssuerDisplayObject,
})}
{selectedIssuerDisplayObject?.logo &&
SvgImage.IssuerIcon({
...props,
displayDetails: selectedIssuerDisplayObject,
})}
</View>
<View style={Theme.IssuersScreenStyles.issuerBoxContent}>
<Text
Expand Down
3 changes: 1 addition & 2 deletions machines/Issuers/IssuersActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,11 @@ export const IssuersActions = (model: any) => {
{
_vcKey: vcMetadata.getVcKey(),
type: 'VC_DOWNLOADED',
id: vcMetadata.id,
id: vcMetadata.displayId,
idType:
context.credentialWrapper.verifiableCredential.credentialTypes,
timestamp: Date.now(),
deviceName: '',
vcLabel: vcMetadata.id,
issuer: context.selectedIssuerId,
},
context.selectedCredentialType,
Expand Down
28 changes: 17 additions & 11 deletions machines/Issuers/IssuersService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,24 @@ export const IssuersService = () => {
let issuersConfig = await CACHED_API.fetchIssuerConfig(
context.selectedIssuerId,
);
const wellknownResponse = await CACHED_API.fetchIssuerWellknownConfig(
context.selectedIssuerId,
issuersConfig['.well-known'],
);
issuersConfig.credential_endpoint =
wellknownResponse?.credential_endpoint;
issuersConfig.credential_audience = wellknownResponse?.credential_issuer;
issuersConfig.credentialTypes = wellknownResponse?.credentials_supported;
if (issuersConfig['.well-known']) {
const wellknownResponse = await CACHED_API.fetchIssuerWellknownConfig(
context.selectedIssuerId,
issuersConfig['.well-known'],
);
if (wellknownResponse) {
issuersConfig.credential_audience =
wellknownResponse.credential_issuer;
issuersConfig.credential_endpoint =
wellknownResponse.credential_endpoint;
issuersConfig.credentials_supported =
wellknownResponse.credentials_supported;
}
}
return issuersConfig;
},
downloadCredentialTypes: async (context: any) => {
return context.selectedIssuer.credentialTypes;
return context.selectedIssuer.credentials_supported;
},
downloadCredential: async (context: any) => {
const downloadTimeout = await vcDownloadTimeout();
Expand All @@ -61,8 +67,8 @@ export const IssuersService = () => {
credentialEndpoint: context.selectedIssuer.credential_endpoint,
downloadTimeoutInMilliSeconds: downloadTimeout,
credentialType: context.selectedCredentialType?.credential_definition
.type ?? ['VerifiableCredential'],
credentialFormat: 'ldp_vc',
?.type ?? ['VerifiableCredential'],
credentialFormat: context.selectedCredentialType.format,
};
const proofJWT = await constructProofJWT(
context.publicKey,
Expand Down
13 changes: 7 additions & 6 deletions machines/QrLogin/QrLoginServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,29 @@ export const QrLoginServices = {

sendAuthenticate: async context => {
let privateKey;
const individualId = context.selectedVc.vcMetadata.id;
const individualId = context.selectedVc.vcMetadata.displayId;
const alias = context.selectedVc.vcMetadata.id;
if (!isHardwareKeystoreExists) {
privateKey = await getPrivateKey(
context.selectedVc.walletBindingResponse?.walletBindingId,
);
}

var config = await getAllConfigurations();
const header = {
const jwtHeader = {
alg: 'RS256',
'x5t#S256': context.thumbprint,
};

const payload = {
const jwtPayload = {
iss: config.issuer,
sub: individualId,
aud: config.audience,
iat: Math.floor(new Date().getTime() / 1000),
exp: Math.floor(new Date().getTime() / 1000) + 18000,
};

const jwt = await getJWT(header, payload, individualId, privateKey);
const jwt = await getJWT(jwtHeader, jwtPayload, alias, privateKey);

const response = await request(
API_URLS.authenticate.method,
Expand All @@ -72,7 +73,7 @@ export const QrLoginServices = {

sendConsent: async context => {
let privateKey;
const individualId = context.selectedVc.vcMetadata.id;
const alias = context.selectedVc.vcMetadata.id;
if (!isHardwareKeystoreExists) {
privateKey = await getPrivateKey(
context.selectedVc.walletBindingResponse?.walletBindingId,
Expand All @@ -90,7 +91,7 @@ export const QrLoginServices = {
permitted_authorized_scopes: context.authorizeScopes,
};

const JWT = await getJWT(header, payload, individualId, privateKey);
const JWT = await getJWT(header, payload, alias, privateKey);
const jwtComponents = JWT.split('.');
const detachedSignature = jwtComponents[0] + '.' + jwtComponents[2];

Expand Down
23 changes: 13 additions & 10 deletions machines/VerifiableCredential/VCItemMachine/VCItemActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,18 @@ export const VCItemActions = model => {
),

setContext: model.assign((context, event) => {
const vcMetadata = context.vcMetadata;
const vcMetadata = VCMetadata.fromVC(context.vcMetadata);
if (!vcMetadata.id) {
const verifiableCredentialId = event.response.verifiableCredential.id;
const credId = verifiableCredentialId.startsWith('did')
? verifiableCredentialId.split(':')
: verifiableCredentialId.split('/');
vcMetadata.id = `${credId[credId.length - 1]} - ${vcMetadata.issuer}`;
}
return {
...context,
...event.response,
vcMetadata: VCMetadata.fromVC(vcMetadata),
vcMetadata: vcMetadata,
};
}),
storeContext: send(
Expand Down Expand Up @@ -451,12 +458,11 @@ export const VCItemActions = model => {
return ActivityLogEvents.LOG_ACTIVITY({
_vcKey: context.vcMetadata.getVcKey(),
type: 'VC_DOWNLOADED',
id: context.vcMetadata.id,
id: context.vcMetadata.displayId,
issuer: context.vcMetadata.issuer!!,
idType: getCredentialTypes(context.verifiableCredential),
timestamp: Date.now(),
deviceName: '',
vcLabel: data.id,
});
},
{
Expand All @@ -469,12 +475,11 @@ export const VCItemActions = model => {
return ActivityLogEvents.LOG_ACTIVITY({
idType: getCredentialTypes(context.verifiableCredential),
issuer: vcMetadata.issuer!!,
id: vcMetadata.id,
id: vcMetadata.displayId,
_vcKey: vcMetadata.getVcKey(),
type: 'VC_REMOVED',
timestamp: Date.now(),
deviceName: '',
vcLabel: vcMetadata.id,
});
},
{
Expand All @@ -489,10 +494,9 @@ export const VCItemActions = model => {
type: 'WALLET_BINDING_SUCCESSFULL',
idType: getCredentialTypes(context.verifiableCredential),
issuer: vcMetadata.issuer!!,
id: vcMetadata.id,
id: vcMetadata.displayId,
timestamp: Date.now(),
deviceName: '',
vcLabel: vcMetadata.id,
});
},
{
Expand All @@ -506,12 +510,11 @@ export const VCItemActions = model => {
return ActivityLogEvents.LOG_ACTIVITY({
_vcKey: vcMetadata.getVcKey(),
type: 'WALLET_BINDING_FAILURE',
id: vcMetadata.id,
id: vcMetadata.displayId,
idType: getCredentialTypes(context.verifiableCredential),
issuer: vcMetadata.issuer!!,
timestamp: Date.now(),
deviceName: '',
vcLabel: vcMetadata.id,
});
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,3 @@ export function selectVc(state: State) {
const {serviceRefs, ...data} = state.context;
return data;
}

export function selectId(state: State) {
return state.context.vcMetadata.id;
}
13 changes: 3 additions & 10 deletions machines/VerifiableCredential/VCItemMachine/VCItemServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const VCItemServices = model => {
request: {
authFactorType: 'WLA',
format: 'jwt',
individualId: VCMetadata.fromVC(context.vcMetadata).id,
individualId: context.vcMetadata.displayId,
transactionId: context.bindingTransactionId,
publicKey: context.publicKey,
challengeList: [
Expand All @@ -80,11 +80,6 @@ export const VCItemServices = model => {
},
},
);
const certificate = response.response.certificate;
await savePrivateKey(
getBindingCertificateConstant(VCMetadata.fromVC(context.vcMetadata).id),
certificate,
);

const walletResponse: WalletBindingResponse = {
walletBindingId: response.response.encryptedWalletBindingId,
Expand All @@ -107,14 +102,13 @@ export const VCItemServices = model => {
);
},
requestBindingOTP: async context => {
const vc = getVerifiableCredential(context.verifiableCredential);
const response = await request(
API_URLS.bindingOtp.method,
API_URLS.bindingOtp.buildURL(),
{
requestTime: String(new Date().toISOString()),
request: {
individualId: VCMetadata.fromVC(context.vcMetadata).id,
individualId: context.vcMetadata.displayId,
otpChannels: ['EMAIL', 'PHONE'],
},
},
Expand Down Expand Up @@ -184,7 +178,7 @@ export const VCItemServices = model => {
API_URLS.credentialDownload.method,
API_URLS.credentialDownload.buildURL(),
{
individualId: context.vcMetadata.id,
individualId: context.vcMetadata.displayId,
requestId: context.vcMetadata.requestId,
},
);
Expand All @@ -194,7 +188,6 @@ export const VCItemServices = model => {
credential: response.credential,
verifiableCredential: response.verifiableCredential,
generatedOn: new Date(),
id: context.vcMetadata.id,
idType: context.vcMetadata.idType,
requestId: context.vcMetadata.requestId,
lastVerifiedOn: null,
Expand Down
3 changes: 1 addition & 2 deletions machines/bleShare/request/requestMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -619,15 +619,14 @@ export const requestMachine =
return ActivityLogEvents.LOG_ACTIVITY({
_vcKey: vcMetadata.getVcKey(),
type: context.receiveLogType,
id: vcMetadata.id,
id: vcMetadata.displayId,
idType: getCredentialTypes(
context.incomingVc.verifiableCredential,
),
issuer: vcMetadata.issuer!!,
timestamp: Date.now(),
deviceName:
context.senderInfo.name || context.senderInfo.deviceName,
vcLabel: vcMetadata.id,
});
},
{to: context => context.serviceRefs.activityLog},
Expand Down
Loading

0 comments on commit af920f2

Please sign in to comment.