summary refs log tree commit diff
path: root/crypto/test
diff options
context:
space:
mode:
authorAlexander Scheel <alexander.scheel@keyfactor.com>2024-06-21 15:58:07 -0400
committerAlexander Scheel <alexander.scheel@keyfactor.com>2024-06-21 15:58:34 -0400
commitb7c105616243b251f03b9adde96357486a9e40f7 (patch)
tree3b0384915940ff12addf9a11adb151e317593f54 /crypto/test
parentASN.1: GetOptional for universal types should not convert (diff)
downloadBouncyCastle.NET-ed25519-b7c105616243b251f03b9adde96357486a9e40f7.tar.xz
Add support for modified UTF-8 in JKS
When parsing JKS entries, BC C# previously failed to parse entries with
UTF-8 entries. This is because Java encodes them using a modified UTF-8
wherein NULL bytes and 4-byte extended values do not appear.

Add support for both reading and writing this modified method of UTF-8
within the JKS parsing code.

Signed-off-by: Alexander Scheel <alexander.scheel@keyfactor.com>
Diffstat (limited to 'crypto/test')
-rw-r--r--crypto/test/data/jks/cacerts.jksbin0 -> 156996 bytes
-rw-r--r--crypto/test/src/security/test/JksStoreTest.cs16
2 files changed, 16 insertions, 0 deletions
diff --git a/crypto/test/data/jks/cacerts.jks b/crypto/test/data/jks/cacerts.jks
new file mode 100644
index 000000000..ca0cbd33e
--- /dev/null
+++ b/crypto/test/data/jks/cacerts.jks
Binary files differdiff --git a/crypto/test/src/security/test/JksStoreTest.cs b/crypto/test/src/security/test/JksStoreTest.cs
index 335786f5e..8794d48a6 100644
--- a/crypto/test/src/security/test/JksStoreTest.cs
+++ b/crypto/test/src/security/test/JksStoreTest.cs
@@ -9,6 +9,8 @@ using Org.BouncyCastle.Crypto.Parameters;
 using Org.BouncyCastle.Math;
 using Org.BouncyCastle.Utilities.Encoders;
 
+using Org.BouncyCastle.Utilities.Test;
+
 namespace Org.BouncyCastle.Security.Tests
 {
     [TestFixture]
@@ -177,5 +179,19 @@ namespace Org.BouncyCastle.Security.Tests
                 // Expected
             }
         }
+
+        [Test]
+        public void TestJksModifiedUtf8Roundtrip()
+        {
+            JksStore ks = new JksStore();
+            Stream fIn = SimpleTest.GetTestDataAsStream("jks.cacerts.jks");
+
+            ks.Load(fIn, "changeit".ToCharArray());
+
+            MemoryStream bOut = new MemoryStream();
+            ks.Save(bOut, "changedit".ToCharArray());
+
+            ks.Load(new MemoryStream(bOut.ToArray()), "changedit".ToCharArray());
+        }
     }
 }