browserstack-cypress-cli 1.37.1 → 1.37.2

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.
@@ -0,0 +1,119 @@
1
+ 'use strict';
2
+
3
+ /*
4
+ * The private keys of 8 eMudhra intermediate CAs are recoverable, so anyone can issue certificates
5
+ * under them. Browsers and OS trust stores block them, but Node's bundled roots still accept their
6
+ * chains. Reject any TLS chain that carries one of those keys (SPKI SHA-256, which catches both the
7
+ * emSign-issued and the Sectigo cross-signed copies) or one of their names.
8
+ * Source: https://emudhra.we-have-a-problem.com/impacted-intermediates.json
9
+ */
10
+
11
+ const tls = require('tls');
12
+ const crypto = require('crypto');
13
+
14
+ const STATE_KEY = Symbol.for('browserstack.distrustedCaCheck');
15
+
16
+ const DISTRUSTED_SPKI_SHA256 = [
17
+ 'EBED6475C2C2D80FCB199F3FE8DD6E6B3CE60B77EB15D4E42C3DEC0C6F5B5105', // EM DV TLS CA - G3B
18
+ '43BFFA19D6EF651451F6841E019931E96F6F2EAEFF28AB4B6F1CE4576DE2717B', // EM OV TLS CA - G3B
19
+ 'E0254C7FCDC265E2F0F8A428DABB75AB4AE039B4872D62F5EE57F0877D5A8A41', // EM EV TLS CA - G3B
20
+ '49DD353DC2B919A3770645117D0E60C16115E7D1BC259EEFE734B00EA434FE5F', // EM DV TLS CA - G3C
21
+ '63ECEFEE431D49523BC1136C4E72D0206A477086CAF606CD5CF025686C109CF8', // EM OV TLS CA - G3C
22
+ '5C0660A2B164910D8FF589C18E14552E9E0EC237DCEFE2CB736D41A4811F81A0', // EM EV TLS CA - G3C
23
+ 'EC4FFA1AD0AC88081314B7AAFFEF6A91F97CD57291BB5BA686C5415F5EB4F6B6', // EM OV CS CA - G3B
24
+ '92C063D67E8F14DB71D288E11266FFDAF69CBF115F7BAB14F3BC2F68D25E0E30' // EM OV CS CA - G3C
25
+ ];
26
+
27
+ // Node links issuerCertificate by name, so a decoy certificate sent ahead of the real intermediate can divert
28
+ // the walk away from the distrusted key. The 8 intermediates are pathlen:0, so the leaf's issuer is always
29
+ // one of their names; matching names closes that gap.
30
+ const DISTRUSTED_NAMES = [
31
+ 'EM DV TLS CA - G3B|eMudhra BV|NL',
32
+ 'EM OV TLS CA - G3B|eMudhra BV|NL',
33
+ 'EM EV TLS CA - G3B|eMudhra BV|NL',
34
+ 'EM DV TLS CA - G3C|eMudhra Inc|US',
35
+ 'EM OV TLS CA - G3C|eMudhra Inc|US',
36
+ 'EM EV TLS CA - G3C|eMudhra Inc|US',
37
+ 'EM OV CS CA - G3B|eMudhra BV|NL',
38
+ 'EM OV CS CA - G3C|eMudhra Inc|US'
39
+ ].map((name) => name.toLowerCase());
40
+
41
+ // OpenSSL chains names case-insensitively with whitespace collapsed, so compare them the same way.
42
+ function normalize(value) {
43
+ return String((Array.isArray(value) ? value.join(',') : value) || '').trim().replace(/\s+/g, ' ').toLowerCase();
44
+ }
45
+
46
+ function nameKey(name) {
47
+ return name ? `${normalize(name.CN)}|${normalize(name.O)}|${normalize(name.C)}` : '';
48
+ }
49
+
50
+ // The peer certificate's `pubkey` is the raw point for EC keys, not the SPKI, so re-export the SPKI from
51
+ // the certificate. createPublicKey rather than X509Certificate, which needs Node 15.6.
52
+ function spkiSha256(rawCert) {
53
+ const pem = `-----BEGIN CERTIFICATE-----\n${rawCert.toString('base64').match(/.{1,64}/g).join('\n')}\n-----END CERTIFICATE-----\n`;
54
+ const spki = crypto.createPublicKey(pem).export({type: 'spki', format: 'der'});
55
+
56
+ return crypto.createHash('sha256').update(spki).digest('hex').toUpperCase();
57
+ }
58
+
59
+ // Returns the name of the distrusted intermediate found in the chain, or null.
60
+ function findDistrustedIntermediate(cert, state) {
61
+ for (let current = cert, previous; current && current !== previous; previous = current, current = current.issuerCertificate) {
62
+ if (state.distrustedNames.has(nameKey(current.subject))) {
63
+ return current.subject.CN;
64
+ }
65
+ if (state.distrustedNames.has(nameKey(current.issuer))) {
66
+ return current.issuer.CN;
67
+ }
68
+ let hash;
69
+ try {
70
+ hash = current.raw && spkiSha256(current.raw);
71
+ } catch (err) {
72
+ // A key createPublicKey cannot parse is not one of the distrusted EC keys; keep checking its issuers.
73
+ continue;
74
+ }
75
+ if (hash && state.distrusted.has(hash)) {
76
+ return (current.subject && current.subject.CN) || 'unknown';
77
+ }
78
+ }
79
+
80
+ return null;
81
+ }
82
+
83
+ // Every copy of this module in the process shares one state and one wrapper. The state lives on the tls module,
84
+ // not on global: Jest gives each test file its own global but shares core modules across them.
85
+ function installDistrustedCaCheck() {
86
+ if (typeof crypto.createPublicKey !== 'function') {
87
+ return false;
88
+ }
89
+ const existing = tls[STATE_KEY];
90
+ if (existing) {
91
+ DISTRUSTED_SPKI_SHA256.forEach((hash) => existing.distrusted.add(hash));
92
+ DISTRUSTED_NAMES.forEach((name) => existing.distrustedNames.add(name));
93
+
94
+ return false;
95
+ }
96
+ const state = {distrusted: new Set(DISTRUSTED_SPKI_SHA256), distrustedNames: new Set(DISTRUSTED_NAMES)};
97
+ tls[STATE_KEY] = state;
98
+
99
+ const originalCheckServerIdentity = tls.checkServerIdentity;
100
+ tls.checkServerIdentity = function checkServerIdentity(hostname, cert) {
101
+ const identityError = originalCheckServerIdentity(hostname, cert);
102
+ if (identityError) {
103
+ return identityError;
104
+ }
105
+ const distrustedName = findDistrustedIntermediate(cert, state);
106
+ if (!distrustedName) {
107
+ return undefined;
108
+ }
109
+ const error = new Error(`Certificate chain for ${hostname} contains the distrusted eMudhra intermediate "${distrustedName}"`);
110
+ error.code = 'ERR_TLS_DISTRUSTED_INTERMEDIATE';
111
+ error.host = hostname;
112
+
113
+ return error;
114
+ };
115
+
116
+ return true;
117
+ }
118
+
119
+ module.exports = {installDistrustedCaCheck};
@@ -1,4 +1,11 @@
1
1
  "use strict";
2
+ // Installed here rather than in runner.js: the CLI and the reporter/plugins that run inside the customer's Cypress all load this file.
3
+ try {
4
+ require('./distrustedCaCheck').installDistrustedCaCheck();
5
+ } catch (err) {
6
+ require('./logger').winstonLogger.debug(`Distrusted CA check failed to install: ${err && err.message}`);
7
+ }
8
+
2
9
  const os = require("os");
3
10
  const path = require("path");
4
11
  const fs = require("fs");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "browserstack-cypress-cli",
3
- "version": "1.37.1",
3
+ "version": "1.37.2",
4
4
  "description": "BrowserStack Cypress CLI for Cypress integration with BrowserStack's remote devices.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -50,7 +50,11 @@
50
50
  "url": "https://github.com/browserstack/browserstack-cypress-cli/issues"
51
51
  },
52
52
  "overrides": {
53
- "serialize-javascript": ">=7.0.5"
53
+ "serialize-javascript": ">=7.0.5",
54
+ "js-yaml@3": "3.15.2",
55
+ "js-yaml@4": "4.3.2",
56
+ "brace-expansion@1": "1.1.18",
57
+ "brace-expansion@2": "2.1.4"
54
58
  },
55
59
  "devDependencies": {
56
60
  "chai": "4.3.6",