@ubercode/channelvault 0.3.0-rc.3 → 0.3.0-rc.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/dist/index.d.ts CHANGED
@@ -69,6 +69,8 @@ interface ClientConfig {
69
69
  https?: boolean;
70
70
  /** default false; set true for self-signed certs */
71
71
  disableTlsCheck?: boolean;
72
+ /** SHA-256 of the only certificate accepted, 64 lowercase hex digits; replaces CA verification. */
73
+ tlsFingerprint?: string;
72
74
  /**
73
75
  * default false. Put the server's response body in error messages. A body
74
76
  * can echo the credentials that were sent; it is decoded and has credential
package/dist/index.js CHANGED
@@ -924,7 +924,9 @@ function createExplodeEngine() {
924
924
 
925
925
  // src/client/index.ts
926
926
  import { CookieJar } from "tough-cookie";
927
- import { Agent } from "undici";
927
+ import { isIP } from "net";
928
+ import { connect as tlsConnect } from "tls";
929
+ import { Agent, buildConnector } from "undici";
928
930
 
929
931
  // src/secrets/detect.ts
930
932
  import { createHash } from "crypto";
@@ -1144,6 +1146,26 @@ function connectionError(url, err) {
1144
1146
  error.code = code;
1145
1147
  return error;
1146
1148
  }
1149
+ function fingerprintOf(socket) {
1150
+ return (socket.getPeerCertificate().fingerprint256 ?? "").replace(/:/g, "").toLowerCase();
1151
+ }
1152
+ function pinnedConnector(pin) {
1153
+ const base = buildConnector({ rejectUnauthorized: false, maxCachedSessions: 0 });
1154
+ return (options, callback) => {
1155
+ base(options, (err, socket) => {
1156
+ if (err) return callback(err, null);
1157
+ const presented = fingerprintOf(socket);
1158
+ if (presented === pin) return callback(null, socket);
1159
+ socket.destroy();
1160
+ const mismatch = new Error(
1161
+ `the server presented certificate SHA-256 ${presented || "(none)"}, but the pinned fingerprint is ${pin}; nothing was sent`
1162
+ );
1163
+ mismatch.code = "TLS_PIN_MISMATCH";
1164
+ mismatch.presented = presented;
1165
+ callback(mismatch, null);
1166
+ });
1167
+ };
1168
+ }
1147
1169
  function redirectTarget(url, response) {
1148
1170
  const location = response.headers.get("location");
1149
1171
  if (!location) return "";
@@ -1175,7 +1197,7 @@ var MirthClientImpl = class {
1175
1197
  const protocol = config.https !== false ? "https" : "http";
1176
1198
  this.baseUrl = `${protocol}://${config.host}:${config.port}/api`;
1177
1199
  this.cookieJar = new CookieJar();
1178
- this.dispatcher = new Agent(config.disableTlsCheck ? { connect: { rejectUnauthorized: false } } : {});
1200
+ this.dispatcher = new Agent(config.tlsFingerprint ? { connect: pinnedConnector(config.tlsFingerprint) } : config.disableTlsCheck ? { connect: { rejectUnauthorized: false } } : {});
1179
1201
  }
1180
1202
  isAuthenticated() {
1181
1203
  return this.authenticated;