@@ -19,6 +19,10 @@ import { hashPassword, isProblemResponse } from './sge.utils';
19
19
20
20
const logger = createLogger ( 'sge:login' ) ;
21
21
22
+ // As of November 2023, the login server's self-signed certificate
23
+ // is valid until Nov 16, 3017. We'll cache it in memory for performance.
24
+ let cachedTlsCertificate : tls . PeerCertificate | undefined ;
25
+
22
26
/**
23
27
* SGE stands for Simutronics Game Entry
24
28
* https://www.play.net/dr/play/sge-info.asp
@@ -158,8 +162,7 @@ async function connect(
158
162
159
163
const { host, port } = mergedOptions ;
160
164
161
- logger . info ( 'downloading login server certificate' , { host, port } ) ;
162
- const certToTrust = await downloadCertificate ( mergedOptions ) ;
165
+ const certToTrust = await getTrustedTlsCertificate ( mergedOptions ) ;
163
166
164
167
mergedOptions = merge (
165
168
mergedOptions ,
@@ -200,6 +203,26 @@ async function connect(
200
203
return socket ;
201
204
}
202
205
206
+ /**
207
+ * Gets the play.net login server's self-signed certificate.
208
+ * Use this anytime we connect to the SGE server to get or send customer data.
209
+ */
210
+ async function getTrustedTlsCertificate (
211
+ connectOptions : tls . ConnectionOptions
212
+ ) : Promise < tls . PeerCertificate > {
213
+ const { host, port } = connectOptions ;
214
+
215
+ if ( cachedTlsCertificate ) {
216
+ logger . info ( 'using cached login server certificate' , { host, port } ) ;
217
+ return cachedTlsCertificate ;
218
+ }
219
+
220
+ logger . info ( 'downloading login server certificate' , { host, port } ) ;
221
+ cachedTlsCertificate = await downloadCertificate ( connectOptions ) ;
222
+
223
+ return cachedTlsCertificate ;
224
+ }
225
+
203
226
/**
204
227
* Authenticate to login server.
205
228
*/
0 commit comments