Skip to content

Commit 017da6e

Browse files
authored
Merge pull request #57 from CyberSource/future
Future
2 parents 9532913 + 056bec7 commit 017da6e

32 files changed

+37321
-15059
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ dlldata.c
5959
*.svclog
6060
*.scc
6161

62+
.vs/
63+
6264
# Chutzpah Test files
6365
_Chutzpah*
6466

CyberSource/Base/Logger.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class Logger
1313
{
1414
public enum LogType
1515
{
16-
FILESTART, TRANSTART, CONFIG, REQUEST, REPLY, FAULT, EXCEPTION
16+
FILESTART, TRANSTART, CONFIG, INFO, REQUEST, REPLY, FAULT, EXCEPTION
1717
};
1818

1919
private static Mutex smMutex = new Mutex(false, "CyberSource.Base.Logger");
@@ -184,7 +184,11 @@ public void LogException(Exception e)
184184
e.Message + NEWLINE +
185185
e.StackTrace);
186186
}
187-
187+
188+
public void LogInfo(string logString)
189+
{
190+
Log(LogType.INFO, logString);
191+
}
188192

189193
public void LogException(string logString)
190194
{

CyberSource/Base/Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@
3131
//
3232
// You can specify all the values or you can default the Revision and Build Numbers
3333
// by using the '*' as shown below:
34-
[assembly: AssemblyVersion("1.4.2")]
35-
[assembly: AssemblyFileVersion("1.4.2")]
34+
[assembly: AssemblyVersion("1.4.3")]
35+
[assembly: AssemblyFileVersion("1.4.3")]

CyberSource/Client/BaseClient.cs

+72-13
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
using CyberSource.Base;
22
using System;
3+
using System.Collections;
34
using System.Net;
45
using System.ServiceModel;
56
using System.Xml.Serialization;
67
using System.ServiceModel.Channels;
78
using System.ServiceModel.Security.Tokens;
8-
9+
using System.Security.Cryptography.X509Certificates;
10+
using System.Collections.Concurrent;
11+
912
namespace CyberSource.Clients
1013
{
1114
/// <summary>
@@ -16,7 +19,8 @@ public abstract class BaseClient
1619
/// <summary>
1720
/// Version of this client.
1821
/// </summary>
19-
public const string CLIENT_LIBRARY_VERSION = "1.4.2";
22+
public const string CLIENT_LIBRARY_VERSION = "1.4.3";
23+
public const string CYBS_SUBJECT_NAME = "CyberSource_SJC_US";
2024

2125
/// <summary>
2226
/// Proxy object that is initialized during start-up, if needed.
@@ -43,12 +47,13 @@ public abstract class BaseClient
4347

4448
public const string CYBERSOURCE_PUBLIC_KEY = "CyberSource_SJC_US";
4549
public const string X509_CLAIMTYPE = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/x500distinguishedname";
50+
protected static ConcurrentDictionary<string, CertificateEntry> merchantIdentities = new ConcurrentDictionary<string, CertificateEntry>();
4651

47-
static BaseClient()
48-
{
49-
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072 | (SecurityProtocolType)768;
50-
SetupProxy();
51-
}
52+
static BaseClient()
53+
{
54+
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072 | (SecurityProtocolType)768;
55+
SetupProxy();
56+
}
5257

5358
private static void SetupProxy()
5459
{
@@ -126,14 +131,14 @@ protected static Configuration BuildConfigurationForRequest(
126131
/// </param>
127132
/// <returns>the built Configuration object</returns>
128133
private static Configuration InternalBuildConfiguration(
129-
string merchantID, bool failIfNoMerchantID )
134+
string merchantID, bool failIfNoMerchantID)
130135
{
131-
Configuration config = new Configuration();
132-
136+
Configuration config = new Configuration();
137+
133138
if (merchantID == null)
134139
{
135140
merchantID
136-
= AppSettings.GetSetting( null, MERCHANT_ID );
141+
= AppSettings.GetSetting(null, MERCHANT_ID);
137142
}
138143
if (merchantID != null || failIfNoMerchantID)
139144
{
@@ -168,7 +173,7 @@ int boolVal
168173
config.setLogProperties(
169174
boolVal == 1,
170175
AppSettings.GetSetting(
171-
merchantID, Configuration.LOG_DIRECTORY) );
176+
merchantID, Configuration.LOG_DIRECTORY));
172177

173178
config.ServerURL
174179
= AppSettings.GetSetting(
@@ -222,6 +227,12 @@ int boolVal
222227
merchantID, Configuration.USE_SIGNED_AND_ENCRYPTED);
223228
if (boolVal != -1) config.UseSignedAndEncrypted = (boolVal == 1);
224229

230+
// certificate cache flag
231+
boolVal
232+
= AppSettings.GetBoolSetting(
233+
merchantID, Configuration.CERTIFICATE_CACHE_ENABLED);
234+
if (boolVal != -1) config.CertificateCacheEnabled = (boolVal == 1);
235+
225236
return (config);
226237
}
227238

@@ -285,7 +296,7 @@ protected static string GetXmlElementAttributeNamespace(Type type)
285296
{
286297
if (logger != null)
287298
{
288-
logger.Log(Logger.LogType.CONFIG,"Failed to get Namespace from Service Reference. This should not prevent the client from working: Type=" + type.FullName);
299+
logger.Log(Logger.LogType.CONFIG, "Failed to get Namespace from Service Reference. This should not prevent the client from working: Type=" + type.FullName);
289300
}
290301
return "";
291302
}
@@ -359,6 +370,54 @@ protected static CustomBinding getWCFCustomBinding(Configuration config)
359370
currentBinding.Elements.Add(textBindingElement);
360371
currentBinding.Elements.Add(httpsTransport);
361372
return currentBinding;
373+
}
374+
375+
376+
/// <summary>
377+
///
378+
/// </summary>
379+
/// <param name="merchantId"></param>
380+
/// <param name="merchantIdentities"></param>
381+
/// <returns></returns>
382+
protected static X509Certificate2 GetOrFindValidMerchantCertFromStore(string merchantId, ConcurrentDictionary<string, CertificateEntry> merchantIdentities)
383+
{
384+
return merchantIdentities[merchantId] != null ? merchantIdentities[merchantId].MerchantCert : null;
385+
}
386+
387+
/// <summary>
388+
///
389+
/// </summary>
390+
/// <param name="merchantId"></param>
391+
/// <param name="merchantIdentities"></param>
392+
/// <returns></returns>
393+
protected static X509Certificate2 GetOrFindValidCybsCertFromStore(string merchantId, ConcurrentDictionary<string, CertificateEntry> merchantIdentities)
394+
{
395+
return merchantIdentities[merchantId] != null ? merchantIdentities[merchantId].CybsCert : null;
396+
}
397+
398+
/// <summary>
399+
///
400+
/// </summary>
401+
/// <param name="merchantIdentities"></param>
402+
/// <param name="logger"></param>
403+
/// <param name="merchantId"></param>
404+
/// <param name="creationTime"></param>
405+
/// <returns></returns>
406+
public static bool IsMerchantCertExpired(Logger logger, string merchantId, DateTime modifiedTime, ConcurrentDictionary<string, CertificateEntry> merchantIdentities)
407+
{
408+
if (merchantIdentities[merchantId] != null)
409+
{
410+
if (merchantIdentities[merchantId].ModifiedTime != modifiedTime)
411+
{
412+
if (logger != null)
413+
{
414+
logger.LogInfo("certificate is expired, will be loaded again in memory for merchantID: " + merchantId);
415+
}
416+
return true;
417+
}
418+
419+
}
420+
return false;
362421
}
363422
}
364423
}
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Configuration;
3+
using System.Security.Cryptography.X509Certificates;
4+
5+
namespace CyberSource.Clients
6+
{
7+
/// <summary>
8+
/// Encapsulates retrieval of application settings. You can modify
9+
/// this code to suit your needs.
10+
/// </summary>
11+
public class CertificateEntry
12+
{
13+
public DateTime ModifiedTime { get; set; }
14+
public X509Certificate2 MerchantCert { get; set; }
15+
public X509Certificate2 CybsCert { get; set; }
16+
}
17+
}

CyberSource/Client/Configuration.cs

+12
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public class Configuration
2828
internal const string SEND_TO_AKAMAI = "sendToAkamai";
2929
internal const string EFFECTIVE_SERVER_URL = "effectiveServerURL";
3030
internal const string USE_SIGNED_AND_ENCRYPTED = "useSignAndEncrypted";
31+
internal const string CERTIFICATE_CACHE_ENABLED = "certificateCacheEnabled";
3132

3233
/// <summary>
3334
/// Default log file name.
@@ -70,6 +71,7 @@ public class Configuration
7071
private bool sendToAkamai = true;
7172
private int connectionLimit = -1;
7273
private bool useSignedAndEncrypted = false;
74+
private bool certificateCacheEnabled = true;
7375

7476
private bool isSendToProductionSet = false;
7577

@@ -338,6 +340,10 @@ public string LogString
338340
buf += NVP_SEPARATOR + EFFECTIVE_SERVER_URL + NV_SEPARATOR + EffectiveServerURL;
339341
}
340342

343+
buf += NVP_SEPARATOR + CERTIFICATE_CACHE_ENABLED + NV_SEPARATOR + certificateCacheEnabled;
344+
345+
buf += NVP_SEPARATOR + USE_SIGNED_AND_ENCRYPTED + NV_SEPARATOR + useSignedAndEncrypted;
346+
341347
return (buf);
342348
}
343349
}
@@ -414,5 +420,11 @@ public bool UseSignedAndEncrypted
414420
get { return useSignedAndEncrypted; }
415421
set { useSignedAndEncrypted = value; }
416422
}
423+
424+
public bool CertificateCacheEnabled
425+
{
426+
get { return certificateCacheEnabled; }
427+
set { certificateCacheEnabled = value; }
428+
}
417429
}
418430
}

CyberSource/Client/CyberSourceClients.csproj

+7-6
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
<Compile Include="Settings.cs" />
128128
<Compile Include="SoapClient.cs" />
129129
<Compile Include="XmlClient.cs" />
130+
<Compile Include="CertificateEntry.cs" />
130131
</ItemGroup>
131132
<ItemGroup>
132133
<None Include="app.config" />
@@ -166,6 +167,12 @@
166167
<WCFMetadataStorage Include="Service References\NVPServiceReference\" />
167168
<WCFMetadataStorage Include="Service References\SoapServiceReference\" />
168169
</ItemGroup>
170+
<ItemGroup>
171+
<ProjectReference Include="..\Base\CyberSourceBase.csproj">
172+
<Project>{6ec4a1fb-44ce-4326-92a5-88a1ecc615bd}</Project>
173+
<Name>CyberSourceBase</Name>
174+
</ProjectReference>
175+
</ItemGroup>
169176
<ItemGroup>
170177
<None Include="Service References\NVPServiceReference\configuration91.svcinfo" />
171178
</ItemGroup>
@@ -190,12 +197,6 @@
190197
<LastGenOutput>Reference.cs</LastGenOutput>
191198
</None>
192199
</ItemGroup>
193-
<ItemGroup>
194-
<ProjectReference Include="..\Base\CyberSourceBase.csproj">
195-
<Project>{6ec4a1fb-44ce-4326-92a5-88a1ecc615bd}</Project>
196-
<Name>CyberSourceBase</Name>
197-
</ProjectReference>
198-
</ItemGroup>
199200
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
200201
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
201202
Other similar extension points exist, see Microsoft.Common.targets.

0 commit comments

Comments
 (0)