Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

1st shims for the LibSsl library.#3979

Merged
eerhardt merged 3 commits into
dotnet:masterfrom
eerhardt:ShimLibSsl
Oct 21, 2015
Merged

1st shims for the LibSsl library.#3979
eerhardt merged 3 commits into
dotnet:masterfrom
eerhardt:ShimLibSsl

Conversation

@eerhardt
Copy link
Copy Markdown
Member

I added shims the first 8 libssl functions and did a little clean up.

  • Put all Interop files under "Common\Interop" in System.Net.Security.
  • Removed some unused fields from StreamSizes.
  • Changed some unnecessary IntPtr usages to byte[] or byte*, where appropriate.

@bartonjs @stephentoub @vijaykota @rajansingh10 @shrutigarg
(optionally, @nguerrera, @sokket if you want to take a look)

I added shims the first 8 libssl functions and did a little clean up.
- Put all Interop files under "Common\Interop" in System.Net.Security.
- Removed some unused fields from StreamSizes.
- Changed some unnecessary IntPtr usages to byte[] or byte*, where appropriate.
@eerhardt
Copy link
Copy Markdown
Member Author

I'm fixing the OSX compile errors... :(. I guess this is a good reason we have shims, we know about these incompatibilities at build time, and not run time.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is SafeSslContextHandle moving now just causing too much of a headache?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I wanted to leave where it is for now and move it with a separate change.
BTW - where do you think it should live? Some SafeHandles live under Microsoft.Win32.SafeHandles, which feels weird to me for Unix code.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For internal ones, I've been leaving them in Microsoft.Win32.SafeHandles.

@bartonjs
Copy link
Copy Markdown
Member

LGTM in principle, modulo not compiling :)

We probably want a cmake functionality test for for OpenSSL compatibility levels, rather than using APPLE. If you end up making one, chime in on https://github.com/dotnet/corefx/pull/3916/files#r42436681 :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Instead of making the method unsafe, can't you use an unsafe block?

@vijaykota
Copy link
Copy Markdown
Contributor

LGTM

@nguerrera
Copy link
Copy Markdown
Contributor

LGTM, but waiting to see where it lands to get things working on OS X.

@eerhardt
Copy link
Copy Markdown
Member Author

Updated for PR feedback and getting it to build on OSX.

@nguerrera - PTAL at how I changed the CMake file to support OSX.

…d TLS methods on OSX.

Adding a decent exception message when SSL methods are not available.

Also responded to PR feedback by using an unsafe code block instead of the whole method being marked as unsafe.
Now that libssl is getting shimmed into System.Security.Cryptography.Native, we need to ensure libssl is initialized properly when libssl shims are getting used.
@eerhardt
Copy link
Copy Markdown
Member Author

@bartonjs, @vijaykota, @shrutigarg - The System.Net.Security.Tests caught an error where it was possible that we tried invoking SSL_CTX_new without first initializing libssl properly. I pushed another commit that fixes this and ensures libssl is initialized.

@nguerrera
Copy link
Copy Markdown
Contributor

I know it was already like this, but it's weird that we have a Interop/Unix/System.Net.Security/ rather than Interop/Unix/libssl. Since this will go away at some point soon with the shimming going quickly, it probably doesn't matter...

Beyond that, would it be better to have all of the SSL shims in an Interop.Ssl class? That would defer libssl initialization until it's definitely needed and also make it easier if we decide to split System.Security.Cryptography.Native along libcrypto/libssl boundaries. I'm finding this extra subtlety of initialization a little confusing to sort out.

@eerhardt
Copy link
Copy Markdown
Member Author

Beyond that, would it be better to have all of the SSL shims in an Interop.Ssl class?

I have contemplated that, but wasn't sure it fit in with the Interop Guidelines.

•Declarations shouldn't be in Interop directly, but rather within a partial, static, internal nested type named for a given library or set of libraries, e.g.

I wasn't sure, so I kept it 'safe' and reused the Crypto class. I think I would prefer splitting the SSL methods out in a separate Interop.Ssl class, and keeping the native shims for interop.Ssl and Interop.Crypto contained in the System.Security.Cryptography.Native library. If people agree on that, I will make the change.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preexisting your change, but especially now that we're using unsafe code, we should consider adding some Debug.Asserts here to validate that we're getting expected inputs for buffer/offset/count.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean:
Debug.Assert(offset + count <= buffer.Length);

Or are there more asserts you had in mind?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, that's the core of what I had in mind, basically the same things that get validated for buffer/offset/count in Stream.Read/Write methods, e.g. https://github.com/dotnet/corefx/blob/master/src/System.IO.UnmanagedMemoryStream/src/System/IO/UnmanagedMemoryStream.cs#L434-L441

@stephentoub
Copy link
Copy Markdown
Member

LGTM

eerhardt added a commit that referenced this pull request Oct 21, 2015
1st shims for the LibSsl library.
@eerhardt eerhardt merged commit bdc6c8f into dotnet:master Oct 21, 2015
@vijaykota
Copy link
Copy Markdown
Contributor

LGTM for the additional changes

@eerhardt eerhardt deleted the ShimLibSsl branch October 28, 2015 15:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants