Skip to content

Commit 37d1d17

Browse files
Sep release (#64)
* network Tokenization changes * added caching * removed parenthesis from request target * sep-release * version update
1 parent ba94022 commit 37d1d17

File tree

328 files changed

+11134
-4562
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

328 files changed

+11134
-4562
lines changed

cybersource-rest-auth-netstandard/AuthenticationSdk/AuthenticationSdk/AuthenticationSdk.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<TargetFramework>netstandard2.1</TargetFramework>
55
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
6-
<Version>0.0.1.10</Version>
6+
<Version>0.0.1.11</Version>
77
<Authors>CyberSource</Authors>
88
<Product>Authentication_SDK</Product>
99
<Description />
@@ -37,6 +37,7 @@
3737
<ItemGroup>
3838
<PackageReference Include="jose-jwt" Version="2.5.0" />
3939
<PackageReference Include="NLog" Version="4.7.4" />
40+
<PackageReference Include="Portable.BouncyCastle" Version="1.9.0" />
4041
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.7.0" />
4142
<PackageReference Include="System.Runtime.Caching" Version="4.7.0" />
4243
</ItemGroup>

cybersource-rest-auth-netstandard/AuthenticationSdk/AuthenticationSdk/authentication/http/HttpTokenGenerator.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ private string SignatureForCategory1()
4444
{
4545
var signatureString = new StringBuilder();
4646
var signatureHeaderValue = new StringBuilder();
47-
const string getOrDeleteHeaders = "host date (request-target) v-c-merchant-id";
47+
const string getOrDeleteHeaders = "host date request-target v-c-merchant-id";
4848

4949
signatureString.Append($"\nhost: {_httpToken.HostName}")
5050
.Append($"\ndate: {_httpToken.GmtDateTime}")
51-
.Append($"\n(request-target): {_httpToken.HttpSignRequestTarget}")
51+
.Append($"\nrequest-target: {_httpToken.HttpSignRequestTarget}")
5252
.Append($"\nv-c-merchant-id: ");
5353

5454
if (_httpToken.UseMetaKey == true)
@@ -81,11 +81,11 @@ private string SignatureForCategory2()
8181
var signatureString = new StringBuilder();
8282
var signatureHeaderValue = new StringBuilder();
8383
_httpToken.Digest = GenerateDigest();
84-
const string postOrPutHeaders = "host date (request-target) digest v-c-merchant-id";
84+
const string postOrPutHeaders = "host date request-target digest v-c-merchant-id";
8585

8686
signatureString.Append($"\nhost: {_httpToken.HostName}")
8787
.Append($"\ndate: {_httpToken.GmtDateTime}")
88-
.Append($"\n(request-target): {_httpToken.HttpSignRequestTarget}")
88+
.Append($"\nrequest-target: {_httpToken.HttpSignRequestTarget}")
8989
.Append($"\ndigest: {_httpToken.Digest}")
9090
.Append($"\nv-c-merchant-id: ");
9191

cybersource-rest-auth-netstandard/AuthenticationSdk/AuthenticationSdk/core/MerchantConfig.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ public MerchantConfig(IReadOnlyDictionary<string, string> merchantConfigDictiona
158158

159159
public bool IsOAuthTokenAuthType { get; set; }
160160

161+
public string PemFileDirectory { get; set; }
162+
161163
#endregion
162164

163165
public void LogMerchantConfigurationProperties()
@@ -217,6 +219,7 @@ private void SetValuesFromAppConfig(NameValueCollection merchantConfigSection)
217219
ProxyPort = merchantConfigSection["proxyPort"];
218220
ProxyUsername = merchantConfigSection["proxyUsername"];
219221
ProxyPassword = merchantConfigSection["proxyPassword"];
222+
PemFileDirectory = merchantConfigSection["pemFileDirectory"];
220223
}
221224

222225
private void SetValuesUsingDictObj(IReadOnlyDictionary<string, string> merchantConfigDictionary)
@@ -417,6 +420,11 @@ private void SetValuesUsingDictObj(IReadOnlyDictionary<string, string> merchantC
417420
{
418421
ProxyPassword = merchantConfigDictionary["proxyPassword"];
419422
}
423+
424+
if (merchantConfigDictionary.ContainsKey("pemFileDirectory"))
425+
{
426+
PemFileDirectory = merchantConfigDictionary["pemFileDirectory"];
427+
}
420428
}
421429
}
422430
catch (KeyNotFoundException err)

cybersource-rest-auth-netstandard/AuthenticationSdk/AuthenticationSdk/util/Cache.cs

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
using System;
1+
using AuthenticationSdk.core;
2+
using Org.BouncyCastle.Crypto.Parameters;
3+
using Org.BouncyCastle.Crypto;
4+
using Org.BouncyCastle.Security;
5+
using Org.BouncyCastle.OpenSsl;
6+
using System;
27
using System.Collections.Generic;
38
using System.IO;
49
using System.Runtime.Caching;
@@ -15,6 +20,10 @@ public static class Cache
1520
/// </summary>
1621
private static readonly object mutex = new object();
1722

23+
private static readonly object mutexForPrivateKeyFromPEM = new object();
24+
25+
private static readonly string regexForFileNameFromDirectory = "(^([a-z]|[A-Z]):(?=\\\\(?![\\0-\\37<>:\"/\\\\|?*])|\\/(?![\\0-\\37<>:\"/\\\\|?*])|$)|^\\\\(?=[\\\\\\/][^\\0-\\37<>:\"/\\\\|?*]+)|^(?=(\\\\|\\/)$)|^\\.(?=(\\\\|\\/)$)|^\\.\\.(?=(\\\\|\\/)$)|^(?=(\\\\|\\/)[^\\0-\\37<>:\"/\\\\|?*]+)|^\\.(?=(\\\\|\\/)[^\\0-\\37<>:\"/\\\\|?*]+)|^\\.\\.(?=(\\\\|\\/)[^\\0-\\37<>:\"/\\\\|?*]+))((\\\\|\\/)([^\\0-\\37<>:\"/\\\\|?*]+|(\\\\|\\/)$))*()$";
26+
1827
public static X509Certificate2 FetchCachedCertificate(string p12FilePath, string keyPassword)
1928
{
2029
try
@@ -23,11 +32,7 @@ public static X509Certificate2 FetchCachedCertificate(string p12FilePath, string
2332
{
2433
ObjectCache cache = MemoryCache.Default;
2534

26-
// (^([a-z]|[A-Z]):(?=\\(?![\0-\37<>:"/\\|?*])|\/(?![\0-\37<>:"/\\|?*])|$)|^\\(?=[\\\/][^\0-\37<>:"/\\|?*]+)|^(?=(\\|\/)$)|^\.(?=(\\|\/)$)|^\.\.(?=(\\|\/)$)|^(?=(\\|\/)[^\0-\37<>:"/\\|?*]+)|^\.(?=(\\|\/)[^\0-\37<>:"/\\|?*]+)|^\.\.(?=(\\|\/)[^\0-\37<>:"/\\|?*]+))((\\|\/)[^\0-\37<>:"/\\|?*]+|(\\|\/)$)*()$
27-
28-
var pattern = "(^([a-z]|[A-Z]):(?=\\\\(?![\\0-\\37<>:\"/\\\\|?*])|\\/(?![\\0-\\37<>:\"/\\\\|?*])|$)|^\\\\(?=[\\\\\\/][^\\0-\\37<>:\"/\\\\|?*]+)|^(?=(\\\\|\\/)$)|^\\.(?=(\\\\|\\/)$)|^\\.\\.(?=(\\\\|\\/)$)|^(?=(\\\\|\\/)[^\\0-\\37<>:\"/\\\\|?*]+)|^\\.(?=(\\\\|\\/)[^\\0-\\37<>:\"/\\\\|?*]+)|^\\.\\.(?=(\\\\|\\/)[^\\0-\\37<>:\"/\\\\|?*]+))((\\\\|\\/)([^\\0-\\37<>:\"/\\\\|?*]+|(\\\\|\\/)$))*()$";
29-
30-
var matches = Regex.Match(p12FilePath, pattern);
35+
var matches = Regex.Match(p12FilePath, regexForFileNameFromDirectory);
3136
var certFile = matches.Groups[11].ToString();
3237

3338
if (!cache.Contains(certFile))
@@ -62,5 +67,34 @@ public static X509Certificate2 FetchCachedCertificate(string p12FilePath, string
6267
throw e;
6368
}
6469
}
70+
71+
public static RSAParameters FetchCachedRSAParameters(MerchantConfig merchantConfig)
72+
{
73+
lock (mutexForPrivateKeyFromPEM)
74+
{
75+
var pemFilePath = merchantConfig.PemFileDirectory;
76+
ObjectCache cache = MemoryCache.Default;
77+
78+
var matches = Regex.Match(merchantConfig.PemFileDirectory, regexForFileNameFromDirectory);
79+
var certFile = matches.Groups[11].ToString();
80+
81+
if (!cache.Contains(certFile))
82+
{
83+
var policy = new CacheItemPolicy();
84+
var filePaths = new List<string>();
85+
var privateKey = File.ReadAllText(merchantConfig.PemFileDirectory);
86+
var cachedFilePath = Path.GetFullPath(pemFilePath);
87+
filePaths.Add(cachedFilePath);
88+
policy.ChangeMonitors.Add(new HostFileChangeMonitor(filePaths));
89+
90+
PemReader pemReader = new PemReader(new StringReader(privateKey));
91+
AsymmetricCipherKeyPair keyPair = (AsymmetricCipherKeyPair)pemReader.ReadObject();
92+
RSAParameters rsaParams = DotNetUtilities.ToRSAParameters((RsaPrivateCrtKeyParameters)keyPair.Private);
93+
94+
cache.Set(certFile, rsaParams, policy);
95+
}
96+
return (RSAParameters)cache[certFile];
97+
}
98+
}
6599
}
66100
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using Jose;
2+
using Org.BouncyCastle.Crypto;
3+
using Org.BouncyCastle.Crypto.Parameters;
4+
using Org.BouncyCastle.OpenSsl;
5+
using Org.BouncyCastle.Security;
6+
using System.IO;
7+
using System.Security.Cryptography;
8+
using AuthenticationSdk.core;
9+
10+
namespace AuthenticationSdk.util
11+
{
12+
public static class JWEUtilty
13+
{
14+
private static string LoadKeyFromFile(string path)
15+
{
16+
return File.ReadAllText(path);
17+
}
18+
19+
public static string DecryptUsingPEM(MerchantConfig merchantConfig, string encodedData)
20+
{
21+
var privateKey = LoadKeyFromFile(merchantConfig.PemFileDirectory);
22+
PemReader pemReader = new PemReader(new StringReader(privateKey));
23+
AsymmetricCipherKeyPair keyPair = (AsymmetricCipherKeyPair)pemReader.ReadObject();
24+
RSAParameters rsaParams = DotNetUtilities.ToRSAParameters((RsaPrivateCrtKeyParameters)keyPair.Private);
25+
var rsa = RSA.Create();
26+
rsa.ImportParameters(rsaParams);
27+
return JWT.Decode(encodedData, rsa, JweAlgorithm.RSA_OAEP_256, JweEncryption.A256GCM);
28+
}
29+
}
30+
}

cybersource-rest-client-netstandard/cybersource-rest-client-netstandard.Test/Api/BatchesApiTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void GetBatchReportTest()
7373
// TODO uncomment below to test the method and replace null with proper value
7474
//string batchId = null;
7575
//var response = instance.GetBatchReport(batchId);
76-
//Assert.IsInstanceOf<InlineResponse20014> (response, "response is InlineResponse20014");
76+
//Assert.IsInstanceOf<InlineResponse2004> (response, "response is InlineResponse2004");
7777
}
7878

7979
/// <summary>
@@ -85,7 +85,7 @@ public void GetBatchStatusTest()
8585
// TODO uncomment below to test the method and replace null with proper value
8686
//string batchId = null;
8787
//var response = instance.GetBatchStatus(batchId);
88-
//Assert.IsInstanceOf<InlineResponse20013> (response, "response is InlineResponse20013");
88+
//Assert.IsInstanceOf<InlineResponse2003> (response, "response is InlineResponse2003");
8989
}
9090

9191
/// <summary>
@@ -100,7 +100,7 @@ public void GetBatchesListTest()
100100
//string fromDate = null;
101101
//string toDate = null;
102102
//var response = instance.GetBatchesList(offset, limit, fromDate, toDate);
103-
//Assert.IsInstanceOf<InlineResponse20012> (response, "response is InlineResponse20012");
103+
//Assert.IsInstanceOf<InlineResponse2002> (response, "response is InlineResponse2002");
104104
}
105105

106106
/// <summary>
@@ -112,7 +112,7 @@ public void PostBatchTest()
112112
// TODO uncomment below to test the method and replace null with proper value
113113
//Body body = null;
114114
//var response = instance.PostBatch(body);
115-
//Assert.IsInstanceOf<InlineResponse2022> (response, "response is InlineResponse2022");
115+
//Assert.IsInstanceOf<InlineResponse202> (response, "response is InlineResponse202");
116116
}
117117

118118
}

cybersource-rest-client-netstandard/cybersource-rest-client-netstandard.Test/Api/DecisionManagerApiTests.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,19 @@ public void InstanceTest()
6464
}
6565

6666

67+
/// <summary>
68+
/// Test ActionDecisionManagerCase
69+
/// </summary>
70+
[Test]
71+
public void ActionDecisionManagerCaseTest()
72+
{
73+
// TODO uncomment below to test the method and replace null with proper value
74+
//string id = null;
75+
//CaseManagementActionsRequest caseManagementActionsRequest = null;
76+
//var response = instance.ActionDecisionManagerCase(id, caseManagementActionsRequest);
77+
//Assert.IsInstanceOf<InlineResponse200> (response, "response is InlineResponse200");
78+
}
79+
6780
/// <summary>
6881
/// Test AddNegative
6982
/// </summary>
@@ -77,6 +90,19 @@ public void AddNegativeTest()
7790
//Assert.IsInstanceOf<RiskV1UpdatePost201Response> (response, "response is RiskV1UpdatePost201Response");
7891
}
7992

93+
/// <summary>
94+
/// Test CommentDecisionManagerCase
95+
/// </summary>
96+
[Test]
97+
public void CommentDecisionManagerCaseTest()
98+
{
99+
// TODO uncomment below to test the method and replace null with proper value
100+
//string id = null;
101+
//CaseManagementCommentsRequest caseManagementCommentsRequest = null;
102+
//var response = instance.CommentDecisionManagerCase(id, caseManagementCommentsRequest);
103+
//Assert.IsInstanceOf<InlineResponse201> (response, "response is InlineResponse201");
104+
}
105+
80106
/// <summary>
81107
/// Test CreateBundledDecisionManagerCase
82108
/// </summary>

cybersource-rest-client-netstandard/cybersource-rest-client-netstandard.Test/Api/KeymanagementApiTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void SearchKeysTest()
8080
//DateTime? expirationStartDate = null;
8181
//DateTime? expirationEndDate = null;
8282
//var response = instance.SearchKeys(offset, limit, sort, organizationIds, keyIds, keyTypes, expirationStartDate, expirationEndDate);
83-
//Assert.IsInstanceOf<InlineResponse20011> (response, "response is InlineResponse20011");
83+
//Assert.IsInstanceOf<InlineResponse2001> (response, "response is InlineResponse2001");
8484
}
8585

8686
}

cybersource-rest-client-netstandard/cybersource-rest-client-netstandard.Test/Api/PlansApiTests.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void ActivatePlanTest()
7373
// TODO uncomment below to test the method and replace null with proper value
7474
//string id = null;
7575
//var response = instance.ActivatePlan(id);
76-
//Assert.IsInstanceOf<InlineResponse2004> (response, "response is InlineResponse2004");
76+
//Assert.IsInstanceOf<ActivateDeactivatePlanResponse> (response, "response is ActivateDeactivatePlanResponse");
7777
}
7878

7979
/// <summary>
@@ -85,7 +85,7 @@ public void CreatePlanTest()
8585
// TODO uncomment below to test the method and replace null with proper value
8686
//CreatePlanRequest createPlanRequest = null;
8787
//var response = instance.CreatePlan(createPlanRequest);
88-
//Assert.IsInstanceOf<InlineResponse201> (response, "response is InlineResponse201");
88+
//Assert.IsInstanceOf<CreatePlanResponse> (response, "response is CreatePlanResponse");
8989
}
9090

9191
/// <summary>
@@ -97,7 +97,7 @@ public void DeactivatePlanTest()
9797
// TODO uncomment below to test the method and replace null with proper value
9898
//string id = null;
9999
//var response = instance.DeactivatePlan(id);
100-
//Assert.IsInstanceOf<InlineResponse2004> (response, "response is InlineResponse2004");
100+
//Assert.IsInstanceOf<ActivateDeactivatePlanResponse> (response, "response is ActivateDeactivatePlanResponse");
101101
}
102102

103103
/// <summary>
@@ -109,7 +109,7 @@ public void DeletePlanTest()
109109
// TODO uncomment below to test the method and replace null with proper value
110110
//string id = null;
111111
//var response = instance.DeletePlan(id);
112-
//Assert.IsInstanceOf<InlineResponse2002> (response, "response is InlineResponse2002");
112+
//Assert.IsInstanceOf<DeletePlanResponse> (response, "response is DeletePlanResponse");
113113
}
114114

115115
/// <summary>
@@ -121,7 +121,7 @@ public void GetPlanTest()
121121
// TODO uncomment below to test the method and replace null with proper value
122122
//string id = null;
123123
//var response = instance.GetPlan(id);
124-
//Assert.IsInstanceOf<InlineResponse2001> (response, "response is InlineResponse2001");
124+
//Assert.IsInstanceOf<GetPlanResponse> (response, "response is GetPlanResponse");
125125
}
126126

127127
/// <summary>
@@ -132,7 +132,7 @@ public void GetPlanCodeTest()
132132
{
133133
// TODO uncomment below to test the method and replace null with proper value
134134
//var response = instance.GetPlanCode();
135-
//Assert.IsInstanceOf<InlineResponse2005> (response, "response is InlineResponse2005");
135+
//Assert.IsInstanceOf<GetPlanCodeResponse> (response, "response is GetPlanCodeResponse");
136136
}
137137

138138
/// <summary>
@@ -148,7 +148,7 @@ public void GetPlansTest()
148148
//string status = null;
149149
//string name = null;
150150
//var response = instance.GetPlans(offset, limit, code, status, name);
151-
//Assert.IsInstanceOf<InlineResponse200> (response, "response is InlineResponse200");
151+
//Assert.IsInstanceOf<GetAllPlansResponse> (response, "response is GetAllPlansResponse");
152152
}
153153

154154
/// <summary>
@@ -161,7 +161,7 @@ public void UpdatePlanTest()
161161
//string id = null;
162162
//UpdatePlanRequest updatePlanRequest = null;
163163
//var response = instance.UpdatePlan(id, updatePlanRequest);
164-
//Assert.IsInstanceOf<InlineResponse2003> (response, "response is InlineResponse2003");
164+
//Assert.IsInstanceOf<UpdatePlanResponse> (response, "response is UpdatePlanResponse");
165165
}
166166

167167
}

0 commit comments

Comments
 (0)