-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Reducing chances of polluting SSL error queue #29351
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,8 +96,24 @@ internal static bool RsaSign(int type, ReadOnlySpan<byte> m, int m_len, Span<byt | |
[return: MarshalAs(UnmanagedType.Bool)] | ||
private static extern bool RsaSign(int type, ref byte m, int m_len, ref byte sigret, out int siglen, SafeRsaHandle rsa); | ||
|
||
internal static bool RsaVerify(int type, ReadOnlySpan<byte> m, int m_len, ReadOnlySpan<byte> sigbuf, int siglen, SafeRsaHandle rsa) => | ||
RsaVerify(type, ref MemoryMarshal.GetReference(m), m_len, ref MemoryMarshal.GetReference(sigbuf), siglen, rsa); | ||
internal static bool RsaVerify(int type, ReadOnlySpan<byte> m, ReadOnlySpan<byte> sigbuf, SafeRsaHandle rsa) | ||
{ | ||
bool ret = RsaVerify( | ||
type, | ||
ref MemoryMarshal.GetReference(m), | ||
m.Length, | ||
ref MemoryMarshal.GetReference(sigbuf), | ||
sigbuf.Length, | ||
rsa); | ||
|
||
if (!ret) | ||
{ | ||
ErrClearError(); | ||
} | ||
|
||
return ret; | ||
} | ||
|
||
|
||
[DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_RsaVerify")] | ||
[return: MarshalAs(UnmanagedType.Bool)] | ||
|
@@ -171,7 +187,8 @@ private static extern bool GetRsaParameters( | |
out IntPtr iqmp); | ||
|
||
[DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SetRsaParameters")] | ||
internal static extern void SetRsaParameters( | ||
[return: MarshalAs(UnmanagedType.Bool)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this MarshalAs necessary? Isn't this the default marshaling for a bool? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be fair I actually don't know I just followed the pattern from other declarations... I will check this during the day. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is not required, but with the exception of 2 "CryptoNative_*" all extern bool have the MarshalAs - unless there is a cost associated to it I would say to keep it for consistency. |
||
internal static extern bool SetRsaParameters( | ||
SafeRsaHandle key, | ||
byte[] n, | ||
int nLength, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,7 +49,8 @@ internal static partial class Ssl | |
private static extern IntPtr SslGetVersion(SafeSslHandle ssl); | ||
|
||
[DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslSetTlsExtHostName")] | ||
internal static extern int SslSetTlsExtHostName(SafeSslHandle ssl, string host); | ||
[return: MarshalAs(UnmanagedType.Bool)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question for all of these. |
||
internal static extern bool SslSetTlsExtHostName(SafeSslHandle ssl, string host); | ||
|
||
[DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslGet0AlpnSelected")] | ||
internal static extern void SslGetAlpnSelected(SafeSslHandle ssl, out IntPtr protocol, out int len); | ||
|
@@ -128,6 +129,7 @@ internal static extern bool GetSslConnectionInfo( | |
internal static extern int SslGetFinished(SafeSslHandle ssl, IntPtr buf, int count); | ||
|
||
[DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslSessionReused")] | ||
[return: MarshalAs(UnmanagedType.Bool)] | ||
internal static extern bool SslSessionReused(SafeSslHandle ssl); | ||
|
||
[DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslAddExtraChainCert")] | ||
|
@@ -161,6 +163,7 @@ internal static bool AddExtraChainCertificates(SafeSslHandle sslContext, X509Cha | |
Crypto.CheckValidOpenSslHandle(dupCertHandle); | ||
if (!SslAddExtraChainCert(sslContext, dupCertHandle)) | ||
{ | ||
Crypto.ErrClearError(); | ||
dupCertHandle.Dispose(); // we still own the safe handle; clean it up | ||
return false; | ||
} | ||
|
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.
Is this necessary? Presumably we're asserting because it's never possible.
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.
It is more on the paranoid side but at least for one of the encode delegates called via this method the OpenSsl docs states the following: "This may be fixed in future so code should not assume that i2d_X509() will always succeed." - granted that it is in the context of not fully initialized struct.
@bartonjs what is your take here?
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.
It depends on the goals. We've never seen the assert fire, so this is probabilisticly dead code.
Under weird not-supported multi-threading modes, though, maybe one of the values being sent to Encode is capable of failing; and that would then cause an error to show up in SslStream.
If we're going for "perfect" then this is warranted. If we're going for "probabilistic" then it isn't.
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.
Let's go for "asymptotically perfect" ...