Skip to content

Commit

Permalink
Merge pull request #57 from CyberSource/future
Browse files Browse the repository at this point in the history
Future
  • Loading branch information
mahendya1002 authored Jul 2, 2020
2 parents 9532913 + 056bec7 commit 017da6e
Show file tree
Hide file tree
Showing 32 changed files with 37,321 additions and 15,059 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ dlldata.c
*.svclog
*.scc

.vs/

# Chutzpah Test files
_Chutzpah*

Expand Down
8 changes: 6 additions & 2 deletions CyberSource/Base/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class Logger
{
public enum LogType
{
FILESTART, TRANSTART, CONFIG, REQUEST, REPLY, FAULT, EXCEPTION
FILESTART, TRANSTART, CONFIG, INFO, REQUEST, REPLY, FAULT, EXCEPTION
};

private static Mutex smMutex = new Mutex(false, "CyberSource.Base.Logger");
Expand Down Expand Up @@ -184,7 +184,11 @@ public void LogException(Exception e)
e.Message + NEWLINE +
e.StackTrace);
}


public void LogInfo(string logString)
{
Log(LogType.INFO, logString);
}

public void LogException(string logString)
{
Expand Down
4 changes: 2 additions & 2 deletions CyberSource/Base/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.4.2")]
[assembly: AssemblyFileVersion("1.4.2")]
[assembly: AssemblyVersion("1.4.3")]
[assembly: AssemblyFileVersion("1.4.3")]
85 changes: 72 additions & 13 deletions CyberSource/Client/BaseClient.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
using CyberSource.Base;
using System;
using System.Collections;
using System.Net;
using System.ServiceModel;
using System.Xml.Serialization;
using System.ServiceModel.Channels;
using System.ServiceModel.Security.Tokens;

using System.Security.Cryptography.X509Certificates;
using System.Collections.Concurrent;

namespace CyberSource.Clients
{
/// <summary>
Expand All @@ -16,7 +19,8 @@ public abstract class BaseClient
/// <summary>
/// Version of this client.
/// </summary>
public const string CLIENT_LIBRARY_VERSION = "1.4.2";
public const string CLIENT_LIBRARY_VERSION = "1.4.3";
public const string CYBS_SUBJECT_NAME = "CyberSource_SJC_US";

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

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

static BaseClient()
{
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072 | (SecurityProtocolType)768;
SetupProxy();
}
static BaseClient()
{
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072 | (SecurityProtocolType)768;
SetupProxy();
}

private static void SetupProxy()
{
Expand Down Expand Up @@ -126,14 +131,14 @@ protected static Configuration BuildConfigurationForRequest(
/// </param>
/// <returns>the built Configuration object</returns>
private static Configuration InternalBuildConfiguration(
string merchantID, bool failIfNoMerchantID )
string merchantID, bool failIfNoMerchantID)
{
Configuration config = new Configuration();
Configuration config = new Configuration();

if (merchantID == null)
{
merchantID
= AppSettings.GetSetting( null, MERCHANT_ID );
= AppSettings.GetSetting(null, MERCHANT_ID);
}
if (merchantID != null || failIfNoMerchantID)
{
Expand Down Expand Up @@ -168,7 +173,7 @@ int boolVal
config.setLogProperties(
boolVal == 1,
AppSettings.GetSetting(
merchantID, Configuration.LOG_DIRECTORY) );
merchantID, Configuration.LOG_DIRECTORY));

config.ServerURL
= AppSettings.GetSetting(
Expand Down Expand Up @@ -222,6 +227,12 @@ int boolVal
merchantID, Configuration.USE_SIGNED_AND_ENCRYPTED);
if (boolVal != -1) config.UseSignedAndEncrypted = (boolVal == 1);

// certificate cache flag
boolVal
= AppSettings.GetBoolSetting(
merchantID, Configuration.CERTIFICATE_CACHE_ENABLED);
if (boolVal != -1) config.CertificateCacheEnabled = (boolVal == 1);

return (config);
}

Expand Down Expand Up @@ -285,7 +296,7 @@ protected static string GetXmlElementAttributeNamespace(Type type)
{
if (logger != null)
{
logger.Log(Logger.LogType.CONFIG,"Failed to get Namespace from Service Reference. This should not prevent the client from working: Type=" + type.FullName);
logger.Log(Logger.LogType.CONFIG, "Failed to get Namespace from Service Reference. This should not prevent the client from working: Type=" + type.FullName);
}
return "";
}
Expand Down Expand Up @@ -359,6 +370,54 @@ protected static CustomBinding getWCFCustomBinding(Configuration config)
currentBinding.Elements.Add(textBindingElement);
currentBinding.Elements.Add(httpsTransport);
return currentBinding;
}


/// <summary>
///
/// </summary>
/// <param name="merchantId"></param>
/// <param name="merchantIdentities"></param>
/// <returns></returns>
protected static X509Certificate2 GetOrFindValidMerchantCertFromStore(string merchantId, ConcurrentDictionary<string, CertificateEntry> merchantIdentities)
{
return merchantIdentities[merchantId] != null ? merchantIdentities[merchantId].MerchantCert : null;
}

/// <summary>
///
/// </summary>
/// <param name="merchantId"></param>
/// <param name="merchantIdentities"></param>
/// <returns></returns>
protected static X509Certificate2 GetOrFindValidCybsCertFromStore(string merchantId, ConcurrentDictionary<string, CertificateEntry> merchantIdentities)
{
return merchantIdentities[merchantId] != null ? merchantIdentities[merchantId].CybsCert : null;
}

/// <summary>
///
/// </summary>
/// <param name="merchantIdentities"></param>
/// <param name="logger"></param>
/// <param name="merchantId"></param>
/// <param name="creationTime"></param>
/// <returns></returns>
public static bool IsMerchantCertExpired(Logger logger, string merchantId, DateTime modifiedTime, ConcurrentDictionary<string, CertificateEntry> merchantIdentities)
{
if (merchantIdentities[merchantId] != null)
{
if (merchantIdentities[merchantId].ModifiedTime != modifiedTime)
{
if (logger != null)
{
logger.LogInfo("certificate is expired, will be loaded again in memory for merchantID: " + merchantId);
}
return true;
}

}
return false;
}
}
}
17 changes: 17 additions & 0 deletions CyberSource/Client/CertificateEntry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Configuration;
using System.Security.Cryptography.X509Certificates;

namespace CyberSource.Clients
{
/// <summary>
/// Encapsulates retrieval of application settings. You can modify
/// this code to suit your needs.
/// </summary>
public class CertificateEntry
{
public DateTime ModifiedTime { get; set; }
public X509Certificate2 MerchantCert { get; set; }
public X509Certificate2 CybsCert { get; set; }
}
}
12 changes: 12 additions & 0 deletions CyberSource/Client/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class Configuration
internal const string SEND_TO_AKAMAI = "sendToAkamai";
internal const string EFFECTIVE_SERVER_URL = "effectiveServerURL";
internal const string USE_SIGNED_AND_ENCRYPTED = "useSignAndEncrypted";
internal const string CERTIFICATE_CACHE_ENABLED = "certificateCacheEnabled";

/// <summary>
/// Default log file name.
Expand Down Expand Up @@ -70,6 +71,7 @@ public class Configuration
private bool sendToAkamai = true;
private int connectionLimit = -1;
private bool useSignedAndEncrypted = false;
private bool certificateCacheEnabled = true;

private bool isSendToProductionSet = false;

Expand Down Expand Up @@ -338,6 +340,10 @@ public string LogString
buf += NVP_SEPARATOR + EFFECTIVE_SERVER_URL + NV_SEPARATOR + EffectiveServerURL;
}

buf += NVP_SEPARATOR + CERTIFICATE_CACHE_ENABLED + NV_SEPARATOR + certificateCacheEnabled;

buf += NVP_SEPARATOR + USE_SIGNED_AND_ENCRYPTED + NV_SEPARATOR + useSignedAndEncrypted;

return (buf);
}
}
Expand Down Expand Up @@ -414,5 +420,11 @@ public bool UseSignedAndEncrypted
get { return useSignedAndEncrypted; }
set { useSignedAndEncrypted = value; }
}

public bool CertificateCacheEnabled
{
get { return certificateCacheEnabled; }
set { certificateCacheEnabled = value; }
}
}
}
13 changes: 7 additions & 6 deletions CyberSource/Client/CyberSourceClients.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
<Compile Include="Settings.cs" />
<Compile Include="SoapClient.cs" />
<Compile Include="XmlClient.cs" />
<Compile Include="CertificateEntry.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
Expand Down Expand Up @@ -166,6 +167,12 @@
<WCFMetadataStorage Include="Service References\NVPServiceReference\" />
<WCFMetadataStorage Include="Service References\SoapServiceReference\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Base\CyberSourceBase.csproj">
<Project>{6ec4a1fb-44ce-4326-92a5-88a1ecc615bd}</Project>
<Name>CyberSourceBase</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="Service References\NVPServiceReference\configuration91.svcinfo" />
</ItemGroup>
Expand All @@ -190,12 +197,6 @@
<LastGenOutput>Reference.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Base\CyberSourceBase.csproj">
<Project>{6ec4a1fb-44ce-4326-92a5-88a1ecc615bd}</Project>
<Name>CyberSourceBase</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
Loading

0 comments on commit 017da6e

Please sign in to comment.