1+ using System ;
12using System . IO ;
23using System . Security . Cryptography . Pkcs ;
4+ using System . Text ;
5+ using Notation . Plugin . Protocol ;
36using Xunit ;
47
58namespace Notation . Plugin . AzureKeyVault . Certificate . Tests
@@ -14,10 +17,36 @@ public void RemoveMac()
1417 Pkcs12Info originPfx = Pkcs12Info . Decode ( data , out _ ) ;
1518 Assert . True ( originPfx . IntegrityMode == Pkcs12IntegrityMode . Password ) ;
1619
20+ // remove MAC for the pfx file
21+ byte [ ] newData = Pkcs12 . RemoveMac ( data ) ;
22+ Pkcs12Info pfxWithoutMac = Pkcs12Info . Decode ( newData , out _ ) ;
23+ Assert . True ( pfxWithoutMac . IntegrityMode == Pkcs12IntegrityMode . None ) ;
24+ }
25+
26+ [ Fact ]
27+ public void RemoveMac_WithInvalidMac ( )
28+ {
29+ // read the pfx file
30+ byte [ ] data = File . ReadAllBytes ( Path . Combine ( Directory . GetCurrentDirectory ( ) , "TestData" , "cert_invalid_mac.pfx" ) ) ;
31+ Pkcs12Info originPfx = Pkcs12Info . Decode ( data , out _ ) ;
32+ Assert . True ( originPfx . IntegrityMode == Pkcs12IntegrityMode . Password ) ;
33+
1734 // decrypt the pfx file
18- byte [ ] decryptedData = Pkcs12 . RemoveMac ( data ) ;
19- Pkcs12Info decryptedPfx = Pkcs12Info . Decode ( decryptedData , out _ ) ;
20- Assert . True ( decryptedPfx . IntegrityMode == Pkcs12IntegrityMode . None ) ;
35+ Assert . Throws < ValidationException > ( ( ) => Pkcs12 . RemoveMac ( data ) ) ;
36+ }
37+
38+ [ Fact ]
39+ public void RemoveMac_withoutMac ( ) {
40+ // read the pfx file
41+ byte [ ] data = File . ReadAllBytes ( Path . Combine ( Directory . GetCurrentDirectory ( ) , "TestData" , "cert_without_mac.pfx" ) ) ;
42+ Pkcs12Info originPfx = Pkcs12Info . Decode ( data , out _ ) ;
43+ Assert . True ( originPfx . IntegrityMode == Pkcs12IntegrityMode . None ) ;
44+
45+ // remove MAC for the pfx file
46+ byte [ ] newData = Pkcs12 . RemoveMac ( data ) ;
47+ Pkcs12Info pfxWithoutMac = Pkcs12Info . Decode ( newData , out _ ) ;
48+ Assert . True ( pfxWithoutMac . IntegrityMode == Pkcs12IntegrityMode . None ) ;
49+
2150 }
2251 }
2352}
0 commit comments