/** * EccEncryptedSecret protect/unprotect — OPC 10000-6 §6.8.3 + OPC 10000-4 §7.40.2.5. * * Used to protect UserIdentityToken secrets (passwords, tokenData) when the * UserTokenPolicy SecurityPolicy is ECC (EccNistP256 / EccNistP384). All * primitives are WebCrypto-only. * * Construction (sender side): * 1. ECDH(senderEphemeralPrivate, receiverEphemeralPublic) -> IKM (x-coordinate) * 2. SecretSalt = L | UTF8("opcua-secret") | SenderPublicKey | ReceiverPublicKey * (L = EncryptionKeyLength + InitializationVectorLength as LE16; * public keys are x||y zero-padded big-endian, as in §6.8.1) * 3. HKDF extract/expand (same T(n) construction as the channel handshake, * Info = SecretSalt) -> EncryptingKey | InitializationVector * (no signing key: Table 71 splits keying material into enc key + IV only) * 4. Payload plaintext = ByteString(Nonce) + ByteString(Secret) + padding + * UInt16(PayloadPaddingSize); AES-CBC encrypt (payload is pre-padded, so * WebCrypto performs no additional padding) * 5. Serialize the EncryptedSecret envelope (ExtensionObject-style with the * EccEncryptedSecret DataType NodeId 17546) and ECDSA-sign everything * after the Length field, excluding the Signature itself. * * Wire conventions chosen where the spec leaves encoding open: * - ECDSA signatures are raw r||s (64 B P-256, 96 B P-384), consistent with * this stack's OPN ECDSA handling (see `ecc.ts`). * - KeyData is ByteString(SenderPublicKey) + ByteString(ReceiverPublicKey) * and is NOT encrypted (Table 186); KeyDataLength is its plain length. * * SCOPE: crypto + envelope codec only. The session handshake that delivers * the receiver EphemeralKey (AdditionalHeader in CreateSession/ActivateSession, * §6.8.2) lives in the session layer; see `parseEccSessionEphemeralKey` below * for the parsing half used by it. */ import { EccPolicyParams } from './ecc'; /** DataType NodeId of EccEncryptedSecret (ns=0). */ export declare const ECC_ENCRYPTED_SECRET_TYPE_ID = 17546; export declare const ECC_SECRET_SALT_LABEL = "opcua-secret"; /** OPC UA DateTime as LE64 100ns ticks since 1601-01-01 UTC. */ export declare function dateToTicks(date: Date): { lo: number; hi: number; }; export declare function ticksToDate(lo: number, hi: number): Date; export interface EccSecretKeys { encryptingKey: Uint8Array; initializationVector: Uint8Array; } /** SecretSalt = L | UTF8("opcua-secret") | SenderPublicKey | ReceiverPublicKey */ export declare function buildSecretSalt(derivedLength: number, senderPublicKey: Uint8Array, receiverPublicKey: Uint8Array): Uint8Array; /** IKM=shared secret, Salt=Info=SecretSalt -> EncryptingKey | InitializationVector. */ export declare function deriveEccSecretKeys(ikm: Uint8Array, salt: Uint8Array, params: EccPolicyParams): Promise; export declare function secretPaddingSize(nonceLength: number, secretLength: number, blockSize: number): number; /** ByteString(Nonce) + ByteString(Secret) + padding + UInt16(PaddingSize). */ export declare function buildSecretPayload(nonce: Uint8Array, secret: Uint8Array, blockSize: number): Uint8Array; /** Inverse of buildSecretPayload with padding validation (constant-shape errors). */ export declare function parseSecretPayload(plain: Uint8Array): { nonce: Uint8Array; secret: Uint8Array; }; export interface ProtectEccSecretOptions { params: EccPolicyParams; /** SecurityPolicyUri recorded in the envelope (the token policy). */ policyUri: string; /** Secret bytes (UTF-8 password, or tokenData). */ secret: Uint8Array; /** Last serverNonce (channel nonce at ActivateSession time). */ nonce: Uint8Array; /** Fresh sender (client) ephemeral ECDH private key + x||y public key. */ senderPrivateKey: CryptoKey; senderPublicKey: Uint8Array; /** Receiver (server session) ephemeral x||y public key. */ receiverPublicKey: Uint8Array; /** ECDSA signing key + DER certificate (may be omitted when known to receiver). */ signingPrivateKey: CryptoKey; signingCertificate?: Uint8Array; signingTime?: Date; } /** * Build a complete EccEncryptedSecret envelope (ExtensionObject-style bytes * suitable for UserNameIdentityToken.password / IssuedIdentityToken.tokenData). */ export declare function protectEccSecret(options: ProtectEccSecretOptions): Promise; export interface ParsedEccEncryptedSecret { policyUri: string; certificate: Uint8Array; signingTime: Date; senderPublicKey: Uint8Array; receiverPublicKey: Uint8Array; encryptedPayload: Uint8Array; signature: Uint8Array; } export declare function parseEccEncryptedSecret(envelope: Uint8Array, params: EccPolicyParams): ParsedEccEncryptedSecret; export interface UnprotectEccSecretOptions { params: EccPolicyParams; /** Receiver (server session) ephemeral ECDH private key. */ receiverPrivateKey: CryptoKey; /** * Signing certificate to verify against when the envelope Certificate is * empty (known-receiver case, e.g. client app cert over SecureChannel). */ trustedCertificate?: Uint8Array; } export interface UnprotectedEccSecret { secret: Uint8Array; nonce: Uint8Array; policyUri: string; senderPublicKey: Uint8Array; signingTime: Date; } /** Verify + decrypt an EccEncryptedSecret envelope. */ export declare function unprotectEccSecret(envelope: Uint8Array, options: UnprotectEccSecretOptions): Promise; //# sourceMappingURL=ecc_secret.d.ts.map