@peculiar/certificates-viewer 4.7.0 → 4.7.1-alpha.4
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/components/attribute-certificate-viewer.js +4 -2
- package/components/attribute-certificate-viewer.js.map +1 -1
- package/components/attribute.js +1 -1
- package/components/certificate-viewer.js +3 -2
- package/components/certificate-viewer.js.map +1 -1
- package/components/crl-viewer.js +4 -2
- package/components/crl-viewer.js.map +1 -1
- package/components/csr-viewer.js +1 -1
- package/components/download.js +1674 -45
- package/components/download.js.map +1 -1
- package/components/index2.js +3 -2
- package/components/index2.js.map +1 -1
- package/components/issuer_name.js +1 -1
- package/components/miscellaneous.js +4 -79
- package/components/miscellaneous.js.map +1 -1
- package/components/peculiar-certificate-decoder.js +32 -16
- package/components/peculiar-certificate-decoder.js.map +1 -1
- package/components/peculiar-certificates-viewer.js +1 -1
- package/components/peculiar-ssh-certificate-viewer.d.ts +11 -0
- package/components/peculiar-ssh-certificate-viewer.js +12 -0
- package/components/peculiar-ssh-certificate-viewer.js.map +1 -0
- package/components/peculiar-text-hider.js +1 -32
- package/components/peculiar-text-hider.js.map +1 -1
- package/components/pkcs10_certificate_request.js +2 -1
- package/components/pkcs10_certificate_request.js.map +1 -1
- package/components/row.js +87 -0
- package/components/row.js.map +1 -0
- package/components/ssh-certificate-viewer.js +210 -0
- package/components/ssh-certificate-viewer.js.map +1 -0
- package/components/subject_name.js +2 -2
- package/components/text-hider.js +40 -0
- package/components/text-hider.js.map +1 -0
- package/components/utils.js +39 -0
- package/components/utils.js.map +1 -0
- package/dist/cjs/extension-DTtJlxk8.js +110 -0
- package/dist/cjs/{extension-CGZpfI3W.js.map → extension-DTtJlxk8.js.map} +1 -1
- package/dist/cjs/index.cjs.js +4 -4
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/{miscellaneous-D_RAtkZz.js → miscellaneous-DCeacaAw.js} +147 -147
- package/dist/cjs/{miscellaneous-D_RAtkZz.js.map → miscellaneous-DCeacaAw.js.map} +1 -1
- package/dist/cjs/peculiar-attribute-certificate-viewer.peculiar-certificate-chain-viewer.peculiar-crl-viewer.peculiar-csr-viewer.peculiar-ssh-certificate-viewer.entry.cjs.js.map +1 -0
- package/dist/cjs/{peculiar-attribute-certificate-viewer_4.cjs.entry.js → peculiar-attribute-certificate-viewer_5.cjs.entry.js} +215 -45
- package/dist/cjs/peculiar-attribute-certificate-viewer_5.cjs.entry.js.map +1 -0
- package/dist/cjs/peculiar-certificate-decoder.cjs.entry.js +25 -21
- package/dist/cjs/peculiar-certificate-decoder.cjs.entry.js.map +1 -1
- package/dist/cjs/peculiar-certificate-decoder.entry.cjs.js.map +1 -1
- package/dist/cjs/peculiar-certificate-viewer.cjs.entry.js +4 -4
- package/dist/cjs/peculiar-certificates-viewer.cjs.entry.js +23 -23
- package/dist/cjs/peculiar-certificates-viewer.cjs.entry.js.map +1 -1
- package/dist/cjs/peculiar-certificates-viewer.entry.cjs.js.map +1 -1
- package/dist/cjs/peculiar.cjs.js +1 -1
- package/dist/cjs/pkcs10_certificate_request-DE-0eDXE.js +146 -0
- package/dist/cjs/{pkcs10_certificate_request-BQkkkT42.js.map → pkcs10_certificate_request-DE-0eDXE.js.map} +1 -1
- package/dist/cjs/{certification_request-DISQwgjn.js → ssh_certificate-D2q_p49O.js} +1676 -16
- package/dist/cjs/ssh_certificate-D2q_p49O.js.map +1 -0
- package/dist/cjs/{x509_certificate-DGRpZGA2.js → x509_certificate-Cto1q-eu.js} +29 -29
- package/dist/cjs/{x509_certificate-DGRpZGA2.js.map → x509_certificate-Cto1q-eu.js.map} +1 -1
- package/dist/cjs/{x509_crl-DMvJk_81.js → x509_crl-CgixMZrh.js} +32 -32
- package/dist/cjs/{x509_crl-DMvJk_81.js.map → x509_crl-CgixMZrh.js.map} +1 -1
- package/dist/collection/collection-manifest.json +1 -0
- package/dist/collection/components/certificate-decoder/certificate-decoder.js +10 -6
- package/dist/collection/components/certificate-decoder/certificate-decoder.js.map +1 -1
- package/dist/collection/components/ssh-certificate-viewer/-components/basic_information.js +29 -0
- package/dist/collection/components/ssh-certificate-viewer/-components/basic_information.js.map +1 -0
- package/dist/collection/components/ssh-certificate-viewer/-components/miscellaneous.js +23 -0
- package/dist/collection/components/ssh-certificate-viewer/-components/miscellaneous.js.map +1 -0
- package/dist/collection/components/ssh-certificate-viewer/-components/public_key.js +26 -0
- package/dist/collection/components/ssh-certificate-viewer/-components/public_key.js.map +1 -0
- package/dist/collection/components/ssh-certificate-viewer/-components/signature_key.js +26 -0
- package/dist/collection/components/ssh-certificate-viewer/-components/signature_key.js.map +1 -0
- package/dist/collection/components/ssh-certificate-viewer/ssh-certificate-viewer.js +194 -0
- package/dist/collection/components/ssh-certificate-viewer/ssh-certificate-viewer.js.map +1 -0
- package/dist/collection/crypto/index.js +1 -0
- package/dist/collection/crypto/index.js.map +1 -1
- package/dist/collection/crypto/ssh_certificate.js +74 -0
- package/dist/collection/crypto/ssh_certificate.js.map +1 -0
- package/dist/collection/locales/en.json +6 -1
- package/dist/collection/utils/download.js +5 -0
- package/dist/collection/utils/download.js.map +1 -1
- package/dist/esm/{extension-CUOKUt7o.js → extension-DmlhftES.js} +3 -3
- package/dist/{esm-es5/extension-CUOKUt7o.js.map → esm/extension-DmlhftES.js.map} +1 -1
- package/dist/esm/index.js +2 -2
- package/dist/esm/loader.js +1 -1
- package/dist/esm/{miscellaneous-DVlekgVM.js → miscellaneous-BTlqwN5_.js} +4 -4
- package/dist/esm/{miscellaneous-DVlekgVM.js.map → miscellaneous-BTlqwN5_.js.map} +1 -1
- package/dist/esm/peculiar-attribute-certificate-viewer.peculiar-certificate-chain-viewer.peculiar-crl-viewer.peculiar-csr-viewer.peculiar-ssh-certificate-viewer.entry.js.map +1 -0
- package/dist/esm/{peculiar-attribute-certificate-viewer_4.entry.js → peculiar-attribute-certificate-viewer_5.entry.js} +185 -16
- package/dist/esm/peculiar-attribute-certificate-viewer_5.entry.js.map +1 -0
- package/dist/esm/peculiar-certificate-decoder.entry.js +14 -10
- package/dist/esm/peculiar-certificate-decoder.entry.js.map +1 -1
- package/dist/esm/peculiar-certificate-viewer.entry.js +4 -4
- package/dist/esm/peculiar-certificates-viewer.entry.js +3 -3
- package/dist/esm/peculiar.js +1 -1
- package/dist/esm/{pkcs10_certificate_request-B9Q42jiE.js → pkcs10_certificate_request-B5C1NYFc.js} +3 -3
- package/dist/esm/{pkcs10_certificate_request-B9Q42jiE.js.map → pkcs10_certificate_request-B5C1NYFc.js.map} +1 -1
- package/dist/esm/{certification_request-CSS3OhZq.js → ssh_certificate-PCn0WXhQ.js} +1676 -17
- package/dist/esm/ssh_certificate-PCn0WXhQ.js.map +1 -0
- package/dist/esm/{x509_certificate-fWXLCtc8.js → x509_certificate-BiAmXJ4S.js} +4 -4
- package/dist/esm/{x509_certificate-fWXLCtc8.js.map → x509_certificate-BiAmXJ4S.js.map} +1 -1
- package/dist/esm/{x509_crl-Dq33Vv-q.js → x509_crl-CCeoLLUZ.js} +5 -5
- package/dist/esm/{x509_crl-Dq33Vv-q.js.map → x509_crl-CCeoLLUZ.js.map} +1 -1
- package/dist/esm-es5/{extension-CUOKUt7o.js → extension-DmlhftES.js} +2 -2
- package/dist/{esm/extension-CUOKUt7o.js.map → esm-es5/extension-DmlhftES.js.map} +1 -1
- package/dist/esm-es5/index.js +1 -1
- package/dist/esm-es5/loader.js +2 -2
- package/dist/esm-es5/{miscellaneous-DVlekgVM.js → miscellaneous-BTlqwN5_.js} +2 -2
- package/dist/esm-es5/{miscellaneous-DVlekgVM.js.map → miscellaneous-BTlqwN5_.js.map} +1 -1
- package/dist/esm-es5/peculiar-attribute-certificate-viewer.peculiar-certificate-chain-viewer.peculiar-crl-viewer.peculiar-csr-viewer.peculiar-ssh-certificate-viewer.entry.js.map +1 -0
- package/dist/esm-es5/{peculiar-attribute-certificate-viewer_4.entry.js → peculiar-attribute-certificate-viewer_5.entry.js} +31 -3
- package/dist/esm-es5/peculiar-attribute-certificate-viewer_5.entry.js.map +1 -0
- package/dist/esm-es5/peculiar-certificate-decoder.entry.js +1 -1
- package/dist/esm-es5/peculiar-certificate-decoder.entry.js.map +1 -1
- package/dist/esm-es5/peculiar-certificate-viewer.entry.js +1 -1
- package/dist/esm-es5/peculiar-certificates-viewer.entry.js +1 -1
- package/dist/esm-es5/peculiar.js +1 -1
- package/dist/esm-es5/{pkcs10_certificate_request-B9Q42jiE.js → pkcs10_certificate_request-B5C1NYFc.js} +2 -2
- package/dist/esm-es5/{pkcs10_certificate_request-B9Q42jiE.js.map → pkcs10_certificate_request-B5C1NYFc.js.map} +1 -1
- package/dist/esm-es5/{certification_request-CSS3OhZq.js → ssh_certificate-PCn0WXhQ.js} +8 -8
- package/dist/esm-es5/ssh_certificate-PCn0WXhQ.js.map +1 -0
- package/dist/esm-es5/{x509_certificate-fWXLCtc8.js → x509_certificate-BiAmXJ4S.js} +4 -4
- package/dist/esm-es5/{x509_certificate-fWXLCtc8.js.map → x509_certificate-BiAmXJ4S.js.map} +1 -1
- package/dist/esm-es5/{x509_crl-Dq33Vv-q.js → x509_crl-CCeoLLUZ.js} +2 -2
- package/dist/esm-es5/{x509_crl-Dq33Vv-q.js.map → x509_crl-CCeoLLUZ.js.map} +1 -1
- package/dist/peculiar/index.esm.js +1 -1
- package/dist/peculiar/locales/en.json +6 -1
- package/dist/peculiar/{p-17ebc78c.system.entry.js → p-24861cf6.system.entry.js} +2 -2
- package/dist/peculiar/{p-a193f8fd.system.entry.js → p-46c17c8d.system.entry.js} +2 -2
- package/dist/peculiar/{p-a4e74904.entry.js → p-71cb31c6.entry.js} +47 -19
- package/dist/peculiar/p-71cb31c6.entry.js.map +1 -0
- package/dist/peculiar/{p-4cc72a56.entry.js → p-71eab586.entry.js} +2 -2
- package/dist/peculiar/p-7273601a.entry.js +5 -0
- package/dist/peculiar/p-7273601a.entry.js.map +1 -0
- package/dist/peculiar/p-83bfd8e5.system.entry.js +5 -0
- package/dist/peculiar/p-83bfd8e5.system.entry.js.map +1 -0
- package/dist/peculiar/{p-e3967e76.entry.js → p-98219569.entry.js} +2 -2
- package/dist/peculiar/p-9MJeDspO.system.js.map +1 -0
- package/dist/peculiar/p-AjXipXSl.system.js +12 -0
- package/dist/peculiar/{p-CgCUixvk.system.js.map → p-AjXipXSl.system.js.map} +1 -1
- package/dist/peculiar/{p-CEzxVCEh.system.js → p-B2FH4Pv2.system.js} +2 -2
- package/dist/peculiar/{p-CEzxVCEh.system.js.map → p-B2FH4Pv2.system.js.map} +1 -1
- package/dist/peculiar/{p-DcTXA-2R.system.js → p-B5GO6_Ut.system.js} +18 -18
- package/dist/peculiar/{p-DcTXA-2R.system.js.map → p-B5GO6_Ut.system.js.map} +1 -1
- package/dist/peculiar/{p-Bsy7Sqzl.system.js.map → p-B82-c-xr.system.js.map} +1 -1
- package/dist/peculiar/p-BGASC3UX.system.js +1 -1
- package/dist/peculiar/p-BHpSDBz_.system.js.map +1 -0
- package/dist/peculiar/p-BwlcJAh0.js +12 -0
- package/dist/peculiar/{p-CZuaTO2G.js.map → p-BwlcJAh0.js.map} +1 -1
- package/dist/peculiar/{p-D8TC0Na9.system.js.map → p-CSz5liuX.system.js.map} +1 -1
- package/dist/peculiar/{p-tl0v45Y7.js → p-CstRxc9v.js} +2 -2
- package/dist/peculiar/{p-tl0v45Y7.js.map → p-CstRxc9v.js.map} +1 -1
- package/dist/peculiar/p-DMDALRLP.system.js +135 -0
- package/dist/peculiar/p-DMDALRLP.system.js.map +1 -0
- package/dist/peculiar/{p-DTz3NA_M.system.js → p-DPbpwYQ8.system.js} +3 -3
- package/dist/peculiar/{p-DTz3NA_M.system.js.map → p-DPbpwYQ8.system.js.map} +1 -1
- package/dist/peculiar/{p-CoPYW15U.js → p-Db41gPxb.js} +4 -4
- package/dist/peculiar/{p-CoPYW15U.js.map → p-Db41gPxb.js.map} +1 -1
- package/dist/peculiar/{p-DKooqn40.js → p-DnOLjFJP.js} +39 -39
- package/dist/peculiar/{p-DKooqn40.js.map → p-DnOLjFJP.js.map} +1 -1
- package/dist/peculiar/{p-CSS3OhZq.js → p-PCn0WXhQ.js} +13 -13
- package/dist/peculiar/p-PCn0WXhQ.js.map +1 -0
- package/dist/peculiar/{p-7fTYvx_V.system.js → p-SjVQtfgD.system.js} +5 -5
- package/dist/peculiar/{p-7fTYvx_V.system.js.map → p-SjVQtfgD.system.js.map} +1 -1
- package/dist/peculiar/{p-e7c60082.system.entry.js → p-cc01a2da.system.entry.js} +47 -19
- package/dist/peculiar/p-cc01a2da.system.entry.js.map +1 -0
- package/dist/peculiar/{p-BTn-wukS.system.js → p-dOkqMp-O.system.js} +2 -2
- package/dist/peculiar/p-dOkqMp-O.system.js.map +1 -0
- package/dist/peculiar/{p-BG_D4qzJ.js → p-h7XP7otl.js} +3 -3
- package/dist/peculiar/{p-BG_D4qzJ.js.map → p-h7XP7otl.js.map} +1 -1
- package/dist/peculiar/peculiar-attribute-certificate-viewer.peculiar-certificate-chain-viewer.peculiar-crl-viewer.peculiar-csr-viewer.peculiar-ssh-certificate-viewer.entry.esm.js.map +1 -0
- package/dist/peculiar/peculiar-certificate-decoder.entry.esm.js.map +1 -1
- package/dist/peculiar/peculiar.esm.js +1 -1
- package/dist/types/components/certificate-decoder/certificate-decoder.d.ts +4 -4
- package/dist/types/components/ssh-certificate-viewer/-components/basic_information.d.ts +21 -0
- package/dist/types/components/ssh-certificate-viewer/-components/miscellaneous.d.ts +14 -0
- package/dist/types/components/ssh-certificate-viewer/-components/public_key.d.ts +14 -0
- package/dist/types/components/ssh-certificate-viewer/-components/signature_key.d.ts +14 -0
- package/dist/types/components/ssh-certificate-viewer/ssh-certificate-viewer.d.ts +43 -0
- package/dist/types/components.d.ts +43 -0
- package/dist/types/crypto/index.d.ts +1 -0
- package/dist/types/crypto/ssh_certificate.d.ts +30 -0
- package/dist/types/utils/download.d.ts +3 -0
- package/dist/types/utils/l10n.d.ts +5 -0
- package/hydrate/index.js +1869 -27
- package/hydrate/index.mjs +1869 -27
- package/package.json +3 -2
- package/dist/cjs/certification_request-DISQwgjn.js.map +0 -1
- package/dist/cjs/extension-CGZpfI3W.js +0 -110
- package/dist/cjs/peculiar-attribute-certificate-viewer.peculiar-certificate-chain-viewer.peculiar-crl-viewer.peculiar-csr-viewer.entry.cjs.js.map +0 -1
- package/dist/cjs/peculiar-attribute-certificate-viewer_4.cjs.entry.js.map +0 -1
- package/dist/cjs/pkcs10_certificate_request-BQkkkT42.js +0 -146
- package/dist/esm/certification_request-CSS3OhZq.js.map +0 -1
- package/dist/esm/peculiar-attribute-certificate-viewer.peculiar-certificate-chain-viewer.peculiar-crl-viewer.peculiar-csr-viewer.entry.js.map +0 -1
- package/dist/esm/peculiar-attribute-certificate-viewer_4.entry.js.map +0 -1
- package/dist/esm-es5/certification_request-CSS3OhZq.js.map +0 -1
- package/dist/esm-es5/peculiar-attribute-certificate-viewer.peculiar-certificate-chain-viewer.peculiar-crl-viewer.peculiar-csr-viewer.entry.js.map +0 -1
- package/dist/esm-es5/peculiar-attribute-certificate-viewer_4.entry.js.map +0 -1
- package/dist/peculiar/p-BTn-wukS.system.js.map +0 -1
- package/dist/peculiar/p-CSS3OhZq.js.map +0 -1
- package/dist/peculiar/p-CZuaTO2G.js +0 -12
- package/dist/peculiar/p-CgCUixvk.system.js +0 -12
- package/dist/peculiar/p-DLsQGkmT.system.js.map +0 -1
- package/dist/peculiar/p-D_WeukQa.system.js +0 -135
- package/dist/peculiar/p-D_WeukQa.system.js.map +0 -1
- package/dist/peculiar/p-a4e74904.entry.js.map +0 -1
- package/dist/peculiar/p-ce006f1c.system.entry.js +0 -5
- package/dist/peculiar/p-ce006f1c.system.entry.js.map +0 -1
- package/dist/peculiar/p-e7c60082.system.entry.js.map +0 -1
- package/dist/peculiar/p-f465afe6.entry.js +0 -5
- package/dist/peculiar/p-f465afe6.entry.js.map +0 -1
- package/dist/peculiar/p-tBL0ekYY.system.js.map +0 -1
- package/dist/peculiar/peculiar-attribute-certificate-viewer.peculiar-certificate-chain-viewer.peculiar-crl-viewer.peculiar-csr-viewer.entry.esm.js.map +0 -1
- /package/dist/peculiar/{p-17ebc78c.system.entry.js.map → p-24861cf6.system.entry.js.map} +0 -0
- /package/dist/peculiar/{p-a193f8fd.system.entry.js.map → p-46c17c8d.system.entry.js.map} +0 -0
- /package/dist/peculiar/{p-4cc72a56.entry.js.map → p-71eab586.entry.js.map} +0 -0
- /package/dist/peculiar/{p-e3967e76.entry.js.map → p-98219569.entry.js.map} +0 -0
|
@@ -505,6 +505,11 @@ Download.crl = {
|
|
|
505
505
|
downloadFromBuffer(raw, name, 'crl', 'application/pkix-crl');
|
|
506
506
|
},
|
|
507
507
|
};
|
|
508
|
+
Download.certSSH = {
|
|
509
|
+
asSSH: (value, name) => {
|
|
510
|
+
downloadFromBuffer(buildExports.Convert.FromString(value), name, 'cert', 'application/ssh-cert');
|
|
511
|
+
},
|
|
512
|
+
};
|
|
508
513
|
|
|
509
514
|
/*!
|
|
510
515
|
Copyright (c) Peculiar Ventures, LLC
|
|
@@ -6765,6 +6770,10 @@ const crlEntryExtensions = "CRL Entry Extensions";
|
|
|
6765
6770
|
const previewCertificate = "Preview certificate";
|
|
6766
6771
|
const viewDetails = "View details";
|
|
6767
6772
|
const downloadOptions = "Download options";
|
|
6773
|
+
const keyId = "Key ID";
|
|
6774
|
+
const principals = "Principals";
|
|
6775
|
+
const criticalOptions = "Critical Options";
|
|
6776
|
+
const signingCA = "Signing CA";
|
|
6768
6777
|
var en = {
|
|
6769
6778
|
basicInformation: basicInformation,
|
|
6770
6779
|
subjectName: subjectName,
|
|
@@ -6776,6 +6785,7 @@ var en = {
|
|
|
6776
6785
|
download: download,
|
|
6777
6786
|
"download.pem": "Download PEM",
|
|
6778
6787
|
"download.der": "Download DER",
|
|
6788
|
+
"download.ssh": "Download SSH",
|
|
6779
6789
|
serialNumber: serialNumber,
|
|
6780
6790
|
version: version,
|
|
6781
6791
|
validity: validity,
|
|
@@ -6812,7 +6822,11 @@ var en = {
|
|
|
6812
6822
|
crlEntryExtensions: crlEntryExtensions,
|
|
6813
6823
|
previewCertificate: previewCertificate,
|
|
6814
6824
|
viewDetails: viewDetails,
|
|
6815
|
-
downloadOptions: downloadOptions
|
|
6825
|
+
downloadOptions: downloadOptions,
|
|
6826
|
+
keyId: keyId,
|
|
6827
|
+
principals: principals,
|
|
6828
|
+
criticalOptions: criticalOptions,
|
|
6829
|
+
signingCA: signingCA
|
|
6816
6830
|
};
|
|
6817
6831
|
|
|
6818
6832
|
/**
|
|
@@ -9232,13 +9246,13 @@ const OIDs = {
|
|
|
9232
9246
|
* This source code is licensed under the MIT license found in the
|
|
9233
9247
|
* LICENSE file in the root directory of this source tree.
|
|
9234
9248
|
*/
|
|
9235
|
-
var __classPrivateFieldSet$
|
|
9249
|
+
var __classPrivateFieldSet$2 = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
9236
9250
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
9237
9251
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
9238
9252
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
9239
9253
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
9240
9254
|
};
|
|
9241
|
-
var __classPrivateFieldGet$
|
|
9255
|
+
var __classPrivateFieldGet$2 = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9242
9256
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9243
9257
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
9244
9258
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
@@ -9248,15 +9262,15 @@ class Name {
|
|
|
9248
9262
|
constructor(data) {
|
|
9249
9263
|
_Name_asn.set(this, new Name$1());
|
|
9250
9264
|
if (buildExports.BufferSourceConverter.isBufferSource(data)) {
|
|
9251
|
-
__classPrivateFieldSet$
|
|
9265
|
+
__classPrivateFieldSet$2(this, _Name_asn, AsnParser.parse(data, Name$1), "f");
|
|
9252
9266
|
}
|
|
9253
9267
|
else {
|
|
9254
|
-
__classPrivateFieldSet$
|
|
9268
|
+
__classPrivateFieldSet$2(this, _Name_asn, data, "f");
|
|
9255
9269
|
}
|
|
9256
9270
|
}
|
|
9257
9271
|
toJSON() {
|
|
9258
9272
|
const res = [];
|
|
9259
|
-
__classPrivateFieldGet$
|
|
9273
|
+
__classPrivateFieldGet$2(this, _Name_asn, "f").forEach((o) => (o.forEach((a) => {
|
|
9260
9274
|
res.push({
|
|
9261
9275
|
type: a.type,
|
|
9262
9276
|
name: OIDs[a.type],
|
|
@@ -10797,13 +10811,13 @@ __decorate([
|
|
|
10797
10811
|
* This source code is licensed under the MIT license found in the
|
|
10798
10812
|
* LICENSE file in the root directory of this source tree.
|
|
10799
10813
|
*/
|
|
10800
|
-
var __classPrivateFieldSet = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
10814
|
+
var __classPrivateFieldSet$1 = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
10801
10815
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
10802
10816
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
10803
10817
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
10804
10818
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
10805
10819
|
};
|
|
10806
|
-
var __classPrivateFieldGet = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
10820
|
+
var __classPrivateFieldGet$1 = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
10807
10821
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10808
10822
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10809
10823
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
@@ -10816,20 +10830,20 @@ class AsnData {
|
|
|
10816
10830
|
_AsnData_raw.set(this, void 0);
|
|
10817
10831
|
if (args.length === 1) {
|
|
10818
10832
|
// asn
|
|
10819
|
-
__classPrivateFieldSet(this, _AsnData_asn, args[0], "f");
|
|
10820
|
-
__classPrivateFieldSet(this, _AsnData_raw, AsnConvert.serialize(__classPrivateFieldGet(this, _AsnData_asn, "f")), "f");
|
|
10833
|
+
__classPrivateFieldSet$1(this, _AsnData_asn, args[0], "f");
|
|
10834
|
+
__classPrivateFieldSet$1(this, _AsnData_raw, AsnConvert.serialize(__classPrivateFieldGet$1(this, _AsnData_asn, "f")), "f");
|
|
10821
10835
|
}
|
|
10822
10836
|
else {
|
|
10823
10837
|
// raw, type
|
|
10824
|
-
__classPrivateFieldSet(this, _AsnData_asn, AsnConvert.parse(args[0], args[1]), "f");
|
|
10825
|
-
__classPrivateFieldSet(this, _AsnData_raw, buildExports.BufferSourceConverter.toArrayBuffer(args[0]), "f");
|
|
10838
|
+
__classPrivateFieldSet$1(this, _AsnData_asn, AsnConvert.parse(args[0], args[1]), "f");
|
|
10839
|
+
__classPrivateFieldSet$1(this, _AsnData_raw, buildExports.BufferSourceConverter.toArrayBuffer(args[0]), "f");
|
|
10826
10840
|
}
|
|
10827
10841
|
}
|
|
10828
10842
|
get asn() {
|
|
10829
|
-
return __classPrivateFieldGet(this, _AsnData_asn, "f");
|
|
10843
|
+
return __classPrivateFieldGet$1(this, _AsnData_asn, "f");
|
|
10830
10844
|
}
|
|
10831
10845
|
get raw() {
|
|
10832
|
-
return __classPrivateFieldGet(this, _AsnData_raw, "f");
|
|
10846
|
+
return __classPrivateFieldGet$1(this, _AsnData_raw, "f");
|
|
10833
10847
|
}
|
|
10834
10848
|
}
|
|
10835
10849
|
_AsnData_asn = new WeakMap(), _AsnData_raw = new WeakMap();
|
|
@@ -12695,7 +12709,1652 @@ __decorate$1([
|
|
|
12695
12709
|
AsnProp({ type: AsnPropTypes.BitString })
|
|
12696
12710
|
], CertificationRequest.prototype, "signature", void 0);
|
|
12697
12711
|
|
|
12698
|
-
|
|
12699
|
-
|
|
12712
|
+
let globalCrypto = globalThis.crypto;
|
|
12713
|
+
function getCrypto() {
|
|
12714
|
+
return globalCrypto;
|
|
12715
|
+
}
|
|
12716
|
+
|
|
12717
|
+
class SshError extends Error {
|
|
12718
|
+
code;
|
|
12719
|
+
constructor(message, code) {
|
|
12720
|
+
super(message);
|
|
12721
|
+
this.code = code;
|
|
12722
|
+
this.name = this.constructor.name;
|
|
12723
|
+
if (Error.captureStackTrace) {
|
|
12724
|
+
Error.captureStackTrace(this, this.constructor);
|
|
12725
|
+
}
|
|
12726
|
+
}
|
|
12727
|
+
}
|
|
12728
|
+
class UnsupportedAlgorithmError extends SshError {
|
|
12729
|
+
constructor(algorithm, supportedAlgorithms) {
|
|
12730
|
+
const supported = supportedAlgorithms ? ` Supported: ${supportedAlgorithms.join(', ')}` : '';
|
|
12731
|
+
super(`Unsupported algorithm: ${algorithm}.${supported}`, 'UNSUPPORTED_ALGORITHM');
|
|
12732
|
+
}
|
|
12733
|
+
}
|
|
12734
|
+
class InvalidFormatError extends SshError {
|
|
12735
|
+
constructor(format, expectedFormat) {
|
|
12736
|
+
const expected = expectedFormat ? ` Expected: ${expectedFormat}` : '';
|
|
12737
|
+
super(`Invalid format: ${format}.${expected}`, 'INVALID_FORMAT');
|
|
12738
|
+
}
|
|
12739
|
+
}
|
|
12740
|
+
class UnsupportedKeyTypeError extends SshError {
|
|
12741
|
+
constructor(keyType, supportedTypes) {
|
|
12742
|
+
const supported = supportedTypes ? ` Supported: ${supportedTypes.join(', ')}` : '';
|
|
12743
|
+
super(`Unsupported key type: ${keyType}.${supported}`, 'UNSUPPORTED_KEY_TYPE');
|
|
12744
|
+
}
|
|
12745
|
+
}
|
|
12746
|
+
class InvalidPrivateKeyFormatError extends SshError {
|
|
12747
|
+
constructor(details) {
|
|
12748
|
+
const message = details
|
|
12749
|
+
? `Invalid SSH private key format: ${details}`
|
|
12750
|
+
: 'Invalid SSH private key format';
|
|
12751
|
+
super(message, 'INVALID_PRIVATE_KEY_FORMAT');
|
|
12752
|
+
}
|
|
12753
|
+
}
|
|
12754
|
+
class EncryptedKeyNotSupportedError extends SshError {
|
|
12755
|
+
constructor(cipher) {
|
|
12756
|
+
const message = cipher
|
|
12757
|
+
? `Encrypted SSH private keys are not supported (cipher: ${cipher})`
|
|
12758
|
+
: 'Encrypted SSH private keys are not supported';
|
|
12759
|
+
super(message, 'ENCRYPTED_KEY_NOT_SUPPORTED');
|
|
12760
|
+
}
|
|
12761
|
+
}
|
|
12762
|
+
class InvalidKeyDataError extends SshError {
|
|
12763
|
+
constructor(details) {
|
|
12764
|
+
const message = details ? `Invalid key data: ${details}` : 'Invalid key data';
|
|
12765
|
+
super(message, 'INVALID_KEY_DATA');
|
|
12766
|
+
}
|
|
12767
|
+
}
|
|
12768
|
+
class UnexpectedEOFError extends SshError {
|
|
12769
|
+
constructor(expected, actual) {
|
|
12770
|
+
const details = expected !== undefined && actual !== undefined
|
|
12771
|
+
? ` Expected ${expected} bytes, got ${actual}`
|
|
12772
|
+
: '';
|
|
12773
|
+
super(`Unexpected end of data${details}`, 'UNEXPECTED_EOF');
|
|
12774
|
+
}
|
|
12775
|
+
}
|
|
12776
|
+
|
|
12777
|
+
const encoder = new TextEncoder();
|
|
12778
|
+
const decoder = new TextDecoder();
|
|
12779
|
+
|
|
12780
|
+
class SshReader {
|
|
12781
|
+
buffer;
|
|
12782
|
+
offset;
|
|
12783
|
+
constructor(data) {
|
|
12784
|
+
this.buffer = data;
|
|
12785
|
+
this.offset = 0;
|
|
12786
|
+
}
|
|
12787
|
+
readUint8() {
|
|
12788
|
+
if (this.offset >= this.buffer.length) {
|
|
12789
|
+
throw new UnexpectedEOFError(1, 0);
|
|
12790
|
+
}
|
|
12791
|
+
return this.buffer[this.offset++];
|
|
12792
|
+
}
|
|
12793
|
+
readUint32() {
|
|
12794
|
+
const value = (this.readUint8() << 24) |
|
|
12795
|
+
(this.readUint8() << 16) |
|
|
12796
|
+
(this.readUint8() << 8) |
|
|
12797
|
+
this.readUint8();
|
|
12798
|
+
return value >>> 0;
|
|
12799
|
+
}
|
|
12800
|
+
readUint64() {
|
|
12801
|
+
const high = this.readUint32();
|
|
12802
|
+
const low = this.readUint32();
|
|
12803
|
+
return (BigInt(high) << 32n) | BigInt(low);
|
|
12804
|
+
}
|
|
12805
|
+
readBytes(length) {
|
|
12806
|
+
if (length < 0) {
|
|
12807
|
+
throw new InvalidFormatError(`Invalid length: ${length}`);
|
|
12808
|
+
}
|
|
12809
|
+
if (this.offset + length > this.buffer.length) {
|
|
12810
|
+
throw new UnexpectedEOFError(length, this.buffer.length - this.offset);
|
|
12811
|
+
}
|
|
12812
|
+
const result = this.buffer.subarray(this.offset, this.offset + length);
|
|
12813
|
+
this.offset += length;
|
|
12814
|
+
return result;
|
|
12815
|
+
}
|
|
12816
|
+
readString() {
|
|
12817
|
+
const length = this.readUint32();
|
|
12818
|
+
const bytes = this.readBytes(length);
|
|
12819
|
+
return decoder.decode(bytes);
|
|
12820
|
+
}
|
|
12821
|
+
peekString(length) {
|
|
12822
|
+
if (this.offset + length > this.buffer.length) {
|
|
12823
|
+
throw new UnexpectedEOFError(length, this.buffer.length - this.offset);
|
|
12824
|
+
}
|
|
12825
|
+
const bytes = this.buffer.subarray(this.offset, this.offset + length);
|
|
12826
|
+
return decoder.decode(bytes);
|
|
12827
|
+
}
|
|
12828
|
+
readMpInt(sshEncoding = false) {
|
|
12829
|
+
const length = this.readUint32();
|
|
12830
|
+
const bytes = this.readBytes(length);
|
|
12831
|
+
if (sshEncoding && bytes.length > 1 && bytes[0] === 0x00) {
|
|
12832
|
+
return bytes.subarray(1);
|
|
12833
|
+
}
|
|
12834
|
+
return bytes;
|
|
12835
|
+
}
|
|
12836
|
+
readMpIntSsh() {
|
|
12837
|
+
return this.readMpInt(true);
|
|
12838
|
+
}
|
|
12839
|
+
remaining() {
|
|
12840
|
+
return this.buffer.length - this.offset;
|
|
12841
|
+
}
|
|
12842
|
+
getOffset() {
|
|
12843
|
+
return this.offset;
|
|
12844
|
+
}
|
|
12845
|
+
seek(offset) {
|
|
12846
|
+
if (offset < 0 || offset > this.buffer.length) {
|
|
12847
|
+
throw new InvalidFormatError(`Invalid offset: ${offset}. Buffer length: ${this.buffer.length}`);
|
|
12848
|
+
}
|
|
12849
|
+
this.offset = offset;
|
|
12850
|
+
}
|
|
12851
|
+
}
|
|
12852
|
+
|
|
12853
|
+
class SshWriter {
|
|
12854
|
+
buffer;
|
|
12855
|
+
offset;
|
|
12856
|
+
constructor(initialSize = 1024) {
|
|
12857
|
+
this.buffer = new Uint8Array(initialSize);
|
|
12858
|
+
this.offset = 0;
|
|
12859
|
+
}
|
|
12860
|
+
ensureCapacity(additional) {
|
|
12861
|
+
const required = this.offset + additional;
|
|
12862
|
+
if (required > this.buffer.length) {
|
|
12863
|
+
const newSize = Math.max(required, this.buffer.length * 2);
|
|
12864
|
+
const newBuffer = new Uint8Array(newSize);
|
|
12865
|
+
newBuffer.set(this.buffer.subarray(0, this.offset));
|
|
12866
|
+
this.buffer = newBuffer;
|
|
12867
|
+
}
|
|
12868
|
+
}
|
|
12869
|
+
reserve(minCapacity) {
|
|
12870
|
+
if (minCapacity > this.buffer.length) {
|
|
12871
|
+
const newBuffer = new Uint8Array(minCapacity);
|
|
12872
|
+
newBuffer.set(this.buffer.subarray(0, this.offset));
|
|
12873
|
+
this.buffer = newBuffer;
|
|
12874
|
+
}
|
|
12875
|
+
}
|
|
12876
|
+
writeUint8(value) {
|
|
12877
|
+
this.ensureCapacity(1);
|
|
12878
|
+
this.buffer[this.offset++] = value & 0xff;
|
|
12879
|
+
}
|
|
12880
|
+
writeUint32(value) {
|
|
12881
|
+
this.ensureCapacity(4);
|
|
12882
|
+
this.buffer[this.offset++] = (value >>> 24) & 0xff;
|
|
12883
|
+
this.buffer[this.offset++] = (value >>> 16) & 0xff;
|
|
12884
|
+
this.buffer[this.offset++] = (value >>> 8) & 0xff;
|
|
12885
|
+
this.buffer[this.offset++] = value & 0xff;
|
|
12886
|
+
}
|
|
12887
|
+
writeUint64(value) {
|
|
12888
|
+
this.ensureCapacity(8);
|
|
12889
|
+
const high = Number(value >> 32n);
|
|
12890
|
+
const low = Number(value & 0xffffffffn);
|
|
12891
|
+
this.writeUint32(high);
|
|
12892
|
+
this.writeUint32(low);
|
|
12893
|
+
}
|
|
12894
|
+
writeBytes(data) {
|
|
12895
|
+
this.ensureCapacity(data.length);
|
|
12896
|
+
this.buffer.set(data, this.offset);
|
|
12897
|
+
this.offset += data.length;
|
|
12898
|
+
}
|
|
12899
|
+
writeString(value) {
|
|
12900
|
+
const bytes = encoder.encode(value);
|
|
12901
|
+
this.writeUint32(bytes.length);
|
|
12902
|
+
this.writeBytes(bytes);
|
|
12903
|
+
}
|
|
12904
|
+
writeMpInt(value, sshEncoding = false) {
|
|
12905
|
+
if (sshEncoding && value.length > 0 && (value[0] & 0x80) !== 0) {
|
|
12906
|
+
const paddedBytes = new Uint8Array(value.length + 1);
|
|
12907
|
+
paddedBytes[0] = 0x00;
|
|
12908
|
+
paddedBytes.set(value, 1);
|
|
12909
|
+
this.writeUint32(paddedBytes.length);
|
|
12910
|
+
this.writeBytes(paddedBytes);
|
|
12911
|
+
}
|
|
12912
|
+
else {
|
|
12913
|
+
this.writeUint32(value.length);
|
|
12914
|
+
this.writeBytes(value);
|
|
12915
|
+
}
|
|
12916
|
+
}
|
|
12917
|
+
writeMpIntSsh(value) {
|
|
12918
|
+
this.writeMpInt(value, true);
|
|
12919
|
+
}
|
|
12920
|
+
toUint8Array() {
|
|
12921
|
+
return this.buffer.subarray(0, this.offset);
|
|
12922
|
+
}
|
|
12923
|
+
getOffset() {
|
|
12924
|
+
return this.offset;
|
|
12925
|
+
}
|
|
12926
|
+
seek(offset) {
|
|
12927
|
+
if (offset < 0 || offset > this.buffer.length) {
|
|
12928
|
+
throw new InvalidFormatError('Invalid offset');
|
|
12929
|
+
}
|
|
12930
|
+
this.offset = offset;
|
|
12931
|
+
}
|
|
12932
|
+
}
|
|
12933
|
+
|
|
12934
|
+
class RsaBinding {
|
|
12935
|
+
hash = 'SHA-256';
|
|
12936
|
+
constructor(hash = 'SHA-256') {
|
|
12937
|
+
this.hash = hash;
|
|
12938
|
+
}
|
|
12939
|
+
async importPublicSsh(params) {
|
|
12940
|
+
const { blob, crypto } = params;
|
|
12941
|
+
const reader = new SshReader(blob);
|
|
12942
|
+
reader.readString();
|
|
12943
|
+
const e = reader.readMpInt(true);
|
|
12944
|
+
const n = reader.readMpInt(true);
|
|
12945
|
+
const jwk = {
|
|
12946
|
+
kty: 'RSA',
|
|
12947
|
+
n: buildExports.Convert.ToBase64Url(n),
|
|
12948
|
+
e: buildExports.Convert.ToBase64Url(e),
|
|
12949
|
+
};
|
|
12950
|
+
return crypto.subtle.importKey('jwk', jwk, {
|
|
12951
|
+
name: 'RSASSA-PKCS1-v1_5',
|
|
12952
|
+
hash: this.hash,
|
|
12953
|
+
}, true, ['verify']);
|
|
12954
|
+
}
|
|
12955
|
+
async exportPublicSsh(params) {
|
|
12956
|
+
const { publicKey, crypto } = params;
|
|
12957
|
+
const jwk = await crypto.subtle.exportKey('jwk', publicKey);
|
|
12958
|
+
if (!jwk.n || !jwk.e) {
|
|
12959
|
+
throw new InvalidKeyDataError('RSA JWK missing required parameters (n, e)');
|
|
12960
|
+
}
|
|
12961
|
+
const n = buildExports.BufferSourceConverter.toUint8Array(buildExports.Convert.FromBase64Url(jwk.n));
|
|
12962
|
+
const e = buildExports.BufferSourceConverter.toUint8Array(buildExports.Convert.FromBase64Url(jwk.e));
|
|
12963
|
+
const writer = new SshWriter();
|
|
12964
|
+
writer.writeString('ssh-rsa');
|
|
12965
|
+
writer.writeMpInt(e, true);
|
|
12966
|
+
writer.writeMpInt(n, true);
|
|
12967
|
+
return writer.toUint8Array();
|
|
12968
|
+
}
|
|
12969
|
+
async importPublicSpki(params) {
|
|
12970
|
+
const { spki, crypto } = params;
|
|
12971
|
+
return crypto.subtle.importKey('spki', spki, {
|
|
12972
|
+
name: 'RSASSA-PKCS1-v1_5',
|
|
12973
|
+
hash: this.hash,
|
|
12974
|
+
}, true, ['verify']);
|
|
12975
|
+
}
|
|
12976
|
+
async exportPublicSpki(params) {
|
|
12977
|
+
const { publicKey, crypto } = params;
|
|
12978
|
+
const spki = await crypto.subtle.exportKey('spki', publicKey);
|
|
12979
|
+
return buildExports.BufferSourceConverter.toUint8Array(spki);
|
|
12980
|
+
}
|
|
12981
|
+
async importPrivatePkcs8(params) {
|
|
12982
|
+
const { pkcs8, crypto } = params;
|
|
12983
|
+
return crypto.subtle.importKey('pkcs8', pkcs8, {
|
|
12984
|
+
name: 'RSASSA-PKCS1-v1_5',
|
|
12985
|
+
hash: this.hash,
|
|
12986
|
+
}, true, ['sign']);
|
|
12987
|
+
}
|
|
12988
|
+
async exportPrivatePkcs8(params) {
|
|
12989
|
+
const { privateKey, crypto } = params;
|
|
12990
|
+
const pkcs8 = await crypto.subtle.exportKey('pkcs8', privateKey);
|
|
12991
|
+
return buildExports.BufferSourceConverter.toUint8Array(pkcs8);
|
|
12992
|
+
}
|
|
12993
|
+
async importPrivateSsh(params) {
|
|
12994
|
+
const { sshKey, crypto } = params;
|
|
12995
|
+
const base64Data = sshKey
|
|
12996
|
+
.replace(/-----BEGIN OPENSSH PRIVATE KEY-----/, '')
|
|
12997
|
+
.replace(/-----END OPENSSH PRIVATE KEY-----/, '')
|
|
12998
|
+
.replace(/\s/g, '');
|
|
12999
|
+
const binaryData = buildExports.Convert.FromBase64(base64Data);
|
|
13000
|
+
const reader = new SshReader(buildExports.BufferSourceConverter.toUint8Array(binaryData));
|
|
13001
|
+
const magic = reader.readBytes(15);
|
|
13002
|
+
if (buildExports.Convert.ToHex(magic) !== '6f70656e7373682d6b65792d763100') {
|
|
13003
|
+
throw new InvalidPrivateKeyFormatError('invalid magic string');
|
|
13004
|
+
}
|
|
13005
|
+
const _cipherName = reader.readString();
|
|
13006
|
+
reader.readString();
|
|
13007
|
+
reader.readString();
|
|
13008
|
+
if (_cipherName !== 'none') {
|
|
13009
|
+
throw new EncryptedKeyNotSupportedError(_cipherName);
|
|
13010
|
+
}
|
|
13011
|
+
const numKeys = reader.readUint32();
|
|
13012
|
+
if (numKeys !== 1) {
|
|
13013
|
+
throw new InvalidPrivateKeyFormatError('multiple keys not supported');
|
|
13014
|
+
}
|
|
13015
|
+
const publicKeyLength = reader.readUint32();
|
|
13016
|
+
reader.readBytes(publicKeyLength);
|
|
13017
|
+
const privateKeyLength = reader.readUint32();
|
|
13018
|
+
const privateKeyData = reader.readBytes(privateKeyLength);
|
|
13019
|
+
const privateReader = new SshReader(privateKeyData);
|
|
13020
|
+
const checkint1 = privateReader.readUint32();
|
|
13021
|
+
const checkint2 = privateReader.readUint32();
|
|
13022
|
+
if (checkint1 !== checkint2) {
|
|
13023
|
+
throw new InvalidPrivateKeyFormatError('invalid checkints');
|
|
13024
|
+
}
|
|
13025
|
+
privateReader.readString();
|
|
13026
|
+
const n = privateReader.readMpInt(true);
|
|
13027
|
+
const e = privateReader.readMpInt(true);
|
|
13028
|
+
const d = privateReader.readMpInt(true);
|
|
13029
|
+
const iqmp = privateReader.readMpInt(true);
|
|
13030
|
+
const p = privateReader.readMpInt(true);
|
|
13031
|
+
const q = privateReader.readMpInt(true);
|
|
13032
|
+
privateReader.readString();
|
|
13033
|
+
const dBig = BigInt('0x' + buildExports.Convert.ToHex(d));
|
|
13034
|
+
const pBig = BigInt('0x' + buildExports.Convert.ToHex(p));
|
|
13035
|
+
const qBig = BigInt('0x' + buildExports.Convert.ToHex(q));
|
|
13036
|
+
const dpBig = dBig % (pBig - 1n);
|
|
13037
|
+
const dqBig = dBig % (qBig - 1n);
|
|
13038
|
+
const dpBytes = buildExports.Convert.FromHex(dpBig.toString(16).padStart(p.length * 2, '0'));
|
|
13039
|
+
const dqBytes = buildExports.Convert.FromHex(dqBig.toString(16).padStart(q.length * 2, '0'));
|
|
13040
|
+
const jwk = {
|
|
13041
|
+
kty: 'RSA',
|
|
13042
|
+
n: buildExports.Convert.ToBase64Url(n),
|
|
13043
|
+
e: buildExports.Convert.ToBase64Url(e),
|
|
13044
|
+
d: buildExports.Convert.ToBase64Url(d),
|
|
13045
|
+
p: buildExports.Convert.ToBase64Url(p),
|
|
13046
|
+
q: buildExports.Convert.ToBase64Url(q),
|
|
13047
|
+
dp: buildExports.Convert.ToBase64Url(dpBytes),
|
|
13048
|
+
dq: buildExports.Convert.ToBase64Url(dqBytes),
|
|
13049
|
+
qi: buildExports.Convert.ToBase64Url(iqmp),
|
|
13050
|
+
};
|
|
13051
|
+
return crypto.subtle.importKey('jwk', jwk, {
|
|
13052
|
+
name: 'RSASSA-PKCS1-v1_5',
|
|
13053
|
+
hash: this.hash,
|
|
13054
|
+
}, true, ['sign']);
|
|
13055
|
+
}
|
|
13056
|
+
async exportPrivateSsh(params) {
|
|
13057
|
+
const { privateKey, crypto, jwk: providedJwk } = params;
|
|
13058
|
+
const jwk = providedJwk || (await crypto.subtle.exportKey('jwk', privateKey));
|
|
13059
|
+
if (!jwk.n || !jwk.e || !jwk.d || !jwk.p || !jwk.q) {
|
|
13060
|
+
throw new InvalidKeyDataError('RSA JWK missing required parameters');
|
|
13061
|
+
}
|
|
13062
|
+
const n = new Uint8Array(buildExports.Convert.FromBase64Url(jwk.n));
|
|
13063
|
+
const e = new Uint8Array(buildExports.Convert.FromBase64Url(jwk.e));
|
|
13064
|
+
const d = new Uint8Array(buildExports.Convert.FromBase64Url(jwk.d));
|
|
13065
|
+
const p = new Uint8Array(buildExports.Convert.FromBase64Url(jwk.p));
|
|
13066
|
+
const q = new Uint8Array(buildExports.Convert.FromBase64Url(jwk.q));
|
|
13067
|
+
const qi = jwk.qi ? new Uint8Array(buildExports.Convert.FromBase64Url(jwk.qi)) : new Uint8Array();
|
|
13068
|
+
const writer = new SshWriter();
|
|
13069
|
+
writer.writeString('ssh-rsa');
|
|
13070
|
+
writer.writeMpInt(n, true);
|
|
13071
|
+
writer.writeMpInt(e, true);
|
|
13072
|
+
writer.writeMpInt(d, true);
|
|
13073
|
+
writer.writeMpInt(qi, true);
|
|
13074
|
+
writer.writeMpInt(p, true);
|
|
13075
|
+
writer.writeMpInt(q, true);
|
|
13076
|
+
return writer.toUint8Array();
|
|
13077
|
+
}
|
|
13078
|
+
async sign(params) {
|
|
13079
|
+
const { privateKey, data, crypto, hash } = params;
|
|
13080
|
+
if (hash && hash !== this.hash) {
|
|
13081
|
+
throw new InvalidKeyDataError(`Hash ${hash} not supported for this RSA algorithm`);
|
|
13082
|
+
}
|
|
13083
|
+
if (!privateKey.extractable) {
|
|
13084
|
+
throw new InvalidKeyDataError('Private key is not extractable');
|
|
13085
|
+
}
|
|
13086
|
+
const pkcs8 = await this.exportPrivatePkcs8({ privateKey, crypto });
|
|
13087
|
+
const keyToUse = await this.importPrivatePkcs8({ pkcs8: new Uint8Array(pkcs8), crypto });
|
|
13088
|
+
const signature = await crypto.subtle.sign('RSASSA-PKCS1-v1_5', keyToUse, data);
|
|
13089
|
+
return buildExports.BufferSourceConverter.toUint8Array(signature);
|
|
13090
|
+
}
|
|
13091
|
+
async verify(params) {
|
|
13092
|
+
const { publicKey, signature, data, crypto, hash } = params;
|
|
13093
|
+
if (hash && hash !== this.hash) {
|
|
13094
|
+
return false;
|
|
13095
|
+
}
|
|
13096
|
+
if (!publicKey.extractable) {
|
|
13097
|
+
throw new InvalidKeyDataError('Public key is not extractable');
|
|
13098
|
+
}
|
|
13099
|
+
const spki = await this.exportPublicSpki({ publicKey, crypto });
|
|
13100
|
+
const keyToUse = await this.importPublicSpki({ spki: new Uint8Array(spki), crypto });
|
|
13101
|
+
return crypto.subtle.verify('RSASSA-PKCS1-v1_5', keyToUse, signature, data);
|
|
13102
|
+
}
|
|
13103
|
+
encodeSignature(params) {
|
|
13104
|
+
const { signature, algo } = params;
|
|
13105
|
+
const writer = new SshWriter();
|
|
13106
|
+
writer.writeString(algo);
|
|
13107
|
+
writer.writeUint32(signature.byteLength);
|
|
13108
|
+
writer.writeBytes(signature);
|
|
13109
|
+
return writer.toUint8Array();
|
|
13110
|
+
}
|
|
13111
|
+
decodeSignature(params) {
|
|
13112
|
+
const { signature } = params;
|
|
13113
|
+
const reader = new SshReader(signature);
|
|
13114
|
+
const algo = reader.readString();
|
|
13115
|
+
const sigLength = reader.readUint32();
|
|
13116
|
+
const sig = reader.readBytes(sigLength);
|
|
13117
|
+
return { signature: sig, algo };
|
|
13118
|
+
}
|
|
13119
|
+
supportsCryptoKey(cryptoKey) {
|
|
13120
|
+
return cryptoKey.algorithm.name === 'RSASSA-PKCS1-v1_5';
|
|
13121
|
+
}
|
|
13122
|
+
parsePublicKey(reader) {
|
|
13123
|
+
const publicKeyExponent = reader.readBytes(reader.readUint32());
|
|
13124
|
+
const publicKeyModulus = reader.readBytes(reader.readUint32());
|
|
13125
|
+
const writer = new SshWriter();
|
|
13126
|
+
writer.writeString('ssh-rsa');
|
|
13127
|
+
writer.writeMpInt(publicKeyExponent);
|
|
13128
|
+
writer.writeMpInt(publicKeyModulus);
|
|
13129
|
+
return {
|
|
13130
|
+
type: 'ssh-rsa',
|
|
13131
|
+
keyData: writer.toUint8Array(),
|
|
13132
|
+
};
|
|
13133
|
+
}
|
|
13134
|
+
writePublicKey(writer, publicKey) {
|
|
13135
|
+
const publicKeyReader = new SshReader(publicKey.keyData);
|
|
13136
|
+
publicKeyReader.readString();
|
|
13137
|
+
const e = publicKeyReader.readMpInt();
|
|
13138
|
+
const n = publicKeyReader.readMpInt();
|
|
13139
|
+
writer.writeUint32(e.length);
|
|
13140
|
+
writer.writeBytes(e);
|
|
13141
|
+
writer.writeUint32(n.length);
|
|
13142
|
+
writer.writeBytes(n);
|
|
13143
|
+
}
|
|
13144
|
+
getCertificateType() {
|
|
13145
|
+
return 'ssh-rsa-cert-v01@openssh.com';
|
|
13146
|
+
}
|
|
13147
|
+
getSignatureAlgo() {
|
|
13148
|
+
return this.hash === 'SHA-256' ? 'rsa-sha2-256' : 'rsa-sha2-512';
|
|
13149
|
+
}
|
|
13150
|
+
}
|
|
13151
|
+
|
|
13152
|
+
class EcdsaBinding {
|
|
13153
|
+
curveName;
|
|
13154
|
+
sshType;
|
|
13155
|
+
namedCurve;
|
|
13156
|
+
constructor(curveName, sshType, namedCurve) {
|
|
13157
|
+
this.curveName = curveName;
|
|
13158
|
+
this.sshType = sshType;
|
|
13159
|
+
this.namedCurve = namedCurve;
|
|
13160
|
+
}
|
|
13161
|
+
getHashAlgorithm() {
|
|
13162
|
+
switch (this.namedCurve) {
|
|
13163
|
+
case 'P-256':
|
|
13164
|
+
return 'SHA-256';
|
|
13165
|
+
case 'P-384':
|
|
13166
|
+
return 'SHA-384';
|
|
13167
|
+
case 'P-521':
|
|
13168
|
+
return 'SHA-512';
|
|
13169
|
+
default:
|
|
13170
|
+
return 'SHA-256';
|
|
13171
|
+
}
|
|
13172
|
+
}
|
|
13173
|
+
getExpectedLength() {
|
|
13174
|
+
switch (this.namedCurve) {
|
|
13175
|
+
case 'P-256':
|
|
13176
|
+
return 32;
|
|
13177
|
+
case 'P-384':
|
|
13178
|
+
return 48;
|
|
13179
|
+
case 'P-521':
|
|
13180
|
+
return 66;
|
|
13181
|
+
default:
|
|
13182
|
+
return 32;
|
|
13183
|
+
}
|
|
13184
|
+
}
|
|
13185
|
+
getSignatureCoordLength() {
|
|
13186
|
+
return this.getExpectedLength();
|
|
13187
|
+
}
|
|
13188
|
+
async importPublicSsh(params) {
|
|
13189
|
+
const { blob, crypto } = params;
|
|
13190
|
+
const reader = new SshReader(blob);
|
|
13191
|
+
reader.readString();
|
|
13192
|
+
const curve = reader.readString();
|
|
13193
|
+
if (curve !== this.curveName) {
|
|
13194
|
+
throw new InvalidKeyDataError(`ECDSA curve name ${curve}, expected ${this.curveName}`);
|
|
13195
|
+
}
|
|
13196
|
+
const q = reader.readMpInt();
|
|
13197
|
+
const coordLength = Math.floor((q.length - 1) / 2);
|
|
13198
|
+
const jwk = {
|
|
13199
|
+
kty: 'EC',
|
|
13200
|
+
crv: this.namedCurve,
|
|
13201
|
+
x: buildExports.Convert.ToBase64Url(q.slice(1, 1 + coordLength)),
|
|
13202
|
+
y: buildExports.Convert.ToBase64Url(q.slice(1 + coordLength)),
|
|
13203
|
+
};
|
|
13204
|
+
return crypto.subtle.importKey('jwk', jwk, {
|
|
13205
|
+
name: 'ECDSA',
|
|
13206
|
+
namedCurve: this.namedCurve,
|
|
13207
|
+
}, true, ['verify']);
|
|
13208
|
+
}
|
|
13209
|
+
async exportPublicSsh(params) {
|
|
13210
|
+
const { publicKey, crypto } = params;
|
|
13211
|
+
const jwk = await crypto.subtle.exportKey('jwk', publicKey);
|
|
13212
|
+
if (!jwk.x || !jwk.y) {
|
|
13213
|
+
throw new InvalidKeyDataError('ECDSA JWK missing x or y parameters');
|
|
13214
|
+
}
|
|
13215
|
+
const x = new Uint8Array(buildExports.Convert.FromBase64Url(jwk.x));
|
|
13216
|
+
const y = new Uint8Array(buildExports.Convert.FromBase64Url(jwk.y));
|
|
13217
|
+
const q = new Uint8Array(1 + x.length + y.length);
|
|
13218
|
+
q[0] = 0x04;
|
|
13219
|
+
q.set(x, 1);
|
|
13220
|
+
q.set(y, 1 + x.length);
|
|
13221
|
+
const writer = new SshWriter();
|
|
13222
|
+
writer.writeString(this.sshType);
|
|
13223
|
+
writer.writeString(this.curveName);
|
|
13224
|
+
writer.writeMpInt(q);
|
|
13225
|
+
return writer.toUint8Array();
|
|
13226
|
+
}
|
|
13227
|
+
async importPublicSpki(params) {
|
|
13228
|
+
const { spki, crypto } = params;
|
|
13229
|
+
return crypto.subtle.importKey('spki', spki, {
|
|
13230
|
+
name: 'ECDSA',
|
|
13231
|
+
namedCurve: this.namedCurve,
|
|
13232
|
+
}, true, ['verify']);
|
|
13233
|
+
}
|
|
13234
|
+
async exportPublicSpki(params) {
|
|
13235
|
+
const { publicKey, crypto } = params;
|
|
13236
|
+
const spki = await crypto.subtle.exportKey('spki', publicKey);
|
|
13237
|
+
return buildExports.BufferSourceConverter.toUint8Array(spki);
|
|
13238
|
+
}
|
|
13239
|
+
async importPrivatePkcs8(params) {
|
|
13240
|
+
const { pkcs8, crypto } = params;
|
|
13241
|
+
return crypto.subtle.importKey('pkcs8', pkcs8, {
|
|
13242
|
+
name: 'ECDSA',
|
|
13243
|
+
namedCurve: this.namedCurve,
|
|
13244
|
+
}, true, ['sign']);
|
|
13245
|
+
}
|
|
13246
|
+
async exportPrivatePkcs8(params) {
|
|
13247
|
+
const { privateKey, crypto } = params;
|
|
13248
|
+
const pkcs8 = await crypto.subtle.exportKey('pkcs8', privateKey);
|
|
13249
|
+
return buildExports.BufferSourceConverter.toUint8Array(pkcs8);
|
|
13250
|
+
}
|
|
13251
|
+
async exportPrivateSsh(params) {
|
|
13252
|
+
const { privateKey, crypto, jwk: providedJwk } = params;
|
|
13253
|
+
const jwk = providedJwk || (await crypto.subtle.exportKey('jwk', privateKey));
|
|
13254
|
+
if (!jwk.d || !jwk.x || !jwk.y) {
|
|
13255
|
+
throw new InvalidKeyDataError('ECDSA private key JWK missing required parameters');
|
|
13256
|
+
}
|
|
13257
|
+
const x = new Uint8Array(buildExports.Convert.FromBase64Url(jwk.x));
|
|
13258
|
+
const y = new Uint8Array(buildExports.Convert.FromBase64Url(jwk.y));
|
|
13259
|
+
const d = new Uint8Array(buildExports.Convert.FromBase64Url(jwk.d));
|
|
13260
|
+
const publicPoint = new Uint8Array(1 + x.length + y.length);
|
|
13261
|
+
publicPoint[0] = 0x04;
|
|
13262
|
+
publicPoint.set(x, 1);
|
|
13263
|
+
publicPoint.set(y, 1 + x.length);
|
|
13264
|
+
const writer = new SshWriter();
|
|
13265
|
+
writer.writeString(this.sshType);
|
|
13266
|
+
writer.writeString(this.curveName);
|
|
13267
|
+
writer.writeMpInt(publicPoint);
|
|
13268
|
+
writer.writeMpInt(d);
|
|
13269
|
+
return writer.toUint8Array();
|
|
13270
|
+
}
|
|
13271
|
+
async importPrivateSsh(params) {
|
|
13272
|
+
const { sshKey, crypto } = params;
|
|
13273
|
+
const base64Data = sshKey
|
|
13274
|
+
.replace(/-----BEGIN OPENSSH PRIVATE KEY-----/, '')
|
|
13275
|
+
.replace(/-----END OPENSSH PRIVATE KEY-----/, '')
|
|
13276
|
+
.replace(/\s/g, '');
|
|
13277
|
+
const binaryData = buildExports.Convert.FromBase64(base64Data);
|
|
13278
|
+
const reader = new SshReader(buildExports.BufferSourceConverter.toUint8Array(binaryData));
|
|
13279
|
+
const magic = reader.readBytes(15);
|
|
13280
|
+
if (buildExports.Convert.ToHex(magic) !== '6f70656e7373682d6b65792d763100') {
|
|
13281
|
+
throw new InvalidPrivateKeyFormatError('invalid magic string');
|
|
13282
|
+
}
|
|
13283
|
+
const _cipherName = reader.readString();
|
|
13284
|
+
reader.readString();
|
|
13285
|
+
reader.readString();
|
|
13286
|
+
if (_cipherName !== 'none') {
|
|
13287
|
+
throw new EncryptedKeyNotSupportedError(_cipherName);
|
|
13288
|
+
}
|
|
13289
|
+
const numKeys = reader.readUint32();
|
|
13290
|
+
if (numKeys !== 1) {
|
|
13291
|
+
throw new InvalidPrivateKeyFormatError('multiple keys not supported');
|
|
13292
|
+
}
|
|
13293
|
+
const publicKeyLength = reader.readUint32();
|
|
13294
|
+
reader.readBytes(publicKeyLength);
|
|
13295
|
+
const privateKeyLength = reader.readUint32();
|
|
13296
|
+
const privateKeyData = reader.readBytes(privateKeyLength);
|
|
13297
|
+
const privateReader = new SshReader(privateKeyData);
|
|
13298
|
+
const checkint1 = privateReader.readUint32();
|
|
13299
|
+
const checkint2 = privateReader.readUint32();
|
|
13300
|
+
if (checkint1 !== checkint2) {
|
|
13301
|
+
throw new InvalidPrivateKeyFormatError('invalid checkints');
|
|
13302
|
+
}
|
|
13303
|
+
privateReader.readString();
|
|
13304
|
+
privateReader.readString();
|
|
13305
|
+
const publicKeyPoint = privateReader.readMpInt();
|
|
13306
|
+
const privateKeyValue = privateReader.readMpInt();
|
|
13307
|
+
privateReader.readString();
|
|
13308
|
+
if (publicKeyPoint[0] !== 0x04) {
|
|
13309
|
+
throw new InvalidKeyDataError('invalid ECDSA public key point format');
|
|
13310
|
+
}
|
|
13311
|
+
const coordLength = Math.floor((publicKeyPoint.length - 1) / 2);
|
|
13312
|
+
const x = publicKeyPoint.slice(1, 1 + coordLength);
|
|
13313
|
+
const y = publicKeyPoint.slice(1 + coordLength);
|
|
13314
|
+
const jwk = {
|
|
13315
|
+
kty: 'EC',
|
|
13316
|
+
crv: this.namedCurve,
|
|
13317
|
+
x: buildExports.Convert.ToBase64Url(x),
|
|
13318
|
+
y: buildExports.Convert.ToBase64Url(y),
|
|
13319
|
+
d: buildExports.Convert.ToBase64Url(privateKeyValue),
|
|
13320
|
+
};
|
|
13321
|
+
return crypto.subtle.importKey('jwk', jwk, {
|
|
13322
|
+
name: 'ECDSA',
|
|
13323
|
+
namedCurve: this.namedCurve,
|
|
13324
|
+
}, true, ['sign']);
|
|
13325
|
+
}
|
|
13326
|
+
async sign(params) {
|
|
13327
|
+
const { privateKey, data, crypto, hash } = params;
|
|
13328
|
+
const expectedHash = this.getHashAlgorithm();
|
|
13329
|
+
if (hash && hash !== expectedHash) {
|
|
13330
|
+
throw new InvalidKeyDataError(`ECDSA ${this.namedCurve} requires ${expectedHash}, got ${hash}`);
|
|
13331
|
+
}
|
|
13332
|
+
const signature = await crypto.subtle.sign({
|
|
13333
|
+
name: 'ECDSA',
|
|
13334
|
+
hash: expectedHash,
|
|
13335
|
+
}, privateKey, data);
|
|
13336
|
+
return buildExports.BufferSourceConverter.toUint8Array(signature);
|
|
13337
|
+
}
|
|
13338
|
+
async verify(params) {
|
|
13339
|
+
const { publicKey, signature, data, crypto, hash } = params;
|
|
13340
|
+
const expectedHash = this.getHashAlgorithm();
|
|
13341
|
+
if (hash && hash !== expectedHash) {
|
|
13342
|
+
throw new InvalidKeyDataError(`ECDSA ${this.namedCurve} requires ${expectedHash}, got ${hash}`);
|
|
13343
|
+
}
|
|
13344
|
+
return crypto.subtle.verify({
|
|
13345
|
+
name: 'ECDSA',
|
|
13346
|
+
hash: expectedHash,
|
|
13347
|
+
}, publicKey, signature, data);
|
|
13348
|
+
}
|
|
13349
|
+
encodeSignature(params) {
|
|
13350
|
+
const { signature, algo } = params;
|
|
13351
|
+
if (algo.startsWith('ecdsa-sha2-')) {
|
|
13352
|
+
const coordLength = this.getSignatureCoordLength();
|
|
13353
|
+
const r = signature.subarray(0, coordLength);
|
|
13354
|
+
const s = signature.subarray(coordLength);
|
|
13355
|
+
const writer = new SshWriter();
|
|
13356
|
+
writer.writeString(algo);
|
|
13357
|
+
const sigWriter = new SshWriter();
|
|
13358
|
+
sigWriter.writeMpInt(r, true);
|
|
13359
|
+
sigWriter.writeMpInt(s, true);
|
|
13360
|
+
const sigData = sigWriter.toUint8Array();
|
|
13361
|
+
writer.writeUint32(sigData.length);
|
|
13362
|
+
writer.writeBytes(sigData);
|
|
13363
|
+
return writer.toUint8Array();
|
|
13364
|
+
}
|
|
13365
|
+
const writer = new SshWriter();
|
|
13366
|
+
writer.writeString(algo);
|
|
13367
|
+
writer.writeUint32(signature.byteLength);
|
|
13368
|
+
writer.writeBytes(signature);
|
|
13369
|
+
return writer.toUint8Array();
|
|
13370
|
+
}
|
|
13371
|
+
decodeSignature(params) {
|
|
13372
|
+
const { signature } = params;
|
|
13373
|
+
const reader = new SshReader(signature);
|
|
13374
|
+
const algo = reader.readString();
|
|
13375
|
+
const sigLength = reader.readUint32();
|
|
13376
|
+
const sig = reader.readBytes(sigLength);
|
|
13377
|
+
if (algo.startsWith('ecdsa-sha2-')) {
|
|
13378
|
+
const sigReader = new SshReader(sig);
|
|
13379
|
+
let r = sigReader.readMpInt();
|
|
13380
|
+
let s = sigReader.readMpInt();
|
|
13381
|
+
if (r[0] === 0x00 && r.length > 1 && (r[1] & 0x80) === 0) {
|
|
13382
|
+
r = r.slice(1);
|
|
13383
|
+
}
|
|
13384
|
+
if (s[0] === 0x00 && s.length > 1 && (s[1] & 0x80) === 0) {
|
|
13385
|
+
s = s.slice(1);
|
|
13386
|
+
}
|
|
13387
|
+
const expectedLength = this.getExpectedLength();
|
|
13388
|
+
const rPadded = new Uint8Array(expectedLength);
|
|
13389
|
+
const sPadded = new Uint8Array(expectedLength);
|
|
13390
|
+
if (r.length <= expectedLength) {
|
|
13391
|
+
rPadded.set(r, expectedLength - r.length);
|
|
13392
|
+
}
|
|
13393
|
+
else {
|
|
13394
|
+
rPadded.set(r.slice(r.length - expectedLength), 0);
|
|
13395
|
+
}
|
|
13396
|
+
if (s.length <= expectedLength) {
|
|
13397
|
+
sPadded.set(s, expectedLength - s.length);
|
|
13398
|
+
}
|
|
13399
|
+
else {
|
|
13400
|
+
sPadded.set(s.slice(s.length - expectedLength), 0);
|
|
13401
|
+
}
|
|
13402
|
+
const rawSignature = new Uint8Array([...rPadded, ...sPadded]);
|
|
13403
|
+
return { signature: rawSignature, algo };
|
|
13404
|
+
}
|
|
13405
|
+
return { signature: sig, algo };
|
|
13406
|
+
}
|
|
13407
|
+
supportsCryptoKey(cryptoKey) {
|
|
13408
|
+
return (cryptoKey.algorithm.name === 'ECDSA' &&
|
|
13409
|
+
cryptoKey.algorithm.namedCurve === this.namedCurve);
|
|
13410
|
+
}
|
|
13411
|
+
parsePublicKey(reader) {
|
|
13412
|
+
const curveName = reader.readString();
|
|
13413
|
+
if (curveName !== this.curveName) {
|
|
13414
|
+
throw new InvalidKeyDataError(`ECDSA certificate curve name ${curveName}, expected ${this.curveName}`);
|
|
13415
|
+
}
|
|
13416
|
+
const publicKeyPoint = reader.readBytes(reader.readUint32());
|
|
13417
|
+
const writer = new SshWriter();
|
|
13418
|
+
writer.writeString(this.sshType);
|
|
13419
|
+
writer.writeString(curveName);
|
|
13420
|
+
writer.writeMpInt(publicKeyPoint);
|
|
13421
|
+
return {
|
|
13422
|
+
type: this.sshType,
|
|
13423
|
+
keyData: writer.toUint8Array(),
|
|
13424
|
+
};
|
|
13425
|
+
}
|
|
13426
|
+
writePublicKey(writer, publicKey) {
|
|
13427
|
+
const publicKeyReader = new SshReader(publicKey.keyData);
|
|
13428
|
+
publicKeyReader.readString();
|
|
13429
|
+
const curveName = publicKeyReader.readString();
|
|
13430
|
+
const publicPoint = publicKeyReader.readMpInt();
|
|
13431
|
+
writer.writeString(curveName);
|
|
13432
|
+
writer.writeUint32(publicPoint.length);
|
|
13433
|
+
writer.writeBytes(publicPoint);
|
|
13434
|
+
}
|
|
13435
|
+
getCertificateType() {
|
|
13436
|
+
return `${this.sshType}-cert-v01@openssh.com`;
|
|
13437
|
+
}
|
|
13438
|
+
getSignatureAlgo() {
|
|
13439
|
+
return this.sshType;
|
|
13440
|
+
}
|
|
13441
|
+
}
|
|
13442
|
+
const EcdsaP256Binding = new EcdsaBinding('nistp256', 'ecdsa-sha2-nistp256', 'P-256');
|
|
13443
|
+
const EcdsaP384Binding = new EcdsaBinding('nistp384', 'ecdsa-sha2-nistp384', 'P-384');
|
|
13444
|
+
const EcdsaP521Binding = new EcdsaBinding('nistp521', 'ecdsa-sha2-nistp521', 'P-521');
|
|
13445
|
+
|
|
13446
|
+
class Ed25519Binding {
|
|
13447
|
+
async importPublicSsh(params) {
|
|
13448
|
+
const { blob, crypto } = params;
|
|
13449
|
+
const reader = new SshReader(blob);
|
|
13450
|
+
reader.readString();
|
|
13451
|
+
const keyLength = reader.readUint32();
|
|
13452
|
+
if (keyLength !== 32) {
|
|
13453
|
+
throw new InvalidKeyDataError(`Ed25519 key length ${keyLength}, expected 32`);
|
|
13454
|
+
}
|
|
13455
|
+
const publicKeyBytes = reader.readBytes(keyLength);
|
|
13456
|
+
return crypto.subtle.importKey('raw', publicKeyBytes, 'Ed25519', true, [
|
|
13457
|
+
'verify',
|
|
13458
|
+
]);
|
|
13459
|
+
}
|
|
13460
|
+
async exportPublicSsh(params) {
|
|
13461
|
+
const { publicKey, crypto } = params;
|
|
13462
|
+
const jwk = await crypto.subtle.exportKey('jwk', publicKey);
|
|
13463
|
+
if (!jwk.x) {
|
|
13464
|
+
throw new InvalidKeyDataError('Ed25519 JWK missing x parameter');
|
|
13465
|
+
}
|
|
13466
|
+
const keyBytes = new Uint8Array(buildExports.Convert.FromBase64Url(jwk.x));
|
|
13467
|
+
const writer = new SshWriter();
|
|
13468
|
+
writer.writeString('ssh-ed25519');
|
|
13469
|
+
writer.writeUint32(keyBytes.length);
|
|
13470
|
+
writer.writeBytes(keyBytes);
|
|
13471
|
+
return writer.toUint8Array();
|
|
13472
|
+
}
|
|
13473
|
+
async importPublicSpki(params) {
|
|
13474
|
+
const { spki, crypto } = params;
|
|
13475
|
+
return crypto.subtle.importKey('spki', spki, 'Ed25519', true, ['verify']);
|
|
13476
|
+
}
|
|
13477
|
+
async exportPublicSpki(params) {
|
|
13478
|
+
const { publicKey, crypto } = params;
|
|
13479
|
+
const spki = await crypto.subtle.exportKey('spki', publicKey);
|
|
13480
|
+
return buildExports.BufferSourceConverter.toUint8Array(spki);
|
|
13481
|
+
}
|
|
13482
|
+
async importPrivatePkcs8(params) {
|
|
13483
|
+
const { pkcs8, crypto } = params;
|
|
13484
|
+
return crypto.subtle.importKey('pkcs8', pkcs8, 'Ed25519', true, ['sign']);
|
|
13485
|
+
}
|
|
13486
|
+
async exportPrivatePkcs8(params) {
|
|
13487
|
+
const { privateKey, crypto } = params;
|
|
13488
|
+
const pkcs8 = await crypto.subtle.exportKey('pkcs8', privateKey);
|
|
13489
|
+
return buildExports.BufferSourceConverter.toUint8Array(pkcs8);
|
|
13490
|
+
}
|
|
13491
|
+
async exportPrivateSsh(params) {
|
|
13492
|
+
const { privateKey, crypto, jwk: providedJwk } = params;
|
|
13493
|
+
const jwk = providedJwk || (await crypto.subtle.exportKey('jwk', privateKey));
|
|
13494
|
+
if (!jwk.d || !jwk.x) {
|
|
13495
|
+
throw new InvalidKeyDataError('Ed25519 private key JWK missing required parameters');
|
|
13496
|
+
}
|
|
13497
|
+
const privateBytes = new Uint8Array(buildExports.Convert.FromBase64Url(jwk.d));
|
|
13498
|
+
const publicBytes = new Uint8Array(buildExports.Convert.FromBase64Url(jwk.x));
|
|
13499
|
+
const writer = new SshWriter();
|
|
13500
|
+
writer.writeString('ssh-ed25519');
|
|
13501
|
+
writer.writeUint32(publicBytes.length);
|
|
13502
|
+
writer.writeBytes(publicBytes);
|
|
13503
|
+
const privKeyPart = new Uint8Array(64);
|
|
13504
|
+
privKeyPart.set(privateBytes, 0);
|
|
13505
|
+
privKeyPart.set(publicBytes, 32);
|
|
13506
|
+
writer.writeUint32(privKeyPart.length);
|
|
13507
|
+
writer.writeBytes(privKeyPart);
|
|
13508
|
+
return writer.toUint8Array();
|
|
13509
|
+
}
|
|
13510
|
+
async importPrivateSsh(params) {
|
|
13511
|
+
const { sshKey, crypto } = params;
|
|
13512
|
+
const base64Data = sshKey
|
|
13513
|
+
.replace(/-----BEGIN OPENSSH PRIVATE KEY-----/, '')
|
|
13514
|
+
.replace(/-----END OPENSSH PRIVATE KEY-----/, '')
|
|
13515
|
+
.replace(/\s/g, '');
|
|
13516
|
+
const binaryData = buildExports.Convert.FromBase64(base64Data);
|
|
13517
|
+
const reader = new SshReader(buildExports.BufferSourceConverter.toUint8Array(binaryData));
|
|
13518
|
+
const magic = reader.readBytes(15);
|
|
13519
|
+
if (buildExports.Convert.ToHex(magic) !== '6f70656e7373682d6b65792d763100') {
|
|
13520
|
+
throw new InvalidPrivateKeyFormatError('invalid magic string');
|
|
13521
|
+
}
|
|
13522
|
+
const _cipherName = reader.readString();
|
|
13523
|
+
reader.readString();
|
|
13524
|
+
reader.readString();
|
|
13525
|
+
if (_cipherName !== 'none') {
|
|
13526
|
+
throw new EncryptedKeyNotSupportedError(_cipherName);
|
|
13527
|
+
}
|
|
13528
|
+
const numKeys = reader.readUint32();
|
|
13529
|
+
if (numKeys !== 1) {
|
|
13530
|
+
throw new InvalidPrivateKeyFormatError('multiple keys not supported');
|
|
13531
|
+
}
|
|
13532
|
+
const publicKeyLength = reader.readUint32();
|
|
13533
|
+
reader.readBytes(publicKeyLength);
|
|
13534
|
+
const privateKeyLength = reader.readUint32();
|
|
13535
|
+
const privateKeyData = reader.readBytes(privateKeyLength);
|
|
13536
|
+
const privateReader = new SshReader(privateKeyData);
|
|
13537
|
+
const checkint1 = privateReader.readUint32();
|
|
13538
|
+
const checkint2 = privateReader.readUint32();
|
|
13539
|
+
if (checkint1 !== checkint2) {
|
|
13540
|
+
throw new InvalidPrivateKeyFormatError('invalid checkints');
|
|
13541
|
+
}
|
|
13542
|
+
privateReader.readString();
|
|
13543
|
+
const pubKeyLength = privateReader.readUint32();
|
|
13544
|
+
const _publicKeyBytes = privateReader.readBytes(pubKeyLength);
|
|
13545
|
+
const privKeyLength = privateReader.readUint32();
|
|
13546
|
+
const privateKeyBytes = privateReader.readBytes(privKeyLength);
|
|
13547
|
+
privateReader.readString();
|
|
13548
|
+
const privateKey = privateKeyBytes.slice(0, 32);
|
|
13549
|
+
const jwk = {
|
|
13550
|
+
kty: 'OKP',
|
|
13551
|
+
crv: 'Ed25519',
|
|
13552
|
+
d: buildExports.Convert.ToBase64Url(privateKey),
|
|
13553
|
+
x: buildExports.Convert.ToBase64Url(_publicKeyBytes),
|
|
13554
|
+
};
|
|
13555
|
+
return crypto.subtle.importKey('jwk', jwk, 'Ed25519', true, ['sign']);
|
|
13556
|
+
}
|
|
13557
|
+
async sign(params) {
|
|
13558
|
+
const { privateKey, data, crypto } = params;
|
|
13559
|
+
const signature = await crypto.subtle.sign('Ed25519', privateKey, data);
|
|
13560
|
+
return buildExports.BufferSourceConverter.toUint8Array(signature);
|
|
13561
|
+
}
|
|
13562
|
+
async verify(params) {
|
|
13563
|
+
const { publicKey, signature, data, crypto } = params;
|
|
13564
|
+
return crypto.subtle.verify('Ed25519', publicKey, signature, data);
|
|
13565
|
+
}
|
|
13566
|
+
encodeSignature(params) {
|
|
13567
|
+
const { signature, algo } = params;
|
|
13568
|
+
const sigBytes = new Uint8Array(signature);
|
|
13569
|
+
const writer = new SshWriter();
|
|
13570
|
+
writer.writeString(algo);
|
|
13571
|
+
writer.writeUint32(sigBytes.length);
|
|
13572
|
+
writer.writeBytes(sigBytes);
|
|
13573
|
+
return writer.toUint8Array();
|
|
13574
|
+
}
|
|
13575
|
+
decodeSignature(params) {
|
|
13576
|
+
const { signature } = params;
|
|
13577
|
+
const reader = new SshReader(signature);
|
|
13578
|
+
const algo = reader.readString();
|
|
13579
|
+
const sigLength = reader.readUint32();
|
|
13580
|
+
const sigBytes = reader.readBytes(sigLength);
|
|
13581
|
+
return {
|
|
13582
|
+
signature: sigBytes,
|
|
13583
|
+
algo,
|
|
13584
|
+
};
|
|
13585
|
+
}
|
|
13586
|
+
supportsCryptoKey(cryptoKey) {
|
|
13587
|
+
return cryptoKey.algorithm.name === 'Ed25519';
|
|
13588
|
+
}
|
|
13589
|
+
parsePublicKey(reader) {
|
|
13590
|
+
const publicKeyData = reader.readBytes(reader.readUint32());
|
|
13591
|
+
const writer = new SshWriter();
|
|
13592
|
+
writer.writeString('ssh-ed25519');
|
|
13593
|
+
writer.writeUint32(publicKeyData.length);
|
|
13594
|
+
writer.writeBytes(publicKeyData);
|
|
13595
|
+
return {
|
|
13596
|
+
type: 'ssh-ed25519',
|
|
13597
|
+
keyData: writer.toUint8Array(),
|
|
13598
|
+
};
|
|
13599
|
+
}
|
|
13600
|
+
writePublicKey(writer, publicKey) {
|
|
13601
|
+
const publicKeyReader = new SshReader(publicKey.keyData);
|
|
13602
|
+
publicKeyReader.readString();
|
|
13603
|
+
const keyLength = publicKeyReader.readUint32();
|
|
13604
|
+
const rawKeyData = publicKeyReader.readBytes(keyLength);
|
|
13605
|
+
writer.writeUint32(rawKeyData.length);
|
|
13606
|
+
writer.writeBytes(rawKeyData);
|
|
13607
|
+
}
|
|
13608
|
+
getCertificateType() {
|
|
13609
|
+
return 'ssh-ed25519-cert-v01@openssh.com';
|
|
13610
|
+
}
|
|
13611
|
+
getSignatureAlgo() {
|
|
13612
|
+
return 'ssh-ed25519';
|
|
13613
|
+
}
|
|
13614
|
+
}
|
|
13615
|
+
|
|
13616
|
+
const registry = new Map();
|
|
13617
|
+
class AlgorithmRegistry {
|
|
13618
|
+
static get(name) {
|
|
13619
|
+
const binding = registry.get(name);
|
|
13620
|
+
if (!binding) {
|
|
13621
|
+
throw new UnsupportedKeyTypeError(name, Array.from(registry.keys()));
|
|
13622
|
+
}
|
|
13623
|
+
return binding;
|
|
13624
|
+
}
|
|
13625
|
+
static register(name, binding) {
|
|
13626
|
+
registry.set(name, binding);
|
|
13627
|
+
}
|
|
13628
|
+
static getSshTypeFromCryptoKey(cryptoKey) {
|
|
13629
|
+
for (const [sshType, binding] of registry.entries()) {
|
|
13630
|
+
if (binding.supportsCryptoKey(cryptoKey)) {
|
|
13631
|
+
return sshType;
|
|
13632
|
+
}
|
|
13633
|
+
}
|
|
13634
|
+
throw new UnsupportedKeyTypeError(cryptoKey.algorithm.name, Array.from(registry.keys()));
|
|
13635
|
+
}
|
|
13636
|
+
static certTypeToKeyType(certType) {
|
|
13637
|
+
const mapping = {
|
|
13638
|
+
'ssh-rsa-cert-v01@openssh.com': 'ssh-rsa',
|
|
13639
|
+
'ssh-ed25519-cert-v01@openssh.com': 'ssh-ed25519',
|
|
13640
|
+
'ecdsa-sha2-nistp256-cert-v01@openssh.com': 'ecdsa-sha2-nistp256',
|
|
13641
|
+
'ecdsa-sha2-nistp384-cert-v01@openssh.com': 'ecdsa-sha2-nistp384',
|
|
13642
|
+
'ecdsa-sha2-nistp521-cert-v01@openssh.com': 'ecdsa-sha2-nistp521',
|
|
13643
|
+
};
|
|
13644
|
+
return mapping[certType];
|
|
13645
|
+
}
|
|
13646
|
+
static getSupportedCertTypes() {
|
|
13647
|
+
return Object.keys({
|
|
13648
|
+
'ssh-rsa-cert-v01@openssh.com': 'ssh-rsa',
|
|
13649
|
+
'ssh-ed25519-cert-v01@openssh.com': 'ssh-ed25519',
|
|
13650
|
+
'ecdsa-sha2-nistp256-cert-v01@openssh.com': 'ecdsa-sha2-nistp256',
|
|
13651
|
+
'ecdsa-sha2-nistp384-cert-v01@openssh.com': 'ecdsa-sha2-nistp384',
|
|
13652
|
+
'ecdsa-sha2-nistp521-cert-v01@openssh.com': 'ecdsa-sha2-nistp521',
|
|
13653
|
+
});
|
|
13654
|
+
}
|
|
13655
|
+
}
|
|
13656
|
+
AlgorithmRegistry.register('ssh-ed25519', new Ed25519Binding());
|
|
13657
|
+
AlgorithmRegistry.register('ssh-rsa', new RsaBinding('SHA-256'));
|
|
13658
|
+
AlgorithmRegistry.register('rsa-sha2-256', new RsaBinding('SHA-256'));
|
|
13659
|
+
AlgorithmRegistry.register('rsa-sha2-512', new RsaBinding('SHA-512'));
|
|
13660
|
+
AlgorithmRegistry.register('ecdsa-sha2-nistp256', EcdsaP256Binding);
|
|
13661
|
+
AlgorithmRegistry.register('ecdsa-sha2-nistp384', EcdsaP384Binding);
|
|
13662
|
+
AlgorithmRegistry.register('ecdsa-sha2-nistp521', EcdsaP521Binding);
|
|
13663
|
+
|
|
13664
|
+
function parsePublicKey(input) {
|
|
13665
|
+
const parts = typeof input === 'string' ? input.trim().split(/\s+/) : null;
|
|
13666
|
+
if (!parts || parts.length < 2) {
|
|
13667
|
+
throw new InvalidFormatError('Invalid SSH public key format');
|
|
13668
|
+
}
|
|
13669
|
+
const type = parts[0];
|
|
13670
|
+
const blob = new Uint8Array(buildExports.Convert.FromBase64(parts[1]));
|
|
13671
|
+
const comment = parts.length > 2 ? parts.slice(2).join(' ') : undefined;
|
|
13672
|
+
const reader = new SshReader(blob);
|
|
13673
|
+
const blobType = reader.readString();
|
|
13674
|
+
if (blobType !== type) {
|
|
13675
|
+
throw new InvalidFormatError('Key type mismatch');
|
|
13676
|
+
}
|
|
13677
|
+
return {
|
|
13678
|
+
type,
|
|
13679
|
+
keyData: blob,
|
|
13680
|
+
comment,
|
|
13681
|
+
};
|
|
13682
|
+
}
|
|
13683
|
+
function serializePublicKey(blob) {
|
|
13684
|
+
const base64 = buildExports.Convert.ToBase64(blob.keyData);
|
|
13685
|
+
const parts = [blob.type, base64];
|
|
13686
|
+
if (blob.comment) {
|
|
13687
|
+
parts.push(blob.comment);
|
|
13688
|
+
}
|
|
13689
|
+
return parts.join(' ');
|
|
13690
|
+
}
|
|
13691
|
+
|
|
13692
|
+
function parse(input) {
|
|
13693
|
+
if (typeof input === 'string') {
|
|
13694
|
+
const parts = input.trim().split(/\s+/);
|
|
13695
|
+
if (parts.length < 2) {
|
|
13696
|
+
throw new InvalidFormatError('SSH certificate string', 'type base64 [comment]');
|
|
13697
|
+
}
|
|
13698
|
+
const type = parts[0];
|
|
13699
|
+
const blob = new Uint8Array(buildExports.Convert.FromBase64(parts[1]));
|
|
13700
|
+
const comment = parts.length > 2 ? parts.slice(2).join(' ') : undefined;
|
|
13701
|
+
const reader = new SshReader(blob);
|
|
13702
|
+
const blobType = reader.readString();
|
|
13703
|
+
if (blobType !== type) {
|
|
13704
|
+
throw new InvalidFormatError(`certificate blob type ${blobType}`, `expected ${type}`);
|
|
13705
|
+
}
|
|
13706
|
+
return {
|
|
13707
|
+
type,
|
|
13708
|
+
keyData: blob,
|
|
13709
|
+
comment,
|
|
13710
|
+
};
|
|
13711
|
+
}
|
|
13712
|
+
else {
|
|
13713
|
+
const reader = new SshReader(input);
|
|
13714
|
+
const type = reader.readString();
|
|
13715
|
+
const keyData = input.slice(reader.getOffset());
|
|
13716
|
+
return {
|
|
13717
|
+
type,
|
|
13718
|
+
keyData,
|
|
13719
|
+
};
|
|
13720
|
+
}
|
|
13721
|
+
}
|
|
13722
|
+
function parseCertificateData(keyData) {
|
|
13723
|
+
const reader = new SshReader(keyData);
|
|
13724
|
+
const certType = reader.readString();
|
|
13725
|
+
const nonce = reader.readBytes(reader.readUint32());
|
|
13726
|
+
const mappedKeyType = AlgorithmRegistry.certTypeToKeyType(certType);
|
|
13727
|
+
if (!mappedKeyType) {
|
|
13728
|
+
throw new UnsupportedAlgorithmError(certType, AlgorithmRegistry.getSupportedCertTypes());
|
|
13729
|
+
}
|
|
13730
|
+
const binding = AlgorithmRegistry.get(mappedKeyType);
|
|
13731
|
+
const publicKey = binding.parsePublicKey(reader);
|
|
13732
|
+
const keyType = mappedKeyType;
|
|
13733
|
+
const serial = reader.readUint64();
|
|
13734
|
+
const typeValue = reader.readUint32();
|
|
13735
|
+
const type = typeValue === 1 ? 'user' : 'host';
|
|
13736
|
+
const keyId = reader.readString();
|
|
13737
|
+
const principalsLength = reader.readUint32();
|
|
13738
|
+
const principalsData = reader.readBytes(principalsLength);
|
|
13739
|
+
const validPrincipals = [];
|
|
13740
|
+
if (principalsData.length > 0) {
|
|
13741
|
+
const principalsReader = new SshReader(principalsData);
|
|
13742
|
+
while (principalsReader.getOffset() < principalsData.length) {
|
|
13743
|
+
try {
|
|
13744
|
+
const principal = principalsReader.readString();
|
|
13745
|
+
validPrincipals.push(principal);
|
|
13746
|
+
}
|
|
13747
|
+
catch {
|
|
13748
|
+
break;
|
|
13749
|
+
}
|
|
13750
|
+
}
|
|
13751
|
+
}
|
|
13752
|
+
const validAfter = reader.readUint64();
|
|
13753
|
+
const validBefore = reader.readUint64();
|
|
13754
|
+
const criticalOptions = {};
|
|
13755
|
+
const criticalLength = reader.readUint32();
|
|
13756
|
+
const criticalData = reader.readBytes(criticalLength);
|
|
13757
|
+
if (criticalData.length > 0) {
|
|
13758
|
+
const optionsReader = new SshReader(criticalData);
|
|
13759
|
+
while (optionsReader.getOffset() < criticalData.length) {
|
|
13760
|
+
try {
|
|
13761
|
+
const name = optionsReader.readString();
|
|
13762
|
+
const valueData = optionsReader.readBytes(optionsReader.readUint32());
|
|
13763
|
+
const value = valueData.length === 0 ? '' : decoder.decode(valueData);
|
|
13764
|
+
criticalOptions[name] = value;
|
|
13765
|
+
}
|
|
13766
|
+
catch {
|
|
13767
|
+
break;
|
|
13768
|
+
}
|
|
13769
|
+
}
|
|
13770
|
+
}
|
|
13771
|
+
const extensions = {};
|
|
13772
|
+
const extensionsLength = reader.readUint32();
|
|
13773
|
+
const extensionsData = reader.readBytes(extensionsLength);
|
|
13774
|
+
if (extensionsData.length > 0) {
|
|
13775
|
+
const extReader = new SshReader(extensionsData);
|
|
13776
|
+
while (extReader.getOffset() < extensionsData.length) {
|
|
13777
|
+
try {
|
|
13778
|
+
const name = extReader.readString();
|
|
13779
|
+
const valueData = extReader.readBytes(extReader.readUint32());
|
|
13780
|
+
const value = valueData.length === 0 ? '' : decoder.decode(valueData);
|
|
13781
|
+
extensions[name] = value;
|
|
13782
|
+
}
|
|
13783
|
+
catch {
|
|
13784
|
+
break;
|
|
13785
|
+
}
|
|
13786
|
+
}
|
|
13787
|
+
}
|
|
13788
|
+
const reservedLength = reader.readUint32();
|
|
13789
|
+
const reserved = reader.readBytes(reservedLength);
|
|
13790
|
+
const signatureKeyLength = reader.readUint32();
|
|
13791
|
+
const signatureKeyData = reader.readBytes(signatureKeyLength);
|
|
13792
|
+
const signatureKeyReader = new SshReader(signatureKeyData);
|
|
13793
|
+
const signatureKeyType = signatureKeyReader.readString();
|
|
13794
|
+
const signatureKey = {
|
|
13795
|
+
type: signatureKeyType,
|
|
13796
|
+
keyData: signatureKeyData,
|
|
13797
|
+
};
|
|
13798
|
+
const signatureLength = reader.readUint32();
|
|
13799
|
+
const signature = reader.readBytes(signatureLength);
|
|
13800
|
+
return {
|
|
13801
|
+
nonce,
|
|
13802
|
+
keyType,
|
|
13803
|
+
publicKey,
|
|
13804
|
+
serial,
|
|
13805
|
+
type,
|
|
13806
|
+
keyId,
|
|
13807
|
+
validPrincipals,
|
|
13808
|
+
validAfter,
|
|
13809
|
+
validBefore,
|
|
13810
|
+
criticalOptions,
|
|
13811
|
+
extensions,
|
|
13812
|
+
reserved,
|
|
13813
|
+
signatureKey,
|
|
13814
|
+
signature,
|
|
13815
|
+
};
|
|
13816
|
+
}
|
|
13817
|
+
function serialize(cert) {
|
|
13818
|
+
const base64 = buildExports.Convert.ToBase64(cert.keyData);
|
|
13819
|
+
const parts = [cert.type, base64];
|
|
13820
|
+
if (cert.comment) {
|
|
13821
|
+
parts.push(cert.comment);
|
|
13822
|
+
}
|
|
13823
|
+
return parts.join(' ');
|
|
13824
|
+
}
|
|
13825
|
+
|
|
13826
|
+
function parseSignature(data) {
|
|
13827
|
+
const reader = new SshReader(data);
|
|
13828
|
+
if (data.length >= 6 && new TextDecoder().decode(data.subarray(0, 6)) === 'SSHSIG') {
|
|
13829
|
+
return parseSshSignatureFormat(reader);
|
|
13830
|
+
}
|
|
13831
|
+
else {
|
|
13832
|
+
return parseLegacyFormat(reader);
|
|
13833
|
+
}
|
|
13834
|
+
}
|
|
13835
|
+
function parseSshSignatureFormat(reader) {
|
|
13836
|
+
const magicBytes = reader.readBytes(6);
|
|
13837
|
+
const magic = new TextDecoder().decode(magicBytes);
|
|
13838
|
+
if (magic !== 'SSHSIG') {
|
|
13839
|
+
throw new InvalidFormatError(magic, 'SSHSIG');
|
|
13840
|
+
}
|
|
13841
|
+
const version = reader.readUint32();
|
|
13842
|
+
const publicKeyLength = reader.readUint32();
|
|
13843
|
+
const publicKey = reader.readBytes(publicKeyLength);
|
|
13844
|
+
const namespace = reader.readString();
|
|
13845
|
+
const reserved = reader.readString();
|
|
13846
|
+
const hashAlgorithm = reader.readString();
|
|
13847
|
+
const signatureLength = reader.readUint32();
|
|
13848
|
+
const signatureData = reader.readBytes(signatureLength);
|
|
13849
|
+
const sigReader = new SshReader(signatureData);
|
|
13850
|
+
const algorithm = sigReader.readString();
|
|
13851
|
+
const signatureLength2 = sigReader.readUint32();
|
|
13852
|
+
const signature = sigReader.readBytes(signatureLength2);
|
|
13853
|
+
return {
|
|
13854
|
+
format: 'ssh-signature',
|
|
13855
|
+
algorithm,
|
|
13856
|
+
signature,
|
|
13857
|
+
version,
|
|
13858
|
+
publicKey,
|
|
13859
|
+
namespace,
|
|
13860
|
+
reserved,
|
|
13861
|
+
hashAlgorithm,
|
|
13862
|
+
};
|
|
13863
|
+
}
|
|
13864
|
+
function parseLegacyFormat(reader) {
|
|
13865
|
+
const algorithm = reader.readString();
|
|
13866
|
+
const signatureLength = reader.readUint32();
|
|
13867
|
+
const signature = reader.readBytes(signatureLength);
|
|
13868
|
+
return {
|
|
13869
|
+
format: 'legacy',
|
|
13870
|
+
algorithm,
|
|
13871
|
+
signature,
|
|
13872
|
+
};
|
|
13873
|
+
}
|
|
13874
|
+
function serializeSignature(blob) {
|
|
13875
|
+
if (blob.format === 'ssh-signature') {
|
|
13876
|
+
return serializeSshSignatureFormat(blob);
|
|
13877
|
+
}
|
|
13878
|
+
else {
|
|
13879
|
+
return serializeLegacyFormat(blob);
|
|
13880
|
+
}
|
|
13881
|
+
}
|
|
13882
|
+
function serializeSshSignatureFormat(blob) {
|
|
13883
|
+
const writer = new SshWriter();
|
|
13884
|
+
writer.writeBytes(new TextEncoder().encode('SSHSIG'));
|
|
13885
|
+
writer.writeUint32(blob.version || 1);
|
|
13886
|
+
if (blob.publicKey) {
|
|
13887
|
+
writer.writeUint32(blob.publicKey.length);
|
|
13888
|
+
writer.writeBytes(blob.publicKey);
|
|
13889
|
+
}
|
|
13890
|
+
else {
|
|
13891
|
+
writer.writeUint32(0);
|
|
13892
|
+
}
|
|
13893
|
+
writer.writeString(blob.namespace || 'file');
|
|
13894
|
+
writer.writeString(blob.reserved || '');
|
|
13895
|
+
writer.writeString(blob.hashAlgorithm || 'sha512');
|
|
13896
|
+
const sigWriter = new SshWriter();
|
|
13897
|
+
sigWriter.writeString(blob.algorithm);
|
|
13898
|
+
sigWriter.writeUint32(blob.signature.length);
|
|
13899
|
+
sigWriter.writeBytes(blob.signature);
|
|
13900
|
+
const sigData = sigWriter.toUint8Array();
|
|
13901
|
+
writer.writeUint32(sigData.length);
|
|
13902
|
+
writer.writeBytes(sigData);
|
|
13903
|
+
return writer.toUint8Array();
|
|
13904
|
+
}
|
|
13905
|
+
function serializeLegacyFormat(blob) {
|
|
13906
|
+
const writer = new SshWriter();
|
|
13907
|
+
writer.writeString(blob.algorithm);
|
|
13908
|
+
writer.writeUint32(blob.signature.length);
|
|
13909
|
+
writer.writeBytes(blob.signature);
|
|
13910
|
+
return writer.toUint8Array();
|
|
13911
|
+
}
|
|
13912
|
+
|
|
13913
|
+
class SshObject {
|
|
13914
|
+
}
|
|
13915
|
+
|
|
13916
|
+
class SshPublicKey extends SshObject {
|
|
13917
|
+
static TYPE = 'public-key';
|
|
13918
|
+
type = SshPublicKey.TYPE;
|
|
13919
|
+
blob;
|
|
13920
|
+
cachedCryptoKey;
|
|
13921
|
+
constructor(blob) {
|
|
13922
|
+
super();
|
|
13923
|
+
this.blob = blob;
|
|
13924
|
+
}
|
|
13925
|
+
async getCryptoKey(crypto = getCrypto()) {
|
|
13926
|
+
if (!this.cachedCryptoKey) {
|
|
13927
|
+
const binding = AlgorithmRegistry.get(this.blob.type);
|
|
13928
|
+
this.cachedCryptoKey = await binding.importPublicSsh({ blob: this.blob.keyData, crypto });
|
|
13929
|
+
}
|
|
13930
|
+
return this.cachedCryptoKey;
|
|
13931
|
+
}
|
|
13932
|
+
static async fromSSH(sshKey, crypto = getCrypto()) {
|
|
13933
|
+
const blob = parsePublicKey(sshKey);
|
|
13934
|
+
const binding = AlgorithmRegistry.get(blob.type);
|
|
13935
|
+
await binding.importPublicSsh({ blob: blob.keyData, crypto });
|
|
13936
|
+
return new SshPublicKey(blob);
|
|
13937
|
+
}
|
|
13938
|
+
static async fromSPKI(spki, type, crypto = getCrypto()) {
|
|
13939
|
+
const binding = AlgorithmRegistry.get(type);
|
|
13940
|
+
const cryptoKey = await binding.importPublicSpki({ spki, crypto });
|
|
13941
|
+
const exported = await binding.exportPublicSsh({ publicKey: cryptoKey, crypto });
|
|
13942
|
+
const blob = {
|
|
13943
|
+
type,
|
|
13944
|
+
keyData: exported,
|
|
13945
|
+
};
|
|
13946
|
+
return new SshPublicKey(blob);
|
|
13947
|
+
}
|
|
13948
|
+
static async fromWebCrypto(cryptoKey, type, crypto = getCrypto()) {
|
|
13949
|
+
const sshType = type || AlgorithmRegistry.getSshTypeFromCryptoKey(cryptoKey);
|
|
13950
|
+
const binding = AlgorithmRegistry.get(sshType);
|
|
13951
|
+
const exported = await binding.exportPublicSsh({ publicKey: cryptoKey, crypto });
|
|
13952
|
+
const blob = {
|
|
13953
|
+
type: sshType,
|
|
13954
|
+
keyData: exported,
|
|
13955
|
+
};
|
|
13956
|
+
return new SshPublicKey(blob);
|
|
13957
|
+
}
|
|
13958
|
+
async export(format = 'ssh', crypto = getCrypto()) {
|
|
13959
|
+
if (format === 'ssh') {
|
|
13960
|
+
return serializePublicKey(this.blob);
|
|
13961
|
+
}
|
|
13962
|
+
else if (format === 'spki') {
|
|
13963
|
+
const cryptoKey = await this.getCryptoKey(crypto);
|
|
13964
|
+
const binding = AlgorithmRegistry.get(this.blob.type);
|
|
13965
|
+
const spki = await binding.exportPublicSpki({ publicKey: cryptoKey, crypto });
|
|
13966
|
+
return new Uint8Array(spki);
|
|
13967
|
+
}
|
|
13968
|
+
throw new UnsupportedKeyTypeError(`Unsupported export format: ${format}`);
|
|
13969
|
+
}
|
|
13970
|
+
async toSSH() {
|
|
13971
|
+
const result = await this.export('ssh');
|
|
13972
|
+
return result;
|
|
13973
|
+
}
|
|
13974
|
+
async toSPKI() {
|
|
13975
|
+
const result = await this.export('spki');
|
|
13976
|
+
return result;
|
|
13977
|
+
}
|
|
13978
|
+
async toWebCrypto(crypto = getCrypto()) {
|
|
13979
|
+
return this.getCryptoKey(crypto);
|
|
13980
|
+
}
|
|
13981
|
+
async verify(algorithm, signature, data, crypto = getCrypto()) {
|
|
13982
|
+
const binding = AlgorithmRegistry.get(algorithm);
|
|
13983
|
+
const cryptoKey = await this.toWebCrypto(crypto);
|
|
13984
|
+
return binding.verify({
|
|
13985
|
+
publicKey: cryptoKey,
|
|
13986
|
+
signature,
|
|
13987
|
+
data,
|
|
13988
|
+
crypto,
|
|
13989
|
+
});
|
|
13990
|
+
}
|
|
13991
|
+
get keyType() {
|
|
13992
|
+
return this.blob.type;
|
|
13993
|
+
}
|
|
13994
|
+
get comment() {
|
|
13995
|
+
return this.blob.comment;
|
|
13996
|
+
}
|
|
13997
|
+
getBlob() {
|
|
13998
|
+
return { ...this.blob };
|
|
13999
|
+
}
|
|
14000
|
+
async thumbprint(algorithm = 'sha256', crypto = getCrypto()) {
|
|
14001
|
+
const hashAlgorithm = algorithm === 'sha256' ? 'SHA-256' : 'SHA-512';
|
|
14002
|
+
const data = this.blob.keyData;
|
|
14003
|
+
const hash = await crypto.subtle.digest(hashAlgorithm, data);
|
|
14004
|
+
return new Uint8Array(hash);
|
|
14005
|
+
}
|
|
14006
|
+
}
|
|
14007
|
+
|
|
14008
|
+
class SshSignature extends SshObject {
|
|
14009
|
+
static TYPE = 'signature';
|
|
14010
|
+
type = SshSignature.TYPE;
|
|
14011
|
+
blob;
|
|
14012
|
+
format;
|
|
14013
|
+
algorithm;
|
|
14014
|
+
signature;
|
|
14015
|
+
version;
|
|
14016
|
+
publicKey;
|
|
14017
|
+
namespace;
|
|
14018
|
+
reserved;
|
|
14019
|
+
hashAlgorithm;
|
|
14020
|
+
constructor(blob) {
|
|
14021
|
+
super();
|
|
14022
|
+
this.blob = blob;
|
|
14023
|
+
this.format = blob.format;
|
|
14024
|
+
this.algorithm = blob.algorithm;
|
|
14025
|
+
this.signature = blob.signature;
|
|
14026
|
+
this.version = blob.version;
|
|
14027
|
+
this.namespace = blob.namespace;
|
|
14028
|
+
this.reserved = blob.reserved;
|
|
14029
|
+
this.hashAlgorithm = blob.hashAlgorithm;
|
|
14030
|
+
if (blob.publicKey) {
|
|
14031
|
+
const reader = new SshReader(blob.publicKey);
|
|
14032
|
+
const type = reader.readString();
|
|
14033
|
+
this.publicKey = new SshPublicKey({ type, keyData: blob.publicKey });
|
|
14034
|
+
}
|
|
14035
|
+
}
|
|
14036
|
+
static parse(data) {
|
|
14037
|
+
const blob = parseSignature(data);
|
|
14038
|
+
return new SshSignature(blob);
|
|
14039
|
+
}
|
|
14040
|
+
static fromBlob(blob) {
|
|
14041
|
+
return new SshSignature(blob);
|
|
14042
|
+
}
|
|
14043
|
+
static fromBase64(base64) {
|
|
14044
|
+
const data = new Uint8Array(buildExports.Convert.FromBase64(base64));
|
|
14045
|
+
return SshSignature.parse(data);
|
|
14046
|
+
}
|
|
14047
|
+
static fromText(text) {
|
|
14048
|
+
const base64 = text
|
|
14049
|
+
.replace(/-----BEGIN SSH SIGNATURE-----/, '')
|
|
14050
|
+
.replace(/-----END SSH SIGNATURE-----/, '')
|
|
14051
|
+
.replace(/[\r\n\s]/g, '');
|
|
14052
|
+
return SshSignature.fromBase64(base64);
|
|
14053
|
+
}
|
|
14054
|
+
serialize() {
|
|
14055
|
+
return serializeSignature(this.blob);
|
|
14056
|
+
}
|
|
14057
|
+
toBase64() {
|
|
14058
|
+
return buildExports.Convert.ToBase64(this.serialize());
|
|
14059
|
+
}
|
|
14060
|
+
toText() {
|
|
14061
|
+
const base64 = this.toBase64();
|
|
14062
|
+
const lines = [];
|
|
14063
|
+
for (let i = 0; i < base64.length; i += 70) {
|
|
14064
|
+
lines.push(base64.substring(i, i + 70));
|
|
14065
|
+
}
|
|
14066
|
+
return ['-----BEGIN SSH SIGNATURE-----', ...lines, '-----END SSH SIGNATURE-----'].join('\n');
|
|
14067
|
+
}
|
|
14068
|
+
async toSSH() {
|
|
14069
|
+
return this.toText();
|
|
14070
|
+
}
|
|
14071
|
+
async verify(data, publicKey) {
|
|
14072
|
+
const binding = AlgorithmRegistry.get(this.algorithm);
|
|
14073
|
+
const cryptoKey = await publicKey['getCryptoKey']();
|
|
14074
|
+
const crypto = getCrypto();
|
|
14075
|
+
let dataToVerify = data;
|
|
14076
|
+
if (this.format === 'ssh-signature') {
|
|
14077
|
+
const hashAlg = this.hashAlgorithm || 'sha512';
|
|
14078
|
+
const namespace = this.namespace || 'file';
|
|
14079
|
+
const reserved = this.reserved || '';
|
|
14080
|
+
const hashAlgorithm = hashAlg === 'sha256' ? 'SHA-256' : 'SHA-512';
|
|
14081
|
+
const messageHash = await crypto.subtle.digest(hashAlgorithm, data);
|
|
14082
|
+
const messageHashBytes = new Uint8Array(messageHash);
|
|
14083
|
+
const writer = new SshWriter();
|
|
14084
|
+
writer.writeBytes(new TextEncoder().encode('SSHSIG'));
|
|
14085
|
+
writer.writeString(namespace);
|
|
14086
|
+
writer.writeString(reserved);
|
|
14087
|
+
writer.writeString(hashAlg);
|
|
14088
|
+
writer.writeUint32(messageHashBytes.length);
|
|
14089
|
+
writer.writeBytes(messageHashBytes);
|
|
14090
|
+
dataToVerify = writer.toUint8Array();
|
|
14091
|
+
}
|
|
14092
|
+
let hashAlgorithm;
|
|
14093
|
+
if (this.algorithm === 'rsa-sha2-256') {
|
|
14094
|
+
hashAlgorithm = 'SHA-256';
|
|
14095
|
+
}
|
|
14096
|
+
else if (this.algorithm === 'rsa-sha2-512') {
|
|
14097
|
+
hashAlgorithm = 'SHA-512';
|
|
14098
|
+
}
|
|
14099
|
+
let signatureToVerify;
|
|
14100
|
+
if (this.format === 'legacy' || this.format === 'ssh-signature') {
|
|
14101
|
+
const sigWriter = new SshWriter();
|
|
14102
|
+
sigWriter.writeString(this.algorithm);
|
|
14103
|
+
sigWriter.writeUint32(this.signature.length);
|
|
14104
|
+
sigWriter.writeBytes(this.signature);
|
|
14105
|
+
const wireFormatSignature = sigWriter.toUint8Array();
|
|
14106
|
+
const decodedSig = binding.decodeSignature({
|
|
14107
|
+
signature: wireFormatSignature,
|
|
14108
|
+
});
|
|
14109
|
+
signatureToVerify = decodedSig.signature;
|
|
14110
|
+
}
|
|
14111
|
+
else {
|
|
14112
|
+
signatureToVerify = this.signature;
|
|
14113
|
+
}
|
|
14114
|
+
return binding.verify({
|
|
14115
|
+
publicKey: cryptoKey,
|
|
14116
|
+
signature: signatureToVerify,
|
|
14117
|
+
data: dataToVerify,
|
|
14118
|
+
crypto,
|
|
14119
|
+
hash: hashAlgorithm,
|
|
14120
|
+
});
|
|
14121
|
+
}
|
|
14122
|
+
static fromLegacy(algorithm, signature) {
|
|
14123
|
+
const binding = AlgorithmRegistry.get(algorithm);
|
|
14124
|
+
const encodedSignature = binding.encodeSignature({
|
|
14125
|
+
signature,
|
|
14126
|
+
algo: algorithm,
|
|
14127
|
+
});
|
|
14128
|
+
const sigReader = new SshReader(encodedSignature);
|
|
14129
|
+
sigReader.readString();
|
|
14130
|
+
const sigLength = sigReader.readUint32();
|
|
14131
|
+
const signatureData = sigReader.readBytes(sigLength);
|
|
14132
|
+
return new SshSignature({
|
|
14133
|
+
format: 'legacy',
|
|
14134
|
+
algorithm,
|
|
14135
|
+
signature: signatureData,
|
|
14136
|
+
});
|
|
14137
|
+
}
|
|
14138
|
+
static fromSshSignature(algorithm, signature, options = {}) {
|
|
14139
|
+
const blob = {
|
|
14140
|
+
format: 'ssh-signature',
|
|
14141
|
+
algorithm,
|
|
14142
|
+
signature,
|
|
14143
|
+
version: options.version || 1,
|
|
14144
|
+
publicKey: options.publicKey ? options.publicKey.getBlob().keyData : undefined,
|
|
14145
|
+
namespace: options.namespace || 'file',
|
|
14146
|
+
reserved: options.reserved || '',
|
|
14147
|
+
hashAlgorithm: options.hashAlgorithm || 'sha512',
|
|
14148
|
+
};
|
|
14149
|
+
return new SshSignature(blob);
|
|
14150
|
+
}
|
|
14151
|
+
static async sign(algorithm, privateKey, data, options = {}) {
|
|
14152
|
+
const { format = 'legacy', namespace = 'file' } = options;
|
|
14153
|
+
if (format === 'legacy') {
|
|
14154
|
+
const rawSignature = await privateKey.sign(algorithm, data);
|
|
14155
|
+
const algorithmUsed = algorithm || privateKey.keyType;
|
|
14156
|
+
return SshSignature.fromLegacy(algorithmUsed, rawSignature);
|
|
14157
|
+
}
|
|
14158
|
+
else {
|
|
14159
|
+
const signatureAlgorithm = algorithm;
|
|
14160
|
+
const binding = AlgorithmRegistry.get(signatureAlgorithm);
|
|
14161
|
+
const hashAlgorithm = algorithm === 'rsa-sha2-256' ? 'sha256' : 'sha512';
|
|
14162
|
+
const publicKey = await privateKey.getPublicKey();
|
|
14163
|
+
const crypto = getCrypto();
|
|
14164
|
+
const webCryptoHashAlg = hashAlgorithm === 'sha256' ? 'SHA-256' : 'SHA-512';
|
|
14165
|
+
const messageHash = await crypto.subtle.digest(webCryptoHashAlg, data);
|
|
14166
|
+
const messageHashBytes = new Uint8Array(messageHash);
|
|
14167
|
+
const writer = new SshWriter();
|
|
14168
|
+
writer.writeBytes(new TextEncoder().encode('SSHSIG'));
|
|
14169
|
+
writer.writeString(namespace);
|
|
14170
|
+
writer.writeString('');
|
|
14171
|
+
writer.writeString(hashAlgorithm);
|
|
14172
|
+
writer.writeUint32(messageHashBytes.length);
|
|
14173
|
+
writer.writeBytes(messageHashBytes);
|
|
14174
|
+
const dataToSign = writer.toUint8Array();
|
|
14175
|
+
const rawSignature = await privateKey.sign(signatureAlgorithm, dataToSign);
|
|
14176
|
+
const encodedSignature = binding.encodeSignature({
|
|
14177
|
+
signature: rawSignature,
|
|
14178
|
+
algo: signatureAlgorithm,
|
|
14179
|
+
});
|
|
14180
|
+
const sigReader = new SshReader(encodedSignature);
|
|
14181
|
+
sigReader.readString();
|
|
14182
|
+
const sigLength = sigReader.readUint32();
|
|
14183
|
+
const signatureData = sigReader.readBytes(sigLength);
|
|
14184
|
+
return SshSignature.fromSshSignature(signatureAlgorithm, signatureData, {
|
|
14185
|
+
namespace,
|
|
14186
|
+
hashAlgorithm,
|
|
14187
|
+
publicKey,
|
|
14188
|
+
});
|
|
14189
|
+
}
|
|
14190
|
+
}
|
|
14191
|
+
}
|
|
14192
|
+
|
|
14193
|
+
let SshCertificate$1 = class SshCertificate extends SshObject {
|
|
14194
|
+
static TYPE = 'certificate';
|
|
14195
|
+
type = SshCertificate.TYPE;
|
|
14196
|
+
_blob;
|
|
14197
|
+
data;
|
|
14198
|
+
_validAfter;
|
|
14199
|
+
_validBefore;
|
|
14200
|
+
keyId;
|
|
14201
|
+
principals;
|
|
14202
|
+
certType;
|
|
14203
|
+
serial;
|
|
14204
|
+
validAfter;
|
|
14205
|
+
validBefore;
|
|
14206
|
+
publicKey;
|
|
14207
|
+
signatureKey;
|
|
14208
|
+
criticalOptions;
|
|
14209
|
+
extensions;
|
|
14210
|
+
constructor(blob) {
|
|
14211
|
+
super();
|
|
14212
|
+
this._blob = blob;
|
|
14213
|
+
this.data = parseCertificateData(blob.keyData);
|
|
14214
|
+
this._validAfter = this.data.validAfter;
|
|
14215
|
+
this._validBefore = this.data.validBefore;
|
|
14216
|
+
this.keyId = this.data.keyId;
|
|
14217
|
+
this.principals = this.data.validPrincipals;
|
|
14218
|
+
this.certType = this.data.type;
|
|
14219
|
+
this.serial = this.data.serial;
|
|
14220
|
+
this.validAfter = new Date(Number(this.data.validAfter) * 1000);
|
|
14221
|
+
this.validBefore = new Date(Number(this.data.validBefore) * 1000);
|
|
14222
|
+
this.publicKey = new SshPublicKey(this.data.publicKey);
|
|
14223
|
+
this.signatureKey = new SshPublicKey(this.data.signatureKey);
|
|
14224
|
+
this.criticalOptions = { ...this.data.criticalOptions };
|
|
14225
|
+
this.extensions = { ...this.data.extensions };
|
|
14226
|
+
}
|
|
14227
|
+
static async fromSSH(text) {
|
|
14228
|
+
const blob = parse(text);
|
|
14229
|
+
return new SshCertificate(blob);
|
|
14230
|
+
}
|
|
14231
|
+
static async fromBlob(blob) {
|
|
14232
|
+
return new SshCertificate(blob);
|
|
14233
|
+
}
|
|
14234
|
+
async toSSH() {
|
|
14235
|
+
return serialize(this._blob);
|
|
14236
|
+
}
|
|
14237
|
+
toBlob() {
|
|
14238
|
+
return { ...this._blob };
|
|
14239
|
+
}
|
|
14240
|
+
get blob() {
|
|
14241
|
+
return this.toBlob();
|
|
14242
|
+
}
|
|
14243
|
+
validate(date = new Date()) {
|
|
14244
|
+
const ts = BigInt(Math.floor(date.getTime() / 1000));
|
|
14245
|
+
const after = this._validAfter;
|
|
14246
|
+
const before = this._validBefore;
|
|
14247
|
+
const INFINITY = 0xffffffffffffffffn;
|
|
14248
|
+
const upper = before === INFINITY ? ts : before;
|
|
14249
|
+
return ts >= after && ts <= upper;
|
|
14250
|
+
}
|
|
14251
|
+
async verify(caPublicKey, crypto = getCrypto()) {
|
|
14252
|
+
const verifyKey = caPublicKey || this.signatureKey;
|
|
14253
|
+
const signedData = this.getSignedData();
|
|
14254
|
+
const sshSignature = SshSignature.parse(this.data.signature);
|
|
14255
|
+
const binding = AlgorithmRegistry.get(sshSignature.algorithm);
|
|
14256
|
+
const cryptoKey = await verifyKey.toWebCrypto(crypto);
|
|
14257
|
+
return binding.verify({
|
|
14258
|
+
publicKey: cryptoKey,
|
|
14259
|
+
signature: sshSignature.signature,
|
|
14260
|
+
data: signedData,
|
|
14261
|
+
crypto,
|
|
14262
|
+
});
|
|
14263
|
+
}
|
|
14264
|
+
getSignedData() {
|
|
14265
|
+
const reader = new SshReader(this._blob.keyData);
|
|
14266
|
+
reader.readString();
|
|
14267
|
+
reader.readBytes(reader.readUint32());
|
|
14268
|
+
if (this.data.keyType === 'ssh-ed25519') {
|
|
14269
|
+
reader.readBytes(reader.readUint32());
|
|
14270
|
+
}
|
|
14271
|
+
else if (this.data.keyType === 'ssh-rsa') {
|
|
14272
|
+
reader.readBytes(reader.readUint32());
|
|
14273
|
+
reader.readBytes(reader.readUint32());
|
|
14274
|
+
}
|
|
14275
|
+
else if (this.data.keyType.startsWith('ecdsa-sha2-')) {
|
|
14276
|
+
reader.readString();
|
|
14277
|
+
reader.readBytes(reader.readUint32());
|
|
14278
|
+
}
|
|
14279
|
+
reader.readUint64();
|
|
14280
|
+
reader.readUint32();
|
|
14281
|
+
reader.readBytes(reader.readUint32());
|
|
14282
|
+
reader.readBytes(reader.readUint32());
|
|
14283
|
+
reader.readUint64();
|
|
14284
|
+
reader.readUint64();
|
|
14285
|
+
reader.readBytes(reader.readUint32());
|
|
14286
|
+
reader.readBytes(reader.readUint32());
|
|
14287
|
+
reader.readBytes(reader.readUint32());
|
|
14288
|
+
reader.readBytes(reader.readUint32());
|
|
14289
|
+
const signedDataEnd = reader.getOffset();
|
|
14290
|
+
return this._blob.keyData.slice(0, signedDataEnd);
|
|
14291
|
+
}
|
|
14292
|
+
};
|
|
14293
|
+
|
|
14294
|
+
var __classPrivateFieldSet = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
14295
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
14296
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
14297
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
14298
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
14299
|
+
};
|
|
14300
|
+
var __classPrivateFieldGet = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
14301
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
14302
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
14303
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
14304
|
+
};
|
|
14305
|
+
var _SshCertificate_cert;
|
|
14306
|
+
class SshCertificate {
|
|
14307
|
+
constructor(raw) {
|
|
14308
|
+
_SshCertificate_cert.set(this, void 0);
|
|
14309
|
+
const blob = parse(raw.trim());
|
|
14310
|
+
// @ts-expect-error - SshCertificateType is not a constructor
|
|
14311
|
+
__classPrivateFieldSet(this, _SshCertificate_cert, new SshCertificate$1(blob), "f");
|
|
14312
|
+
this.notBefore = __classPrivateFieldGet(this, _SshCertificate_cert, "f").validAfter;
|
|
14313
|
+
this.notAfter = __classPrivateFieldGet(this, _SshCertificate_cert, "f").validBefore;
|
|
14314
|
+
this.validity = dateDiff(this.notBefore, this.notAfter);
|
|
14315
|
+
this.type = [__classPrivateFieldGet(this, _SshCertificate_cert, "f").blob.type, __classPrivateFieldGet(this, _SshCertificate_cert, "f").certType, __classPrivateFieldGet(this, _SshCertificate_cert, "f").type].join(' ');
|
|
14316
|
+
this.serialNumber = __classPrivateFieldGet(this, _SshCertificate_cert, "f").serial.toString();
|
|
14317
|
+
this.keyId = __classPrivateFieldGet(this, _SshCertificate_cert, "f").keyId;
|
|
14318
|
+
this.principals = __classPrivateFieldGet(this, _SshCertificate_cert, "f").principals;
|
|
14319
|
+
this.extensions = __classPrivateFieldGet(this, _SshCertificate_cert, "f").extensions;
|
|
14320
|
+
this.criticalOptions = __classPrivateFieldGet(this, _SshCertificate_cert, "f").criticalOptions;
|
|
14321
|
+
}
|
|
14322
|
+
async parseSignatureKey() {
|
|
14323
|
+
const key = await __classPrivateFieldGet(this, _SshCertificate_cert, "f").signatureKey.toWebCrypto();
|
|
14324
|
+
const blob = __classPrivateFieldGet(this, _SshCertificate_cert, "f").signatureKey.getBlob();
|
|
14325
|
+
const thumbprint = await __classPrivateFieldGet(this, _SshCertificate_cert, "f").signatureKey.thumbprint('sha256');
|
|
14326
|
+
this.signatureKey = {
|
|
14327
|
+
algorithm: key.algorithm.name,
|
|
14328
|
+
type: blob.type,
|
|
14329
|
+
value: await __classPrivateFieldGet(this, _SshCertificate_cert, "f").signatureKey.toSSH(),
|
|
14330
|
+
thumbprint: buildExports.Convert.ToBase64(thumbprint),
|
|
14331
|
+
};
|
|
14332
|
+
}
|
|
14333
|
+
async parsePublicKey() {
|
|
14334
|
+
const key = await __classPrivateFieldGet(this, _SshCertificate_cert, "f").publicKey.toWebCrypto();
|
|
14335
|
+
const blob = __classPrivateFieldGet(this, _SshCertificate_cert, "f").publicKey.getBlob();
|
|
14336
|
+
const thumbprint = await __classPrivateFieldGet(this, _SshCertificate_cert, "f").publicKey.thumbprint('sha256');
|
|
14337
|
+
this.publicKey = {
|
|
14338
|
+
algorithm: key.algorithm.name,
|
|
14339
|
+
type: blob.type,
|
|
14340
|
+
value: await __classPrivateFieldGet(this, _SshCertificate_cert, "f").publicKey.toSSH(),
|
|
14341
|
+
thumbprint: buildExports.Convert.ToBase64(thumbprint),
|
|
14342
|
+
};
|
|
14343
|
+
}
|
|
14344
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
14345
|
+
async toString(_format = 'pem') {
|
|
14346
|
+
return __classPrivateFieldGet(this, _SshCertificate_cert, "f").toSSH();
|
|
14347
|
+
}
|
|
14348
|
+
get commonName() {
|
|
14349
|
+
return __classPrivateFieldGet(this, _SshCertificate_cert, "f").principals.join('_') || __classPrivateFieldGet(this, _SshCertificate_cert, "f").keyId || __classPrivateFieldGet(this, _SshCertificate_cert, "f").certType;
|
|
14350
|
+
}
|
|
14351
|
+
async downloadAsSSH(name) {
|
|
14352
|
+
Download.certSSH.asSSH(await this.toString(), name || this.commonName);
|
|
14353
|
+
}
|
|
14354
|
+
}
|
|
14355
|
+
_SshCertificate_cert = new WeakMap();
|
|
14356
|
+
|
|
14357
|
+
export { OIDs as $, AsnData as A, id_pkcs9_at_extensionRequest as B, Certificate as C, Download as D, ECParameters as E, id_pkcs9_at_unstructuredName as F, id_pkcs9_at_challengePassword as G, id_ValuationRanking as H, InsuranceValue as I, id_InsuranceValue as J, id_WebGDPR as K, id_ActivityDescription as L, id_TypeRelationship as M, Name as N, id_DomainNameTechnicalOperator as O, PemConverter as P, id_DomainNameOwner as Q, RSAPublicKey as R, id_DomainNameLegalRepresentative as S, TypeRelationship as T, UnstructuredName as U, ValuationRanking as V, WebGDPR as W, id_DomainNameBeneficiary as X, CertificationRequest as Y, l10n as Z, dateShort as _, dateDiff as a, id_ce_subjectDirectoryAttributes as a$, OctetString as a0, ByteStream as a1, SignedCertificateTimestamp as a2, Extension$1 as a3, CabforganizationIdentifier as a4, NonStandardKeyDescription as a5, BaseCRLNumber as a6, CRLNumber as a7, SubjectInfoAccessSyntax as a8, TNAuthorizationList as a9, IssuingDistributionPoint as aA, CRLDistributionPoints as aB, CertificatePolicies as aC, CertificateIssuer as aD, BasicConstraints as aE, AuthorityKeyIdentifier as aF, AuthorityInfoAccessSyntax as aG, id_cabforganizationIdentifier as aH, id_ce_keyDescription as aI, id_ce_deltaCRLIndicator as aJ, id_ce_cRLNumber as aK, id_pe_subjectInfoAccess as aL, id_pe_TNAuthList as aM, id_pe_biometricInfo as aN, id_entrust_entrustVersInfo as aO, id_ce_privateKeyUsagePeriod as aP, id_adbe_archiveRevInfo as aQ, id_adbe_timestamp as aR, id_role as aS, id_lei as aT, id_caVersion as aU, id_netscapeCertType as aV, id_netscapeComment as aW, id_enrollCertType as aX, id_certificateTemplate as aY, id_pe_qcStatements as aZ, id_ce_subjectKeyIdentifier as a_, LogotypeExtn as aa, BiometricSyntax as ab, EntrustVersionInfo as ac, PrivateKeyUsagePeriod as ad, ArchiveRevInfo as ae, Timestamp as af, LeiRole as ag, LeiChoice as ah, CaVersion as ai, NetscapeCertType as aj, NetscapeComment as ak, EnrollCertTypeChoice as al, CertificateTemplate as am, QCStatements as an, SubjectKeyIdentifier as ao, SubjectDirectoryAttributes as ap, SubjectAlternativeName as aq, PolicyMappings as ar, PolicyConstraints as as, NameConstraints as at, KeyUsage as au, IssueAlternativeName as av, InvalidityDate as aw, InhibitAnyPolicy as ax, ExtendedKeyUsage as ay, CRLReason as az, buildExports as b, id_ce_subjectAltName as b0, id_ce_policyMappings as b1, id_ce_policyConstraints as b2, id_ce_nameConstraints as b3, id_ce_keyUsage as b4, id_ce_issuerAltName as b5, id_ce_invalidityDate as b6, id_ce_inhibitAnyPolicy as b7, id_ce_extKeyUsage as b8, id_ce_cRLReasons as b9, AsnIntegerArrayBufferConverter as bA, AttestationApplicationId as bB, RootOfTrust as bC, IntegerSet as bD, id_ce_issuingDistributionPoint as ba, id_ce_cRLDistributionPoints as bb, id_ce_certificatePolicies as bc, id_ce_certificateIssuer as bd, id_ce_basicConstraints as be, id_ce_authorityKeyIdentifier as bf, id_pe_authorityInfoAccess as bg, SignedData as bh, EncapsulatedContent as bi, CertificateSet as bj, CertificateChoices as bk, ContentInfo as bl, SshCertificate as bm, Name$1 as bn, OtherName as bo, DisplayText as bp, UserNotice as bq, EDIPartyName as br, __decorate$1 as bs, AsnProp as bt, AsnPropTypes as bu, AsnType as bv, AsnTypeTypes as bw, AsnArray as bx, id_qcs_pkixQCSyntax_v2 as by, SemanticsInformation as bz, certificateRawToBuffer as c, downloadFromBuffer as d, AsnConvert as e, id_rsaEncryption as f, id_composite_key as g, CompositePublicKey as h, id_ecPublicKey as i, id_alg_composite as j, CompositeSignatureValue as k, CompositeParams as l, getCertificateThumbprint as m, AttributeCertificate as n, CertificateList as o, Attribute$1 as p, AsnParser as q, PrivateKeyPossessionStatement as r, ExtensionRequest as s, ChallengePassword as t, ActivityDescription as u, DomainNameTechnicalOperator as v, DomainNameOwner as w, DomainNameLegalRepresentative as x, DomainNameBeneficiary as y, id_at_statementOfPossession as z };
|
|
14358
|
+
//# sourceMappingURL=ssh_certificate-PCn0WXhQ.js.map
|
|
12700
14359
|
|
|
12701
|
-
//# sourceMappingURL=
|
|
14360
|
+
//# sourceMappingURL=ssh_certificate-PCn0WXhQ.js.map
|