blob: 7837e95774b0e4da7ddb29b380b1b24368ac23e8 [file] [log] [blame]
Jan Tattermuschb0829eb2015-03-03 09:30:55 -08001#region Copyright notice and license
2
Jan Tattermusch7897ae92017-06-07 22:57:36 +02003// Copyright 2015 gRPC authors.
Jan Tattermuschb0829eb2015-03-03 09:30:55 -08004//
Jan Tattermusch7897ae92017-06-07 22:57:36 +02005// 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
Jan Tattermuschb0829eb2015-03-03 09:30:55 -08008//
Jan Tattermusch7897ae92017-06-07 22:57:36 +02009// http://www.apache.org/licenses/LICENSE-2.0
Jan Tattermuschb0829eb2015-03-03 09:30:55 -080010//
Jan Tattermusch7897ae92017-06-07 22:57:36 +020011// 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.
Jan Tattermuschb0829eb2015-03-03 09:30:55 -080016
17#endregion
18
19using System;
20using System.Collections.Generic;
21using System.Diagnostics;
22using System.IO;
Jan Tattermusch10e85f12016-04-09 13:16:37 -070023using System.Reflection;
Jan Tattermuschb0829eb2015-03-03 09:30:55 -080024using System.Text.RegularExpressions;
25using System.Threading.Tasks;
Jan Tattermuschb0829eb2015-03-03 09:30:55 -080026using Grpc.Core;
27using Grpc.Core.Utils;
28using NUnit.Framework;
Jan Tattermuschb0829eb2015-03-03 09:30:55 -080029
30namespace 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
Jan Tattermuschb3236082016-04-08 17:08:57 -070039 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 }
Jan Tattermuschb0829eb2015-03-03 09:30:55 -080062
Jan Tattermuschbeffc772015-10-22 13:28:22 -070063 public static SslCredentials CreateSslCredentials()
Jan Tattermuschb0829eb2015-03-03 09:30:55 -080064 {
Jan Tattermuschbeffc772015-10-22 13:28:22 -070065 return new SslCredentials(File.ReadAllText(ClientCertAuthorityPath));
Jan Tattermuschb0829eb2015-03-03 09:30:55 -080066 }
67
Jan Tattermuschbeffc772015-10-22 13:28:22 -070068 public static SslServerCredentials CreateSslServerCredentials()
Jan Tattermuschb0829eb2015-03-03 09:30:55 -080069 {
70 var keyCertPair = new KeyCertificatePair(
71 File.ReadAllText(ServerCertChainPath),
72 File.ReadAllText(ServerPrivateKeyPath));
Jan Tattermuscheea59552015-07-23 22:05:32 -070073 return new SslServerCredentials(new[] { keyCertPair });
Jan Tattermuschb0829eb2015-03-03 09:30:55 -080074 }
Jan Tattermuschb3236082016-04-08 17:08:57 -070075
76 private static string GetPath(string relativePath)
77 {
Jan Tattermusch317b8ac2016-06-16 09:36:11 -070078 var assemblyDir = Path.GetDirectoryName(typeof(TestCredentials).GetTypeInfo().Assembly.Location);
Jan Tattermusch10e85f12016-04-09 13:16:37 -070079 return Path.Combine(assemblyDir, relativePath);
Jan Tattermuschb3236082016-04-08 17:08:57 -070080 }
Jan Tattermuschb0829eb2015-03-03 09:30:55 -080081 }
82}