@pkistudio/pvkgadgets 0.3.0

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/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ MIT License
2
+
3
+ Private Key Gadgets - browser tools for PKI key material
4
+
5
+ Copyright (c) 2000-2026 pkistudio
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,245 @@
1
+ # Private Key Gadgets
2
+
3
+ Private Key Gadgets is an experimental browser tool for generating and inspecting PKI key material. It keeps key-related objects in a PkiStudioJS-style tree on the left, and sends the selected DER object to the embedded PkiStudioJS ASN.1 viewer on the right.
4
+
5
+ Current version: 0.3.0
6
+
7
+ ## Features
8
+
9
+ ### Key Pair Management
10
+
11
+ - Detects key pair algorithms supported by the current browser through WebCrypto.
12
+ - Generates supported key pairs from the New menu, including RSA, EC, Ed25519, and X25519 when available.
13
+ - Normalizes duplicate WebCrypto variants to the first supported key material for each family, such as RSA and EC.
14
+ - Allows repeated New Key operations; each generated key pair is added as a separate top-level tree item.
15
+ - Lets the top-level key pair label be edited in the tree.
16
+ - Rejects an empty top-level key pair label and restores the previous label in the tree.
17
+ - Shows generated private keys as PKCS#8 DER and generated public keys as SPKI DER.
18
+ - Recognizes labels such as `RSA 2048`, `EC P-256`, `Ed25519`, and `X25519` from DER AlgorithmIdentifier data instead of storing a separate algorithm label.
19
+
20
+ ### PKCS#12 Import
21
+
22
+ - Imports PKCS#12 files (`.p12`, `.pfx`) through the Open menu.
23
+ - Supports password-protected PKCS#12 files.
24
+ - Extracts private key material and matching certificates when present.
25
+ - Adds matching certificates as child items under the imported key pair.
26
+ - Uses the certificate public key internally when needed, but does not create a separate PublicKey child item for PKCS#12 imports that already include a certificate.
27
+ - Supports key-only PKCS#12 files that do not contain a certificate; those imports create a PrivateKey child item.
28
+ - Reads friendly names and local key identifiers when available to produce useful key pair labels.
29
+
30
+ ### Certificate Management
31
+
32
+ - Adds a Certificate child item from the top-level key pair menu through Load Certificate.
33
+ - Loads certificates from files through Load Certificate > from File, including DER certificates and PEM files with a `-----BEGIN CERTIFICATE-----` block.
34
+ - Loads certificates from the clipboard through Load Certificate > from Clipboard as PEM and Load Certificate > from Clipboard as HEX.
35
+ - Checks the certificate public key against the key pair before adding it.
36
+ - Compares the certificate public key with an existing PublicKey item when one is present.
37
+ - When no PublicKey item is present, checks the certificate against the PrivateKey by signing and verifying test data for supported signing keys.
38
+ - Shows a confirmation dialog when the certificate public key does not match the key pair; accepting the dialog applies the certificate anyway.
39
+ - Updates `publicKeyDer` from the certificate only when the certificate key matches the key pair.
40
+ - Does not create or replace a PublicKey item when a mismatching certificate is applied and no PublicKey item exists.
41
+ - Does not hide or delete an existing PublicKey item just because a Certificate item is added.
42
+ - Keeps only one Certificate child item per key pair; adding another certificate replaces the current Certificate item.
43
+ - Creates a self-signed Certificate from the PrivateKey item menu when a usable SubjectDN item is present.
44
+ - Allows SHA-256, SHA-384, and SHA-512 as self-signed certificate hash algorithm choices.
45
+ - Allows the self-signed certificate validity span to be set in days, defaulting to 365 days.
46
+ - Adds BasicConstraints and KeyUsage extensions to self-signed certificates; `certSign` and `crlSign` are checked by default.
47
+ - Copies Certificate objects as PEM from the Certificate item icon menu using a `CERTIFICATE` PEM block.
48
+
49
+ ### PKCS#12 Export
50
+
51
+ - Saves selected top-level key pair items through the Save menu.
52
+ - Shows a checkbox list of key pair items before saving.
53
+ - Checks the currently selected key pair by default when a tree item is already selected.
54
+ - Prompts for a PKCS#12 password before writing the file.
55
+ - Generates a password-protected PKCS#12 file with shrouded private key bags.
56
+ - Includes matching Certificate child items in the exported PKCS#12 when they are present.
57
+ - Uses the browser's native save-file picker when available, with a download fallback for browsers that do not support it.
58
+
59
+ ### Tree View
60
+
61
+ - Displays key material in a PkiStudioJS-like tree with compact New, Open, and Save actions plus a message area.
62
+ - Uses a PkiStudioJS-style tree card, connector lines, node icons, selection colors, and lower message area for the left pane.
63
+ - Supports multiple top-level key pair items.
64
+ - Supports child items for SubjectDN, PrivateKey, PublicKey, Certificate, and CSR objects.
65
+ - Opens node menus from the tree item icon, matching the interaction style used by PkiStudioJS.
66
+ - Closes open node menus when clicking empty space in the left pane or elsewhere in the document.
67
+ - Provides Load Certificate, New SubjectDN, and Delete from the top-level key pair icon menu.
68
+ - Provides New CSR, New self-signed Cert, and Delete from the PrivateKey item icon menu.
69
+ - Provides New SubjectDN, Copy as PEM, and Delete from the Certificate item icon menu.
70
+ - Provides Copy as PEM for CSR items from the child item icon menu.
71
+ - Allows child items to be deleted from their icon menu.
72
+ - Allows top-level key pair items to be deleted from their icon menu; deleting a key pair removes all child items as well.
73
+ - Selecting a top-level key pair item resets the ASN.1 viewer to its initial empty display because the key pair itself does not contain DER data.
74
+ - Lets the left and right panes be resized with the splitter between them.
75
+ - Centers the empty tree message in the left pane content area.
76
+
77
+ ### Application Shell
78
+
79
+ - Fills the browser viewport and resizes the workspace, key tree, ASN.1 viewer, and API Log with the available browser area.
80
+ - Lets the bottom API Log pane be resized with the horizontal splitter between it and the upper workspace.
81
+ - Follows the browser or operating system light/dark theme preference and passes the effective theme to embedded PkiStudioJS viewer windows.
82
+ - Supports `?theme=light` and `?theme=dark` for forcing the application shell and embedded viewer to a specific theme.
83
+ - Shows an About menu in the top application bar with the current Private Key Gadgets version.
84
+
85
+ ### SubjectDN Objects
86
+
87
+ - Creates a SubjectDN child item from the key pair menu.
88
+ - Creates a SubjectDN child item from a Certificate item menu by copying the certificate subject.
89
+ - Keeps only one SubjectDN child item per key pair; creating another SubjectDN asks for overwrite confirmation.
90
+ - Accepts SubjectDN input in LDAP-style order, such as `CN=example.com, O=Example, C=JP`.
91
+ - Stores SubjectDN data as DER and displays it through the ASN.1 viewer.
92
+ - Synchronizes SubjectDN child item data when the SubjectDN DER is edited in the embedded viewer.
93
+
94
+ ### CSR Generation
95
+
96
+ - Creates a PKCS#10 certification request from the PrivateKey item menu.
97
+ - Uses the existing SubjectDN child item DER as the CSR subject source.
98
+ - Shows an error and disables CSR creation when the key pair has no usable SubjectDN item.
99
+ - Supports RSA and EC signing keys for CSR generation.
100
+ - Allows SHA-256, SHA-384, and SHA-512 as CSR hash algorithm choices.
101
+ - Keeps only one CSR child item per key pair; creating another CSR asks for overwrite confirmation.
102
+ - Displays generated CSR DER in the embedded ASN.1 viewer.
103
+ - Copies CSR objects as PEM from the CSR item icon menu using a `CERTIFICATE REQUEST` PEM block.
104
+
105
+ ### Self-Signed Certificate Generation
106
+
107
+ - Creates a self-signed X.509 certificate from the PrivateKey item menu.
108
+ - Requires an existing SubjectDN child item and uses its DER as both issuer and subject.
109
+ - Supports RSA and EC signing keys for certificate generation.
110
+ - Allows SHA-256, SHA-384, and SHA-512 as signing hash algorithm choices.
111
+ - Allows KeyUsage flags to be selected before signing; `certSign` and `crlSign` are selected by default.
112
+ - Allows the validity span to be entered as a number of days, defaulting to 365.
113
+ - Replaces the current Certificate child item after confirmation when one already exists.
114
+ - Displays the generated certificate DER in the embedded ASN.1 viewer.
115
+
116
+ ### Embedded ASN.1 Viewer
117
+
118
+ - Embeds the npm-provided PkiStudioJS viewer directly in the right pane.
119
+ - Displays the selected PrivateKey, PublicKey, Certificate, SubjectDN, or CSR DER object.
120
+ - Keeps Viewer editing actions enabled only while a SubjectDN item is selected.
121
+ - Disables the Viewer Load and Close actions, plus node Edit, Delete, Add, and Insert before actions, including the Insert before/Add submenus, for read-only key material such as PrivateKey, PublicKey, Certificate, and CSR.
122
+ - Keeps the PkiStudioJS Save menu available for writing the currently displayed DER document to a file.
123
+ - Opens PkiStudioJS New Window output in a standalone viewer-only page instead of a new pvkgadgets application shell.
124
+ - Hides the standalone PkiStudioJS file picker in the embedded application shell.
125
+
126
+ ### PvkGadgetsCore API
127
+
128
+ - Exposes `PvkGadgetsCore` through npm imports and `window.PvkGadgetsCore` as a UI-independent helper API for private-key operations used by the app.
129
+ - Detects supported WebCrypto key pair algorithms and generates PKCS#8/SPKI DER key material.
130
+ - Recognizes key families and labels from DER key material.
131
+ - Creates SubjectDN DER, PKCS#10 CSR DER, and self-signed X.509 certificate DER without depending on the tree UI.
132
+ - Checks whether a certificate public key matches key material.
133
+ - Reads and writes PKCS#12 key material through the same API surface.
134
+ - Converts DER objects to PEM and PEM blocks back to DER.
135
+
136
+ ### npm Package API
137
+
138
+ - Exports the core helper API from `@pkistudio/pvkgadgets` and `@pkistudio/pvkgadgets/core`.
139
+ - Exports PKCS#12 helpers from `@pkistudio/pvkgadgets/pkcs12`.
140
+ - Exports the browser app initializer from `@pkistudio/pvkgadgets/app`.
141
+ - Exports app styling from `@pkistudio/pvkgadgets/styles.css`.
142
+ - Lets Webview hosts provide confirmation, save-file, and DER-viewer callbacks without depending on VS Code APIs inside this package.
143
+
144
+ ### API Log
145
+
146
+ - Shows a bottom API Log pane for browser and PKI operation activity.
147
+ - Logs operations such as PkiStudioJS initialization, WebCrypto key generation and export, PKCS#12 import/export, certificate loading, clipboard access, file-system saves, CSR creation, and self-signed certificate signing.
148
+ - Displays timestamps with millisecond precision.
149
+ - Keeps the newest 200 log entries and drops older entries automatically.
150
+ - Provides a right-aligned Clear button for resetting the visible log.
151
+
152
+ The application provides Save Key for exporting selected key pairs as PKCS#12 files. Individual DER objects are shown in the PkiStudioJS viewer, and users can use the viewer's Save menu when they want to write the currently displayed DER document to a file.
153
+
154
+ Generated and imported key material is kept as DER in browser memory. Private keys are stored as PKCS#8 DER, public keys are stored as SPKI DER, certificates are stored as certificate DER, SubjectDN items are stored as RDNSequence DER, and CSR items are stored as PKCS#10 DER. PublicKey and Certificate are independent child objects in the tree: adding a Certificate does not remove PublicKey, and a mismatching Certificate does not populate PublicKey data.
155
+
156
+ ## Development
157
+
158
+ Install dependencies:
159
+
160
+ ```sh
161
+ npm install
162
+ ```
163
+
164
+ Start the local development server:
165
+
166
+ ```sh
167
+ npm run dev
168
+ ```
169
+
170
+ Run the TypeScript and production build checks:
171
+
172
+ ```sh
173
+ npm run check
174
+ npm run build
175
+ ```
176
+
177
+ Check the npm package contents before publication:
178
+
179
+ ```sh
180
+ npm run pack:dry-run
181
+ ```
182
+
183
+ ## Reusing from npm
184
+
185
+ Install the package in a browser or Webview project:
186
+
187
+ ```sh
188
+ npm install @pkistudio/pvkgadgets
189
+ ```
190
+
191
+ Use the UI-independent API:
192
+
193
+ ```ts
194
+ import { PvkGadgetsCore } from '@pkistudio/pvkgadgets';
195
+
196
+ const algorithms = await PvkGadgetsCore.getSupportedKeyAlgorithms();
197
+ const keyPair = await PvkGadgetsCore.generateKeyPair(algorithms[0].id);
198
+ ```
199
+
200
+ Use the PKCS#12 helpers directly when a host application owns the surrounding UI:
201
+
202
+ ```ts
203
+ import { readPkcs12Keys, writePkcs12Keys } from '@pkistudio/pvkgadgets/pkcs12';
204
+ ```
205
+
206
+ Mount the browser application from an embedded Webview or browser app:
207
+
208
+ ```ts
209
+ import { initPrivateKeyGadgets } from '@pkistudio/pvkgadgets/app';
210
+ import '@pkistudio/pvkgadgets/styles.css';
211
+
212
+ initPrivateKeyGadgets({
213
+ mount: '#app',
214
+ theme: 'dark',
215
+ host: {
216
+ confirm: async (message) => window.confirm(message),
217
+ saveFile: async ({ bytes, suggestedName }) => {
218
+ // Host applications can bridge this to their native save dialog.
219
+ console.log(`save ${suggestedName}`, bytes.byteLength);
220
+ },
221
+ openDerViewer: async ({ title, bytes }) => {
222
+ // VS Code extensions can open a separate DER viewer Webview here.
223
+ console.log(`open ${title}`, bytes.byteLength);
224
+ }
225
+ }
226
+ });
227
+ ```
228
+
229
+ The package keeps VS Code-specific file access, dialogs, and Webview lifecycle outside `@pkistudio/pvkgadgets`; hosts pass those behaviors through the `host` callbacks.
230
+
231
+ ## License
232
+
233
+ Private Key Gadgets is licensed under the MIT License. See [LICENSE](LICENSE).
234
+
235
+ ## PkiStudioJS Dependency
236
+
237
+ The application imports PkiStudioJS from the published `pkistudiojs` npm package:
238
+
239
+ - `pkistudiojs/core`
240
+ - `pkistudiojs/oid-resolver`
241
+ - `pkistudiojs/viewer`
242
+
243
+ The PkiStudioJS OID name table is provided through `pkistudiojs/oid-resolver`, so no vendored browser assets are required under `public/`.
244
+
245
+ PKCS#12 parsing is handled by PKIjs, with ASN.1 support from asn1js.