summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2015-11-12 17:32:38 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2015-11-12 17:32:38 +0700
commit005288002936b16dce66912f06fcd1ba09ed2508 (patch)
tree08addda717ec485c44c2babefe1441fd31dac1d8
parentAdd sanity check on input length (diff)
downloadBouncyCastle.NET-ed25519-005288002936b16dce66912f06fcd1ba09ed2508.tar.xz
Use culture-independent prefix-check in MacUtilities.GetMac
- Fix for https://github.com/bcgit/bc-csharp/pull/40 (modified from original patch)
-rw-r--r--crypto/Contributors.html6
-rw-r--r--crypto/crypto.csproj5
-rw-r--r--crypto/src/security/MacUtilities.cs4
-rw-r--r--crypto/test/src/security/test/TestMacUtil.cs38
4 files changed, 50 insertions, 3 deletions
diff --git a/crypto/Contributors.html b/crypto/Contributors.html
index 8908b857a..5211b193f 100644
--- a/crypto/Contributors.html
+++ b/crypto/Contributors.html
@@ -136,8 +136,10 @@
                 <p>John Allberg &lt;john&#064ayoy.se&gt; - improvements to Portable Class Library patch.</p>
             </li>
             <li>
-                <p>Oren Novotny (https://github.com/onovotny) - developed and maintained a fork supporting Portable Class Library, worked closely with us
-                to integrate the changes back into the main project.</p>
+                <p>Oren Novotny (https://github.com/onovotny) - developed and maintained a fork supporting Portable Class Library, worked closely with us to integrate the changes back into the main project.</p>
+            </li>
+            <li>
+                <p>Nicolas Dorier (https://github.com/NicolasDorier) - patch to fix culture-dependent lookups in MacUtilities.
             </li>
 		</ul>
 	</body>
diff --git a/crypto/crypto.csproj b/crypto/crypto.csproj
index 3f942800c..28d0b19b3 100644
--- a/crypto/crypto.csproj
+++ b/crypto/crypto.csproj
@@ -12115,6 +12115,11 @@
                     BuildAction = "Compile"
                 />
                 <File
+                    RelPath = "test\src\security\test\TestMacUtil.cs"
+                    SubType = "Code"
+                    BuildAction = "Compile"
+                />
+                <File
                     RelPath = "test\src\security\test\TestSignerUtil.cs"
                     SubType = "Code"
                     BuildAction = "Compile"
diff --git a/crypto/src/security/MacUtilities.cs b/crypto/src/security/MacUtilities.cs
index d7fe91142..41cf5e9e2 100644
--- a/crypto/src/security/MacUtilities.cs
+++ b/crypto/src/security/MacUtilities.cs
@@ -1,4 +1,6 @@
+using System;
 using System.Collections;
+using System.Globalization;
 
 using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Asn1.Iana;
@@ -117,7 +119,7 @@ namespace Org.BouncyCastle.Security
                 mechanism = mechanism.Substring("PBEWITH".Length);
             }
 
-            if (mechanism.StartsWith("HMAC"))
+            if (CultureInfo.InvariantCulture.CompareInfo.IsPrefix(mechanism, "HMAC", CompareOptions.Ordinal))
             {
                 string digestName;
                 if (mechanism.StartsWith("HMAC-") || mechanism.StartsWith("HMAC/"))
diff --git a/crypto/test/src/security/test/TestMacUtil.cs b/crypto/test/src/security/test/TestMacUtil.cs
new file mode 100644
index 000000000..1eb6f35b0
--- /dev/null
+++ b/crypto/test/src/security/test/TestMacUtil.cs
@@ -0,0 +1,38 @@
+using System;
+using System.Globalization;
+using System.Threading;
+
+using NUnit.Framework;
+
+using Org.BouncyCastle.Crypto;
+
+namespace Org.BouncyCastle.Security.Tests
+{
+    [TestFixture]
+    public class TestMacUtilities
+    {
+        [Test]
+        public void TestCultureIndependence()
+        {
+            Thread t = Thread.CurrentThread;
+            CultureInfo ci = t.CurrentCulture;
+            try
+            {
+                /*
+                 * In Hungarian, the "CS" in "HMACSHA256" is linguistically a single character, so "HMAC" is not a prefix.
+                 */
+                t.CurrentCulture = new CultureInfo("hu-HU");
+                IMac mac = MacUtilities.GetMac("HMACSHA256");
+                Assert.NotNull(mac);
+            }
+            catch (Exception e)
+            {
+                Assert.Fail("Culture-specific lookup failed: " + e.Message);
+            }
+            finally
+            {
+                t.CurrentCulture = ci;
+            }
+        }
+    }
+}