Index: third_party/grpc/src/csharp/Grpc.Core/Internal/DefaultSslRootsOverride.cs |
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/DescriptorUtil.cs b/third_party/grpc/src/csharp/Grpc.Core/Internal/DefaultSslRootsOverride.cs |
similarity index 57% |
copy from third_party/protobuf/csharp/src/Google.Protobuf/Reflection/DescriptorUtil.cs |
copy to third_party/grpc/src/csharp/Grpc.Core/Internal/DefaultSslRootsOverride.cs |
index f5570fc40a24f9e91017280b4f6389607be6e1a7..dfaee5d9d7cd207d52a28e2c4f2795bf82459402 100644 |
--- a/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/DescriptorUtil.cs |
+++ b/third_party/grpc/src/csharp/Grpc.Core/Internal/DefaultSslRootsOverride.cs |
@@ -1,7 +1,7 @@ |
#region Copyright notice and license |
-// Protocol Buffers - Google's data interchange format |
-// Copyright 2008 Google Inc. All rights reserved. |
-// https://developers.google.com/protocol-buffers/ |
+ |
+// Copyright 2015-2016, Google Inc. |
+// All rights reserved. |
// |
// Redistribution and use in source and binary forms, with or without |
// modification, are permitted provided that the following conditions are |
@@ -28,37 +28,45 @@ |
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+ |
#endregion |
-using System.Collections.Generic; |
-using System.Collections.ObjectModel; |
+using System; |
+using System.Collections.Concurrent; |
+using System.Diagnostics; |
+using System.IO; |
+using System.Reflection; |
+using System.Runtime.InteropServices; |
+using System.Threading; |
-namespace Google.Protobuf.Reflection |
+namespace Grpc.Core.Internal |
{ |
/// <summary> |
- /// Internal class containing utility methods when working with descriptors. |
+ /// Overrides the content of default SSL roots. |
/// </summary> |
- internal static class DescriptorUtil |
+ internal static class DefaultSslRootsOverride |
{ |
- /// <summary> |
- /// Equivalent to Func[TInput, int, TOutput] but usable in .NET 2.0. Only used to convert |
- /// arrays. |
- /// </summary> |
- internal delegate TOutput IndexedConverter<TInput, TOutput>(TInput element, int index); |
+ const string RootsPemResourceName = "Grpc.Core.Resources.roots.pem"; |
+ static object staticLock = new object(); |
/// <summary> |
- /// Converts the given array into a read-only list, applying the specified conversion to |
- /// each input element. |
+ /// Overrides C core's default roots with roots.pem loaded as embedded resource. |
/// </summary> |
- internal static IList<TOutput> ConvertAndMakeReadOnly<TInput, TOutput> |
- (IList<TInput> input, IndexedConverter<TInput, TOutput> converter) |
+ public static void Override(NativeMethods native) |
{ |
- TOutput[] array = new TOutput[input.Count]; |
- for (int i = 0; i < array.Length; i++) |
+ lock (staticLock) |
{ |
- array[i] = converter(input[i], i); |
+ var stream = typeof(DefaultSslRootsOverride).GetTypeInfo().Assembly.GetManifestResourceStream(RootsPemResourceName); |
+ if (stream == null) |
+ { |
+ throw new IOException(string.Format("Error loading the embedded resource \"{0}\"", RootsPemResourceName)); |
+ } |
+ using (var streamReader = new StreamReader(stream)) |
+ { |
+ var pemRootCerts = streamReader.ReadToEnd(); |
+ native.grpcsharp_override_default_ssl_roots(pemRootCerts); |
+ } |
} |
- return new ReadOnlyCollection<TOutput>(array); |
} |
} |
-} |
+} |