Skip to content

Commit b24c68e

Browse files
Initial changes for x509 support (#1482)
Signed-off-by: Rinkal Bhojani <[email protected]>
1 parent 5b3d0e3 commit b24c68e

File tree

28 files changed

+2128
-19
lines changed

28 files changed

+2128
-19
lines changed

.env.demo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ UTILITIES_NKEY_SEED=
102102
CLOUD_WALLET_NKEY_SEED=
103103
GEOLOCATION_NKEY_SEED=
104104
NOTIFICATION_NKEY_SEED=
105+
X509_NKEY_SEED=
105106

106107
KEYCLOAK_DOMAIN=http://localhost:8080/
107108
KEYCLOAK_ADMIN_URL=http://localhost:8080

.env.sample

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ CREDENTAILDEFINITION_NKEY_SEED= xxxxxxxxxxxxx // Please provide Nkeys secret for
121121
SCHEMA_NKEY_SEED= xxxxxxxxxxxxx // Please provide Nkeys secret for schema service
122122
UTILITIES_NKEY_SEED= xxxxxxxxxxxxx // Please provide Nkeys secret for utilities service
123123
GEOLOCATION_NKEY_SEED= xxxxxxxxxxx // Please provide Nkeys secret for geo-location service
124+
X509_NKEY_SEED= xxxxxxxxxxx // Please provide Nkeys secret for x509 service
124125

125126
AFJ_AGENT_TOKEN_PATH=/apps/agent-provisioning/AFJ/token/
126127

apps/agent-service/src/agent-service.controller.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ import { user } from '@prisma/client';
2727
import { InvitationMessage } from '@credebl/common/interfaces/agent-service.interface';
2828
import { AgentSpinUpStatus } from '@credebl/enum/enum';
2929
import { SignDataDto } from '../../api-gateway/src/agent-service/dto/agent-service.dto';
30+
import {
31+
IX509ImportCertificateOptionsDto,
32+
x509CertificateDecodeDto,
33+
X509CreateCertificateOptions
34+
} from '@credebl/common/interfaces/x509.interface';
3035

3136
@Controller()
3237
export class AgentServiceController {
@@ -380,4 +385,31 @@ export class AgentServiceController {
380385
async oidcDeleteCredentialOffer(payload: { url: string; orgId: string }): Promise<any> {
381386
return this.agentServiceService.oidcDeleteCredentialOffer(payload.url, payload.orgId);
382387
}
388+
389+
@MessagePattern({ cmd: 'agent-create-x509-certificate' })
390+
async createX509Certificate(payload: {
391+
options: X509CreateCertificateOptions;
392+
url: string;
393+
orgId: string;
394+
}): Promise<object> {
395+
return this.agentServiceService.createX509Certificate(payload.options, payload.url, payload.orgId);
396+
}
397+
398+
@MessagePattern({ cmd: 'agent-decode-x509-certificate' })
399+
async decodeX509Certificate(payload: {
400+
options: x509CertificateDecodeDto;
401+
url: string;
402+
orgId: string;
403+
}): Promise<object> {
404+
return this.agentServiceService.decodeX509Certificate(payload.options, payload.url, payload.orgId);
405+
}
406+
407+
@MessagePattern({ cmd: 'agent-import-x509-certificate' })
408+
async importX509Certificate(payload: {
409+
options: IX509ImportCertificateOptionsDto;
410+
url: string;
411+
orgId: string;
412+
}): Promise<object> {
413+
return this.agentServiceService.importX509Certificate(payload.options, payload.url, payload.orgId);
414+
}
383415
}

apps/agent-service/src/agent-service.service.ts

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ import { NATSClient } from '@credebl/common/NATSClient';
8080
import { SignDataDto } from '../../api-gateway/src/agent-service/dto/agent-service.dto';
8181
import { IVerificationMethod } from 'apps/organization/interfaces/organization.interface';
8282
import { getAgentUrl } from '@credebl/common/common.utils';
83+
import {
84+
IX509ImportCertificateOptionsDto,
85+
x509CertificateDecodeDto,
86+
X509CreateCertificateOptions
87+
} from '@credebl/common/interfaces/x509.interface';
8388
@Injectable()
8489
@WebSocketGateway()
8590
export class AgentServiceService {
@@ -89,7 +94,6 @@ export class AgentServiceService {
8994
private readonly agentServiceRepository: AgentServiceRepository,
9095
private readonly prisma: PrismaService,
9196
private readonly commonService: CommonService,
92-
private readonly connectionService: ConnectionService,
9397
@Inject('NATS_CLIENT') private readonly agentServiceProxy: ClientProxy,
9498
@Inject(CACHE_MANAGER) private cacheService: Cache,
9599
private readonly userActivityRepository: UserActivityRepository,
@@ -2221,4 +2225,49 @@ export class AgentServiceService {
22212225
throw error;
22222226
}
22232227
}
2228+
2229+
async createX509Certificate(options: X509CreateCertificateOptions, url: string, orgId: string): Promise<object> {
2230+
try {
2231+
this.logger.log('Start creating X509 certificate');
2232+
this.logger.debug('Creating X509 certificate with options', options);
2233+
const getApiKey = await this.getOrgAgentApiKey(orgId);
2234+
const x509Certificate = await this.commonService
2235+
.httpPost(url, options, { headers: { authorization: getApiKey } })
2236+
.then(async (response) => response);
2237+
return x509Certificate;
2238+
} catch (error) {
2239+
this.logger.error(`Error in creating x509 certificate in agent service : ${JSON.stringify(error)}`);
2240+
throw error;
2241+
}
2242+
}
2243+
2244+
async decodeX509Certificate(options: x509CertificateDecodeDto, url: string, orgId: string): Promise<object> {
2245+
try {
2246+
this.logger.log('Start decoding X509 certificate');
2247+
this.logger.debug('Decoding X509 certificate with options', options);
2248+
const getApiKey = await this.getOrgAgentApiKey(orgId);
2249+
const x509Certificate = await this.commonService
2250+
.httpPost(url, options, { headers: { authorization: getApiKey } })
2251+
.then(async (response) => response);
2252+
return x509Certificate;
2253+
} catch (error) {
2254+
this.logger.error(`Error in decoding x509 certificate in agent service : ${JSON.stringify(error)}`);
2255+
throw error;
2256+
}
2257+
}
2258+
2259+
async importX509Certificate(options: IX509ImportCertificateOptionsDto, url: string, orgId: string): Promise<object> {
2260+
try {
2261+
this.logger.log('Start importing X509 certificate');
2262+
this.logger.debug(`Importing X509 certificate with options`, options.certificate);
2263+
const getApiKey = await this.getOrgAgentApiKey(orgId);
2264+
const x509Certificate = await this.commonService
2265+
.httpPost(url, options, { headers: { authorization: getApiKey } })
2266+
.then(async (response) => response);
2267+
return x509Certificate;
2268+
} catch (error) {
2269+
this.logger.error(`Error in creating x509 certificate in agent service : ${JSON.stringify(error)}`);
2270+
throw error;
2271+
}
2272+
}
22242273
}

apps/api-gateway/src/app.module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { LoggerModule } from '@credebl/logger/logger.module';
3333
import { GlobalConfigModule } from '@credebl/config/global-config.module';
3434
import { ConfigModule as PlatformConfig } from '@credebl/config/config.module';
3535
import { Oid4vcIssuanceModule } from './oid4vc-issuance/oid4vc-issuance.module';
36+
import { X509Module } from './x509/x509.module';
3637

3738
@Module({
3839
imports: [
@@ -66,7 +67,8 @@ import { Oid4vcIssuanceModule } from './oid4vc-issuance/oid4vc-issuance.module';
6667
CacheModule.register({ store: redisStore, host: process.env.REDIS_HOST, port: process.env.REDIS_PORT }),
6768
GeoLocationModule,
6869
CloudWalletModule,
69-
Oid4vcIssuanceModule
70+
Oid4vcIssuanceModule,
71+
X509Module
7072
],
7173
controllers: [AppController],
7274
providers: [

apps/api-gateway/src/oid4vc-issuance/dtos/issuer-sessions.dto.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ import {
2222
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
2323
import { Type } from 'class-transformer';
2424

25-
/* ========= Enums ========= */
26-
export enum CredentialFormat {
27-
SdJwtVc = 'vc+sd-jwt',
28-
Mdoc = 'mdoc'
29-
}
30-
3125
/* ========= disclosureFrame custom validator ========= */
3226
function isDisclosureFrameValue(v: unknown): boolean {
3327
if ('boolean' === typeof v) {

apps/api-gateway/src/oid4vc-issuance/oid4vc-issuance.service.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { BaseService } from 'libs/service/base.service';
77
import { oidc_issuer, user } from '@prisma/client';
88
import { CreateCredentialTemplateDto, UpdateCredentialTemplateDto } from './dtos/oid4vc-issuer-template.dto';
99
import {
10+
CreateCredentialOfferD2ADto,
1011
CreateOidcCredentialOfferDto,
1112
GetAllCredentialOfferDto,
1213
UpdateCredentialRequestDto
@@ -98,7 +99,10 @@ export class Oid4vcIssuanceService extends BaseService {
9899
return this.natsClient.sendNatsMessage(this.issuanceProxy, 'oid4vc-create-credential-offer', payload);
99100
}
100101

101-
async createOidcCredentialOfferD2A(oidcCredentialD2APayload, orgId: string): Promise<object> {
102+
async createOidcCredentialOfferD2A(
103+
oidcCredentialD2APayload: CreateCredentialOfferD2ADto,
104+
orgId: string
105+
): Promise<object> {
102106
const payload = { oidcCredentialD2APayload, orgId };
103107
return this.natsClient.sendNatsMessage(this.issuanceProxy, 'oid4vc-create-credential-offer-D2A', payload);
104108
}

0 commit comments

Comments
 (0)