You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/DataProtection/README.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
DataProtection
2
2
==============
3
3
4
-
Data Protection APIs for protecting and unprotecting data. You can find documentation for Data Protection in the [ASP.NET Core Documentation](https://docs.microsoft.com/en-us/aspnet/core/security/data-protection/).
4
+
Data Protection APIs for protecting and unprotecting data. You can find documentation for Data Protection in the [ASP.NET Core Documentation](https://docs.microsoft.com/aspnet/core/security/data-protection/).
5
5
6
6
## Community Maintained Data Protection Providers & Projects
Copy file name to clipboardExpand all lines: src/Security/Authentication/Certificate/src/README.md
+28-56Lines changed: 28 additions & 56 deletions
Original file line number
Diff line number
Diff line change
@@ -1,31 +1,22 @@
1
1
# Microsoft.AspNetCore.Authentication.Certificate
2
2
3
-
This project sort of contains an implementation of [Certificate Authentication](https://tools.ietf.org/html/rfc5246#section-7.4.4) for ASP.NET Core.
4
-
Certificate authentication happens at the TLS level, long before it ever gets to ASP.NET Core, so, more accurately this is an authentication handler
5
-
that validates the certificate and then gives you an event where you can resolve that certificate to a ClaimsPrincipal.
3
+
This project sort of contains an implementation of [Certificate Authentication](https://tools.ietf.org/html/rfc5246#section-7.4.4) for ASP.NET Core. Certificate authentication happens at the TLS level, long before it ever gets to ASP.NET Core, so, more accurately this is an authentication handler that validates the certificate and then gives you an event where you can resolve that certificate to a ClaimsPrincipal.
6
4
7
-
You **must**[configure your host](#hostConfiguration) for certificate authentication, be it IIS, Kestrel, Azure Web Applications or whatever else you're using.
5
+
You **must**[configure your host](#configuring-your-host-to-require-certificates) for certificate authentication, be it IIS, Kestrel, Azure Web Applications or whatever else you're using.
8
6
9
7
## Getting started
10
8
11
-
First acquire an HTTPS certificate, apply it and then [configure your host](#hostConfiguration) to require certificates.
9
+
First acquire an HTTPS certificate, apply it and then [configure your host](#configuring-your-host-to-require-certificates) to require certificates.
12
10
13
-
In your web application add a reference to the package, then in the `ConfigureServices` method in `startup.cs` call
14
-
`app.AddAuthentication(CertificateAuthenticationDefaults.AuthenticationScheme).UseCertificateAuthentication(...);` with your options,
15
-
providing a delegate for `OnValidateCertificate` to validate the client certificate sent with requests and turn that information
16
-
into an `ClaimsPrincipal`, set it on the `context.Principal` property and call `context.Success()`.
11
+
In your web application add a reference to the package, then in the `ConfigureServices` method in `startup.cs` call `app.AddAuthentication(CertificateAuthenticationDefaults.AuthenticationScheme).UseCertificateAuthentication(...);` with your options, providing a delegate for `OnValidateCertificate` to validate the client certificate sent with requests and turn that information into an `ClaimsPrincipal`, set it on the `context.Principal` property and call `context.Success()`.
17
12
18
-
If you change your scheme name in the options for the authentication handler you need to change the scheme name in
19
-
`AddAuthentication()` to ensure it's used on every request which ends in an endpoint that requires authorization.
13
+
If you change your scheme name in the options for the authentication handler you need to change the scheme name in `AddAuthentication()` to ensure it's used on every request which ends in an endpoint that requires authorization.
20
14
21
-
If authentication fails this handler will return a `403 (Forbidden)` response rather a `401 (Unauthorized)` as you
22
-
might expect - this is because the authentication should happen during the initial TLS connection - by the time it
23
-
reaches the handler it's too late, and there's no way to actually upgrade the connection from an anonymous connection
24
-
to one with a certificate.
15
+
If authentication fails this handler will return a `403 (Forbidden)` response rather a `401 (Unauthorized)` as you might expect - this is because the authentication should happen during the initial TLS connection - by the time it reaches the handler it's too late, and there's no way to actually upgrade the connection from an anonymous connection to one with a certificate.
25
16
26
17
You must also add `app.UseAuthentication();` in the `Configure` method, otherwise nothing will ever get called.
@@ -47,50 +38,41 @@ In the sample above you can see the default way to add certificate authenticatio
47
38
48
39
## Configuring Certificate Validation
49
40
50
-
The `CertificateAuthenticationOptions` handler has some built in validations that are the minimium validations you should perform on
51
-
a certificate. Each of these settings are turned on by default.
41
+
The `CertificateAuthenticationOptions` handler has some built in validations that are the minimum validations you should perform on a certificate. Each of these settings are turned on by default.
52
42
53
43
### ValidateCertificateChain
54
44
55
-
This check validates that the issuer for the certificate is trusted by the application host OS. If
56
-
you are going to accept self-signed certificates you must disable this check.
45
+
This check validates that the issuer for the certificate is trusted by the application host OS. If you are going to accept self-signed certificates you must disable this check.
57
46
58
47
### ValidateCertificateUse
59
48
60
-
This check validates that the certificate presented by the client has the Client Authentication
61
-
extended key use, or no EKUs at all (as the specifications say if no EKU is specified then all EKUs
62
-
are valid).
49
+
This check validates that the certificate presented by the client has the Client Authentication extended key use, or no EKUs at all (as the specifications say if no EKU is specified then all EKUs are valid).
63
50
64
51
### ValidateValidityPeriod
65
52
66
-
This check validates that the certificate is within its validity period. As the handler runs on every
67
-
request this ensures that a certificate that was valid when it was presented has not expired during
68
-
its current session.
53
+
This check validates that the certificate is within its validity period. As the handler runs on every request this ensures that a certificate that was valid when it was presented has not expired during its current session.
69
54
70
55
### RevocationFlag
71
56
72
57
A flag which specifies which certificates in the chain are checked for revocation.
73
58
74
59
Revocation checks are only performed when the certificate is chained to a root certificate.
75
60
76
-
### RevocationMode
61
+
### RevocationMode
77
62
78
63
A flag which specifies how revocation checks are performed.
64
+
79
65
Specifying an on-line check can result in a long delay while the certificate authority is contacted.
80
66
81
67
Revocation checks are only performed when the certificate is chained to a root certificate.
82
68
83
69
### Can I configure my application to require a certificate only on certain paths?
84
70
85
-
Not possible, remember the certificate exchange is done that the start of the HTTPS conversation,
86
-
it's done by the host, not the application. Kestrel, IIS, Azure Web Apps don't have any configuration for
87
-
this sort of thing.
71
+
Not possible, remember the certificate exchange is done that the start of the HTTPS conversation, it's done by the host, not the application. Kestrel, IIS, Azure Web Apps don't have any configuration for this sort of thing.
88
72
89
-
# Handler events
73
+
##Handler events
90
74
91
-
The handler has two events, `OnAuthenticationFailed()`, which is called if an exception happens during authentication and allows you to react, and `OnValidateCertificate()` which is
92
-
called after certificate has been validated, passed validation, abut before the default principal has been created. This allows you to perform your own validation, for example
93
-
checking if the certificate is one your services knows about, and to construct your own principal. For example,
75
+
The handler has two events, `OnAuthenticationFailed()`, which is called if an exception happens during authentication and allows you to react, and `OnValidateCertificate()` which is called after certificate has been validated, passed validation, abut before the default principal has been created. This allows you to perform your own validation, for example checking if the certificate is one your services knows about, and to construct your own principal. For example:
If you find the inbound certificate doesn't meet your extra validation call `context.Fail("failure Reason")` with a failure reason.
119
101
120
-
For real functionality you will probably want to call a service registered in DI which talks to a database or other type of
121
-
user store. You can grab your service by using the context passed into your delegates, like so
102
+
For real functionality you will probably want to call a service registered in DI which talks to a database or other type of user store. You can grab your service by using the context passed into your delegates, like so
Note that conceptually the validation of the certification is an authorization concern, and putting a check on, for example, an issuer or thumbprint in an authorization policy rather
152
134
than inside OnCertificateValidated() is perfectly acceptable.
153
135
154
-
## <aname="hostConfiguration"></a>Configuring your host to require certificates
136
+
## Configuring your host to require certificates
155
137
156
138
### Kestrel
157
139
@@ -170,12 +152,12 @@ public static IWebHost BuildWebHost(string[] args)
170
152
})
171
153
.Build();
172
154
```
173
-
You must set the `ClientCertificateValidation` delegate to `CertificateValidator.DisableChannelValidation` in order to stop Kestrel using the default OS certificate validation routine and,
174
-
instead, letting the authentication handler perform the validation.
155
+
156
+
You must set the `ClientCertificateValidation` delegate to `CertificateValidator.DisableChannelValidation` in order to stop Kestrel using the default OS certificate validation routine and, instead, letting the authentication handler perform the validation.
175
157
176
158
### IIS
177
159
178
-
In the IIS Manager
160
+
In the IIS Manager:
179
161
180
162
1. Select your Site in the Connections tab.
181
163
2. Double click the SSL Settings in the Features View window.
@@ -185,28 +167,21 @@ In the IIS Manager
185
167
186
168
### Azure
187
169
188
-
See the [Azure documentation](https://docs.microsoft.com/en-us/azure/app-service/app-service-web-configure-tls-mutual-auth)
189
-
to configure Azure Web Apps then add the following to your application startup method, `Configure(IApplicationBuilder app)` add the
190
-
following line before the call to `app.UseAuthentication();`
170
+
See the [Azure documentation](https://docs.microsoft.com/azure/app-service/app-service-web-configure-tls-mutual-auth) to configure Azure Web Apps then add the following to your application startup method, `Configure(IApplicationBuilder app)` add the following line before the call to `app.UseAuthentication();`:
191
171
192
172
```c#
193
173
app.UseCertificateHeaderForwarding();
194
174
```
195
175
196
176
### Random custom web proxies
197
177
198
-
If you're using a proxy which isn't IIS or Azure's Web Apps Application Request Routing you will need to configure your proxy
199
-
to forward the certificate it received in an HTTP header.
200
-
In your application startup method, `Configure(IApplicationBuilder app)`, add the
201
-
following line before the call to `app.UseAuthentication();`
178
+
If you're using a proxy which isn't IIS or Azure's Web Apps Application Request Routing you will need to configure your proxy to forward the certificate it received in an HTTP header. In your application startup method, `Configure(IApplicationBuilder app)`, add the following line before the call to `app.UseAuthentication();`:
202
179
203
180
```c#
204
181
app.UseCertificateForwarding();
205
182
```
206
183
207
-
You will also need to configure the Certificate Forwarding middleware to specify the header name.
208
-
In your service configuration method, `ConfigureServices(IServiceCollection services)` add
209
-
the following code to configure the header the forwarding middleware will build a certificate from;
184
+
You will also need to configure the Certificate Forwarding middleware to specify the header name. In your service configuration method, `ConfigureServices(IServiceCollection services)` add the following code to configure the header the forwarding middleware will build a certificate from:
Finally, if your proxy is doing something weird to pass the header on, rather than base 64 encoding it
219
-
(looking at you nginx (╯°□°)╯︵ ┻━┻) you can override the converter option to be a func that will
220
-
perform the optional conversion, for example
193
+
Finally, if your proxy is doing something weird to pass the header on, rather than base 64 encoding it (looking at you nginx (╯°□°)╯︵ ┻━┻) you can override the converter option to be a func that will perform the optional conversion, for example
Copy file name to clipboardExpand all lines: src/Security/Authentication/Negotiate/test/Negotiate.FunctionalTest/CrossMachineReadMe.md
+7-7Lines changed: 7 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -1,24 +1,24 @@
1
1
Cross Machine Tests
2
2
3
-
Kerberos can only be tested in a multi-machine environment. On localhost it always falls back to NTLM which has different requirements. Multi-machine is also neccisary for interop testing across OSs. Kerberos also requires domain controler SPN configuration so we can't test it on arbitrary test boxes.
3
+
Kerberos can only be tested in a multi-machine environment. On localhost it always falls back to NTLM which has different requirements. Multi-machine is also necessary for interop testing across OSs. Kerberos also requires domain controller SPN configuration so we can't test it on arbitrary test boxes.
4
4
5
5
Test structure:
6
6
- A remote test server with various endpoints with different authentication restrictions.
7
-
- A remote test client with endpoints that execute specific scenarios. The input for these endpoints is theory data. The output is either 200Ok, or a failure code and desciption.
7
+
- A remote test client with endpoints that execute specific scenarios. The input for these endpoints is theory data. The output is either 200Ok, or a failure code and description.
8
8
- The CrossMachineTest class that drives the tests. It invokes the client app with the theory data and confirms the results.
9
9
10
-
We use these three components beceause it allows us to run the tests from a dev machine or CI agent that is not part of the dedicated test domain/environment.
10
+
We use these three components because it allows us to run the tests from a dev machine or CI agent that is not part of the dedicated test domain/environment.
11
11
12
12
(Static) Environment Setup:
13
13
- Warning, this environment can take a day to set up. That's why we want a static test environment that we can re-use.
14
14
- Create a Windows server running DNS and Active Directory. Promote it to a domain controller.
15
15
- Create an SPN on this machine for Windows -> Windows testing. `setspn -S "http/chrross-dc.crkerberos.com" -U administrator`
16
16
- Future: Can we replace the domain controller with an AAD instance? We'd still want a second windows machine for Windows -> Windows testing, but AAD might be easier to configure.
Copy file name to clipboardExpand all lines: src/Security/README.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -3,9 +3,9 @@ ASP.NET Core Security
3
3
4
4
Contains the security and authorization middlewares for ASP.NET Core.
5
5
6
-
A list of community projects related to authentication and security for ASP.NET Core are listed in the [documentation](https://docs.microsoft.com/en-us/aspnet/core/security/authentication/community).
6
+
A list of community projects related to authentication and security for ASP.NET Core are listed in the [documentation](https://docs.microsoft.com/aspnet/core/security/authentication/community).
7
7
8
-
See the [ASP.NET Core security documentation](https://docs.microsoft.com/en-us/aspnet/core/security/).
8
+
See the [ASP.NET Core security documentation](https://docs.microsoft.com/aspnet/core/security/).
Sample demonstrating copying over static and dynamic external claims from Google authentication during login:
5
5
6
6
Steps:
7
-
1. Configure a google OAuth2 project. See https://docs.microsoft.com/en-us/aspnet/core/security/authentication/social/google-logins?tabs=aspnetcore2x for basic setup using google logins.
7
+
1. Configure a google OAuth2 project. See https://docs.microsoft.com/aspnet/core/security/authentication/social/google-logins for basic setup using google logins.
8
8
2. Update Startup.cs AddGoogle()'s options with ClientId and ClientSecret for your google app.
9
9
3. Run the app and click on the MyClaims tab, this should trigger a redirect to login.
10
10
4. Login via the Google button, this should redirect you to google.
0 commit comments