• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #region Copyright notice and license
2 
3 // Copyright 2015 gRPC authors.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #endregion
18 
19 using System;
20 using System.Collections.Generic;
21 using System.Diagnostics;
22 using System.IO;
23 using System.Reflection;
24 using System.Text.RegularExpressions;
25 using System.Threading.Tasks;
26 using Grpc.Core;
27 using Grpc.Core.Utils;
28 using NUnit.Framework;
29 
30 namespace Grpc.IntegrationTesting
31 {
32     /// <summary>
33     /// SSL Credentials for testing.
34     /// </summary>
35     public static class TestCredentials
36     {
37         public const string DefaultHostOverride = "foo.test.google.fr";
38 
39         public static string ClientCertAuthorityPath
40         {
41             get
42             {
43                 return GetPath("data/ca.pem");
44             }
45         }
46 
47         public static string ServerCertChainPath
48         {
49             get
50             {
51                 return GetPath("data/server1.pem");
52             }
53         }
54 
55         public static string ServerPrivateKeyPath
56         {
57             get
58             {
59                 return GetPath("data/server1.key");
60             }
61         }
62 
CreateSslCredentials()63         public static SslCredentials CreateSslCredentials()
64         {
65             return new SslCredentials(File.ReadAllText(ClientCertAuthorityPath));
66         }
67 
CreateSslServerCredentials()68         public static SslServerCredentials CreateSslServerCredentials()
69         {
70             var keyCertPair = new KeyCertificatePair(
71                 File.ReadAllText(ServerCertChainPath),
72                 File.ReadAllText(ServerPrivateKeyPath));
73             return new SslServerCredentials(new[] { keyCertPair });
74         }
75 
GetPath(string relativePath)76         private static string GetPath(string relativePath)
77         {
78             var assemblyDir = Path.GetDirectoryName(typeof(TestCredentials).GetTypeInfo().Assembly.Location);
79             return Path.Combine(assemblyDir, relativePath);
80         }
81     }
82 }
83