From b7c105616243b251f03b9adde96357486a9e40f7 Mon Sep 17 00:00:00 2001 From: Alexander Scheel Date: Fri, 21 Jun 2024 15:58:07 -0400 Subject: 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 --- crypto/test/data/jks/cacerts.jks | Bin 0 -> 156996 bytes crypto/test/src/security/test/JksStoreTest.cs | 16 ++++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 crypto/test/data/jks/cacerts.jks (limited to 'crypto/test') diff --git a/crypto/test/data/jks/cacerts.jks b/crypto/test/data/jks/cacerts.jks new file mode 100644 index 000000000..ca0cbd33e Binary files /dev/null and b/crypto/test/data/jks/cacerts.jks differ diff --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()); + } } } -- cgit 1.4.1