Skip to content

Conversation

@ngussek
Copy link

@ngussek ngussek commented Jul 1, 2025

Readiness checklist

  • I added/updated tests.
  • I ensured that the PR title is good enough for the changelog.
  • I labeled the PR.
  • I self-reviewed the PR.

Integrates the rust crypto-layer (CAL) into the runtime to support secure elements for key storage and crypto operations.

@ngussek ngussek added the enhancement New feature or request label Jul 1, 2025
public async init(): Promise<Transport> {
log.trace("Initializing Libsodium...");
await SodiumWrapper.ready();
const sodium = SodiumWrapper.ready();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you split the await of SodiumWrapper?

await this.identity.init(deviceSharedSecret.identity);
await this.identityDeletionProcess.init();
await this.activeDevice.init(privBaseDevice, device);
await this.activeDevice.init(privBaseDevice as DeviceBoundKeyHandle, device);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Careful here, it is DeviceBoundKeyHandle | CryptoSecretKey. I guess you could add this to the top at the definition of let privBaseDevice

this.info.set("device", device.toJSON()),
this.info.set("identity", deviceSharedSecret.identity.toJSON()),
this.info.set("baseKey", privBaseDevice.toJSON()),
this.info.set("isHardwareBased", isHardwareBased),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather go with setting baseKey for legacy and baseKeyHandle with the CAL. Or we should rename isHardwareBased to isBaseKeyStoredOnHardware.

| CryptoSignatureKeypair
| CryptoSignaturePrivateKey
| CryptoSecretKey
| DeviceBoundKeyHandle,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to store the DeviceBoundKeyHandle to the DeviceSecretController? I mean the KeyHandle is not a secret.

import path from "path";
import * as tmp from "tmp";
import { AccountController, DeviceSharedSecret, Transport } from "../../src";
import { ALL_CRYPTO_PROVIDERS } from "../../src/core/CryptoProviderMapping";
Copy link
Contributor

@stnmtz stnmtz Jul 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests shouldn't import from "../../src", you might need to export CryptoProviderMapping to import from "@nmshd/transport"?

Copy link
Contributor

@jkoenig134 jkoenig134 Jul 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import from src is ok, but there might be an export missing (so that CryptoProviderMapping is available at ../../src)

Software: "Software",
Hardware: "Hardware",
Network: "Network",
LEGACY: "LEGACY"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is LEGACY Uppercase?

const FALLBACK_PREFERENCE: SecurityLevel = CryptoProviderTypes.Software;

export function getPreferredProviderLevel(cryptoObject: CryptoObject, cryptoOperation: CryptoKeyType, purpose?: Exclude<CryptoPurpose, undefined>): SecurityLevel {
const allowedOps = CRYPTO_OPERATION_OBJECT_MAP[cryptoObject];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need this autorization on code level base?


export const ALL_CRYPTO_PROVIDERS = ["SoftwareProvider", "AndroidProvider"];

const CRYPTO_OPERATION_OBJECT_MAP: Partial<Record<CryptoObject, CryptoKeyType[]>> = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me, this is a duplicate of OBJECT_OPERATION_PREFERENCES with less details :)

} as const;
type CryptoObject = (typeof CryptoObject)[keyof typeof CryptoObject];

export const ALL_CRYPTO_PROVIDERS = ["SoftwareProvider", "AndroidProvider"];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get the AndroidProvider here. Shouldn't this information come either from CAL or the app?

.gitignore Outdated
tsconfig.tsbuildinfo
node_modules
packages/*/coverage
nmshd-runtime.code-workspace
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undo that please.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants