14
14
* limitations under the License.
15
15
*/
16
16
#if canImport(NIOSSL)
17
+ import NIOCore
17
18
import NIOSSL
18
19
#endif
19
20
@@ -310,6 +311,38 @@ extension GRPCTLSConfiguration {
310
311
trustRoots: NIOSSLTrustRoots = . default,
311
312
certificateVerification: CertificateVerification = . none,
312
313
requireALPN: Bool = true
314
+ ) -> GRPCTLSConfiguration {
315
+ return Self . makeServerConfigurationBackedByNIOSSL (
316
+ certificateChain: certificateChain,
317
+ privateKey: privateKey,
318
+ trustRoots: trustRoots,
319
+ certificateVerification: certificateVerification,
320
+ requireALPN: requireALPN,
321
+ customVerificationCallback: nil
322
+ )
323
+ }
324
+
325
+ /// TLS Configuration with suitable defaults for servers.
326
+ ///
327
+ /// This is a wrapper around `NIOSSL.TLSConfiguration` to restrict input to values which comply
328
+ /// with the gRPC protocol.
329
+ ///
330
+ /// - Parameter certificateChain: The certificate to offer during negotiation.
331
+ /// - Parameter privateKey: The private key associated with the leaf certificate.
332
+ /// - Parameter trustRoots: The trust roots to validate certificates, this defaults to using a
333
+ /// root provided by the platform.
334
+ /// - Parameter certificateVerification: Whether to verify the remote certificate. Defaults to
335
+ /// `.none`.
336
+ /// - Parameter requireALPN: Whether ALPN is required or not.
337
+ /// - Parameter customVerificationCallback: A callback to provide to override the certificate verification logic,
338
+ /// defaults to `nil`.
339
+ public static func makeServerConfigurationBackedByNIOSSL(
340
+ certificateChain: [ NIOSSLCertificateSource ] ,
341
+ privateKey: NIOSSLPrivateKeySource ,
342
+ trustRoots: NIOSSLTrustRoots = . default,
343
+ certificateVerification: CertificateVerification = . none,
344
+ requireALPN: Bool = true ,
345
+ customVerificationCallback: NIOSSLCustomVerificationCallback ? = nil
313
346
) -> GRPCTLSConfiguration {
314
347
var configuration = TLSConfiguration . makeServerConfiguration (
315
348
certificateChain: certificateChain,
@@ -323,7 +356,8 @@ extension GRPCTLSConfiguration {
323
356
324
357
return GRPCTLSConfiguration . makeServerConfigurationBackedByNIOSSL (
325
358
configuration: configuration,
326
- requireALPN: requireALPN
359
+ requireALPN: requireALPN,
360
+ customVerificationCallback: customVerificationCallback
327
361
)
328
362
}
329
363
@@ -338,6 +372,28 @@ extension GRPCTLSConfiguration {
338
372
public static func makeServerConfigurationBackedByNIOSSL(
339
373
configuration: TLSConfiguration ,
340
374
requireALPN: Bool = true
375
+ ) -> GRPCTLSConfiguration {
376
+ return Self . makeServerConfigurationBackedByNIOSSL (
377
+ configuration: configuration,
378
+ requireALPN: requireALPN,
379
+ customVerificationCallback: nil
380
+ )
381
+ }
382
+
383
+ /// Creates a gRPC TLS Configuration suitable for servers using the given
384
+ /// `NIOSSL.TLSConfiguration`.
385
+ ///
386
+ /// - Note: If no ALPN tokens are set in `configuration.applicationProtocols` then "grpc-exp",
387
+ /// "h2", and "http/1.1" will be used.
388
+ /// - Parameters:
389
+ /// - configuration: The `NIOSSL.TLSConfiguration` to base this configuration on.
390
+ /// - requiresALPN: Whether the server enforces ALPN. Defaults to `true`.
391
+ /// - Parameter customVerificationCallback: A callback to provide to override the certificate verification logic,
392
+ /// defaults to `nil`.
393
+ public static func makeServerConfigurationBackedByNIOSSL(
394
+ configuration: TLSConfiguration ,
395
+ requireALPN: Bool = true ,
396
+ customVerificationCallback: NIOSSLCustomVerificationCallback ? = nil
341
397
) -> GRPCTLSConfiguration {
342
398
var configuration = configuration
343
399
@@ -348,7 +404,7 @@ extension GRPCTLSConfiguration {
348
404
349
405
let nioConfiguration = NIOConfiguration (
350
406
configuration: configuration,
351
- customVerificationCallback: nil ,
407
+ customVerificationCallback: customVerificationCallback ,
352
408
hostnameOverride: nil ,
353
409
requireALPN: requireALPN
354
410
)
0 commit comments