forked from dotnet/corefx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Lakshmi Priya Sekar
committed
Aug 29, 2017
1 parent
0758534
commit 76548cc
Showing
17 changed files
with
330 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,9 @@ | |
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Runtime.InteropServices; | ||
using System.Text; | ||
using Microsoft.Win32.SafeHandles; | ||
|
||
internal static partial class Interop | ||
|
@@ -12,6 +14,7 @@ internal static partial class Ssl | |
{ | ||
internal delegate int AppVerifyCallback(IntPtr storeCtx, IntPtr arg); | ||
internal delegate int ClientCertCallback(IntPtr ssl, out IntPtr x509, out IntPtr pkey); | ||
internal delegate int SslCtxSetAplnCallback(IntPtr ssl, out IntPtr outp, out byte outlen, IntPtr inp, uint inlen, IntPtr arg); | ||
|
||
[DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslCtxCreate")] | ||
internal static extern SafeSslContextHandle SslCtxCreate(IntPtr method); | ||
|
@@ -24,6 +27,45 @@ internal static partial class Ssl | |
|
||
[DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslCtxSetClientCertCallback")] | ||
internal static extern void SslCtxSetClientCertCallback(IntPtr ctx, ClientCertCallback callback); | ||
|
||
[DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslCtxSetAlpnProtos")] | ||
internal static extern int SslCtxSetAlpnProtos(SafeSslContextHandle ctx, IntPtr protos, int len); | ||
|
||
[DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslCtxSetAplnSelectCb")] | ||
internal static unsafe extern void SslCtxSetAplnSelectCb(SafeSslContextHandle ctx, SslCtxSetAplnCallback callback, IntPtr arg); | ||
|
||
internal static unsafe int SslCtxSetAplnProtos(SafeSslContextHandle ctx, IList<string> protocols) | ||
{ | ||
byte[] buffer = AlpnStringListToByteArray(protocols); | ||
fixed (byte* b = buffer) | ||
{ | ||
return SslCtxSetAlpnProtos(ctx, (IntPtr)b, buffer.Length); | ||
} | ||
} | ||
|
||
internal static byte[] AlpnStringListToByteArray(IList<string> protocols) | ||
{ | ||
int protocolSize = 0; | ||
foreach (string protocol in protocols) | ||
{ | ||
if (string.IsNullOrEmpty(protocol) || protocol.Length > byte.MaxValue) | ||
{ | ||
throw new ArgumentException(SR.net_ssl_app_protocols_invalid, nameof(protocols)); | ||
} | ||
|
||
protocolSize += protocol.Length + 1; | ||
} | ||
|
||
byte[] buffer = new byte[protocolSize]; | ||
var offset = 0; | ||
foreach (string protocol in protocols) | ||
{ | ||
buffer[offset++] = (byte)(protocol.Length); | ||
offset += Encoding.ASCII.GetBytes(protocol, 0, protocol.Length, buffer, offset); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Priya91
Owner
|
||
} | ||
|
||
return buffer; | ||
} | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
There should either be a check here that GCHandle.IsAllocated after you rehydrate and that protocols.Target is a valid value or at minimum a debug.assert. If for whatever reason it is null you will throw a null ref exception from within a native callback which is never nice. Ideally