|
1 | 1 | /* |
2 | | - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2016, 2025, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
|
21 | 21 | * questions. |
22 | 22 | */ |
23 | 23 |
|
| 24 | +/* |
| 25 | + * @test |
| 26 | + * @bug 8158633 |
| 27 | + * @summary BASE64 encoded cert not correctly parsed with UTF-16 |
| 28 | + * @library /test/lib |
| 29 | + */ |
| 30 | + |
| 31 | +import jdk.test.lib.process.ProcessTools; |
| 32 | + |
24 | 33 | import java.io.FileInputStream; |
| 34 | +import java.nio.charset.Charset; |
| 35 | +import java.nio.file.Path; |
25 | 36 | import java.security.cert.CertificateFactory; |
26 | 37 |
|
27 | 38 | public class PemEncoding { |
28 | 39 | public static void main(String[] args) throws Exception { |
29 | | - try (FileInputStream fis = new FileInputStream(args[0])) { |
30 | | - CertificateFactory cf = CertificateFactory.getInstance("X.509"); |
31 | | - System.out.println(cf.generateCertificate(fis)); |
| 40 | + |
| 41 | + final var certPath = Path.of(System.getProperty("test.src", ".")) |
| 42 | + .getParent() |
| 43 | + .resolve("HostnameChecker") |
| 44 | + .resolve("cert5.crt") |
| 45 | + .toString(); |
| 46 | + |
| 47 | + final var testCommand = new String[]{"-Dfile.encoding=UTF-16", |
| 48 | + PemEncoding.PemEncodingTest.class.getName(), |
| 49 | + certPath}; |
| 50 | + |
| 51 | + final var result = ProcessTools.executeTestJava(testCommand); |
| 52 | + result.shouldHaveExitValue(0); |
| 53 | + |
| 54 | + } |
| 55 | + |
| 56 | + static class PemEncodingTest { |
| 57 | + public static void main(String[] args) throws Exception { |
| 58 | + |
| 59 | + try (FileInputStream fis = new FileInputStream(args[0])) { |
| 60 | + CertificateFactory cf = CertificateFactory.getInstance("X.509"); |
| 61 | + System.out.println(cf.generateCertificate(fis)); |
| 62 | + } |
| 63 | + |
| 64 | + if (!"UTF-16".equals(Charset.defaultCharset().displayName())) { |
| 65 | + throw new RuntimeException("File encoding is not UTF-16"); |
| 66 | + } |
32 | 67 | } |
33 | 68 | } |
34 | 69 | } |
0 commit comments