|
7 | 7 | using System.ServiceModel.Channels;
|
8 | 8 | using System.ServiceModel.Security.Tokens;
|
9 | 9 | using System.Security.Cryptography.X509Certificates;
|
10 |
| -using System.Collections.Concurrent; |
| 10 | +using System.Collections.Concurrent; |
| 11 | +using System.Security; |
11 | 12 |
|
12 | 13 | namespace CyberSource.Clients
|
13 | 14 | {
|
@@ -70,15 +71,22 @@ string proxyUser
|
70 | 71 | = AppSettings.GetSetting(null, PROXY_USER);
|
71 | 72 | if (proxyUser != null)
|
72 | 73 | {
|
73 |
| - string proxyPassword |
74 |
| - = AppSettings.GetSetting(null, PROXY_PASSWORD); |
| 74 | + SecureString proxyPassword = new SecureString(); |
| 75 | + |
| 76 | + foreach (char c in AppSettings.GetSetting(null, PROXY_PASSWORD)) |
| 77 | + { |
| 78 | + proxyPassword.AppendChar(c); |
| 79 | + } |
| 80 | + |
| 81 | + proxyPassword.MakeReadOnly(); |
75 | 82 |
|
76 | 83 | NetworkCredential credential
|
77 | 84 | = new NetworkCredential(proxyUser, proxyPassword);
|
78 | 85 |
|
79 | 86 | CredentialCache cache = new CredentialCache();
|
80 | 87 | cache.Add(new Uri(proxyURL), BASIC_AUTH, credential);
|
81 | 88 | mProxy.Credentials = cache;
|
| 89 | + proxyPassword.Dispose(); |
82 | 90 | }
|
83 | 91 | }
|
84 | 92 | }
|
@@ -201,8 +209,8 @@ int boolVal
|
201 | 209 | merchantID, Configuration.KEY_ALIAS);
|
202 | 210 |
|
203 | 211 | config.Password
|
204 |
| - = AppSettings.GetSetting( |
205 |
| - merchantID, Configuration.PASSWORD); |
| 212 | + = convertToSecureString(AppSettings.GetSetting( |
| 213 | + merchantID, Configuration.PASSWORD)); |
206 | 214 |
|
207 | 215 | config.LogFilename
|
208 | 216 | = AppSettings.GetSetting(
|
@@ -422,6 +430,22 @@ public static bool IsMerchantCertExpired(Logger logger, string merchantId, DateT
|
422 | 430 |
|
423 | 431 | }
|
424 | 432 | return false;
|
| 433 | + } |
| 434 | + |
| 435 | + private static SecureString convertToSecureString(string originalString) |
| 436 | + { |
| 437 | + if (originalString == null) |
| 438 | + { |
| 439 | + return null; |
| 440 | + } |
| 441 | + |
| 442 | + var secureString = new SecureString(); |
| 443 | + |
| 444 | + foreach (char c in originalString) |
| 445 | + secureString.AppendChar(c); |
| 446 | + |
| 447 | + secureString.MakeReadOnly(); |
| 448 | + return secureString; |
425 | 449 | }
|
426 | 450 | }
|
427 | 451 | }
|
0 commit comments