Skip to content

Commit

Permalink
Add Hmac SHA384/SHA512 with Pbes2 in PKCS#12
Browse files Browse the repository at this point in the history
This adds support for SHA-384 and SHA-512 in conjunction with Pbes2
PKCS#12 bundles after seeing one in the wild.

Signed-off-by: Alexander Scheel <alexander.scheel@keyfactor.com>
  • Loading branch information
cipherboy authored and peterdettman committed Jan 30, 2024
1 parent 3468223 commit 4948872
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion crypto/test/src/pkcs/test/PKCS12StoreTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,44 @@ public class Pkcs12StoreTest
+ "TK5wp093iTAxMCEwCQYFKw4DAhoFAAQU1SGg9xV7jfLcJh3tzd+phZTMN38E"
+ "CL6WgCtEom7kAgIIAA==");

private static readonly char[] hmacSha384TestPassword = "changeit".ToCharArray();
private static readonly byte[] hmacSha384Test = Base64.Decode(
"MIIHqwIBAzCCB1MGCSqGSIb3DQEHAaCCB0QEggdAMIIHPDCCA8EGCSqGSIb3DQEHAaCCA7IEggOu"
+ "MIIDqjCCA6YGCyqGSIb3DQEMCgECoIIC4TCCAt0wVwYJKoZIhvcNAQUNMEowKQYJKoZIhvcNAQUM"
+ "MBwECHr9d4C/ERNtAgEFAgEgMAoGCCqGSIb3DQIKMB0GCWCGSAFlAwQBKgQQBBHQHKcLHAX7jo6J"
+ "M/sMzQSCAoD91XNClszEu+poVuGFzgwUGEhASjEv5mr6RYcCmrISM2jmEFsgnwImwTi0BUlmKpwe"
+ "mLYFMEwxpQ4ee5Vn9WLNDxGB1T8CNWNNmwWAftB8LdlElMqJgUeQUGNJYbkatYH04ntGl0G9DVt4"
+ "553zfLH8/QnQbUne/dm2Ja45ITWLh6xrCrt/lkNwHBKojh3yGVI2Gl8taS3I8KMEO8WK4YWATPeL"
+ "ogSKcq0vIrbYwzFNOwrZflRRb5EE4y9CIiIt6mdK27KTpZtDZPTgMZ4d7Bibdr7Sk9Z0Ww7v3dLp"
+ "cu53X6VNmLr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vKOyeSpHeYJpUPVud6BnZT/lQ71ZTYwv"
+ "05M2znIOOdFEiVubcf9IBAgdTcmL1rwzgQICBAA=");

private readonly SecureRandom Random = new SecureRandom();

/**
Expand Down Expand Up @@ -1426,6 +1464,13 @@ private void DoTestLoadRepeatedLocalKeyID()
IsTrue(store.GetCertificateChain("45cbf1116fb3f38b2984b3c7224cae70a74f7789").Length == 1);
}

private void DoTestHmacSha384()
{
Pkcs12Store store = new Pkcs12StoreBuilder().Build();
store.Load(new MemoryStream(hmacSha384Test, false), hmacSha384TestPassword);
IsTrue(store.GetCertificateChain("test").Length == 1);
}

public override string Name
{
get { return "PKCS12Store"; }
Expand All @@ -1436,14 +1481,15 @@ public override void PerformTest()
DoTestCertsOnly();
DoTestPkcs12Store();
DoTestLoadRepeatedLocalKeyID();
DoTestHmacSha384();
}

[Test]
public void TestFunction()
{
string resultText = Perform().ToString();

Assert.AreEqual(Name + ": Okay", resultText);
Assert.AreEqual(Name + ": Okay", resultText, resultText);
}
}
}

0 comments on commit 4948872

Please sign in to comment.