Skip to content

Commit 8e3fbc0

Browse files
committed
(maint) Don't attempt to decrypt empty strings
If a string is null, we can't use System.Convert.FromBase64String to get a byte array from it. This commit reverts the previous change to NugetCommon, and instead puts the check in the DefaultEncryptionUtility to prevent it in any place where we might pass in a null string.
1 parent 16f48b3 commit 8e3fbc0

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

src/chocolatey/infrastructure.app/nuget/NugetCommon.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public static IEnumerable<SourceRepository> GetRemoteRepositories(ChocolateyConf
219219
if (!string.IsNullOrWhiteSpace(machineSource.Certificate))
220220
{
221221
"chocolatey".Log().Debug("Using configured certificate for source {0}".FormatWith(source));
222-
sourceClientCertificates.Add(new X509Certificate2(machineSource.Certificate, string.IsNullOrWhiteSpace(machineSource.EncryptedCertificatePassword) ? null : NugetEncryptionUtility.DecryptString(machineSource.EncryptedCertificatePassword)));
222+
sourceClientCertificates.Add(new X509Certificate2(machineSource.Certificate, NugetEncryptionUtility.DecryptString(machineSource.EncryptedCertificatePassword)));
223223
}
224224
}
225225
}

src/chocolatey/infrastructure/cryptography/DefaultEncryptionUtility.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ This is can be because the machine keyfile cannot be written as a normal user.
6161

6262
public string DecryptString(string encryptedString)
6363
{
64+
// don't attempt decryption on an empty string.
65+
if (string.IsNullOrEmpty(encryptedString))
66+
{
67+
return encryptedString;
68+
}
69+
6470
var encryptedByteArray = Convert.FromBase64String(encryptedString);
6571
byte[] decryptedByteArray;
6672

0 commit comments

Comments
 (0)