@@ -171,6 +171,27 @@ extension HTTP2ServerTransport.Posix.Config {
171
171
///
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
+
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
+ }
174
195
175
196
/// Create a new HTTP2 NIO Posix transport TLS config, with some values defaulted:
176
197
/// - `clientCertificateVerificationMode` equals `doNotVerify`
@@ -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
}
@@ -255,6 +284,27 @@ extension HTTP2ClientTransport.Posix.Config {
255
284
256
285
/// An optional server hostname to use when verifying certificates.
257
286
public var serverHostname : String ?
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 ? = nil ,
298
+ serverCertificateVerification: TLSConfig . CertificateVerification ,
299
+ trustRoots: TLSConfig . TrustRootsSource ,
300
+ serverHostname: String ? = nil
301
+ ) {
302
+ self . certificateChain = certificateChain
303
+ self . privateKey = privateKey
304
+ self . serverCertificateVerification = serverCertificateVerification
305
+ self . trustRoots = trustRoots
306
+ self . serverHostname = serverHostname
307
+ }
258
308
259
309
/// Create a new HTTP2 NIO Posix transport TLS config, with some values defaulted:
260
310
/// - `certificateChain` equals `[]`
@@ -263,35 +313,46 @@ extension HTTP2ClientTransport.Posix.Config {
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
275
331
}
276
332
277
333
/// Create a new HTTP2 NIO Posix transport TLS config, with some values defaulted to match
278
334
/// the requirements of mTLS:
279
335
/// - `trustRoots` equals `systemDefault`
336
+ /// - `serverCertificateVerification` equals `fullVerification`
280
337
///
281
338
/// - Parameters:
282
339
/// - certificateChain: The certificates the client will offer during negotiation.
283
340
/// - privateKey: The private key associated with the leaf certificate.
341
+ /// - configure: A closure which allows you to modify the defaults before returning them.
284
342
/// - Returns: A new HTTP2 NIO Posix transport TLS config.
285
343
public static func mTLS(
286
344
certificateChain: [ TLSConfig . CertificateSource ] ,
287
- privateKey: TLSConfig . PrivateKeySource
345
+ privateKey: TLSConfig . PrivateKeySource ,
346
+ configure: ( _ config: inout Self ) -> Void = { _ in }
288
347
) -> Self {
289
- Self (
348
+ var config = Self (
290
349
certificateChain: certificateChain,
291
350
privateKey: privateKey,
292
351
serverCertificateVerification: . fullVerification,
293
352
trustRoots: . systemDefault
294
353
)
354
+ configure ( & config)
355
+ return config
295
356
}
296
357
}
297
358
}
0 commit comments