@@ -16,12 +16,13 @@ internal class ConfigurationReader
16
16
private const string CertificatesKey = "Certificates" ;
17
17
private const string CertificateKey = "Certificate" ;
18
18
private const string SslProtocolsKey = "SslProtocols" ;
19
- private const string EndpointDefaultsKey = "EndpointDefaults" ;
20
19
private const string EndpointsKey = "Endpoints" ;
21
20
private const string UrlKey = "Url" ;
22
21
private const string ClientCertificateModeKey = "ClientCertificateMode" ;
23
22
private const string SniKey = "Sni" ;
24
23
24
+ internal const string EndpointDefaultsKey = "EndpointDefaults" ;
25
+
25
26
private readonly IConfiguration _configuration ;
26
27
27
28
private IDictionary < string , CertificateConfig > _certificates ;
@@ -51,9 +52,20 @@ private IDictionary<string, CertificateConfig> ReadCertificates()
51
52
}
52
53
53
54
// "EndpointDefaults": {
54
- // "Protocols": "Http1AndHttp2",
55
- // "SslProtocols": [ "Tls11", "Tls12", "Tls13"],
56
- // "ClientCertificateMode" : "NoCertificate"
55
+ // "Protocols": "Http1AndHttp2",
56
+ // "SslProtocols": [ "Tls11", "Tls12", "Tls13"],
57
+ // "ClientCertificateMode" : "NoCertificate",
58
+ // "Sni": {
59
+ // "a.example.org": {
60
+ // "Certificate": {
61
+ // "Path": "testCertA.pfx",
62
+ // "Password": "testPassword"
63
+ // }
64
+ // },
65
+ // "*.example.org": {
66
+ // "Protocols": "Http1",
67
+ // }
68
+ // }
57
69
// }
58
70
private EndpointDefaults ReadEndpointDefaults ( )
59
71
{
@@ -62,7 +74,8 @@ private EndpointDefaults ReadEndpointDefaults()
62
74
{
63
75
Protocols = ParseProtocols ( configSection [ ProtocolsKey ] ) ,
64
76
SslProtocols = ParseSslProcotols ( configSection . GetSection ( SslProtocolsKey ) ) ,
65
- ClientCertificateMode = ParseClientCertificateMode ( configSection [ ClientCertificateModeKey ] )
77
+ ClientCertificateMode = ParseClientCertificateMode ( configSection [ ClientCertificateModeKey ] ) ,
78
+ Sni = ReadSni ( configSection . GetSection ( SniKey ) , EndpointDefaultsKey )
66
79
} ;
67
80
}
68
81
@@ -74,14 +87,25 @@ private IEnumerable<EndpointConfig> ReadEndpoints()
74
87
foreach ( var endpointConfig in endpointsConfig )
75
88
{
76
89
// "EndpointName": {
77
- // "Url": "https://*:5463",
78
- // "Protocols": "Http1AndHttp2",
79
- // "SslProtocols": [ "Tls11", "Tls12", "Tls13"],
80
- // "Certificate": {
81
- // "Path": "testCert.pfx",
82
- // "Password": "testPassword"
83
- // },
84
- // "ClientCertificateMode" : "NoCertificate"
90
+ // "Url": "https://*:5463",
91
+ // "Protocols": "Http1AndHttp2",
92
+ // "SslProtocols": [ "Tls11", "Tls12", "Tls13"],
93
+ // "Certificate": {
94
+ // "Path": "testCert.pfx",
95
+ // "Password": "testPassword"
96
+ // },
97
+ // "ClientCertificateMode" : "NoCertificate",
98
+ // "Sni": {
99
+ // "a.example.org": {
100
+ // "Certificate": {
101
+ // "Path": "testCertA.pfx",
102
+ // "Password": "testPassword"
103
+ // }
104
+ // },
105
+ // "*.example.org": {
106
+ // "Protocols": "Http1",
107
+ // }
108
+ // }
85
109
// }
86
110
87
111
var url = endpointConfig [ UrlKey ] ;
@@ -116,20 +140,22 @@ private Dictionary<string, SniConfig> ReadSni(IConfigurationSection sniConfig, s
116
140
{
117
141
// "Sni": {
118
142
// "a.example.org": {
119
- // "Protocols": "Http1AndHttp2 ",
143
+ // "Protocols": "Http1 ",
120
144
// "SslProtocols": [ "Tls11", "Tls12", "Tls13"],
121
145
// "Certificate": {
122
- // "Path": "testCert .pfx",
146
+ // "Path": "testCertA .pfx",
123
147
// "Password": "testPassword"
124
148
// },
125
149
// "ClientCertificateMode" : "NoCertificate"
126
150
// },
127
151
// "*.example.org": {
128
152
// "Certificate": {
129
- // "Path": "testCert2 .pfx",
153
+ // "Path": "testCertWildcard .pfx",
130
154
// "Password": "testPassword"
131
155
// }
132
156
// }
157
+ // // The following should work once https://github.com/dotnet/runtime/issues/40218 is resolved
158
+ // "*": {}
133
159
// }
134
160
135
161
if ( string . IsNullOrEmpty ( sniChild . Key ) )
@@ -139,8 +165,8 @@ private Dictionary<string, SniConfig> ReadSni(IConfigurationSection sniConfig, s
139
165
140
166
var sni = new SniConfig
141
167
{
142
- Protocols = ParseProtocols ( sniChild [ ProtocolsKey ] ) ,
143
168
Certificate = new CertificateConfig ( sniChild . GetSection ( CertificateKey ) ) ,
169
+ Protocols = ParseProtocols ( sniChild [ ProtocolsKey ] ) ,
144
170
SslProtocols = ParseSslProcotols ( sniChild . GetSection ( SslProtocolsKey ) ) ,
145
171
ClientCertificateMode = ParseClientCertificateMode ( sniChild [ ClientCertificateModeKey ] )
146
172
} ;
@@ -189,44 +215,37 @@ private Dictionary<string, SniConfig> ReadSni(IConfigurationSection sniConfig, s
189
215
}
190
216
191
217
// "EndpointDefaults": {
192
- // "Protocols": "Http1AndHttp2",
193
- // "SslProtocols": [ "Tls11", "Tls12", "Tls13"],
194
- // "ClientCertificateMode" : "NoCertificate"
218
+ // "Protocols": "Http1AndHttp2",
219
+ // "SslProtocols": [ "Tls11", "Tls12", "Tls13"],
220
+ // "ClientCertificateMode" : "NoCertificate"
195
221
// }
196
222
internal class EndpointDefaults
197
223
{
198
224
public HttpProtocols ? Protocols { get ; set ; }
199
225
public SslProtocols ? SslProtocols { get ; set ; }
200
226
public ClientCertificateMode ? ClientCertificateMode { get ; set ; }
227
+ public Dictionary < string , SniConfig > Sni { get ; set ; }
201
228
}
202
229
203
230
// "EndpointName": {
204
- // "Url": "https://*:5463",
205
- // "Protocols": "Http1AndHttp2",
206
- // "SslProtocols": [ "Tls11", "Tls12", "Tls13"],
207
- // "Certificate": {
208
- // "Path": "testCert.pfx",
209
- // "Password": "testPassword"
210
- // },
211
- // "ClientCertificateMode" : "NoCertificate"
231
+ // "Url": "https://*:5463",
232
+ // "Protocols": "Http1AndHttp2",
233
+ // "SslProtocols": [ "Tls11", "Tls12", "Tls13"],
234
+ // "Certificate": {
235
+ // "Path": "testCert.pfx",
236
+ // "Password": "testPassword"
237
+ // },
238
+ // "ClientCertificateMode" : "NoCertificate",
212
239
// "Sni": {
213
240
// "a.example.org": {
214
- // "Protocols": "Http1AndHttp2",
215
- // "SslProtocols": [ "Tls11", "Tls12", "Tls13"],
216
- // "Certificate": {
217
- // "Path": "testCert.pfx",
218
- // "Password": "testPassword"
219
- // },
220
- // "ClientCertificateMode" : "NoCertificate"
221
- // },
222
- // "*.example.org": {
223
241
// "Certificate": {
224
- // "Path": "testCert2 .pfx",
225
- // "Password": "testPassword "
242
+ // "Path": "testCertA .pfx",
243
+ // "Password": "testPasswordA "
226
244
// }
227
245
// },
228
- // // The following should work once https://github.com/dotnet/runtime/issues/40218 is resolved
229
- // "*": {}
246
+ // "*.example.org": {
247
+ // "Protocols": "Http1",
248
+ // }
230
249
// }
231
250
// }
232
251
internal class EndpointConfig
@@ -304,8 +323,8 @@ internal class SniConfig
304
323
public override bool Equals ( object obj ) =>
305
324
obj is SniConfig other &&
306
325
( Protocols ?? ListenOptions . DefaultHttpProtocols ) == ( other . Protocols ?? ListenOptions . DefaultHttpProtocols ) &&
307
- Certificate == other . Certificate &&
308
326
( SslProtocols ?? System . Security . Authentication . SslProtocols . None ) == ( other . SslProtocols ?? System . Security . Authentication . SslProtocols . None ) &&
327
+ Certificate == other . Certificate &&
309
328
( ClientCertificateMode ?? Https . ClientCertificateMode . NoCertificate ) == ( other . ClientCertificateMode ?? Https . ClientCertificateMode . NoCertificate ) ;
310
329
311
330
public override int GetHashCode ( ) => HashCode . Combine (
@@ -317,8 +336,8 @@ public override int GetHashCode() => HashCode.Combine(
317
336
}
318
337
319
338
// "CertificateName": {
320
- // "Path": "testCert.pfx",
321
- // "Password": "testPassword"
339
+ // "Path": "testCert.pfx",
340
+ // "Password": "testPassword"
322
341
// }
323
342
internal class CertificateConfig
324
343
{
0 commit comments