-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[System]: Cleanup SslStream
callbacks and internal validation code.
#8753
Conversation
* `SslStream`: Reject attempts of setting conflicting callbacks using both the Mono-specific `MonoTlsSettings` and the new `SslClientAuthenticationOptions` / `SslServerAuthenticationOptions`. This makes it consistent with CoreFx behavior where those callbacks may only be specified in one of the possible places. * `ChainValidationHelper` - this internal class has received a major overhaul and lots of old and unused code removed. All callbacks are not invoked with the correct `sender` parameter to make it match the .NET / CoreFx behavior. * `Mono.Security.Interface.CertificateValidationHelper`: remove unused internal code.
This is the second and final part to bring Client Certificate support. It needs to be landed on top of mono#8753 and mono#8756. * `Mono.Security.Interface.IMonoSslStream`: Add `CanRenegotiate` and `RenegotiateAsync()`. * `Mono.Security.Interface.MonoTlsSettings`: Add `DisallowUnauthenticatedCertificateRequest`. * `AppleTlsContext`: fully support renegotiation. - we may now receive `SslStatus.PeerAuthCompleted` and `SslStatus.PeerClientCertRequested` during `Read()`. It should in theory not happen during `Write()`, but I added it there as well just to be on the safe side. - `SetSessionOption()` may only be called before the initial handshake. * `MobileAuthenticatedStream`: this is the major part of the work and the most complex one. - added a new `Operation` enum to keep track of what is going on and detect invalid state. - a renegotion may only be triggered while we're idle - that is no handshake, read or write operation is currently active. - `InternalWrite()` may now be called from `SSLRead()`, the new `Operation` tells us what is currently happening. - `ProcessHandshake()` now takes a `bool renegotiate` argument. - added sanity checks to `ProcessRead()` and `ProcessWrite()`. * `MobileTlsContext.SelectClientCertificate()`: check for `MonoTlsSettings.DisallowUnauthenticatedCertificateRequest` * `MonoTlsProviderFactory.InternalVersion`: bump the internal version number. Tests have already been added to `web-tests/master`, they will auto-enable themselves when using a Mono runtime that contains this code.
@@ -66,83 +66,43 @@ namespace Mono.Net.Security | |||
|
|||
internal class ChainValidationHelper : ICertificateValidator2 | |||
{ | |||
readonly object sender; | |||
readonly WeakReference<SslStream> owner; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, is this because there might be unmanaged state and we do not want to create a strong cycle, or something else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was simply worried about creating a cycle, considering the memory leaks that we had in the past.
This is the second and final part to bring Client Certificate support. It needs to be landed on top of mono#8753 and mono#8756. * `Mono.Security.Interface.IMonoSslStream`: Add `CanRenegotiate` and `RenegotiateAsync()`. * `Mono.Security.Interface.MonoTlsSettings`: Add `DisallowUnauthenticatedCertificateRequest`. * `AppleTlsContext`: fully support renegotiation. - we may now receive `SslStatus.PeerAuthCompleted` and `SslStatus.PeerClientCertRequested` during `Read()`. It should in theory not happen during `Write()`, but I added it there as well just to be on the safe side. - `SetSessionOption()` may only be called before the initial handshake. * `MobileAuthenticatedStream`: this is the major part of the work and the most complex one. - added a new `Operation` enum to keep track of what is going on and detect invalid state. - a renegotion may only be triggered while we're idle - that is no handshake, read or write operation is currently active. - `InternalWrite()` may now be called from `SSLRead()`, the new `Operation` tells us what is currently happening. - `ProcessHandshake()` now takes a `bool renegotiate` argument. - added sanity checks to `ProcessRead()` and `ProcessWrite()`. * `MobileTlsContext.SelectClientCertificate()`: check for `MonoTlsSettings.DisallowUnauthenticatedCertificateRequest` * `MonoTlsProviderFactory.InternalVersion`: bump the internal version number. Tests have already been added to `web-tests/master`, they will auto-enable themselves when using a Mono runtime that contains this code.
This is the second and final part to bring Client Certificate support. It needs to be landed on top of mono#8753 and mono#8756. * `Mono.Security.Interface.IMonoSslStream`: Add `CanRenegotiate` and `RenegotiateAsync()`. * `Mono.Security.Interface.MonoTlsSettings`: Add `DisallowUnauthenticatedCertificateRequest`. * `AppleTlsContext`: fully support renegotiation. - we may now receive `SslStatus.PeerAuthCompleted` and `SslStatus.PeerClientCertRequested` during `Read()`. It should in theory not happen during `Write()`, but I added it there as well just to be on the safe side. - `SetSessionOption()` may only be called before the initial handshake. * `MobileAuthenticatedStream`: this is the major part of the work and the most complex one. - added a new `Operation` enum to keep track of what is going on and detect invalid state. - a renegotion may only be triggered while we're idle - that is no handshake, read or write operation is currently active. - `InternalWrite()` may now be called from `SSLRead()`, the new `Operation` tells us what is currently happening. - `ProcessHandshake()` now takes a `bool renegotiate` argument. - added sanity checks to `ProcessRead()` and `ProcessWrite()`. * `MobileTlsContext.SelectClientCertificate()`: check for `MonoTlsSettings.DisallowUnauthenticatedCertificateRequest` * `MonoTlsProviderFactory.InternalVersion`: bump the internal version number. Tests have already been added to `web-tests/master`, they will auto-enable themselves when using a Mono runtime that contains this code.
This is the second and final part to bring Client Certificate support. It needs to be landed on top of #8753 and #8756. * `Mono.Security.Interface.IMonoSslStream`: Add `CanRenegotiate` and `RenegotiateAsync()`. * `Mono.Security.Interface.MonoTlsSettings`: Add `DisallowUnauthenticatedCertificateRequest`. * `AppleTlsContext`: fully support renegotiation. - we may now receive `SslStatus.PeerAuthCompleted` and `SslStatus.PeerClientCertRequested` during `Read()`. It should in theory not happen during `Write()`, but I added it there as well just to be on the safe side. - `SetSessionOption()` may only be called before the initial handshake. * `MobileAuthenticatedStream`: this is the major part of the work and the most complex one. - added a new `Operation` enum to keep track of what is going on and detect invalid state. - a renegotion may only be triggered while we're idle - that is no handshake, read or write operation is currently active. - `InternalWrite()` may now be called from `SSLRead()`, the new `Operation` tells us what is currently happening. - `ProcessHandshake()` now takes a `bool renegotiate` argument. - added sanity checks to `ProcessRead()` and `ProcessWrite()`. * `MobileTlsContext.SelectClientCertificate()`: check for `MonoTlsSettings.DisallowUnauthenticatedCertificateRequest` * `MonoTlsProviderFactory.InternalVersion`: bump the internal version number. Tests have already been added to `web-tests/master`, they will auto-enable themselves when using a Mono runtime that contains this code.
This is the second and final part to bring Client Certificate support. It needs to be landed on top of mono/mono#8753 and mono/mono#8756. * `Mono.Security.Interface.IMonoSslStream`: Add `CanRenegotiate` and `RenegotiateAsync()`. * `Mono.Security.Interface.MonoTlsSettings`: Add `DisallowUnauthenticatedCertificateRequest`. * `AppleTlsContext`: fully support renegotiation. - we may now receive `SslStatus.PeerAuthCompleted` and `SslStatus.PeerClientCertRequested` during `Read()`. It should in theory not happen during `Write()`, but I added it there as well just to be on the safe side. - `SetSessionOption()` may only be called before the initial handshake. * `MobileAuthenticatedStream`: this is the major part of the work and the most complex one. - added a new `Operation` enum to keep track of what is going on and detect invalid state. - a renegotion may only be triggered while we're idle - that is no handshake, read or write operation is currently active. - `InternalWrite()` may now be called from `SSLRead()`, the new `Operation` tells us what is currently happening. - `ProcessHandshake()` now takes a `bool renegotiate` argument. - added sanity checks to `ProcessRead()` and `ProcessWrite()`. * `MobileTlsContext.SelectClientCertificate()`: check for `MonoTlsSettings.DisallowUnauthenticatedCertificateRequest` * `MonoTlsProviderFactory.InternalVersion`: bump the internal version number. Tests have already been added to `web-tests/master`, they will auto-enable themselves when using a Mono runtime that contains this code. Commit migrated from mono/mono@5715aee
SslStream
: Reject attempts of setting conflicting callbacks using both theMono-specific
MonoTlsSettings
and the newSslClientAuthenticationOptions
/SslServerAuthenticationOptions
.This makes it consistent with CoreFx behavior where those callbacks may only be
specified in one of the possible places.
ChainValidationHelper
- this internal class has received a major overhaul andlots of old and unused code removed.
All callbacks are not invoked with the correct
sender
parameter to make itmatch the .NET / CoreFx behavior.
Mono.Security.Interface.CertificateValidationHelper
: remove unused internal code.