author | weijun |
Thu, 18 Jul 2019 08:53:06 +0800 | |
changeset 57488 | 94691d8e746f |
permissions | -rw-r--r-- |
57488
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
1 |
/* |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
4 |
* |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
8 |
* |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
13 |
* accompanied this code). |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
14 |
* |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
18 |
* |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
21 |
* questions. |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
22 |
*/ |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
23 |
|
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
24 |
import java.nio.file.Path; |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
25 |
import java.util.jar.Manifest; |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
26 |
import java.util.jar.Attributes.Name; |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
27 |
|
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
28 |
import jdk.test.lib.util.JarUtils; |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
29 |
import jdk.test.lib.SecurityTools; |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
30 |
import org.testng.annotations.Test; |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
31 |
import org.testng.annotations.BeforeClass; |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
32 |
|
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
33 |
import static java.nio.charset.StandardCharsets.UTF_8; |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
34 |
import static org.testng.Assert.*; |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
35 |
|
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
36 |
/** |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
37 |
* @test |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
38 |
* @bug 8217375 |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
39 |
* @modules java.base/sun.security.util |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
40 |
* @library /test/lib /lib/testlibrary |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
41 |
* @run testng EmptyJar |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
42 |
* @summary Checks that signing an empty jar file does not result in an NPE or |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
43 |
* other error condition. |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
44 |
*/ |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
45 |
public class EmptyJar { |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
46 |
|
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
47 |
static final String KEYSTORE_FILENAME = "test.jks"; |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
48 |
|
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
49 |
@BeforeClass |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
50 |
public void prepareKeyStore() throws Exception { |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
51 |
SecurityTools.keytool("-genkeypair -keyalg EC -keystore " |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
52 |
+ KEYSTORE_FILENAME + " -storepass changeit -keypass changeit" |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
53 |
+ " -alias a -dname CN=A").shouldHaveExitValue(0); |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
54 |
} |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
55 |
|
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
56 |
@Test |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
57 |
public void test() throws Exception { |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
58 |
String jarFilename = "test.jar"; |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
59 |
JarUtils.createJarFile(Path.of(jarFilename), (Manifest) null, |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
60 |
Path.of(".")); |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
61 |
SecurityTools.jarsigner("-keystore " + KEYSTORE_FILENAME + |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
62 |
" -storepass changeit -verbose -debug " + jarFilename + " a") |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
63 |
.shouldHaveExitValue(0); |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
64 |
|
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
65 |
// verify that jarsigner has added a default manifest |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
66 |
byte[] mfBytes = Utils.readJarManifestBytes(jarFilename); |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
67 |
Utils.echoManifest(mfBytes, "manifest"); |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
68 |
assertTrue(new String(mfBytes, UTF_8).startsWith( |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
69 |
Name.MANIFEST_VERSION + ": 1.0\r\nCreated-By: ")); |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
70 |
} |
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
71 |
|
94691d8e746f
8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff
changeset
|
72 |
} |