Skip to content

Commit

Permalink
fix: macOS PKCS12 confidential mode = None & Integrity mode = Passwor…
Browse files Browse the repository at this point in the history
…d(null) (#134)

When import a PKCS12 certificate to AKV, it is possible that
authenticatedSafe confidential mode = None & Integrity mode =
Password(null)

Resolves #133 
Signed-off-by: Junjie Gao <[email protected]>

---------

Signed-off-by: Junjie Gao <[email protected]>
  • Loading branch information
JeyJeyGao authored Sep 1, 2023
1 parent a31b29e commit 7e45e69
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
18 changes: 17 additions & 1 deletion Notation.Plugin.AzureKeyVault.Tests/Certificate/Pkcs12Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Notation.Plugin.AzureKeyVault.Certificate.Tests
{
public class Pkcs12Tests
{
// MAC integrity mode is password(null) and saftContent confidential mode is password(null)
[Fact]
public void ReEncode()
{
Expand Down Expand Up @@ -34,7 +35,8 @@ public void ReEncode_WithInvalidMac()
}

[Fact]
public void ReEncode_withoutMac(){
public void ReEncode_withoutMac()
{
// read the pfx file
byte[] data = File.ReadAllBytes(Path.Combine(Directory.GetCurrentDirectory(), "TestData", "cert_without_mac.pfx"));
Pkcs12Info originPfx = Pkcs12Info.Decode(data, out _);
Expand All @@ -44,7 +46,21 @@ public void ReEncode_withoutMac(){
byte[] newData = Pkcs12.ReEncode(data);
Pkcs12Info pfxWithoutMac = Pkcs12Info.Decode(newData, out _);
Assert.True(pfxWithoutMac.IntegrityMode == Pkcs12IntegrityMode.None);
}

// MAC integrity mode is password(null) and saftContent confidential mode is none
[Fact]
public void ReEncode_akv_imported()
{
// read the pfx file
byte[] data = File.ReadAllBytes(Path.Combine(Directory.GetCurrentDirectory(), "TestData", "akv_imported_cert.pfx"));
Pkcs12Info originPfx = Pkcs12Info.Decode(data, out _);
Assert.True(originPfx.IntegrityMode == Pkcs12IntegrityMode.Password);

// re-encode the pfx file
byte[] newData = Pkcs12.ReEncode(data);
Pkcs12Info pfxWithoutMac = Pkcs12Info.Decode(newData, out _);
Assert.True(pfxWithoutMac.IntegrityMode == Pkcs12IntegrityMode.None);
}
}
}
Binary file not shown.
5 changes: 4 additions & 1 deletion Notation.Plugin.AzureKeyVault/Certificate/Pkcs12.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ public static byte[] ReEncode(byte[] data)
foreach (var safeContent in pfx.AuthenticatedSafe)
{
// decrypt with null password
safeContent.Decrypt((byte[]?)null);
if (safeContent.ConfidentialityMode == Pkcs12ConfidentialityMode.Password)
{
safeContent.Decrypt((byte[]?)null);
}

// create a newSafeContent and only contains the certificate bag
var newSafeContent = new Pkcs12SafeContents();
Expand Down

0 comments on commit 7e45e69

Please sign in to comment.