@@ -449,9 +449,9 @@ public struct TLSConfiguration {
449449 self . signingSignatureAlgorithms = signingSignatureAlgorithms
450450 self . minimumTLSVersion = minimumTLSVersion
451451 self . maximumTLSVersion = maximumTLSVersion
452- self . certificateVerification = certificateVerification
453452 self . trustRoots = trustRoots
454453 self . additionalTrustRoots = additionalTrustRoots
454+ self . certificateVerification = certificateVerification
455455 self . certificateChain = certificateChain
456456 self . privateKey = privateKey
457457 self . encodedApplicationProtocols = [ ]
@@ -642,6 +642,47 @@ extension TLSConfiguration {
642642 pskHint: nil
643643 )
644644 }
645+
646+ /// Create a TLS configuration for use with server-side contexts that expect to validate a client
647+ /// certificate (often called mTLS).
648+ ///
649+ /// This provides sensible defaults while requiring that you provide any data that is necessary
650+ /// for server-side function. For servers that don't need mTLS, try
651+ /// ``TLSConfiguration/makeServerConfiguration()`` instead.
652+ ///
653+ /// This configuration is very similar to ``TLSConfiguration/makeServerConfiguration()`` but
654+ /// adds a `trustRoots` requirement. These roots will be used to validate the certificate
655+ /// presented by the peer. It also sets the ``certificateVerification`` field to
656+ /// ``CertificateVerification/noHostnameVerification``, which enables verification but disables
657+ /// any hostname checking, which cannot succeed in a server context.
658+ ///
659+ /// For customising fields, modify the returned TLSConfiguration object.
660+ public static func makeServerConfigurationWithMTLS(
661+ certificateChain: [ NIOSSLCertificateSource ] ,
662+ privateKey: NIOSSLPrivateKeySource ,
663+ trustRoots: NIOSSLTrustRoots
664+ ) -> TLSConfiguration {
665+ TLSConfiguration (
666+ cipherSuites: defaultCipherSuites,
667+ verifySignatureAlgorithms: nil ,
668+ signingSignatureAlgorithms: nil ,
669+ minimumTLSVersion: . tlsv1,
670+ maximumTLSVersion: nil ,
671+ certificateVerification: . noHostnameVerification,
672+ trustRoots: trustRoots,
673+ certificateChain: certificateChain,
674+ privateKey: privateKey,
675+ applicationProtocols: [ ] ,
676+ shutdownTimeout: . seconds( 5 ) ,
677+ keyLogCallback: nil ,
678+ renegotiationSupport: . none,
679+ additionalTrustRoots: [ ] ,
680+ sendCANameList: false ,
681+ pskClientProvider: nil ,
682+ pskServerProvider: nil ,
683+ pskHint: nil
684+ )
685+ }
645686}
646687
647688// MARK: Deprecated constructors.
0 commit comments