From cf3bb331bcf8e817f96d283d2a995b95c7b1e7c4 Mon Sep 17 00:00:00 2001 From: gnongsie Date: Tue, 27 Aug 2024 15:50:54 +0530 Subject: [PATCH 1/3] Fix for client library version --- CyberSource/Client/BaseClient.cs | 812 ++++++++++++++++--------------- 1 file changed, 422 insertions(+), 390 deletions(-) diff --git a/CyberSource/Client/BaseClient.cs b/CyberSource/Client/BaseClient.cs index daed9b4..5f3bb8f 100644 --- a/CyberSource/Client/BaseClient.cs +++ b/CyberSource/Client/BaseClient.cs @@ -1,387 +1,399 @@ -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; +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; using System.Security; +using System.Reflection; +using System.Linq; + +namespace CyberSource.Clients +{ + /// + /// Base class for all clients. + /// + public abstract class BaseClient + { + /// + /// Version of this client. + /// + public static string CLIENT_LIBRARY_VERSION; + public const string CYBS_SUBJECT_NAME = "CyberSource_SJC_US"; + + /// + /// Proxy object that is initialized during start-up, if needed. + /// + protected static WebProxy mProxy = null; + + /// + /// String containing information about the working environment. + /// + protected static string mEnvironmentInfo = + Environment.OSVersion.Platform + + Environment.OSVersion.Version.ToString() + "-CLR" + + Environment.Version.ToString(); + + /// + /// Field for merchantID used in requests. + /// + protected const string MERCHANT_ID = "merchantID"; + + private const string PROXY_URL = "proxyURL"; + private const string PROXY_USER = "proxyUser"; + private const string PROXY_PASSWORD = "proxyPassword"; + private const string BASIC_AUTH = "Basic"; + + 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 merchantIdentities = new ConcurrentDictionary(); -namespace CyberSource.Clients -{ - /// - /// Base class for all clients. - /// - public abstract class BaseClient - { - /// - /// Version of this client. - /// - public const string CLIENT_LIBRARY_VERSION = "1.4.4"; - public const string CYBS_SUBJECT_NAME = "CyberSource_SJC_US"; - - /// - /// Proxy object that is initialized during start-up, if needed. - /// - protected static WebProxy mProxy = null; - - /// - /// String containing information about the working environment. - /// - protected static string mEnvironmentInfo = - Environment.OSVersion.Platform + - Environment.OSVersion.Version.ToString() + "-CLR" + - Environment.Version.ToString(); - - /// - /// Field for merchantID used in requests. - /// - protected const string MERCHANT_ID = "merchantID"; - - private const string PROXY_URL = "proxyURL"; - private const string PROXY_USER = "proxyUser"; - private const string PROXY_PASSWORD = "proxyPassword"; - private const string BASIC_AUTH = "Basic"; - - 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 merchantIdentities = new ConcurrentDictionary(); - static BaseClient() { ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072 | (SecurityProtocolType)768; + CLIENT_LIBRARY_VERSION = GetClientId(); SetupProxy(); - } - - private static void SetupProxy() - { - // if a proxyURL is specified in the configuration file, - // create a WebProxy object for later use. - string proxyURL = AppSettings.GetSetting(null, PROXY_URL); - if (proxyURL != null) - { - mProxy = new WebProxy(proxyURL); - - // if a proxyUser is specified in the configuration file, - // set up the proxy object's Credentials. - string proxyUser - = AppSettings.GetSetting(null, PROXY_USER); - if (proxyUser != null) - { - SecureString proxyPassword = new SecureString(); - + } + + private static string GetClientId() + { + var assembly = typeof(Configuration).Assembly; + + var assemblyVersion = AssemblyHelper.GetAssemblyAttribute(assembly).Version; + + return assemblyVersion; + } + + private static void SetupProxy() + { + // if a proxyURL is specified in the configuration file, + // create a WebProxy object for later use. + string proxyURL = AppSettings.GetSetting(null, PROXY_URL); + if (proxyURL != null) + { + mProxy = new WebProxy(proxyURL); + + // if a proxyUser is specified in the configuration file, + // set up the proxy object's Credentials. + string proxyUser + = AppSettings.GetSetting(null, PROXY_USER); + if (proxyUser != null) + { + SecureString proxyPassword = new SecureString(); + foreach (char c in AppSettings.GetSetting(null, PROXY_PASSWORD)) { proxyPassword.AppendChar(c); - } - - proxyPassword.MakeReadOnly(); - - NetworkCredential credential - = new NetworkCredential(proxyUser, proxyPassword); - - CredentialCache cache = new CredentialCache(); - cache.Add(new Uri(proxyURL), BASIC_AUTH, credential); - mProxy.Credentials = cache; - proxyPassword.Dispose(); - } - } - } - - /// - /// Builds a Configuration object using settings from the - /// appsettings section of the application/web config file. - /// This is a public static method that can potentially be - /// used to create and cache Configuration object(s) when - /// the application starts. - /// - /// - /// If not null, this method will get the settings specific to - /// this merchant id. - /// - /// the built Configuration object - public static Configuration BuildConfiguration( - string merchantID) - { - return (InternalBuildConfiguration(merchantID, false)); - } - - /// - /// Builds a Configuration object using settings from the - /// appsettings section of the application/web config file. - /// - /// - /// merchantID in the request. If not null, this method will get - /// the settings specific to this merchant id. - /// - /// the built Configuration object - protected static Configuration BuildConfigurationForRequest( - string requestMerchantID) - { - return (InternalBuildConfiguration(requestMerchantID, true)); - } - - /// - /// Builds a Configuration object using settings from the - /// appsettings section of the application/web config file. - /// - /// - /// If not null, this method will get the settings specific to - /// this merchant id. - /// - /// - /// If set to true, an ApplicationException will be thrown if - /// merchantID is null and there is no merchantID in the - /// appsettings, either. - /// - /// the built Configuration object - private static Configuration InternalBuildConfiguration( - string merchantID, bool failIfNoMerchantID) - { + } + + proxyPassword.MakeReadOnly(); + + NetworkCredential credential + = new NetworkCredential(proxyUser, proxyPassword); + + CredentialCache cache = new CredentialCache(); + cache.Add(new Uri(proxyURL), BASIC_AUTH, credential); + mProxy.Credentials = cache; + proxyPassword.Dispose(); + } + } + } + + /// + /// Builds a Configuration object using settings from the + /// appsettings section of the application/web config file. + /// This is a public static method that can potentially be + /// used to create and cache Configuration object(s) when + /// the application starts. + /// + /// + /// If not null, this method will get the settings specific to + /// this merchant id. + /// + /// the built Configuration object + public static Configuration BuildConfiguration( + string merchantID) + { + return (InternalBuildConfiguration(merchantID, false)); + } + + /// + /// Builds a Configuration object using settings from the + /// appsettings section of the application/web config file. + /// + /// + /// merchantID in the request. If not null, this method will get + /// the settings specific to this merchant id. + /// + /// the built Configuration object + protected static Configuration BuildConfigurationForRequest( + string requestMerchantID) + { + return (InternalBuildConfiguration(requestMerchantID, true)); + } + + /// + /// Builds a Configuration object using settings from the + /// appsettings section of the application/web config file. + /// + /// + /// If not null, this method will get the settings specific to + /// this merchant id. + /// + /// + /// If set to true, an ApplicationException will be thrown if + /// merchantID is null and there is no merchantID in the + /// appsettings, either. + /// + /// the built Configuration object + private static Configuration InternalBuildConfiguration( + string merchantID, bool failIfNoMerchantID) + { Configuration config = new Configuration(); - if (merchantID == null) - { - merchantID - = AppSettings.GetSetting(null, MERCHANT_ID); - } - if (merchantID != null || failIfNoMerchantID) - { - // if merchantID is null, the assignment below will - // throw an exception. - config.MerchantID = merchantID; - } - - string keysDirectory - = AppSettings.GetSetting( - merchantID, Configuration.KEYS_DIRECTORY); - if (keysDirectory != null) - { - config.KeysDirectory = keysDirectory; - } - else - { - // look for "keysDir" for backwards-compatibility - config.KeysDirectory - = AppSettings.GetSetting( - merchantID, Configuration.KEYS_DIR); - } - - int boolVal - = AppSettings.GetBoolSetting( - merchantID, Configuration.SEND_TO_PRODUCTION); - if (boolVal != -1) config.SendToProduction = (boolVal == 1); - - boolVal - = AppSettings.GetBoolSetting( - merchantID, Configuration.ENABLE_LOG); - config.setLogProperties( - boolVal == 1, - AppSettings.GetSetting( - merchantID, Configuration.LOG_DIRECTORY)); - - config.ServerURL - = AppSettings.GetSetting( - merchantID, Configuration.SERVER_URL); - if (config.ServerURL == null) - { - // look for "cybersourceURL" for backwards-compatibility - config.ServerURL - = AppSettings.GetSetting( - merchantID, Configuration.CYBERSOURCE_URL); - } - - //See if akamai flag has been set or not which eventually gives effective server URL - boolVal - = AppSettings.GetBoolSetting( - merchantID, Configuration.SEND_TO_AKAMAI); - if (boolVal != -1) config.SendToAkamai = (boolVal == 1); - - config.KeyFilename - = AppSettings.GetSetting( - merchantID, Configuration.KEY_FILENAME); - - config.KeyAlias - = AppSettings.GetSetting( - merchantID, Configuration.KEY_ALIAS); - - config.Password - = convertToSecureString(AppSettings.GetSetting( - merchantID, Configuration.PASSWORD)); - - config.LogFilename - = AppSettings.GetSetting( - merchantID, Configuration.LOG_FILENAME); - - config.LogMaximumSize - = AppSettings.GetIntSetting( - merchantID, Configuration.LOG_MAXIMUM_SIZE); - - config.Timeout - = AppSettings.GetIntSetting( - merchantID, Configuration.TIMEOUT); - - boolVal - = AppSettings.GetBoolSetting( - merchantID, Configuration.DEMO); - if (boolVal != -1) config.Demo = (boolVal == 1); - - config.ConnectionLimit - = AppSettings.GetIntSetting( - merchantID, Configuration.CONNECTION_LIMIT); - - // Encryption enable flag - boolVal - = AppSettings.GetBoolSetting( - 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); - } - - /// - /// Prepares the log file and logs transaction-start stuff - /// if logging is enabled. Otherwise, it does nothing. - /// - /// - /// Configuration object for the current transaction. - /// - /// the Logger object if logging is enabled. Returns null - /// otherwise. - /// - protected static Logger PrepareLog(Configuration config) - { - Logger logger = null; - if (config.EnableLog) - { - logger - = Logger.GetInstance( - config.LogDirectory, config.LogFilename, - config.LogMaximumSize); - if (logger != null) - { - logger.LogTransactionStart(config.LogString); - } - } - return (logger); - } - - /// - /// This method will extract the XmlElementAttribute from the - /// custom attributes and get its Namespace property. - /// - /// - /// - /// - /// the Namespace property of the XmlElementAttribute. - /// - protected static string GetXmlElementAttributeNamespace(Type type) - { - //With WCF the namespace is no longer used. But it might be nice to have it. - //However I don't want the client to fail if for some reason it can't get the namespace; - - Logger logger = null; - try - { - logger = PrepareLog(InternalBuildConfiguration(null, false)); - - switch (type.Name) - { - case "RequestMessage": - return ((XmlTypeAttribute)type.GetCustomAttributes(typeof(XmlTypeAttribute), false)[0]).Namespace; - case "inputNVPMessageIn": - return ((MessageBodyMemberAttribute)type.GetMember("nvpRequest")[0].GetCustomAttributes(typeof(MessageBodyMemberAttribute), false)[0]).Namespace; - default: - return ""; - } - } - catch - { - 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); - } - return ""; - } - } - - /// - /// Sets the ConnectionLimit of the ServicePoint object for the - /// URL in the Configuration object. - /// - /// - /// Configuration object containing the URL and the connection - /// limit. - /// - protected static void SetConnectionLimit(Configuration config) - { - if (config.ConnectionLimit != -1) - { - Uri uri = new Uri(config.EffectiveServerURL); - ServicePoint sp = ServicePointManager.FindServicePoint(uri); - sp.ConnectionLimit = config.ConnectionLimit; - } - } - - - /// - /// Returns a custom wcf binding that will create a SOAP request - /// compatible with the Simple Order API Service - /// - protected static CustomBinding getWCFCustomBinding(Configuration config) - { - //Setup custom binding with HTTPS + Body Signing - CustomBinding currentBinding = new CustomBinding(); - - //Sign the body - AsymmetricSecurityBindingElement asec = (AsymmetricSecurityBindingElement)SecurityBindingElement.CreateMutualCertificateDuplexBindingElement(MessageSecurityVersion.WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10); - asec.SetKeyDerivation(false); - asec.IncludeTimestamp = false; - asec.EnableUnsecuredResponse = true; - asec.SecurityHeaderLayout = SecurityHeaderLayout.Lax; - - if (config.UseSignedAndEncrypted) - { - asec.LocalClientSettings.IdentityVerifier = new CustomeIdentityVerifier(); - asec.RecipientTokenParameters = new System.ServiceModel.Security.Tokens.X509SecurityTokenParameters { InclusionMode = SecurityTokenInclusionMode.Once }; - asec.MessageProtectionOrder = System.ServiceModel.Security.MessageProtectionOrder.SignBeforeEncrypt; - asec.EndpointSupportingTokenParameters.SignedEncrypted.Add(new System.ServiceModel.Security.Tokens.X509SecurityTokenParameters()); - asec.SetKeyDerivation(false); - } - - //Use custom encoder to strip unsigned timestamp in response - CustomTextMessageBindingElement textBindingElement = new CustomTextMessageBindingElement(); - - - //Setup https transport - HttpsTransportBindingElement httpsTransport = new HttpsTransportBindingElement(); - httpsTransport.RequireClientCertificate = true; - httpsTransport.AuthenticationScheme = AuthenticationSchemes.Anonymous; - httpsTransport.MaxReceivedMessageSize = 2147483647; - httpsTransport.UseDefaultWebProxy = false; - - //Setup Proxy if needed - if (mProxy != null) - { - WebRequest.DefaultWebProxy = mProxy; - httpsTransport.UseDefaultWebProxy = true; - } - - - //Bind in order (Security layer, message layer, transport layer) - currentBinding.Elements.Add(asec); - currentBinding.Elements.Add(textBindingElement); - currentBinding.Elements.Add(httpsTransport); - return currentBinding; + if (merchantID == null) + { + merchantID + = AppSettings.GetSetting(null, MERCHANT_ID); + } + if (merchantID != null || failIfNoMerchantID) + { + // if merchantID is null, the assignment below will + // throw an exception. + config.MerchantID = merchantID; + } + + string keysDirectory + = AppSettings.GetSetting( + merchantID, Configuration.KEYS_DIRECTORY); + if (keysDirectory != null) + { + config.KeysDirectory = keysDirectory; + } + else + { + // look for "keysDir" for backwards-compatibility + config.KeysDirectory + = AppSettings.GetSetting( + merchantID, Configuration.KEYS_DIR); + } + + int boolVal + = AppSettings.GetBoolSetting( + merchantID, Configuration.SEND_TO_PRODUCTION); + if (boolVal != -1) config.SendToProduction = (boolVal == 1); + + boolVal + = AppSettings.GetBoolSetting( + merchantID, Configuration.ENABLE_LOG); + config.setLogProperties( + boolVal == 1, + AppSettings.GetSetting( + merchantID, Configuration.LOG_DIRECTORY)); + + config.ServerURL + = AppSettings.GetSetting( + merchantID, Configuration.SERVER_URL); + if (config.ServerURL == null) + { + // look for "cybersourceURL" for backwards-compatibility + config.ServerURL + = AppSettings.GetSetting( + merchantID, Configuration.CYBERSOURCE_URL); + } + + //See if akamai flag has been set or not which eventually gives effective server URL + boolVal + = AppSettings.GetBoolSetting( + merchantID, Configuration.SEND_TO_AKAMAI); + if (boolVal != -1) config.SendToAkamai = (boolVal == 1); + + config.KeyFilename + = AppSettings.GetSetting( + merchantID, Configuration.KEY_FILENAME); + + config.KeyAlias + = AppSettings.GetSetting( + merchantID, Configuration.KEY_ALIAS); + + config.Password + = convertToSecureString(AppSettings.GetSetting( + merchantID, Configuration.PASSWORD)); + + config.LogFilename + = AppSettings.GetSetting( + merchantID, Configuration.LOG_FILENAME); + + config.LogMaximumSize + = AppSettings.GetIntSetting( + merchantID, Configuration.LOG_MAXIMUM_SIZE); + + config.Timeout + = AppSettings.GetIntSetting( + merchantID, Configuration.TIMEOUT); + + boolVal + = AppSettings.GetBoolSetting( + merchantID, Configuration.DEMO); + if (boolVal != -1) config.Demo = (boolVal == 1); + + config.ConnectionLimit + = AppSettings.GetIntSetting( + merchantID, Configuration.CONNECTION_LIMIT); + + // Encryption enable flag + boolVal + = AppSettings.GetBoolSetting( + 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); + } + + /// + /// Prepares the log file and logs transaction-start stuff + /// if logging is enabled. Otherwise, it does nothing. + /// + /// + /// Configuration object for the current transaction. + /// + /// the Logger object if logging is enabled. Returns null + /// otherwise. + /// + protected static Logger PrepareLog(Configuration config) + { + Logger logger = null; + if (config.EnableLog) + { + logger + = Logger.GetInstance( + config.LogDirectory, config.LogFilename, + config.LogMaximumSize); + if (logger != null) + { + logger.LogTransactionStart(config.LogString); + } + } + return (logger); + } + + /// + /// This method will extract the XmlElementAttribute from the + /// custom attributes and get its Namespace property. + /// + /// + /// + /// + /// the Namespace property of the XmlElementAttribute. + /// + protected static string GetXmlElementAttributeNamespace(Type type) + { + //With WCF the namespace is no longer used. But it might be nice to have it. + //However I don't want the client to fail if for some reason it can't get the namespace; + + Logger logger = null; + try + { + logger = PrepareLog(InternalBuildConfiguration(null, false)); + + switch (type.Name) + { + case "RequestMessage": + return ((XmlTypeAttribute)type.GetCustomAttributes(typeof(XmlTypeAttribute), false)[0]).Namespace; + case "inputNVPMessageIn": + return ((MessageBodyMemberAttribute)type.GetMember("nvpRequest")[0].GetCustomAttributes(typeof(MessageBodyMemberAttribute), false)[0]).Namespace; + default: + return ""; + } + } + catch + { + 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); + } + return ""; + } + } + + /// + /// Sets the ConnectionLimit of the ServicePoint object for the + /// URL in the Configuration object. + /// + /// + /// Configuration object containing the URL and the connection + /// limit. + /// + protected static void SetConnectionLimit(Configuration config) + { + if (config.ConnectionLimit != -1) + { + Uri uri = new Uri(config.EffectiveServerURL); + ServicePoint sp = ServicePointManager.FindServicePoint(uri); + sp.ConnectionLimit = config.ConnectionLimit; + } + } + + + /// + /// Returns a custom wcf binding that will create a SOAP request + /// compatible with the Simple Order API Service + /// + protected static CustomBinding getWCFCustomBinding(Configuration config) + { + //Setup custom binding with HTTPS + Body Signing + CustomBinding currentBinding = new CustomBinding(); + + //Sign the body + AsymmetricSecurityBindingElement asec = (AsymmetricSecurityBindingElement)SecurityBindingElement.CreateMutualCertificateDuplexBindingElement(MessageSecurityVersion.WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10); + asec.SetKeyDerivation(false); + asec.IncludeTimestamp = false; + asec.EnableUnsecuredResponse = true; + asec.SecurityHeaderLayout = SecurityHeaderLayout.Lax; + + if (config.UseSignedAndEncrypted) + { + asec.LocalClientSettings.IdentityVerifier = new CustomeIdentityVerifier(); + asec.RecipientTokenParameters = new System.ServiceModel.Security.Tokens.X509SecurityTokenParameters { InclusionMode = SecurityTokenInclusionMode.Once }; + asec.MessageProtectionOrder = System.ServiceModel.Security.MessageProtectionOrder.SignBeforeEncrypt; + asec.EndpointSupportingTokenParameters.SignedEncrypted.Add(new System.ServiceModel.Security.Tokens.X509SecurityTokenParameters()); + asec.SetKeyDerivation(false); + } + + //Use custom encoder to strip unsigned timestamp in response + CustomTextMessageBindingElement textBindingElement = new CustomTextMessageBindingElement(); + + + //Setup https transport + HttpsTransportBindingElement httpsTransport = new HttpsTransportBindingElement(); + httpsTransport.RequireClientCertificate = true; + httpsTransport.AuthenticationScheme = AuthenticationSchemes.Anonymous; + httpsTransport.MaxReceivedMessageSize = 2147483647; + httpsTransport.UseDefaultWebProxy = false; + + //Setup Proxy if needed + if (mProxy != null) + { + WebRequest.DefaultWebProxy = mProxy; + httpsTransport.UseDefaultWebProxy = true; + } + + + //Bind in order (Security layer, message layer, transport layer) + currentBinding.Elements.Add(asec); + currentBinding.Elements.Add(textBindingElement); + currentBinding.Elements.Add(httpsTransport); + return currentBinding; } @@ -391,22 +403,22 @@ protected static CustomBinding getWCFCustomBinding(Configuration config) /// /// /// - protected static X509Certificate2 GetOrFindValidMerchantCertFromStore(string merchantId, ConcurrentDictionary merchantIdentities) - { - return merchantIdentities[merchantId] != null ? merchantIdentities[merchantId].MerchantCert : null; - } - + protected static X509Certificate2 GetOrFindValidMerchantCertFromStore(string merchantId, ConcurrentDictionary merchantIdentities) + { + return merchantIdentities[merchantId] != null ? merchantIdentities[merchantId].MerchantCert : null; + } + /// /// /// /// /// - /// - protected static X509Certificate2 GetOrFindValidCybsCertFromStore(string merchantId, ConcurrentDictionary merchantIdentities) - { - return merchantIdentities[merchantId] != null ? merchantIdentities[merchantId].CybsCert : null; - } - + /// + protected static X509Certificate2 GetOrFindValidCybsCertFromStore(string merchantId, ConcurrentDictionary merchantIdentities) + { + return merchantIdentities[merchantId] != null ? merchantIdentities[merchantId].CybsCert : null; + } + /// /// /// @@ -415,8 +427,8 @@ protected static X509Certificate2 GetOrFindValidCybsCertFromStore(string merchan /// /// /// - public static bool IsMerchantCertExpired(Logger logger, string merchantId, DateTime modifiedTime, ConcurrentDictionary merchantIdentities) - { + public static bool IsMerchantCertExpired(Logger logger, string merchantId, DateTime modifiedTime, ConcurrentDictionary merchantIdentities) + { if (merchantIdentities[merchantId] != null) { if (merchantIdentities[merchantId].ModifiedTime != modifiedTime) @@ -429,7 +441,7 @@ public static bool IsMerchantCertExpired(Logger logger, string merchantId, DateT } } - return false; + return false; } private static SecureString convertToSecureString(string originalString) @@ -446,6 +458,26 @@ private static SecureString convertToSecureString(string originalString) secureString.MakeReadOnly(); return secureString; - } - } -} + } + } + + /// + /// Code to process AssemblyInfo.cs information + /// + public static class AssemblyHelper + { + /// + /// + /// + /// + /// + /// + public static T GetAssemblyAttribute(this Assembly ass) where T : Attribute + { + object[] attributes = ass.GetCustomAttributes(typeof(T), false); + if (attributes == null || attributes.Length == 0) + return null; + return attributes.OfType().SingleOrDefault(); + } + } +} From 81e17779ad6d2528687ab916ba5aa31b0c444d5e Mon Sep 17 00:00:00 2001 From: Bansal Date: Thu, 19 Sep 2024 12:50:08 +0530 Subject: [PATCH 2/3] fixing client version --- CyberSource/Client/NVPClient.cs | 2 +- CyberSource/Client/SoapClient.cs | 2 +- CyberSource/Client/XmlClient.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CyberSource/Client/NVPClient.cs b/CyberSource/Client/NVPClient.cs index d5f8747..daca153 100644 --- a/CyberSource/Client/NVPClient.cs +++ b/CyberSource/Client/NVPClient.cs @@ -286,7 +286,7 @@ private static void SetVersionInformation(Hashtable request) request["clientLibrary"] = ".NET NVP"; request["clientLibraryVersion"] = CLIENT_LIBRARY_VERSION; request["clientEnvironment"] = mEnvironmentInfo; - request["clientSecurityLibraryVersion"] =".Net 1.4.4"; + request["clientSecurityLibraryVersion"] = ".Net " + CLIENT_LIBRARY_VERSION; } } } diff --git a/CyberSource/Client/SoapClient.cs b/CyberSource/Client/SoapClient.cs index 5eac54e..36e8c74 100644 --- a/CyberSource/Client/SoapClient.cs +++ b/CyberSource/Client/SoapClient.cs @@ -286,7 +286,7 @@ private static void SetVersionInformation( requestMessage.clientLibrary = ".NET Soap"; requestMessage.clientLibraryVersion = CLIENT_LIBRARY_VERSION; requestMessage.clientEnvironment = mEnvironmentInfo; - requestMessage.clientSecurityLibraryVersion = ".Net 1.4.4"; + requestMessage.clientSecurityLibraryVersion = ".Net " + CLIENT_LIBRARY_VERSION; } } } diff --git a/CyberSource/Client/XmlClient.cs b/CyberSource/Client/XmlClient.cs index 2d04107..e0792eb 100644 --- a/CyberSource/Client/XmlClient.cs +++ b/CyberSource/Client/XmlClient.cs @@ -545,7 +545,7 @@ XmlNode previousSibling SetField(requestMessageNode, ref previousSibling, "clientSecurityLibraryVersion", - ".Net 1.4.4", nspace); + ".Net "+CLIENT_LIBRARY_VERSION, nspace); } private static void SetField( From f8fe30f6049018f79a8f7b3ea0ea3331ab2405f9 Mon Sep 17 00:00:00 2001 From: Bansal Date: Wed, 25 Sep 2024 13:30:33 +0530 Subject: [PATCH 3/3] version update --- CyberSource.nuspec | 2 +- CyberSource/Base/Properties/AssemblyInfo.cs | 4 ++-- CyberSource/Client/Properties/AssemblyInfo.cs | 4 ++-- CyberSourceTests/BaseTest/Properties/AssemblyInfo.cs | 4 ++-- CyberSourceTests/MTTest/Properties/AssemblyInfo.cs | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/CyberSource.nuspec b/CyberSource.nuspec index 2a11eba..0e10e5a 100644 --- a/CyberSource.nuspec +++ b/CyberSource.nuspec @@ -2,7 +2,7 @@ CyberSource - 1.4.7 + 1.4.8 CyberSource Corporation CyberSource Corporation CyberSource Corporation diff --git a/CyberSource/Base/Properties/AssemblyInfo.cs b/CyberSource/Base/Properties/AssemblyInfo.cs index 192fc95..72e5e6f 100644 --- a/CyberSource/Base/Properties/AssemblyInfo.cs +++ b/CyberSource/Base/Properties/AssemblyInfo.cs @@ -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.7")] -[assembly: AssemblyFileVersion("1.4.7")] +[assembly: AssemblyVersion("1.4.8")] +[assembly: AssemblyFileVersion("1.4.8")] diff --git a/CyberSource/Client/Properties/AssemblyInfo.cs b/CyberSource/Client/Properties/AssemblyInfo.cs index 022c3d7..bdfd36f 100644 --- a/CyberSource/Client/Properties/AssemblyInfo.cs +++ b/CyberSource/Client/Properties/AssemblyInfo.cs @@ -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.7")] -[assembly: AssemblyFileVersion("1.4.7")] +[assembly: AssemblyVersion("1.4.8")] +[assembly: AssemblyFileVersion("1.4.8")] diff --git a/CyberSourceTests/BaseTest/Properties/AssemblyInfo.cs b/CyberSourceTests/BaseTest/Properties/AssemblyInfo.cs index 4eaab9c..dbbc583 100644 --- a/CyberSourceTests/BaseTest/Properties/AssemblyInfo.cs +++ b/CyberSourceTests/BaseTest/Properties/AssemblyInfo.cs @@ -29,5 +29,5 @@ // Build Number // Revision // -[assembly: AssemblyVersion("1.4.4.0")] -[assembly: AssemblyFileVersion("1.4.4.0")] +[assembly: AssemblyVersion("1.4.8.0")] +[assembly: AssemblyFileVersion("1.4.8.0")] diff --git a/CyberSourceTests/MTTest/Properties/AssemblyInfo.cs b/CyberSourceTests/MTTest/Properties/AssemblyInfo.cs index 2424675..dde9102 100644 --- a/CyberSourceTests/MTTest/Properties/AssemblyInfo.cs +++ b/CyberSourceTests/MTTest/Properties/AssemblyInfo.cs @@ -29,5 +29,5 @@ // Build Number // Revision // -[assembly: AssemblyVersion("1.4.4.0")] -[assembly: AssemblyFileVersion("1.4.4.0")] +[assembly: AssemblyVersion("1.4.8.0")] +[assembly: AssemblyFileVersion("1.4.8.0")]