Skip to content

Commit

Permalink
Feature/pass profile name in devicesharedsecret (#106)
Browse files Browse the repository at this point in the history
* feat: pass profile name in DeviceSharedSecret

* chore: version bumps

* chore: rebuild schemas
  • Loading branch information
jkoenig134 authored Apr 16, 2024
1 parent fbd3337 commit 56b83f1
Show file tree
Hide file tree
Showing 12 changed files with 129 additions and 78 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions packages/runtime/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nmshd/runtime",
"version": "4.4.2",
"version": "4.5.0",
"description": "The enmeshed client runtime.",
"homepage": "https://enmeshed.eu",
"repository": {
Expand Down Expand Up @@ -68,7 +68,7 @@
"@nmshd/consumption": "3.9.7",
"@nmshd/content": "2.8.11",
"@nmshd/crypto": "2.0.6",
"@nmshd/transport": "2.4.2",
"@nmshd/transport": "2.5.0",
"ajv": "^8.12.0",
"ajv-errors": "^3.0.0",
"ajv-formats": "^3.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface DeviceOnboardingInfoDTO {
createdByDevice: string;
name?: string;
description?: string;
profileName?: string;
secretBaseKey: string;
deviceIndex: number;
synchronizationKey: string;
Expand Down
142 changes: 85 additions & 57 deletions packages/runtime/src/useCases/common/Schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16570,7 +16570,8 @@ export const GetOwnSharedAttributesRequest: any = {
"type": "boolean"
},
"onlyLatestVersions": {
"type": "boolean"
"type": "boolean",
"description": "default: true"
}
},
"required": [
Expand Down Expand Up @@ -16770,7 +16771,8 @@ export const GetPeerSharedAttributesRequest: any = {
"type": "boolean"
},
"onlyLatestVersions": {
"type": "boolean"
"type": "boolean",
"description": "default: true"
}
},
"required": [
Expand Down Expand Up @@ -16945,7 +16947,8 @@ export const GetRepositoryAttributesRequest: any = {
"type": "object",
"properties": {
"onlyLatestVersions": {
"type": "boolean"
"type": "boolean",
"description": "default: true"
},
"query": {
"$ref": "#/definitions/GetRepositoryAttributesRequestQuery"
Expand All @@ -16959,19 +16962,6 @@ export const GetRepositoryAttributesRequest: any = {
"createdAt": {
"type": "string"
},
"content.@type": {
"anyOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
]
},
"content.tags": {
"anyOf": [
{
Expand Down Expand Up @@ -17011,45 +17001,6 @@ export const GetRepositoryAttributesRequest: any = {
}
]
},
"content.key": {
"anyOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
]
},
"content.isTechnical": {
"anyOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
]
},
"content.confidentiality": {
"anyOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
]
},
"content.value.@type": {
"anyOf": [
{
Expand Down Expand Up @@ -17086,7 +17037,8 @@ export const GetSharedVersionsOfRepositoryAttributeRequest: any = {
}
},
"onlyLatestVersions": {
"type": "boolean"
"type": "boolean",
"description": "default: true"
}
},
"required": [
Expand Down Expand Up @@ -19967,6 +19919,29 @@ export const CreateRelationshipChallengeRequest: any = {
}
}

export const isCreateRelationshipChallengeRequest: any = {
"$schema": "http://json-schema.org/draft-07/schema#",
"$ref": "#/definitions/isCreateRelationshipChallengeRequest",
"definitions": {
"isCreateRelationshipChallengeRequest": {
"$comment": "(value: any) => value is CreateRelationshipChallengeRequest",
"type": "object",
"properties": {
"namedArgs": {
"type": "object",
"properties": {
"value": {}
},
"required": [
"value"
],
"additionalProperties": false
}
}
}
}
}

export const CreateIdentityChallengeRequest: any = {
"$schema": "http://json-schema.org/draft-07/schema#",
"$ref": "#/definitions/CreateIdentityChallengeRequest",
Expand All @@ -19987,6 +19962,29 @@ export const CreateIdentityChallengeRequest: any = {
}
}

export const isCreateIdentityChallengeRequest: any = {
"$schema": "http://json-schema.org/draft-07/schema#",
"$ref": "#/definitions/isCreateIdentityChallengeRequest",
"definitions": {
"isCreateIdentityChallengeRequest": {
"$comment": "(value: any) => value is CreateIdentityChallengeRequest",
"type": "object",
"properties": {
"namedArgs": {
"type": "object",
"properties": {
"value": {}
},
"required": [
"value"
],
"additionalProperties": false
}
}
}
}
}

export const CreateDeviceChallengeRequest: any = {
"$schema": "http://json-schema.org/draft-07/schema#",
"$ref": "#/definitions/CreateDeviceChallengeRequest",
Expand All @@ -20007,6 +20005,29 @@ export const CreateDeviceChallengeRequest: any = {
}
}

export const isCreateDeviceChallengeRequest: any = {
"$schema": "http://json-schema.org/draft-07/schema#",
"$ref": "#/definitions/isCreateDeviceChallengeRequest",
"definitions": {
"isCreateDeviceChallengeRequest": {
"$comment": "(value: any) => value is CreateDeviceChallengeRequest",
"type": "object",
"properties": {
"namedArgs": {
"type": "object",
"properties": {
"value": {}
},
"required": [
"value"
],
"additionalProperties": false
}
}
}
}
}

export const CreateChallengeRequest: any = {
"$schema": "http://json-schema.org/draft-07/schema#",
"$ref": "#/definitions/CreateChallengeRequest",
Expand Down Expand Up @@ -20131,6 +20152,9 @@ export const CreateDeviceOnboardingTokenRequest: any = {
},
"expiresAt": {
"$ref": "#/definitions/ISO8601DateTimeString"
},
"profileName": {
"type": "string"
}
},
"required": [
Expand Down Expand Up @@ -20205,6 +20229,9 @@ export const GetDeviceOnboardingInfoRequest: any = {
"properties": {
"id": {
"$ref": "#/definitions/GenericIdString"
},
"profileName": {
"type": "string"
}
},
"required": [
Expand Down Expand Up @@ -21171,7 +21198,8 @@ export const GetAttributesForRelationshipRequest: any = {
"type": "boolean"
},
"onlyLatestVersions": {
"type": "boolean"
"type": "boolean",
"description": "default: true"
}
},
"required": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { TokenMapper } from "../tokens/TokenMapper";
export interface CreateDeviceOnboardingTokenRequest {
id: DeviceIdString;
expiresAt?: ISO8601DateTimeString;
profileName?: string;
}

class Validator extends SchemaValidator<CreateDeviceOnboardingTokenRequest> {
Expand All @@ -26,7 +27,7 @@ export class CreateDeviceOnboardingTokenUseCase extends UseCase<CreateDeviceOnbo
}

protected async executeInternal(request: CreateDeviceOnboardingTokenRequest): Promise<Result<TokenDTO>> {
const sharedSecret = await this.devicesController.getSharedSecret(CoreId.from(request.id));
const sharedSecret = await this.devicesController.getSharedSecret(CoreId.from(request.id), request.profileName);
const expiresAt = request.expiresAt ? CoreDate.from(request.expiresAt) : CoreDate.utc().add({ minutes: 5 });

const tokenContent = TokenContentDeviceSharedSecret.from({ sharedSecret });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export class DeviceMapper {
realm: deviceSharedSecret.identity.realm.toString()
},
password: deviceSharedSecret.password,
username: deviceSharedSecret.username
username: deviceSharedSecret.username,
profileName: deviceSharedSecret.profileName
};
}

Expand All @@ -60,7 +61,8 @@ export class DeviceMapper {
realm: deviceOnboardingDTO.identity.realm as Realm
},
password: deviceOnboardingDTO.password,
username: deviceOnboardingDTO.username
username: deviceOnboardingDTO.username,
profileName: deviceOnboardingDTO.profileName
});
return sharedSecret;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { DeviceMapper } from "./DeviceMapper";

export interface GetDeviceOnboardingInfoRequest {
id: GenericIdString;
profileName?: string;
}

class Validator extends SchemaValidator<GetDeviceOnboardingInfoRequest> {
Expand All @@ -24,7 +25,7 @@ export class GetDeviceOnboardingInfoUseCase extends UseCase<GetDeviceOnboardingI
}

protected async executeInternal(request: GetDeviceOnboardingInfoRequest): Promise<Result<DeviceOnboardingInfoDTO>> {
const onboardingInfo = await this.devicesController.getSharedSecret(CoreId.from(request.id));
const onboardingInfo = await this.devicesController.getSharedSecret(CoreId.from(request.id), request.profileName);

return Result.ok(DeviceMapper.toDeviceOnboardingInfoDTO(onboardingInfo));
}
Expand Down
21 changes: 17 additions & 4 deletions packages/runtime/test/transport/account.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CoreDate } from "@nmshd/transport";
import { DateTime } from "luxon";
import { TransportServices } from "../../src";
import { DeviceDTO, DeviceOnboardingInfoDTO, TransportServices } from "../../src";
import { RuntimeServiceProvider, uploadFile } from "../lib";

const serviceProvider = new RuntimeServiceProvider();
Expand Down Expand Up @@ -148,17 +148,30 @@ describe("LoadItemFromTruncatedReference", () => {
});

describe("DeviceOnboardingInfo", () => {
let deviceOnboardingInfoReference: string;
let device: DeviceDTO;

beforeAll(async () => {
const device = (await sTransportServices.devices.createDevice({})).value;
deviceOnboardingInfoReference = (await sTransportServices.devices.getDeviceOnboardingToken({ id: device.id })).value.truncatedReference;
device = (await sTransportServices.devices.createDevice({})).value;
});

test("loads the DeviceOnboardingInfo with the truncated reference", async () => {
const deviceOnboardingInfoReference = (await sTransportServices.devices.getDeviceOnboardingToken({ id: device.id })).value.truncatedReference;

const result = await sTransportServices.account.loadItemFromTruncatedReference({ reference: deviceOnboardingInfoReference });

expect(result).toBeSuccessful();
expect(result.value.type).toBe("DeviceOnboardingInfo");
});

test("loads the DeviceOnboardingInfo with the truncated reference including a profile name", async () => {
const profileName = "aProfileName";
const deviceOnboardingInfoReference = (await sTransportServices.devices.getDeviceOnboardingToken({ id: device.id, profileName })).value.truncatedReference;

const result = await sTransportServices.account.loadItemFromTruncatedReference({ reference: deviceOnboardingInfoReference });

expect(result).toBeSuccessful();
expect(result.value.type).toBe("DeviceOnboardingInfo");
expect((result.value.value as DeviceOnboardingInfoDTO).profileName).toBe(profileName);
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/transport/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nmshd/transport",
"version": "2.4.2",
"version": "2.5.0",
"description": "The transport library handles backbone communication and content encryption.",
"homepage": "https://enmeshed.eu",
"repository": {
Expand Down
Loading

0 comments on commit 56b83f1

Please sign in to comment.