Skip to content

Commit 80222f9

Browse files
Triton Circonflexepeterdettman
authored andcommitted
Fix NullReferenceException in PbeUtilities
Add support for SHA-384 and SHA-512 HMAC algorithms as they already exist in the field. Throw a proper SecurityUtilityException when the HMAC algorithm is not handled.
1 parent 4e0fd4b commit 80222f9

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

crypto/src/security/PbeUtilities.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ static PbeUtilities()
131131
Algorithms["PBEWITHHMACSHA256"] = "PBEwithHmacSHA-256";
132132
Algorithms["PBEWITHHMACSHA-256"] = "PBEwithHmacSHA-256";
133133
Algorithms[NistObjectIdentifiers.IdSha256.Id] = "PBEwithHmacSHA-256";
134+
Algorithms["PBEWITHHMACSHA384"] = "PBEwithHmacSHA-384";
135+
Algorithms["PBEWITHHMACSHA-384"] = "PBEwithHmacSHA-384";
136+
Algorithms[NistObjectIdentifiers.IdSha384.Id] = "PBEwithHmacSHA-384";
137+
Algorithms["PBEWITHHMACSHA512"] = "PBEwithHmacSHA-512";
138+
Algorithms["PBEWITHHMACSHA-512"] = "PBEwithHmacSHA-512";
139+
Algorithms[NistObjectIdentifiers.IdSha512.Id] = "PBEwithHmacSHA-512";
134140
Algorithms["PBEWITHHMACRIPEMD128"] = "PBEwithHmacRipeMD128";
135141
Algorithms[TeleTrusTObjectIdentifiers.RipeMD128.Id] = "PBEwithHmacRipeMD128";
136142
Algorithms["PBEWITHHMACRIPEMD160"] = "PBEwithHmacRipeMD160";
@@ -169,6 +175,8 @@ static PbeUtilities()
169175
AlgorithmType["PBEwithHmacSHA-1"] = Pkcs12;
170176
AlgorithmType["PBEwithHmacSHA-224"] = Pkcs12;
171177
AlgorithmType["PBEwithHmacSHA-256"] = Pkcs12;
178+
AlgorithmType["PBEwithHmacSHA-384"] = Pkcs12;
179+
AlgorithmType["PBEwithHmacSHA-512"] = Pkcs12;
172180
AlgorithmType["PBEwithHmacRipeMD128"] = Pkcs12;
173181
AlgorithmType["PBEwithHmacRipeMD160"] = Pkcs12;
174182
AlgorithmType["PBEwithHmacRipeMD256"] = Pkcs12;
@@ -193,6 +201,8 @@ static PbeUtilities()
193201
Oids["PBEwithHmacSHA-1"] = OiwObjectIdentifiers.IdSha1;
194202
Oids["PBEwithHmacSHA-224"] = NistObjectIdentifiers.IdSha224;
195203
Oids["PBEwithHmacSHA-256"] = NistObjectIdentifiers.IdSha256;
204+
Oids["PBEwithHmacSHA-384"] = NistObjectIdentifiers.IdSha384;
205+
Oids["PBEwithHmacSHA-512"] = NistObjectIdentifiers.IdSha512;
196206
Oids["PBEwithHmacRipeMD128"] = TeleTrusTObjectIdentifiers.RipeMD128;
197207
Oids["PBEwithHmacRipeMD160"] = TeleTrusTObjectIdentifiers.RipeMD160;
198208
Oids["PBEwithHmacRipeMD256"] = TeleTrusTObjectIdentifiers.RipeMD256;
@@ -401,7 +411,15 @@ public static ICipherParameters GenerateCipherParameters(
401411
bool wrongPkcs12Zero,
402412
Asn1Encodable pbeParameters)
403413
{
414+
if (algorithm == null)
415+
{
416+
throw new ArgumentNullException(nameof(algorithm));
417+
}
404418
string mechanism = CollectionUtilities.GetValueOrNull(Algorithms, algorithm);
419+
if (mechanism == null)
420+
{
421+
throw new SecurityUtilityException("Algorithm " + algorithm + " not recognised.");
422+
}
405423

406424
byte[] keyBytes = null;
407425
byte[] salt = null;

0 commit comments

Comments
 (0)