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

fix: Add DID deactivation check for credential issuing [DEV-3136] #345

Merged
merged 35 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
97934a6
Add parameter allowDeactivated for allowing issue
abdulla-ashurov Aug 17, 2023
aec917e
Update package-lock.json.
abdulla-ashurov Aug 17, 2023
f11f141
Remove the custom implementation of JSON.stringify
abdulla-ashurov Aug 28, 2023
427286c
Fix login/logout dynamic custom button panel.
abdulla-ashurov Aug 28, 2023
9bf6ebe
Revert code.
abdulla-ashurov Aug 28, 2023
d09bba8
Update custom-button.ts.
abdulla-ashurov Aug 28, 2023
f9de902
Merge branch 'DEV-3162' into DEV-3136
abdulla-ashurov Aug 29, 2023
11dd5f9
Refactor code.
abdulla-ashurov Aug 29, 2023
38d4cbd
Remove an unnecessary use of boolean literals in
abdulla-ashurov Aug 29, 2023
a9a6671
Merge branch 'develop' into DEV-3136
abdulla-ashurov Aug 30, 2023
6b6c59d
Merge branch 'develop' into DEV-3136
abdulla-ashurov Aug 31, 2023
8cdd97a
Add allowDeactivatedDid query parameter to
abdulla-ashurov Aug 31, 2023
d2a94f9
Remove an unnecessary use of boolean literals in
abdulla-ashurov Aug 31, 2023
436d7d2
Add implementation for blocking issue credential
abdulla-ashurov Aug 31, 2023
bfb415d
Merge branch 'develop' into DEV-3136
abdulla-ashurov Aug 31, 2023
b1c7aec
Merge branch 'develop' into DEV-3136
abdulla-ashurov Sep 5, 2023
82f878f
Add allowDeactivatedDid query parameter for
abdulla-ashurov Sep 5, 2023
4df947f
Update package-lock.json.
abdulla-ashurov Sep 5, 2023
94a95a1
Merge branch 'develop' into DEV-3136
ankurdotb Sep 5, 2023
e648f3c
Update package-lock.json
ankurdotb Sep 5, 2023
08eb2bc
Add more wide error code when result is empty and
abdulla-ashurov Sep 6, 2023
3bbe5de
Add more wide error code for presentation/verify.
abdulla-ashurov Sep 6, 2023
d03a1ee
Merge branch 'develop' into DEV-3136
abdulla-ashurov Sep 7, 2023
2593f81
Update package-lock.json.
abdulla-ashurov Sep 7, 2023
789183f
Merge branch 'develop' into DEV-3136
abdulla-ashurov Sep 8, 2023
cdf8599
Move a common logic of decode JWT to helper.ts.
abdulla-ashurov Sep 8, 2023
0227980
Remove duplicate import packages.
abdulla-ashurov Sep 8, 2023
9ee05ac
Update package-lock.json.
abdulla-ashurov Sep 8, 2023
e9c725d
Add static validation for JWT.
abdulla-ashurov Sep 8, 2023
69f7534
Update .eslintrc.json
ankurdotb Sep 8, 2023
4260ff8
Check credential status before suspension/reinstate
ankurdotb Sep 8, 2023
726dda8
Update package-lock.json
ankurdotb Sep 8, 2023
ca1810b
npm run format
ankurdotb Sep 8, 2023
d21afa3
PresentationVerifyRequest
ankurdotb Sep 8, 2023
1ff3d1c
Add presentation validator JWT check
ankurdotb Sep 8, 2023
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

81 changes: 79 additions & 2 deletions src/controllers/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { check, query, validationResult } from 'express-validator';

import { Credentials } from '../services/credentials.js';
import { IdentityServiceStrategySetup } from '../services/identity/index.js';
import InvalidTokenError from "jwt-decode";
import jwt_decode from 'jwt-decode';

export class CredentialController {
public static issueValidator = [
Expand Down Expand Up @@ -101,6 +103,13 @@ export class CredentialController {
request.body['@context'] = [request.body['@context']];
}

const resolvedResult = await new IdentityServiceStrategySetup(response.locals.customerId).agent.resolveDid(request.body.issuerDid);
if (!resolvedResult?.didDocument || resolvedResult.didDocumentMetadata.deactivated) {
return response.status(StatusCodes.BAD_REQUEST).send({
error: `${request.body.issuerDid} is either Deactivated or Not found`,
abdulla-ashurov marked this conversation as resolved.
Show resolved Hide resolved
});
}

try {
const credential: VerifiableCredential = await Credentials.instance.issue_credential(
request.body,
Expand Down Expand Up @@ -136,6 +145,12 @@ export class CredentialController {
* schema:
* type: boolean
* default: false
* - in: query
* name: allowDeactivatedDid
* description: If set to `true` allow to verify credential which based on deactivated DID.
* schema:
* type: boolean
* default: false
* requestBody:
* content:
* application/x-www-form-urlencoded:
Expand Down Expand Up @@ -165,7 +180,35 @@ export class CredentialController {
}

const { credential, policies } = request.body;
const verifyStatus = request.query.verifyStatus === 'true' ? true : false;
const verifyStatus = request.query.verifyStatus === 'true';
const allowDeactivatedDid = request.query.allowDeactivatedDid === "true";

let issuerDid = "";
let decoded: any;

if (credential.issuer?.id) {
issuerDid = credential.issuer.id;
} else {
try {
abdulla-ashurov marked this conversation as resolved.
Show resolved Hide resolved
decoded = jwt_decode(credential);
issuerDid = decoded.iss;
} catch (e) {
// If it's not a JWT - just skip it
if (!(e instanceof InvalidTokenError)) {
throw e;
}
}
}

if (!allowDeactivatedDid) {
const result = await new IdentityServiceStrategySetup(response.locals.customerId).agent.resolveDid(issuerDid);
if (!result?.didDocument || result.didDocumentMetadata.deactivated) {
abdulla-ashurov marked this conversation as resolved.
Show resolved Hide resolved
return response.status(StatusCodes.BAD_REQUEST).send({
error: `${issuerDid} is either Deactivated or Not found`,
});
}
}

try {
const result = await new IdentityServiceStrategySetup(response.locals.customerId).agent.verifyCredential(
credential,
Expand Down Expand Up @@ -394,6 +437,12 @@ export class CredentialController {
* schema:
* type: boolean
* default: false
* - in: query
* name: allowDeactivatedDid
* description: If set to `true` allow to verify credential which based on deactivated DID.
* schema:
* type: boolean
* default: false
* requestBody:
* content:
* application/x-www-form-urlencoded:
Expand Down Expand Up @@ -423,7 +472,35 @@ export class CredentialController {
}

const { presentation, verifierDid, policies } = request.body;
const verifyStatus = request.query.verifyStatus === 'true' ? true : false;
const verifyStatus = request.query.verifyStatus === 'true';
const allowDeactivatedDid = request.query.allowDeactivatedDid === "true";

let issuerDid = "";
let decoded: any;

if (presentation.issuer?.id) {
issuerDid = presentation.issuer.id;
} else {
try {
decoded = jwt_decode(presentation);
abdulla-ashurov marked this conversation as resolved.
Show resolved Hide resolved
issuerDid = decoded.iss;
} catch (e) {
// If it's not a JWT - just skip it
if (!(e instanceof InvalidTokenError)) {
throw e;
}
}
}

if (!allowDeactivatedDid) {
const result = await new IdentityServiceStrategySetup(response.locals.customerId).agent.resolveDid(issuerDid);
if (!result?.didDocument || result.didDocumentMetadata.deactivated) {
return response.status(StatusCodes.BAD_REQUEST).send({
error: `${issuerDid} is either Deactivated or Not found`,
});
}
}

try {
const result = await new IdentityServiceStrategySetup(response.locals.customerId).agent.verifyPresentation(
presentation,
Expand Down
18 changes: 18 additions & 0 deletions src/static/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@
"type": "boolean",
"default": false
}
},
{
"in": "query",
"name": "allowDeactivatedDid",
"description": "If set to `true` allow to verify credential which based on deactivated DID.",
"schema": {
"type": "boolean",
"default": false
}
}
],
"requestBody": {
Expand Down Expand Up @@ -329,6 +338,15 @@
"type": "boolean",
"default": false
}
},
{
"in": "query",
"name": "allowDeactivatedDid",
"description": "If set to `true` allow to verify credential which based on deactivated DID.",
"schema": {
"type": "boolean",
"default": false
}
}
],
"requestBody": {
Expand Down