@@ -172,6 +172,27 @@ extension HTTP2ServerTransport.Posix.Config {
172
172
/// If this is set to `true` but the client does not support ALPN, then the connection will be rejected.
173
173
public var requireALPN : Bool
174
174
175
+ /// Create a new HTTP2 NIO Posix server transport TLS config.
176
+ /// - Parameters:
177
+ /// - certificateChain: The certificates the server will offer during negotiation.
178
+ /// - privateKey: The private key associated with the leaf certificate.
179
+ /// - clientCertificateVerification: How to verify the client certificate, if one is presented.
180
+ /// - trustRoots: The trust roots to be used when verifying client certificates.
181
+ /// - requireALPN: Whether ALPN is required.
182
+ public init (
183
+ certificateChain: [ TLSConfig . CertificateSource ] ,
184
+ privateKey: TLSConfig . PrivateKeySource ,
185
+ clientCertificateVerification: TLSConfig . CertificateVerification ,
186
+ trustRoots: TLSConfig . TrustRootsSource ,
187
+ requireALPN: Bool
188
+ ) {
189
+ self . certificateChain = certificateChain
190
+ self . privateKey = privateKey
191
+ self . clientCertificateVerification = clientCertificateVerification
192
+ self . trustRoots = trustRoots
193
+ self . requireALPN = requireALPN
194
+ }
195
+
175
196
/// Create a new HTTP2 NIO Posix transport TLS config, with some values defaulted:
176
197
/// - `clientCertificateVerificationMode` equals `doNotVerify`
177
198
/// - `trustRoots` equals `systemDefault`
@@ -180,18 +201,22 @@ extension HTTP2ServerTransport.Posix.Config {
180
201
/// - Parameters:
181
202
/// - certificateChain: The certificates the server will offer during negotiation.
182
203
/// - privateKey: The private key associated with the leaf certificate.
204
+ /// - configure: A closure which allows you to modify the defaults before returning them.
183
205
/// - Returns: A new HTTP2 NIO Posix transport TLS config.
184
206
public static func defaults(
185
207
certificateChain: [ TLSConfig . CertificateSource ] ,
186
- privateKey: TLSConfig . PrivateKeySource
208
+ privateKey: TLSConfig . PrivateKeySource ,
209
+ configure: ( _ config: inout Self ) -> Void = { _ in }
187
210
) -> Self {
188
- Self (
211
+ var config = Self (
189
212
certificateChain: certificateChain,
190
213
privateKey: privateKey,
191
214
clientCertificateVerification: . noVerification,
192
215
trustRoots: . systemDefault,
193
216
requireALPN: false
194
217
)
218
+ configure ( & config)
219
+ return config
195
220
}
196
221
197
222
/// Create a new HTTP2 NIO Posix transport TLS config, with some values defaulted to match
@@ -203,18 +228,22 @@ extension HTTP2ServerTransport.Posix.Config {
203
228
/// - Parameters:
204
229
/// - certificateChain: The certificates the server will offer during negotiation.
205
230
/// - privateKey: The private key associated with the leaf certificate.
231
+ /// - configure: A closure which allows you to modify the defaults before returning them.
206
232
/// - Returns: A new HTTP2 NIO Posix transport TLS config.
207
233
public static func mTLS(
208
234
certificateChain: [ TLSConfig . CertificateSource ] ,
209
- privateKey: TLSConfig . PrivateKeySource
235
+ privateKey: TLSConfig . PrivateKeySource ,
236
+ configure: ( _ config: inout Self ) -> Void = { _ in }
210
237
) -> Self {
211
- Self (
238
+ var config = Self (
212
239
certificateChain: certificateChain,
213
240
privateKey: privateKey,
214
241
clientCertificateVerification: . noHostnameVerification,
215
242
trustRoots: . systemDefault,
216
243
requireALPN: false
217
244
)
245
+ configure ( & config)
246
+ return config
218
247
}
219
248
}
220
249
}
@@ -256,42 +285,85 @@ extension HTTP2ClientTransport.Posix.Config {
256
285
/// An optional server hostname to use when verifying certificates.
257
286
public var serverHostname : String ?
258
287
288
+ /// Create a new HTTP2 NIO Posix client transport TLS config.
289
+ /// - Parameters:
290
+ /// - certificateChain: The certificates the client will offer during negotiation.
291
+ /// - privateKey: The private key associated with the leaf certificate.
292
+ /// - serverCertificateVerification: How to verify the server certificate, if one is presented.
293
+ /// - trustRoots: The trust roots to be used when verifying server certificates.
294
+ /// - serverHostname: An optional server hostname to use when verifying certificates.
295
+ public init (
296
+ certificateChain: [ TLSConfig . CertificateSource ] ,
297
+ privateKey: TLSConfig . PrivateKeySource ? ,
298
+ serverCertificateVerification: TLSConfig . CertificateVerification ,
299
+ trustRoots: TLSConfig . TrustRootsSource ,
300
+ serverHostname: String ?
301
+ ) {
302
+ self . certificateChain = certificateChain
303
+ self . privateKey = privateKey
304
+ self . serverCertificateVerification = serverCertificateVerification
305
+ self . trustRoots = trustRoots
306
+ self . serverHostname = serverHostname
307
+ }
308
+
259
309
/// Create a new HTTP2 NIO Posix transport TLS config, with some values defaulted:
260
310
/// - `certificateChain` equals `[]`
261
311
/// - `privateKey` equals `nil`
262
312
/// - `serverCertificateVerification` equals `fullVerification`
263
313
/// - `trustRoots` equals `systemDefault`
264
314
/// - `serverHostname` equals `nil`
265
315
///
316
+ /// - Parameters:
317
+ /// - configure: A closure which allows you to modify the defaults before returning them.
266
318
/// - Returns: A new HTTP2 NIO Posix transport TLS config.
267
- public static var defaults : Self {
268
- Self (
319
+ public static func defaults(
320
+ configure: ( _ config: inout Self ) -> Void = { _ in }
321
+ ) -> Self {
322
+ var config = Self (
269
323
certificateChain: [ ] ,
270
324
privateKey: nil ,
271
325
serverCertificateVerification: . fullVerification,
272
326
trustRoots: . systemDefault,
273
327
serverHostname: nil
274
328
)
329
+ configure ( & config)
330
+ return config
331
+ }
332
+
333
+ /// Create a new HTTP2 NIO Posix transport TLS config, with some values defaulted:
334
+ /// - `certificateChain` equals `[]`
335
+ /// - `privateKey` equals `nil`
336
+ /// - `serverCertificateVerification` equals `fullVerification`
337
+ /// - `trustRoots` equals `systemDefault`
338
+ /// - `serverHostname` equals `nil`
339
+ public static var defaults : Self {
340
+ Self . defaults ( )
275
341
}
276
342
277
343
/// Create a new HTTP2 NIO Posix transport TLS config, with some values defaulted to match
278
344
/// the requirements of mTLS:
279
345
/// - `trustRoots` equals `systemDefault`
346
+ /// - `serverCertificateVerification` equals `fullVerification`
280
347
///
281
348
/// - Parameters:
282
349
/// - certificateChain: The certificates the client will offer during negotiation.
283
350
/// - privateKey: The private key associated with the leaf certificate.
351
+ /// - configure: A closure which allows you to modify the defaults before returning them.
284
352
/// - Returns: A new HTTP2 NIO Posix transport TLS config.
285
353
public static func mTLS(
286
354
certificateChain: [ TLSConfig . CertificateSource ] ,
287
- privateKey: TLSConfig . PrivateKeySource
355
+ privateKey: TLSConfig . PrivateKeySource ,
356
+ configure: ( _ config: inout Self ) -> Void = { _ in }
288
357
) -> Self {
289
- Self (
358
+ var config = Self (
290
359
certificateChain: certificateChain,
291
360
privateKey: privateKey,
292
361
serverCertificateVerification: . fullVerification,
293
- trustRoots: . systemDefault
362
+ trustRoots: . systemDefault,
363
+ serverHostname: nil
294
364
)
365
+ configure ( & config)
366
+ return config
295
367
}
296
368
}
297
369
}
0 commit comments