@@ -2,7 +2,7 @@ import { isLoopbackIpAddress, type ParsedIpAddress } from "@openclaw/net-policy/
22import { isWssUrl } from "@openclaw/net-policy/url-protocol" ;
33import type { ClientOptions , CertMeta , WebSocket } from "ws" ;
44import {
5- normalizeFingerprint ,
5+ normalizeTlsFingerprint ,
66 parseGatewayIpAddress ,
77 parseHostForAddressChecks ,
88} from "./client-address-utils.js" ;
@@ -124,20 +124,28 @@ export function resolveGatewayWebSocketTransport(params: {
124124 ) ;
125125 }
126126
127- const normalize = params . normalizeTlsFingerprint ?? normalizeFingerprint ;
127+ const normalize = params . normalizeTlsFingerprint ?? normalizeTlsFingerprint ;
128+ const expectedFingerprint = params . tlsFingerprint
129+ ? normalizeTlsFingerprint ( params . tlsFingerprint )
130+ : undefined ;
131+ if ( params . tlsFingerprint && ! expectedFingerprint ) {
132+ throw new GatewayWebSocketTransportConfigurationError (
133+ "gateway tls fingerprint must be a SHA-256 fingerprint" ,
134+ ) ;
135+ }
128136 const options : FingerprintCheckingClientOptions = { ...params . options } ;
129- if ( usesTls && params . tlsFingerprint ) {
137+ if ( usesTls && expectedFingerprint ) {
130138 options . rejectUnauthorized = false ;
131139 options . checkServerIdentity = ( _hostValue : string , cert : CertMeta ) => {
132140 const fingerprintValue =
133141 typeof cert === "object" && cert && "fingerprint256" in cert
134142 ? ( ( cert as { fingerprint256 ?: string } ) . fingerprint256 ?? "" )
135143 : "" ;
136- const fingerprint = normalize ( typeof fingerprintValue === "string" ? fingerprintValue : "" ) ;
137- const expected = normalize ( params . tlsFingerprint ) ;
138- if ( ! expected ) {
139- return undefined ;
140- }
144+ const canonicalFingerprint = normalizeTlsFingerprint (
145+ typeof fingerprintValue === "string" ? fingerprintValue : "" ,
146+ ) ;
147+ const fingerprint = canonicalFingerprint ? normalize ( canonicalFingerprint ) : "" ;
148+ const expected = normalize ( expectedFingerprint ) ;
141149 if ( ! fingerprint ) {
142150 return new Error ( "Missing server TLS fingerprint" ) ;
143151 }
@@ -154,7 +162,7 @@ export function resolveGatewayWebSocketTransport(params: {
154162 if ( ! params . tlsFingerprint ) {
155163 return null ;
156164 }
157- const expected = normalize ( params . tlsFingerprint ) ;
165+ const expected = expectedFingerprint ? normalize ( expectedFingerprint ) : "" ;
158166 if ( ! expected ) {
159167 return new Error ( "gateway tls fingerprint missing" ) ;
160168 }
@@ -167,7 +175,8 @@ export function resolveGatewayWebSocketTransport(params: {
167175 return new Error ( "gateway tls fingerprint unavailable" ) ;
168176 }
169177 const cert = rawSocket . getPeerCertificate ( ) ;
170- const fingerprint = normalize ( cert ?. fingerprint256 ?? "" ) ;
178+ const canonicalFingerprint = normalizeTlsFingerprint ( cert ?. fingerprint256 ?? "" ) ;
179+ const fingerprint = canonicalFingerprint ? normalize ( canonicalFingerprint ) : "" ;
171180 if ( ! fingerprint ) {
172181 return new Error ( "gateway tls fingerprint unavailable" ) ;
173182 }
0 commit comments