Skip to content

Commit 91d4b86

Browse files
committed
heap inspection issue fix by using secure string
1 parent dcb9ad7 commit 91d4b86

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

Client/ApiClient.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
using AuthenticationSdk.util;
2525
using System.Security.Cryptography.X509Certificates;
2626
using NLog;
27+
using System.Security;
2728

2829
namespace CyberSource.Client
2930
{
@@ -456,11 +457,16 @@ public object CallApi(
456457
{
457458
string clientCertDirectory = Configuration.MerchantConfigDictionaryObj["clientCertDirectory"];
458459
string clientCertFile = Configuration.MerchantConfigDictionaryObj["clientCertFile"];
459-
string clientCertPassword = Configuration.MerchantConfigDictionaryObj["clientCertPassword"];
460+
SecureString clientCertPassword = new SecureString();
461+
foreach (char c in Configuration.MerchantConfigDictionaryObj["clientCertPassword"])
462+
{
463+
clientCertPassword.AppendChar(c);
464+
}
465+
clientCertPassword.MakeReadOnly();
460466
string fileName = Path.Combine(clientCertDirectory, clientCertFile);
461467
// Importing Certificates
462468
var certificate = new X509Certificate2(fileName, clientCertPassword);
463-
clientCertPassword=string.Empty;
469+
clientCertPassword.Dispose();
464470
RestClient.Options.ClientCertificates = new X509CertificateCollection { certificate };
465471
}
466472

generator/cybersource-csharp-template/ApiClient.mustache

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,11 +498,16 @@ namespace {{packageName}}.Client
498498
{
499499
string clientCertDirectory = Configuration.MerchantConfigDictionaryObj["clientCertDirectory"];
500500
string clientCertFile = Configuration.MerchantConfigDictionaryObj["clientCertFile"];
501-
string clientCertPassword = Configuration.MerchantConfigDictionaryObj["clientCertPassword"];
501+
SecureString clientCertPassword = new SecureString();
502+
foreach (char c in Configuration.MerchantConfigDictionaryObj["clientCertPassword"])
503+
{
504+
clientCertPassword.AppendChar(c);
505+
}
506+
clientCertPassword.MakeReadOnly();
502507
string fileName = Path.Combine(clientCertDirectory, clientCertFile);
503508
// Importing Certificates
504509
var certificate = new X509Certificate2(fileName, clientCertPassword);
505-
clientCertPassword=string.Empty;
510+
clientCertPassword.Dispose();
506511
RestClient.Options.ClientCertificates = new X509CertificateCollection { certificate };
507512
}
508513

0 commit comments

Comments
 (0)