@webex/internal-plugin-identity 0.0.0-stage → 3.13.0-next.1
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/README.md +7 -2
- package/babel.config.js +3 -0
- package/dist/config.js +14 -0
- package/dist/config.js.map +1 -0
- package/dist/constants.js +23 -0
- package/dist/constants.js.map +1 -0
- package/dist/identity.js +185 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/types/config.d.ts +7 -0
- package/dist/types/constants.d.ts +11 -0
- package/dist/types/identity.d.ts +45 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/types.d.ts +25 -0
- package/dist/types/utils.d.ts +31 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.js +132 -0
- package/dist/utils.js.map +1 -0
- package/jest.config.js +3 -0
- package/package.json +48 -3
- package/src/config.ts +5 -0
- package/src/constants.ts +102 -0
- package/src/identity.ts +164 -0
- package/src/index.ts +18 -0
- package/src/types.ts +29 -0
- package/src/utils.ts +95 -0
- package/test/unit/spec/identity.ts +198 -0
- package/test/unit/spec/utils.ts +160 -0
- package/tsconfig.json +4 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["pkijs","_interopRequireWildcard","require","asn1js","e","t","_WeakMap","r","n","__esModule","o","i","f","__proto__","default","_typeof","has","get","set","_t","hasOwnProperty","call","_Object$defineProperty","_Object$getOwnPropertyDescriptor","CERTIFICATE_RENEWAL_WINDOW_MS","exports","isCertificateExpiringSoon","certificateDer","now","arguments","length","undefined","_now","_asn1js$fromBER","fromBER","offset","result","certificate","Certificate","schema","notAfter","value","getTime","_error","generateCsr","_x","_generateCsr","apply","_asyncToGenerator2","_regenerator","mark","_callee","contactId","keyPair","privKeyDer","pkcs10","csrDer","csr","wrap","_context","prev","next","crypto","subtle","generateKey","name","namedCurve","sent","exportKey","privateKey","CertificationRequest","subject","typesAndValues","push","AttributeTypeAndValue","type","Utf8String","concat","subjectPublicKeyInfo","importKey","publicKey","sign","toSchema","toBER","Buffer","from","toString","abrupt","Uint8Array","stop","pemToUint8Array","pem","contents","split","filter","line","includes","join","binary","atob","bytes","charCodeAt","pemToUint8Arrays","pemString","_pemString$match","matches","match","map"],"sources":["utils.ts"],"sourcesContent":["/*!\n * Copyright (c) 2015-2026 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport * as pkijs from 'pkijs';\nimport * as asn1js from 'asn1js';\n\nimport type {CertSigningRequest} from './types';\n\nexport const CERTIFICATE_RENEWAL_WINDOW_MS = 24 * 60 * 60 * 1000;\n\n/**\n * Returns whether an X.509 certificate expires within the renewal window.\n * An unreadable certificate is treated as expiring so malformed cached credentials are refreshed.\n * @param {Uint8Array} certificateDer\n * @param {number} [now]\n * @returns {boolean}\n */\nexport function isCertificateExpiringSoon(certificateDer: Uint8Array, now = Date.now()): boolean {\n try {\n const {offset, result} = asn1js.fromBER(certificateDer);\n\n if (offset === -1) {\n return true;\n }\n\n const certificate = new pkijs.Certificate({schema: result});\n\n return certificate.notAfter.value.getTime() - now < CERTIFICATE_RENEWAL_WINDOW_MS;\n } catch (_error) {\n return true;\n }\n}\n\n/**\n * Generates an EC P-256 key pair and a matching PKCS#10 CSR (subject CN = \"email:<contactId>\").\n * @param {string} contactId\n * @returns {Promise<CertSigningRequest>}\n */\nexport async function generateCsr(contactId: string): Promise<CertSigningRequest> {\n const keyPair = await crypto.subtle.generateKey({name: 'ECDSA', namedCurve: 'P-256'}, true, [\n 'sign',\n 'verify',\n ]);\n\n const privKeyDer = await crypto.subtle.exportKey('pkcs8', keyPair.privateKey);\n const pkcs10 = new pkijs.CertificationRequest();\n\n pkcs10.subject.typesAndValues.push(\n new pkijs.AttributeTypeAndValue({\n type: '2.5.4.3',\n value: new asn1js.Utf8String({value: `email:${contactId}`}),\n })\n );\n\n await pkcs10.subjectPublicKeyInfo.importKey(keyPair.publicKey);\n await pkcs10.sign(keyPair.privateKey, 'SHA-256');\n\n const csrDer = pkcs10.toSchema().toBER(false);\n const csr = Buffer.from(csrDer).toString('base64');\n\n return {privKeyDer: new Uint8Array(privKeyDer), csr};\n}\n\n/**\n * Converts one PEM certificate block to DER bytes.\n * @param {string} pem\n * @returns {Uint8Array}\n */\nexport function pemToUint8Array(pem: string): Uint8Array {\n const contents = pem\n .split('\\n')\n .filter((line) => !line.includes('-----BEGIN') && !line.includes('-----END'))\n .join('');\n const binary = atob(contents);\n const bytes = new Uint8Array(binary.length);\n\n for (let i = 0; i < binary.length; i += 1) {\n bytes[i] = binary.charCodeAt(i);\n }\n\n return bytes;\n}\n\n/**\n * Converts concatenated PEM certificates to DER byte arrays.\n * @param {string} pemString\n * @returns {Uint8Array[]}\n */\nexport function pemToUint8Arrays(pemString: string): Uint8Array[] {\n const matches =\n pemString.match(/-----BEGIN CERTIFICATE-----[\\s\\S]*?-----END CERTIFICATE-----/g) ?? [];\n\n return matches.map(pemToUint8Array);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAIA,IAAAA,KAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAF,uBAAA,CAAAC,OAAA;AAAiC,SAAAD,wBAAAG,CAAA,EAAAC,CAAA,6BAAAC,QAAA,MAAAC,CAAA,OAAAD,QAAA,IAAAE,CAAA,OAAAF,QAAA,YAAAL,uBAAA,YAAAA,wBAAAG,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,gBAAAW,OAAA,CAAAX,CAAA,0BAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAM,GAAA,CAAAZ,CAAA,UAAAM,CAAA,CAAAO,GAAA,CAA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F,CAAC,CAAC;EACjC;EAEA,OAAOyF,KAAK;AACd;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASE,gBAAgBA,CAACC,SAAiB,EAAgB;EAAA,IAAAC,gBAAA;EAChE,IAAMC,OAAO,IAAAD,gBAAA,GACXD,SAAS,CAACG,KAAK,CAAC,+DAA+D,CAAC,cAAAF,gBAAA,cAAAA,gBAAA,GAAI,EAAE;EAExF,OAAOC,OAAO,CAACE,GAAG,CAACjB,eAAe,CAAC;AACrC","ignoreList":[]}
|
package/jest.config.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,51 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webex/internal-plugin-identity",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"description": "Webex identity and certificate credentials plugin",
|
|
4
|
+
"license": "Cisco's General Terms (https://www.cisco.com/site/us/en/about/legal/contract-experience/index.html)",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/types/index.d.ts",
|
|
7
|
+
"devMain": "src/index.ts",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/webex/webex-js-sdk.git",
|
|
11
|
+
"directory": "packages/@webex/internal-plugin-identity"
|
|
12
|
+
},
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=18"
|
|
15
|
+
},
|
|
16
|
+
"browserify": {
|
|
17
|
+
"transform": [
|
|
18
|
+
"babelify",
|
|
19
|
+
"envify"
|
|
20
|
+
]
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@webex/common": "3.12.0-next.13",
|
|
24
|
+
"@webex/webex-core": "3.13.0-next.1",
|
|
25
|
+
"asn1js": "3.0.10",
|
|
26
|
+
"pkijs": "3.3.3"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@babel/core": "^7.17.10",
|
|
30
|
+
"@webex/babel-config-legacy": "0.0.0",
|
|
31
|
+
"@webex/eslint-config-legacy": "0.0.0",
|
|
32
|
+
"@webex/jest-config-legacy": "0.0.0",
|
|
33
|
+
"@webex/legacy-tools": "0.0.0",
|
|
34
|
+
"@webex/test-helper-chai": "3.12.0-next.13",
|
|
35
|
+
"@webex/test-helper-mock-webex": "3.12.0-next.13",
|
|
36
|
+
"eslint": "^8.24.0",
|
|
37
|
+
"jsdom": "19.0.0",
|
|
38
|
+
"jsdom-global": "3.0.2",
|
|
39
|
+
"prettier": "^2.7.1",
|
|
40
|
+
"sinon": "^9.2.4"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "yarn build:src",
|
|
44
|
+
"build:src": "yarn run -T tsc --declaration true --declarationDir ./dist/types -p ./tsconfig.json && webex-legacy-tools build -dest \"./dist\" -src \"./src\" -js -ts -maps",
|
|
45
|
+
"deploy:npm": "yarn npm publish",
|
|
46
|
+
"typecheck": "yarn run -T tsc --noEmit --emitDeclarationOnly false -p ./tsconfig.json",
|
|
47
|
+
"test:style": "eslint ./src/**/*.*",
|
|
48
|
+
"test:unit": "webex-legacy-tools test --unit --runner jest"
|
|
49
|
+
},
|
|
50
|
+
"version": "3.13.0-next.1"
|
|
6
51
|
}
|
package/src/config.ts
ADDED
package/src/constants.ts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2015-2026 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/** Webex Certificate Authority service name used to issue client identities. */
|
|
6
|
+
export const CERTIFICATE_AUTHORITY_SERVICE = 'webex-certificate-authority';
|
|
7
|
+
|
|
8
|
+
/** Webex Microservices production root CA used to validate member certificates. */
|
|
9
|
+
export const WEBEX_CA_PRODUCTION_ROOTS =
|
|
10
|
+
'-----BEGIN CERTIFICATE-----\n' +
|
|
11
|
+
'MIICBjCCAYygAwIBAgIJAZOu2g1dR9NhMAoGCCqGSM49BAMDMEcxDzANBgNVBAsT\n' +
|
|
12
|
+
'BkNhZWx1bTEOMAwGA1UEChMFQ2lzY28xJDAiBgNVBAMTG1dlYmV4IE1pY3Jvc2Vy\n' +
|
|
13
|
+
'dmljZXMgUm9vdCBDQTAgFw0yMTA0MDgxNzQ5NTlaGA8yMDUxMDQwODE3NDk1OVow\n' +
|
|
14
|
+
'RzEPMA0GA1UECxMGQ2FlbHVtMQ4wDAYDVQQKEwVDaXNjbzEkMCIGA1UEAxMbV2Vi\n' +
|
|
15
|
+
'ZXggTWljcm9zZXJ2aWNlcyBSb290IENBMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE\n' +
|
|
16
|
+
'dS1B5KM1hoIPodrKjjIdDCUMF9N3HCxwkVshIj+E2m1Qcws3TBygEd3L5hwVtLxO\n' +
|
|
17
|
+
'r3FezXFEGSQy9dR9WhWbCTyAp5UIHFkwNAqPe8hQCEOwsmhC8O8q82Eso02vMAPR\n' +
|
|
18
|
+
'o0IwQDAOBgNVHQ8BAf8EBAMCAQYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQU\n' +
|
|
19
|
+
'wAfEJpw+1x4HTK+0MN0Or6aO0hwwCgYIKoZIzj0EAwMDaAAwZQIwBIXZXTASZl4s\n' +
|
|
20
|
+
'tLchC6wdmhUiVxMedK6VT3rimaQl2gOomZBv2UUDoX/Kfo+cwfl6AjEA8sKyFlqX\n' +
|
|
21
|
+
'eykGJ9XgUKTXeNXXmT+3wHxS2g/T3qIGblPAXaNP7MwIfySJfqolV+IC\n' +
|
|
22
|
+
'-----END CERTIFICATE-----';
|
|
23
|
+
|
|
24
|
+
/** Webex Certificate Authority roots used in integration environments. */
|
|
25
|
+
export const WEBEX_CA_INTEGRATION_ROOTS = `-----BEGIN CERTIFICATE-----
|
|
26
|
+
MIIChDCCAeagAwIBAgIUBk4BdCkJNb07JrkbKtGjT2/83LMwCgYIKoZIzj0EAwIw
|
|
27
|
+
WjELMAkGA1UEBhMCVVMxDjAMBgNVBAoMBUNp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AG2xwtgrAr1SSeg=
|
|
72
|
+
-----END CERTIFICATE-----
|
|
73
|
+
-----BEGIN CERTIFICATE-----
|
|
74
|
+
MIICLDCCAbKgAwIBAgIOaTNnW+Yw3+7spargwqYwCgYIKoZIzj0EAwMwRzEOMAwG
|
|
75
|
+
A1UEChMFQ2lzY28xDzANBgNVBAsTBkNhZWx1bTEkMCIGA1UEAxMbV2ViZXggTWlj
|
|
76
|
+
cm9zZXJ2aWNlcyBSb290IENBMCAXDTI2MDQwOTE0NTg0OVoYDzIwNTEwNDA5MTQ1
|
|
77
|
+
ODQ5WjBHMQ4wDAYDVQQKEwVDaXNjbzEPMA0GA1UECxMGQ2FlbHVtMSQwIgYDVQQD
|
|
78
|
+
ExtXZWJleCBNaWNyb3NlcnZpY2VzIFJvb3QgQ0EwdjAQBgcqhkjOPQIBBgUrgQQA
|
|
79
|
+
IgNiAARFolh8NnB2ZPOyNtYYzqW6Xdo8lCAYb/2SnnQthSwE5Og1kDLoSi2VrZ+i
|
|
80
|
+
ROUmgbVYrU/SftNuVOdQ4WtYxJGQ2T4scRJ3SGicetsiTIahCF9Z/a4UZI3Nxsm4
|
|
81
|
+
ScfVGISjYzBhMA4GA1UdDwEB/wQEAwIBhjASBgNVHRMBAf8ECDAGAQH/AgEBMB0G
|
|
82
|
+
A1UdDgQWBBRu6kGB5uqizjPJ1q73hhg9agOU7DAcBggrBgEFBQcBAQQQMA4wDAYI
|
|
83
|
+
KwYBBQUHMAKGADAKBggqhkjOPQQDAwNoADBlAjEA1yoDQUz/xBKvHEQ1Lg37xbXR
|
|
84
|
+
kOGgGHqK/9cE4HuMiVT/dP6Y761GjyTL+NlegTWlAjBTftI6QN/yW6VGbSqkUr+F
|
|
85
|
+
W2VmDzvQzqD9C3OrorN9KNmUJn7sXMWE/f3t//JG/ek=
|
|
86
|
+
-----END CERTIFICATE-----`;
|
|
87
|
+
|
|
88
|
+
/** Webex Certificate Authority root used in FedRAMP environments. */
|
|
89
|
+
export const WEBEX_CA_FEDRAMP_ROOTS = `-----BEGIN CERTIFICATE-----
|
|
90
|
+
MIICHTCCAaKgAwIBAgIJCUkw6t06bV7xMAoGCCqGSM49BAMDMFIxEjAQBgNVBAsT
|
|
91
|
+
CVJldGljdWx1bTEOMAwGA1UEChMFQ2lzY28xLDAqBgNVBAMTI1dlYmV4IE1pY3Jv
|
|
92
|
+
c2VydmljZXMgRmVkUkFNUCBSb290IENBMCAXDTIxMDkwMjE0NDEyOFoYDzIwNTEw
|
|
93
|
+
OTAyMTQ0MTI4WjBSMRIwEAYDVQQLEwlSZXRpY3VsdW0xDjAMBgNVBAoTBUNpc2Nv
|
|
94
|
+
MSwwKgYDVQQDEyNXZWJleCBNaWNyb3NlcnZpY2VzIEZlZFJBTVAgUm9vdCBDQTB2
|
|
95
|
+
MBAGByqGSM49AgEGBSuBBAAiA2IABJqJCUFTBFGJeOcWk5daRmUU/kHtMpXTd4ic
|
|
96
|
+
xUmhwIUQp9JRmEB2wUPVBYLzjp1u/RA5AwKLPHH4oWI764/QqvK9iwtb+XM5dIRM
|
|
97
|
+
KZRdxoo+Ri68OHgD2EXK9nuz6G4Yi6NCMEAwDgYDVR0PAQH/BAQDAgEGMA8GA1Ud
|
|
98
|
+
EwEB/wQFMAMBAf8wHQYDVR0OBBYEFJIXb6Wv/GgLxGkTS2nWQLJ6V8mkMAoGCCqG
|
|
99
|
+
SM49BAMDA2kAMGYCMQC280u1VjS7tcdAV0EcOZngC+X36E3pGSXe13xuz2qbjTTU
|
|
100
|
+
wEwubBDjRu7CuzXwkD8CMQCWgH1Xb60pIS1X8XXVswvFrq8Y5BF3DWfMMy7S6g0V
|
|
101
|
+
hZRuaW5Lx1Jo+WbCibskoq4=
|
|
102
|
+
-----END CERTIFICATE-----`;
|
package/src/identity.ts
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2015-2026 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {WebexPlugin} from '@webex/webex-core';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
CERTIFICATE_AUTHORITY_SERVICE,
|
|
9
|
+
WEBEX_CA_FEDRAMP_ROOTS,
|
|
10
|
+
WEBEX_CA_INTEGRATION_ROOTS,
|
|
11
|
+
WEBEX_CA_PRODUCTION_ROOTS,
|
|
12
|
+
} from './constants';
|
|
13
|
+
import type {IdentityCredentials, IdentityTrustAnchors} from './types';
|
|
14
|
+
import {
|
|
15
|
+
CERTIFICATE_RENEWAL_WINDOW_MS,
|
|
16
|
+
generateCsr,
|
|
17
|
+
isCertificateExpiringSoon,
|
|
18
|
+
pemToUint8Arrays,
|
|
19
|
+
} from './utils';
|
|
20
|
+
|
|
21
|
+
// PKCS#8 P-256: the raw 32-byte EC private key starts at this offset in the DER encoding.
|
|
22
|
+
const PKCS8_P256_RAW_KEY_OFFSET = 36;
|
|
23
|
+
const RAW_EC_P256_KEY_LENGTH = 32;
|
|
24
|
+
|
|
25
|
+
class Identity extends WebexPlugin {
|
|
26
|
+
namespace = 'Identity';
|
|
27
|
+
credentialsCache: Map<string, Promise<IdentityCredentials>>;
|
|
28
|
+
|
|
29
|
+
constructor(attrs = {}, options = {}) {
|
|
30
|
+
super(attrs, options);
|
|
31
|
+
this.credentialsCache = new Map();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @returns {IdentityTrustAnchors} trust anchors for validating member certificates.
|
|
36
|
+
*/
|
|
37
|
+
getTrustAnchors(): IdentityTrustAnchors {
|
|
38
|
+
const isIntegrationEnvironment =
|
|
39
|
+
this.webex.internal?.services?.isIntegrationEnvironment?.() ?? false;
|
|
40
|
+
const webexCaRoots = isIntegrationEnvironment
|
|
41
|
+
? WEBEX_CA_INTEGRATION_ROOTS
|
|
42
|
+
: `${WEBEX_CA_PRODUCTION_ROOTS}\n${WEBEX_CA_FEDRAMP_ROOTS}`;
|
|
43
|
+
|
|
44
|
+
this.logger.info(
|
|
45
|
+
`identity: getTrustAnchors returning ${
|
|
46
|
+
isIntegrationEnvironment ? 'integration' : 'production'
|
|
47
|
+
} trust anchors`
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
webexCaRoots,
|
|
52
|
+
userIdentityRoots: '',
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Returns credentials for the given contact, generating and caching them on first use.
|
|
58
|
+
* @param {string} contactId
|
|
59
|
+
* @returns {Promise<IdentityCredentials>}
|
|
60
|
+
*/
|
|
61
|
+
getCredentials(contactId: string): Promise<IdentityCredentials> {
|
|
62
|
+
const cachedCredentials = this.credentialsCache.get(contactId);
|
|
63
|
+
|
|
64
|
+
if (cachedCredentials) {
|
|
65
|
+
this.logger.info('identity: getCredentials: checking cached certificate expiry');
|
|
66
|
+
|
|
67
|
+
return cachedCredentials.then((credentials) => {
|
|
68
|
+
const leafCertificate = credentials.certChain[0];
|
|
69
|
+
|
|
70
|
+
if (leafCertificate && !isCertificateExpiringSoon(leafCertificate)) {
|
|
71
|
+
this.logger.info('identity: getCredentials: returning cached credentials');
|
|
72
|
+
|
|
73
|
+
return credentials;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
this.logger.info(
|
|
77
|
+
`identity: getCredentials: cached certificate expires within ${CERTIFICATE_RENEWAL_WINDOW_MS}ms, requesting new credentials`
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
return this.refreshCredentials(contactId, cachedCredentials);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
this.logger.info('identity: getCredentials: cache miss, requesting new credentials');
|
|
85
|
+
|
|
86
|
+
return this.cacheCredentials(contactId);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Replaces a cached credential request if it is still the current cache entry. This prevents
|
|
91
|
+
* concurrent callers from triggering duplicate renewals for the same contact.
|
|
92
|
+
* @param {string} contactId
|
|
93
|
+
* @param {Promise<IdentityCredentials>} cachedCredentials
|
|
94
|
+
* @returns {Promise<IdentityCredentials>}
|
|
95
|
+
*/
|
|
96
|
+
private refreshCredentials(
|
|
97
|
+
contactId: string,
|
|
98
|
+
cachedCredentials: Promise<IdentityCredentials>
|
|
99
|
+
): Promise<IdentityCredentials> {
|
|
100
|
+
if (this.credentialsCache.get(contactId) !== cachedCredentials) {
|
|
101
|
+
return this.credentialsCache.get(contactId) ?? this.cacheCredentials(contactId);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return this.cacheCredentials(contactId);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Requests credentials and caches the in-flight promise so concurrent callers share it.
|
|
109
|
+
* @param {string} contactId
|
|
110
|
+
* @returns {Promise<IdentityCredentials>}
|
|
111
|
+
*/
|
|
112
|
+
private cacheCredentials(contactId: string): Promise<IdentityCredentials> {
|
|
113
|
+
const credentials = this.requestCredentials(contactId);
|
|
114
|
+
|
|
115
|
+
this.credentialsCache.set(contactId, credentials);
|
|
116
|
+
credentials.catch(() => {
|
|
117
|
+
if (this.credentialsCache.get(contactId) === credentials) {
|
|
118
|
+
this.credentialsCache.delete(contactId);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
return credentials;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Requests credentials from the CA and returns the certificate chain and raw key.
|
|
127
|
+
* @param {string} contactId
|
|
128
|
+
* @returns {Promise<IdentityCredentials>}
|
|
129
|
+
*/
|
|
130
|
+
private async requestCredentials(contactId: string): Promise<IdentityCredentials> {
|
|
131
|
+
this.logger.info('identity: requestCredentials: generating CSR');
|
|
132
|
+
const {privKeyDer, csr} = await generateCsr(contactId);
|
|
133
|
+
|
|
134
|
+
this.logger.info('identity: requestCredentials: requesting certificate from CA');
|
|
135
|
+
const response = await this.webex.request({
|
|
136
|
+
method: 'POST',
|
|
137
|
+
service: CERTIFICATE_AUTHORITY_SERVICE,
|
|
138
|
+
resource: 'certificates',
|
|
139
|
+
headers: {'include-root-cert': 'false'},
|
|
140
|
+
body: {csr},
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
this.logger.info('identity: requestCredentials: received signed certificate from CA');
|
|
144
|
+
const certChain = pemToUint8Arrays(response.body);
|
|
145
|
+
|
|
146
|
+
if (certChain.length === 0 || certChain.some((certificate) => certificate.length === 0)) {
|
|
147
|
+
throw new Error('Certificate authority response did not contain a certificate chain');
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const privateKey = privKeyDer.slice(
|
|
151
|
+
PKCS8_P256_RAW_KEY_OFFSET,
|
|
152
|
+
PKCS8_P256_RAW_KEY_OFFSET + RAW_EC_P256_KEY_LENGTH
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
return {privateKey, certChain};
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
interface Identity {
|
|
160
|
+
logger: any;
|
|
161
|
+
webex: any;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export default Identity;
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2015-2026 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {registerInternalPlugin} from '@webex/webex-core';
|
|
6
|
+
|
|
7
|
+
import Identity from './identity';
|
|
8
|
+
import config from './config';
|
|
9
|
+
|
|
10
|
+
registerInternalPlugin('identity', Identity, {config});
|
|
11
|
+
|
|
12
|
+
export {default} from './identity';
|
|
13
|
+
export type {
|
|
14
|
+
CertSigningRequest,
|
|
15
|
+
IdentityCredentials,
|
|
16
|
+
IdentityProvider,
|
|
17
|
+
IdentityTrustAnchors,
|
|
18
|
+
} from './types';
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2015-2026 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export interface IdentityCredentials {
|
|
6
|
+
privateKey: Uint8Array;
|
|
7
|
+
certChain: Uint8Array[];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface IdentityTrustAnchors {
|
|
11
|
+
webexCaRoots?: string;
|
|
12
|
+
/** PEM-encoded domain-name trust anchors. */
|
|
13
|
+
domainNameRoots?: string;
|
|
14
|
+
/** Signed PKCS#7 domain-name trust-anchor bundle. */
|
|
15
|
+
domainNameRootsP7b?: Uint8Array;
|
|
16
|
+
userIdentityRoots?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Methods exposed by the shared identity plugin to consuming plugins. */
|
|
20
|
+
export interface IdentityProvider {
|
|
21
|
+
getCredentials(contactId: string): Promise<IdentityCredentials>;
|
|
22
|
+
getTrustAnchors(): IdentityTrustAnchors;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Generated certificate signing request and its PKCS#8 private key. */
|
|
26
|
+
export interface CertSigningRequest {
|
|
27
|
+
privKeyDer: Uint8Array;
|
|
28
|
+
csr: string;
|
|
29
|
+
}
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2015-2026 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import * as pkijs from 'pkijs';
|
|
6
|
+
import * as asn1js from 'asn1js';
|
|
7
|
+
|
|
8
|
+
import type {CertSigningRequest} from './types';
|
|
9
|
+
|
|
10
|
+
export const CERTIFICATE_RENEWAL_WINDOW_MS = 24 * 60 * 60 * 1000;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Returns whether an X.509 certificate expires within the renewal window.
|
|
14
|
+
* An unreadable certificate is treated as expiring so malformed cached credentials are refreshed.
|
|
15
|
+
* @param {Uint8Array} certificateDer
|
|
16
|
+
* @param {number} [now]
|
|
17
|
+
* @returns {boolean}
|
|
18
|
+
*/
|
|
19
|
+
export function isCertificateExpiringSoon(certificateDer: Uint8Array, now = Date.now()): boolean {
|
|
20
|
+
try {
|
|
21
|
+
const {offset, result} = asn1js.fromBER(certificateDer);
|
|
22
|
+
|
|
23
|
+
if (offset === -1) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const certificate = new pkijs.Certificate({schema: result});
|
|
28
|
+
|
|
29
|
+
return certificate.notAfter.value.getTime() - now < CERTIFICATE_RENEWAL_WINDOW_MS;
|
|
30
|
+
} catch (_error) {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Generates an EC P-256 key pair and a matching PKCS#10 CSR (subject CN = "email:<contactId>").
|
|
37
|
+
* @param {string} contactId
|
|
38
|
+
* @returns {Promise<CertSigningRequest>}
|
|
39
|
+
*/
|
|
40
|
+
export async function generateCsr(contactId: string): Promise<CertSigningRequest> {
|
|
41
|
+
const keyPair = await crypto.subtle.generateKey({name: 'ECDSA', namedCurve: 'P-256'}, true, [
|
|
42
|
+
'sign',
|
|
43
|
+
'verify',
|
|
44
|
+
]);
|
|
45
|
+
|
|
46
|
+
const privKeyDer = await crypto.subtle.exportKey('pkcs8', keyPair.privateKey);
|
|
47
|
+
const pkcs10 = new pkijs.CertificationRequest();
|
|
48
|
+
|
|
49
|
+
pkcs10.subject.typesAndValues.push(
|
|
50
|
+
new pkijs.AttributeTypeAndValue({
|
|
51
|
+
type: '2.5.4.3',
|
|
52
|
+
value: new asn1js.Utf8String({value: `email:${contactId}`}),
|
|
53
|
+
})
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
await pkcs10.subjectPublicKeyInfo.importKey(keyPair.publicKey);
|
|
57
|
+
await pkcs10.sign(keyPair.privateKey, 'SHA-256');
|
|
58
|
+
|
|
59
|
+
const csrDer = pkcs10.toSchema().toBER(false);
|
|
60
|
+
const csr = Buffer.from(csrDer).toString('base64');
|
|
61
|
+
|
|
62
|
+
return {privKeyDer: new Uint8Array(privKeyDer), csr};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Converts one PEM certificate block to DER bytes.
|
|
67
|
+
* @param {string} pem
|
|
68
|
+
* @returns {Uint8Array}
|
|
69
|
+
*/
|
|
70
|
+
export function pemToUint8Array(pem: string): Uint8Array {
|
|
71
|
+
const contents = pem
|
|
72
|
+
.split('\n')
|
|
73
|
+
.filter((line) => !line.includes('-----BEGIN') && !line.includes('-----END'))
|
|
74
|
+
.join('');
|
|
75
|
+
const binary = atob(contents);
|
|
76
|
+
const bytes = new Uint8Array(binary.length);
|
|
77
|
+
|
|
78
|
+
for (let i = 0; i < binary.length; i += 1) {
|
|
79
|
+
bytes[i] = binary.charCodeAt(i);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return bytes;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Converts concatenated PEM certificates to DER byte arrays.
|
|
87
|
+
* @param {string} pemString
|
|
88
|
+
* @returns {Uint8Array[]}
|
|
89
|
+
*/
|
|
90
|
+
export function pemToUint8Arrays(pemString: string): Uint8Array[] {
|
|
91
|
+
const matches =
|
|
92
|
+
pemString.match(/-----BEGIN CERTIFICATE-----[\s\S]*?-----END CERTIFICATE-----/g) ?? [];
|
|
93
|
+
|
|
94
|
+
return matches.map(pemToUint8Array);
|
|
95
|
+
}
|