@katlux/toolkit 0.1.1-alpha.140 → 0.1.1-alpha.141
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/module.json +1 -1
- package/dist/runtime/components/KButton/KButton.global.d.vue.ts +1 -1
- package/dist/runtime/components/KButton/KButton.global.vue.d.ts +1 -1
- package/dist/runtime/components/KCheckbox/KCheckbox.global.d.vue.ts +1 -1
- package/dist/runtime/components/KCheckbox/KCheckbox.global.vue.d.ts +1 -1
- package/dist/runtime/components/KCombobox/KCombobox.global.d.vue.ts +1 -1
- package/dist/runtime/components/KCombobox/KCombobox.global.vue.d.ts +1 -1
- package/dist/runtime/components/KDatatable/KDataIterator.global.d.vue.ts +1 -1
- package/dist/runtime/components/KDatatable/KDataIterator.global.vue.d.ts +1 -1
- package/dist/runtime/components/KDatePicker/KDatePicker.global.d.vue.ts +1 -1
- package/dist/runtime/components/KDatePicker/KDatePicker.global.vue.d.ts +1 -1
- package/dist/runtime/components/KHourPicker/KHourPicker.global.d.vue.ts +1 -1
- package/dist/runtime/components/KHourPicker/KHourPicker.global.vue.d.ts +1 -1
- package/dist/runtime/components/KRangeSlider/KRangeSlider.global.d.vue.ts +1 -1
- package/dist/runtime/components/KRangeSlider/KRangeSlider.global.vue.d.ts +1 -1
- package/dist/runtime/components/KSlider/KSlider.global.d.vue.ts +1 -1
- package/dist/runtime/components/KSlider/KSlider.global.vue.d.ts +1 -1
- package/dist/runtime/components/KTreePicker/KTreePicker.global.d.vue.ts +1 -1
- package/dist/runtime/components/KTreePicker/KTreePicker.global.vue.d.ts +1 -1
- package/dist/skills/katlux-config/SKILL.md +7 -7
- package/dist/skills/katlux-providers/SKILL.md +1 -1
- package/dist/skills/katlux-providers/providers/encryption-asymmetric.md +102 -0
- package/dist/skills/katlux-providers/providers/encryption-field-level.md +260 -0
- package/dist/skills/katlux-providers/providers/encryption-key-management.md +196 -0
- package/dist/skills/katlux-providers/providers/encryption-key-pinning.md +115 -0
- package/dist/skills/katlux-providers/providers/encryption-streaming.md +84 -0
- package/dist/skills/katlux-providers/providers/encryption-symmetric.md +139 -0
- package/dist/skills/katlux-providers/providers/encryption-threat-model.md +110 -0
- package/dist/skills/katlux-providers/providers/encryption.md +44 -267
- package/package.json +2 -2
|
@@ -1,267 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
- **Account & HMAC Key Wrapping (`CKeyManager`)**:
|
|
46
|
-
- `wrapAccountKeyForUser(adek, userPublicKey): Promise<string>`: Wraps an ADEK for a user using RSA-OAEP.
|
|
47
|
-
- `unwrapAccountKeyForUser(wrappedKeyBase64, userPrivateKey, unwrappedKeyAlgorithm?, extractable?): Promise<CryptoKey>`: Restores an unextractable AES-GCM ADEK from envelope using RSA-OAEP.
|
|
48
|
-
- `wrapHMACKeyForUser(hmacKey, userPublicKey): Promise<string>`: Wraps an HMAC blind indexing key for a user using RSA-OAEP.
|
|
49
|
-
- `unwrapHMACKeyForUser(wrappedKeyBase64, userPrivateKey, hash?, extractable?): Promise<CryptoKey>`: Restores an HMAC search key using recipient RSA-OAEP private key.
|
|
50
|
-
- `rewrapAccountKeyForUser(wrappedKeyBase64, myPrivateKey, recipientPublicKey): Promise<string>`: Atomically re-wraps an ADEK envelope for a new recipient without exposing raw extractable keys to application memory, guaranteeing memory zeroization via `finally`.
|
|
51
|
-
- **Blind Index & Token Utilities (`CKeyManager` / `CSearchIndex`)**:
|
|
52
|
-
- `CKeyManager.computeBlindIndex(value, hmacKey): Promise<string>`: Computes deterministic HMAC-SHA256 blind index hash for arbitrary values.
|
|
53
|
-
- `searchIndex.computeBlindIndex(term): Promise<string>`: Computes blind index using configured search HMAC key.
|
|
54
|
-
- `searchIndex.indexRowDecrypted(row, decryptedPlaintext): Promise<void>`: Indexes a row using pre-decrypted plaintext fields while preserving raw ciphertext in data tables.
|
|
55
|
-
- **Digital Signatures & Access Grants (`CKeyManager` / `canonicalizeJson`)**:
|
|
56
|
-
- `canonicalizeJson(value): string`: Serializes a JavaScript value to a deterministic, canonical JSON string conforming to RFC 8785 (JCS).
|
|
57
|
-
- `generateSigningKeyPair(curve?, extractable?): Promise<IKeyPair>` / `generateECDSAKeyPair()`: Generates an ECDSA signing key pair (`P-256`, `P-384`, `P-521`).
|
|
58
|
-
- `getKeyFingerprint(publicKey): Promise<string>`: Generates a deterministic SHA-256 fingerprint for a public key formatted as `SHA256:<base64url>`.
|
|
59
|
-
- `sign(data, privateKey): Promise<string>`: Signs arbitrary data or JSON objects using an ECDSA P-256 private key (objects automatically canonicalized via RFC 8785).
|
|
60
|
-
- `verify(data, signature, publicKey): Promise<boolean>`: Verifies an ECDSA P-256 signature against original data or JSON object.
|
|
61
|
-
- `signGrant(grant: IAccessGrant, granterPrivateKey, granterPublicKey?): Promise<ISignedGrant>`: Signs a structured access grant, embedding signature and granter key fingerprint.
|
|
62
|
-
- `verifyGrant(signedGrant: ISignedGrant, granterPublicKey, options?): Promise<boolean>`: Verifies authenticity, integrity, and granter key fingerprint of an access grant, defeating key-substitution attacks.
|
|
63
|
-
- **Domain-Separated Key Derivation (`CKeyManager.deriveAuthAndEncryptionKeys`)**:
|
|
64
|
-
- `deriveAuthAndEncryptionKeys(password, salt?, options?): Promise<IDomainDerivedKeys>`: Hardened two-stage derivation pipeline. PBKDF2 stretches low-entropy user password and salt, then HKDF-Expand produces two cryptographically isolated keys (`authKey` for authentication challenges and `encryptionKey` for AES-GCM data encryption) using domain-separated context tags (`katlux-auth-key-v1` and `katlux-encryption-key-v1`). Full compromise of `authKey` reveals zero mathematical information about `encryptionKey`. Intermediate master secret buffers are immediately zeroized in memory.
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
- **Envelope Contract (`IEncryptedPayload`)**:
|
|
69
|
-
```ts
|
|
70
|
-
interface IEncryptedPayload {
|
|
71
|
-
__encrypted: true
|
|
72
|
-
ciphertext: string // Base64 ciphertext (always present)
|
|
73
|
-
alg: string // 'AES-GCM' | 'AES-CBC-256+HMAC-SHA-256' | 'RSA-OAEP-4096+AES-GCM-256' | 'ECDH-P-256+AES-GCM-256'
|
|
74
|
-
kid?: string // Key identifier / version for key rotation tracking
|
|
75
|
-
iv?: string // Base64 IV
|
|
76
|
-
salt?: string // Base64 KDF salt
|
|
77
|
-
kdf?: string // 'PBKDF2' | 'HKDF'
|
|
78
|
-
iter?: number // PBKDF2 iteration count (default: 310,000, clamped [1,000, 600,000])
|
|
79
|
-
tag?: string // Explicit HMAC tag (AES-CBC)
|
|
80
|
-
wrappedKey?: string // Base64 RSA-wrapped AES key (RSA hybrid)
|
|
81
|
-
sharedKey?: boolean // Shared DEK marker for field-level encryption
|
|
82
|
-
epk?: JsonWebKey // Ephemeral public key (ECDH)
|
|
83
|
-
}
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
- **`IProviderEncryptionOptions`**:
|
|
87
|
-
```ts
|
|
88
|
-
interface IProviderEncryptionOptions {
|
|
89
|
-
enabled?: boolean // Master toggle (default: false)
|
|
90
|
-
key?: TKeyProvider // Single key or key provider (legacy/simple mode)
|
|
91
|
-
keys?: Record<string, TKeyProvider | IKeyPair> // Built-in Keyring dictionary mapping kid to keys
|
|
92
|
-
activeKid?: string // Active key identifier from keys to use for outbound encryption
|
|
93
|
-
kid?: string // Key identifier / version (e.g. 'v1', 'tenant-a-key-2026')
|
|
94
|
-
aad?: string | Uint8Array | ArrayBuffer | ((record: any, field: string) => string | Uint8Array | ArrayBuffer) // AEAD Additional Data or dynamic callback
|
|
95
|
-
aadFields?: string[] // Sibling record fields to deterministically bind into AAD (e.g. ['contact_id', 'version'])
|
|
96
|
-
baseAad?: string // Optional base prefix for AAD context binding
|
|
97
|
-
decryptOnSSR?: boolean // default: false. Prevents SSR decryption unless explicitly enabled with server secrets
|
|
98
|
-
fields?: string[] // Field-level encryption: only encrypt listed fields
|
|
99
|
-
strict?: boolean // Enforces strict decryption: unencrypted plaintext in `fields` triggers injection violation; defaults allowedAlgorithms to ['AES-GCM']
|
|
100
|
-
allowedAlgorithms?: string[] // Whitelist of permitted cipher algorithms (e.g. ['AES-GCM'])
|
|
101
|
-
allowedKids?: string[] // Whitelist of permitted Key Identifiers (kid); defaults to Object.keys(keys)
|
|
102
|
-
onDecryptError?: ((info: IDecryptErrorInfo) => any) | boolean | string // Per-field error hook, safe fallback marker, or true for '[⚠ Decryption Error]'
|
|
103
|
-
searchIndex?: boolean // Enables HMAC-SHA256 blind index and trigram search index on encrypted fields
|
|
104
|
-
preEncrypted?: boolean // Set to true if API endpoints return pre-encrypted ciphertext envelopes; enables in-memory index decryption
|
|
105
|
-
hmacKey?: TKeyProvider // Optional dedicated HMAC key for search indexing (defaults to encryption key)
|
|
106
|
-
algorithm?: 'AES-GCM' | string // default: 'AES-GCM'
|
|
107
|
-
customProvider?: IEncryptionProvider // Custom cipher adapter (e.g. CRSA, CECDH, AES-CBC)
|
|
108
|
-
kdf?: 'none' | 'pbkdf2' | 'hkdf' // Key derivation strategy:
|
|
109
|
-
// - 'pbkdf2': Recommended for human passphrases/passwords (OWASP recommended rounds)
|
|
110
|
-
// - 'hkdf': For high-entropy IKM / subkey derivation (warns if used with string passwords)
|
|
111
|
-
// - 'none': When supplying pre-derived 256-bit raw keys, Buffers, or CryptoKeys
|
|
112
|
-
kdfIterations?: number // PBKDF2 rounds (default: 310,000 per OWASP, clamped [1,000, 600,000])
|
|
113
|
-
kdfHash?: 'SHA-256' | 'SHA-512' // KDF hash algorithm
|
|
114
|
-
kdfSalt?: string | Uint8Array | ArrayBuffer // Optional static salt (random salt in envelope if omitted)
|
|
115
|
-
publicKey?: CryptoKey // Optional public key for asymmetric encryption
|
|
116
|
-
privateKey?: CryptoKey // Optional private key for asymmetric decryption
|
|
117
|
-
recipientPublicKey?: CryptoKey // Recipient public key for hybrid encryption
|
|
118
|
-
recipientPrivateKey?: CryptoKey // Recipient private key for hybrid decryption
|
|
119
|
-
curve?: 'P-256' | 'P-384' | 'P-521' // Curve for ECDH providers
|
|
120
|
-
info?: string // Optional context/info string for HKDF
|
|
121
|
-
}
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
- **Factory & Provider Creation**:
|
|
125
|
-
- `createEncryptionProvider(options: IProviderEncryptionOptions): IEncryptionProvider`: Unified factory that instantiates and configures the appropriate cipher provider based on `options.algorithm` (`'AES-GCM'`, `'AES-CBC'`, `'RSA-OAEP'`, `'ECDH'`) or returns `options.customProvider`. Supports `IKeyPair` or individual keys, HKDF info, curve configuration, and KDF options.
|
|
126
|
-
|
|
127
|
-
- **Usage in DataProvider (Client & Server)**:
|
|
128
|
-
Supported uniformly across **all** client and server data providers:
|
|
129
|
-
- **Local (Non-API)**: `CFlatClientDataProvider`, `CTreeClientDataProvider` (via `AEncryptedClientProvider`)
|
|
130
|
-
- **API Client-Side**: `CAPIFlatClientDataProvider`, `CAPITreeClientDataProvider`
|
|
131
|
-
- **Server-Side**: `CAPIFlatServerDataProvider`, `CAPITreeServerDataProvider`
|
|
132
|
-
|
|
133
|
-
#### Local DataProvider Encryption Architecture
|
|
134
|
-
- **Eager Encryption**: `setData(rows)` encrypts designated `fields` immediately before storing in `allData`. Plaintext never persists in `allData`.
|
|
135
|
-
- **Pre-Encrypted Ingest & Search**: When datasets arrive already encrypted (`preEncrypted: true`), data providers (`CFlatClientDataProvider`, `CAPIFlatClientDataProvider`) perform a transient in-memory decryption pass on indexed fields to populate `CSearchIndex` without modifying or leaking the persistent ciphertext rows in `allData`.
|
|
136
|
-
- **Non-blocking Ingestion**: `setDataChunked(rows, { chunkSize: 250, yieldStrategy: 'idle' })` yields between chunks to prevent main-thread freezing on large datasets.
|
|
137
|
-
- **Idempotent Ingestion**: Pre-encrypted envelopes (`__encrypted: true`, e.g. from IndexedDB or Web Workers) pass through untouched without double-encryption.
|
|
138
|
-
- **Lazy Page-Level Decryption**: `loadPageData()` slices `allData` and decrypts only the active page (`pageSize` rows) into `pageData`. Only visible rows are plaintext in memory.
|
|
139
|
-
- **Blind Index Search (`CSearchIndex`)**: When `searchIndex: true`, exact match (`==`, `!=`) and substring search (`in`) operate directly on encrypted fields via deterministic HMAC-SHA256 blind tokens and trigram sets without full dataset decryption.
|
|
140
|
-
- **Zero-Cost Path**: When `enabled` is false, `setData` runs 100% synchronously with zero microtask overhead.
|
|
141
|
-
|
|
142
|
-
```ts
|
|
143
|
-
import { CFlatClientDataProvider } from '@katlux/providers'
|
|
144
|
-
|
|
145
|
-
const customerProvider = new CFlatClientDataProvider({
|
|
146
|
-
pageSize: 20,
|
|
147
|
-
encryption: {
|
|
148
|
-
enabled: true,
|
|
149
|
-
key: 'secret-key-32-chars-long-12345!',
|
|
150
|
-
kid: 'tenant-key-v1',
|
|
151
|
-
fields: ['ssn', 'salary', 'creditCard'],
|
|
152
|
-
searchIndex: true // Enables search/filter on encrypted fields via CSearchIndex
|
|
153
|
-
}
|
|
154
|
-
})
|
|
155
|
-
|
|
156
|
-
// Eagerly encrypts sensitive fields; leaves id, role, department in plaintext
|
|
157
|
-
await customerProvider.setData(rawEmployees)
|
|
158
|
-
|
|
159
|
-
// Large dataset ingestion with progress reporting:
|
|
160
|
-
await customerProvider.setDataChunked(largeEmployees, {
|
|
161
|
-
chunkSize: 500,
|
|
162
|
-
onProgress: (p) => console.log(`Encryption progress: ${(p * 100).toFixed(0)}%`)
|
|
163
|
-
})
|
|
164
|
-
|
|
165
|
-
// Dynamically rotate key:
|
|
166
|
-
customerProvider.setEncryption({ enabled: true, key: newKey, kid: 'tenant-key-v2', fields: ['ssn', 'salary'] })
|
|
167
|
-
|
|
168
|
-
// Upon user logout / session termination:
|
|
169
|
-
customerProvider.clearEncryption() // Clears keys, zeroes memory, and disables encryption
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
- **Usage with RequestProvider**:
|
|
173
|
-
```ts
|
|
174
|
-
const rp = new RequestProvider()
|
|
175
|
-
rp.setEncryption({ enabled: true, key: 'my-secret-32-char-key!!!', kid: 'tenant-key-2026' })
|
|
176
|
-
// Outbound POST/PUT/PATCH bodies encrypted; encrypted responses auto-decrypted
|
|
177
|
-
|
|
178
|
-
// Upon user logout:
|
|
179
|
-
rp.clearEncryption() // Safely clears cached cipher instance, scoped WeakMap instances, and zeroes keys
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
#### Authenticated Additional Data (AAD) & Security Guarantees
|
|
183
|
-
In multi-tenant, field-encrypted, and SSR scenarios, Katlux cryptographic providers enforce strict, integration-tested security guarantees:
|
|
184
|
-
- **Field & Record Binding**: During value-level and field-level encryption, `AEncryptionProvider` and `CNodeCryptoEncryptionProvider` automatically bind:
|
|
185
|
-
`aad:${baseAad}|record:${recordId}|field:${fieldName}`
|
|
186
|
-
Where `recordId` is extracted from `record.id`, `record._id`, or `options.recordId`.
|
|
187
|
-
- **Transposition Tamper Resistance**: Moving or swapping an encrypted envelope from one database row to another, or from one column (`ssn`) to another (`phone`), causes AES-GCM tag verification to immediately fail with an authentication error.
|
|
188
|
-
- **Cache-at-Rest Full Envelope**: When caching responses where field-level encryption is active (`fields: [...]`), `RequestProvider` automatically wraps the entire object in a full envelope at rest. Neither targeted sensitive fields nor unlisted metadata fields appear as plaintext in raw storage across any client or server cache adapter.
|
|
189
|
-
- **Node GCM 16-Byte Tag Enforcement**: `CNodeCryptoEncryptionProvider` strictly validates a 16-byte (128-bit) authentication tag across all synchronous and asynchronous decryption paths (rejecting truncated 12, 8, or 4-byte tags).
|
|
190
|
-
- **Nonce Misuse Resistance**: Initialization Vectors (IVs) are freshly generated via cryptographically secure RNG per operation (12 bytes for GCM, 16 bytes for CBC) with proven uniqueness across sibling fields, batch arrays, and concurrent executions.
|
|
191
|
-
- **Deterministic Search Token Segregation**: `CSearchIndex` HMAC-SHA256 blind index tokens are deterministic for search matching and strictly segregated from non-deterministic ciphertext IVs.
|
|
192
|
-
- **Non-Extractable Tenant Keys**: `CKeyManager.generateAccountDataKey()` and `CKeyManager.unwrapAccountKeyForUser()` produce `CryptoKey` instances with `extractable: false` by default, safeguarding unwrapped symmetric tenant keys against exfiltration via developer tools or malicious extensions.
|
|
193
|
-
- **Atomic Key Re-Wrapping (`CKeyManager.rewrapAccountKeyForUser`)**: When sharing an Account Data Encryption Key (ADEK) between users, `CKeyManager.rewrapAccountKeyForUser(wrappedKey, myPrivateKey, recipientPublicKey)` atomically decrypts the raw key material and re-encrypts it with the recipient's RSA-OAEP public key without ever exposing the raw extractable symmetric key to caller application memory or leaving extractable CryptoKeys in memory. Immediate memory zeroization (`fill(0)`) is guaranteed across all paths.
|
|
194
|
-
- **SSR Confidentiality & Cache Auth Guard**: With `decryptOnSSR: false` (the secure zero-trust default), plaintext is never exposed in server memory or serialized HTML hydration payloads. Requests with `cookie` or `Authorization` headers automatically bypass shared server caches (`CApplicationCache`), preventing cross-user session cache poisoning.
|
|
195
|
-
|
|
196
|
-
#### Built-in Keyring & Multi-Key Rotation Architecture
|
|
197
|
-
- **Zero-Downtime Key Rotation**: Configuring `keys: { 'k2025': key1, 'k2026': key2 }` alongside `activeKid: 'k2026'` ensures all outbound writes are automatically tagged with `kid: 'k2026'` and encrypted with `key2`, while legacy records tagged with `k2025` decrypt seamlessly under `key1`.
|
|
198
|
-
- **Automatic Whitelisting & Untrusted `kid` Protection**: `allowedKids` automatically defaults to `Object.keys(keys)` when `keys` is provided. Incoming envelopes carrying an unknown or unregistered `kid` are immediately rejected with an unauthorized key security error (`Unauthorized key: kid '${payload.kid}' is not in allowedKids.`).
|
|
199
|
-
- **Concurrent Multi-Key Warmup**: Calling `warmupKey()` (or `warmupKeySync()` on Node) resolves and primes all cryptographic keys across the entire keyring concurrently using `Promise.all`, preventing runtime latency spikes or race conditions during rotation periods.
|
|
200
|
-
- **Dynamic Runtime Keyring Management**: Keyrings can be rotated dynamically at runtime using `provider.setKeyring(newKeys, newActiveKid)` or `provider.setActiveKid(newKid)` without recreating provider instances or dropping existing session caches.
|
|
201
|
-
|
|
202
|
-
#### Backend Persistence & Datatable Encrypted Search Architecture
|
|
203
|
-
To enable fast exact-match and substring search across AES-256-GCM encrypted records in persisted storage and server-side datatables without decrypting rows or leaking plaintext to the persistence server:
|
|
204
|
-
|
|
205
|
-
1. **Schema Column Mapping**:
|
|
206
|
-
- **Ciphertext (`JSONB` or `TEXT`)**: Holds the complete Katlux envelope `{ __encrypted: true, ciphertext, iv, tag, v: 1 }`.
|
|
207
|
-
- **Blind Index (`CHAR(64)`)**: Deterministic HMAC-SHA256 hash of normalized plaintext, indexed with a **B-Tree** for $O(\log N)$ point lookups (`=` / `IN`).
|
|
208
|
-
- **Trigram Array (`TEXT[]` or `BIGINT[]`)**: Set of hashed 3-character slices, indexed with an **inverted index (e.g. GIN / array index)** for substring queries.
|
|
209
|
-
|
|
210
|
-
```sql
|
|
211
|
-
CREATE TABLE contacts (
|
|
212
|
-
id SERIAL PRIMARY KEY,
|
|
213
|
-
name_encrypted JSONB NOT NULL,
|
|
214
|
-
email_encrypted JSONB NOT NULL,
|
|
215
|
-
salary_encrypted JSONB,
|
|
216
|
-
name_bidx CHAR(64) NOT NULL,
|
|
217
|
-
email_bidx CHAR(64) NOT NULL,
|
|
218
|
-
name_trigrams TEXT[] NOT NULL,
|
|
219
|
-
email_trigrams TEXT[] NOT NULL,
|
|
220
|
-
role VARCHAR(100),
|
|
221
|
-
department VARCHAR(100),
|
|
222
|
-
status VARCHAR(50) DEFAULT 'Active'
|
|
223
|
-
);
|
|
224
|
-
|
|
225
|
-
-- B-Tree for exact lookups:
|
|
226
|
-
CREATE INDEX idx_contacts_name_bidx ON contacts (name_bidx);
|
|
227
|
-
CREATE INDEX idx_contacts_email_bidx ON contacts (email_bidx);
|
|
228
|
-
|
|
229
|
-
-- Inverted index for fast array containment substring search:
|
|
230
|
-
CREATE INDEX idx_contacts_name_trigrams ON contacts USING GIN (name_trigrams);
|
|
231
|
-
CREATE INDEX idx_contacts_email_trigrams ON contacts USING GIN (email_trigrams);
|
|
232
|
-
```
|
|
233
|
-
|
|
234
|
-
2. **Ingestion Pipeline**:
|
|
235
|
-
- Normalize plaintext (`NFKC` + lowercase).
|
|
236
|
-
- Generate exact blind index token via `CKeyManager.computeBlindIndex(plain, hmacKey)` or `searchIndex.computeToken(plain)`.
|
|
237
|
-
- Extract 3-character slices via `extractTrigrams(plain)` and hash each trigram with `searchIndex.computeTrigramTokens(plain)`.
|
|
238
|
-
- Encrypt sensitive columns with `cipher.encryptField(plain, { recordId: id, fieldName: 'name' })`.
|
|
239
|
-
- Persist encrypted envelopes and token arrays into the persistence datatable storage.
|
|
240
|
-
|
|
241
|
-
3. **Query Execution**:
|
|
242
|
-
- **Exact Match (`name = $1`)**:
|
|
243
|
-
```sql
|
|
244
|
-
-- Compute HMAC token in API, then point-lookup using B-Tree:
|
|
245
|
-
SELECT id, name_encrypted, email_encrypted, role FROM contacts WHERE name_bidx = $1;
|
|
246
|
-
```
|
|
247
|
-
- **Substring Search (`name CONTAINS $1`)**:
|
|
248
|
-
```sql
|
|
249
|
-
-- Extract & hash search query trigrams, then query via array containment operator (@>):
|
|
250
|
-
SELECT id, name_encrypted, email_encrypted, role
|
|
251
|
-
FROM contacts
|
|
252
|
-
WHERE name_trigrams @> $1::text[]
|
|
253
|
-
ORDER BY id ASC
|
|
254
|
-
LIMIT 10 OFFSET 0;
|
|
255
|
-
```
|
|
256
|
-
- **Compound Filtering**:
|
|
257
|
-
Combine plain columns with encrypted token clauses:
|
|
258
|
-
```sql
|
|
259
|
-
WHERE name_trigrams @> $1::text[] AND department = 'Security'
|
|
260
|
-
```
|
|
261
|
-
|
|
262
|
-
4. **Security & Production Best Practices**:
|
|
263
|
-
- **Strict Key Isolation**: Isolate `DATA_ENCRYPTION_KEY` (AES-256-GCM) from `BLIND_INDEX_HMAC_KEY`. Persistence storage compromise cannot decrypt plaintext; cipher key exposure cannot reverse blind indices.
|
|
264
|
-
- **Short Queries (< 3 chars)**: Substring search requires at least 3 characters to form a valid trigram. Enforce a 3-character minimum in client UI.
|
|
265
|
-
- **Low-Cardinality Isolation**: Never blind index low-cardinality fields (boolean flags, binary status) to avoid frequency analysis leakage.
|
|
266
|
-
- **Client Decryption Pipeline**: API responses return encrypted envelopes (`__encrypted: true`). Frontend `CAPIFlatServerDataProvider` decrypts only the received page slice via `decryptPageRows()` on arrival.
|
|
267
|
-
|
|
1
|
+
# Katlux Cryptographic Architecture & Encryption Suite (`@katlux/providers`) Master Index
|
|
2
|
+
|
|
3
|
+
> **Atomic Architecture**: To minimize prompt context and token consumption, the Katlux encryption architecture is split into 7 focused atomic specifications. Read **only** the atomic document required for your task.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 1. Atomic Encryption Specifications
|
|
8
|
+
|
|
9
|
+
| Document | Topic & Focus | Core Classes & Primitives | Document Link |
|
|
10
|
+
| :--- | :--- | :--- | :--- |
|
|
11
|
+
| **Threat Model & Contracts** | E2EE architecture, boundary rules, non-goals, envelope schema, provider options | `IEncryptedPayload`, `IProviderEncryptionOptions`, `createEncryptionProvider`, `isEncrypted` | [encryption-threat-model.md](encryption-threat-model.md) |
|
|
12
|
+
| **Symmetric Ciphers** | AES-GCM-256, authenticated AES-CBC, Node sync cipher, keyring rotation, strict decryption, dynamic AAD | `CWebCryptoEncryptionProvider`, `CWebCryptoAESCBCProvider`, `CNodeCryptoEncryptionProvider` | [encryption-symmetric.md](encryption-symmetric.md) |
|
|
13
|
+
| **Asymmetric Hybrid Ciphers** | RSA-OAEP-4096 and ECDH ephemeral hybrid encryption, SPKI/PKCS#8 PEM import/export | `CRSAEncryptionProvider`, `CECDHEncryptionProvider`, `importPublicKeyFromPEM` | [encryption-asymmetric.md](encryption-asymmetric.md) |
|
|
14
|
+
| **Key Lifecycle & Derivation** | Tenant key generation, ADEK wrapping/rewrapping, RFC 8785 canonical JSON access grants, domain-separated KDF, master passphrase re-keying | `CKeyManager`, `canonicalizeJson`, `deriveAuthAndEncryptionKeys`, `rekeyUserKeypair` | [encryption-key-management.md](encryption-key-management.md) |
|
|
15
|
+
| **Key Pinning (TOFU) & Attestations** | Trust-On-First-Use key store, signed key-reset attestation protocol, 6 strict verification rules, memory/storage adapters | `IKeyPinningStore`, `CMemoryKeyPinningStore`, `CLocalStorageKeyPinningStore`, `CIndexedDBKeyPinningStore`, `verifyAndPinKey`, `signKeyResetAttestation` | [encryption-key-pinning.md](encryption-key-pinning.md) |
|
|
16
|
+
| **Web Streams Chunked AEAD** | Constant-memory chunked streaming cipher, 16-byte header framing protocol, blob helpers, Node stream interoperability | `CWebCryptoStreamCipher`, `createEncryptionStream`, `createDecryptionStream`, `encryptBlob`, `decryptBlob` | [encryption-streaming.md](encryption-streaming.md) |
|
|
17
|
+
| **Field Encryption & Ingestion** | Row scalar encryption, eager client ingestion, pre-encrypted datasets, blind indexing, trigram substring queries, SQL schema | `encryptField`, `decryptField`, `AEncryptedClientProvider`, `CSearchIndex`, `computeBlindIndex` | [encryption-field-level.md](encryption-field-level.md) |
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## 2. Decision Matrix: Which Cryptographic Tool to Use?
|
|
22
|
+
|
|
23
|
+
| Requirement / Scenario | Recommended Solution | Documentation |
|
|
24
|
+
| :--- | :--- | :--- |
|
|
25
|
+
| Encrypting database rows or API payloads in browser/server | `CWebCryptoEncryptionProvider` (AES-GCM-256) | [encryption-symmetric.md](encryption-symmetric.md) |
|
|
26
|
+
| Fast synchronous encryption in high-throughput Node.js server routes | `CNodeCryptoEncryptionProvider.encryptSync` | [encryption-symmetric.md](encryption-symmetric.md) |
|
|
27
|
+
| Encrypting large files, media, or archives (> 5 MB) without memory bloat | `createEncryptionStream` / `encryptBlob` | [encryption-streaming.md](encryption-streaming.md) |
|
|
28
|
+
| Sharing tenant symmetric keys with specific users | `CKeyManager.wrapAccountKeyForUser` (RSA-OAEP) | [encryption-key-management.md](encryption-key-management.md) |
|
|
29
|
+
| Re-wrapping keys between users without exposing raw bytes | `CKeyManager.rewrapAccountKeyForUser` | [encryption-key-management.md](encryption-key-management.md) |
|
|
30
|
+
| Forward-secure ephemeral key exchange | `CECDHEncryptionProvider` | [encryption-asymmetric.md](encryption-asymmetric.md) |
|
|
31
|
+
| User password change without re-encrypting database payloads | `CKeyManager.rekeyUserKeypair` | [encryption-key-management.md](encryption-key-management.md) |
|
|
32
|
+
| Preventing rogue-admin public key substitution on peers | `CKeyManager.verifyAndPinKey` (TOFU store) | [encryption-key-pinning.md](encryption-key-pinning.md) |
|
|
33
|
+
| Encrypting sensitive columns while leaving IDs plaintext for sorting | `encryptField` / `AEncryptedClientProvider` | [encryption-field-level.md](encryption-field-level.md) |
|
|
34
|
+
| Exact-match lookups or substring search on encrypted database fields | `CSearchIndex` (HMAC-SHA256 blind indices & trigrams) | [encryption-field-level.md](encryption-field-level.md) |
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## 3. Showcase Live Reference Pages
|
|
39
|
+
|
|
40
|
+
- **Overview & SSR**: `/providers/request/encryption`
|
|
41
|
+
- **Symmetric**: `/providers/classes/CWebCryptoEncryptionProvider` · `/providers/classes/CWebCryptoAESCBCProvider` · `/providers/classes/CNodeCryptoEncryptionProvider`
|
|
42
|
+
- **Asymmetric / Hybrid**: `/providers/classes/CRSAEncryptionProvider` · `/providers/classes/CECDHEncryptionProvider`
|
|
43
|
+
- **Key Management**: `/providers/classes/CKeyManager`
|
|
44
|
+
- **Base & Contracts**: `/providers/classes/AEncryptionProvider` · `/providers/interfaces/IEncryptionProvider` · `/providers/interfaces/IProviderEncryptionOptions`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@katlux/toolkit",
|
|
3
|
-
"version": "0.1.1-alpha.
|
|
3
|
+
"version": "0.1.1-alpha.141",
|
|
4
4
|
"description": "Core UI toolkit and utilities for the Katlux ecosystem",
|
|
5
5
|
"author": "Katlux",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"**/*.sass"
|
|
55
55
|
],
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@katlux/providers": "^0.1.1-alpha.
|
|
57
|
+
"@katlux/providers": "^0.1.1-alpha.129",
|
|
58
58
|
"@nuxt/kit": "^3.12.0",
|
|
59
59
|
"@nuxtjs/i18n": "^10.4.0",
|
|
60
60
|
"pug": "^3.0.0",
|