@@ -459,9 +459,9 @@ public struct TLSConfiguration {
459459 self . signingSignatureAlgorithms = signingSignatureAlgorithms
460460 self . minimumTLSVersion = minimumTLSVersion
461461 self . maximumTLSVersion = maximumTLSVersion
462- self . certificateVerification = certificateVerification
463462 self . trustRoots = trustRoots
464463 self . additionalTrustRoots = additionalTrustRoots
464+ self . certificateVerification = certificateVerification
465465 self . certificateChain = certificateChain
466466 self . privateKey = privateKey
467467 self . encodedApplicationProtocols = [ ]
@@ -652,6 +652,47 @@ extension TLSConfiguration {
652652 pskHint: nil
653653 )
654654 }
655+
656+ /// Create a TLS configuration for use with server-side contexts that expect to validate a client
657+ /// certificate (often called mTLS).
658+ ///
659+ /// This provides sensible defaults while requiring that you provide any data that is necessary
660+ /// for server-side function. For servers that don't need mTLS, try
661+ /// ``TLSConfiguration/makeServerConfiguration()`` instead.
662+ ///
663+ /// This configuration is very similar to ``TLSConfiguration/makeServerConfiguration()`` but
664+ /// adds a `trustRoots` requirement. These roots will be used to validate the certificate
665+ /// presented by the peer. It also sets the ``certificateVerification`` field to
666+ /// ``CertificateVerification/noHostnameVerification``, which enables verification but disables
667+ /// any hostname checking, which cannot succeed in a server context.
668+ ///
669+ /// For customising fields, modify the returned TLSConfiguration object.
670+ public static func makeServerConfigurationWithMTLS(
671+ certificateChain: [ NIOSSLCertificateSource ] ,
672+ privateKey: NIOSSLPrivateKeySource ,
673+ trustRoots: NIOSSLTrustRoots
674+ ) -> TLSConfiguration {
675+ TLSConfiguration (
676+ cipherSuites: defaultCipherSuites,
677+ verifySignatureAlgorithms: nil ,
678+ signingSignatureAlgorithms: nil ,
679+ minimumTLSVersion: . tlsv1,
680+ maximumTLSVersion: nil ,
681+ certificateVerification: . noHostnameVerification,
682+ trustRoots: trustRoots,
683+ certificateChain: certificateChain,
684+ privateKey: privateKey,
685+ applicationProtocols: [ ] ,
686+ shutdownTimeout: . seconds( 5 ) ,
687+ keyLogCallback: nil ,
688+ renegotiationSupport: . none,
689+ additionalTrustRoots: [ ] ,
690+ sendCANameList: false ,
691+ pskClientProvider: nil ,
692+ pskServerProvider: nil ,
693+ pskHint: nil
694+ )
695+ }
655696}
656697
657698// MARK: Deprecated constructors.
0 commit comments