Fix certmgr when a unicode encoded null is used as password
[mono.git] / mcs / class / Mono.Security / Mono.Security.X509 / PKCS12.cs
index fc8ac2bb306ec90519e2c0e4da4afd84d6a90bd1..01e6ffd67a812f6178c8ac6b006abd8d333f14f7 100644 (file)
@@ -383,8 +383,13 @@ namespace Mono.Security.X509 {
 
                                byte[] authSafeData = authSafe.Content [0].Value;
                                byte[] calculatedMac = MAC (_password, macSalt.Value, _iterations, authSafeData);
-                               if (!Compare (macValue, calculatedMac))
-                                       throw new CryptographicException ("Invalid MAC - file may have been tampered!");
+                               if (!Compare (macValue, calculatedMac)) {
+                                       byte[] nullPassword = {0, 0};
+                                       calculatedMac = MAC(nullPassword, macSalt.Value, _iterations, authSafeData);
+                                       if (!Compare (macValue, calculatedMac))
+                                               throw new CryptographicException ("Invalid MAC - file may have been tampe red!");
+                                       _password = nullPassword;
+                               }
                        }
 
                        // we now returns to our original presentation - PFX