Skip to content

Commit 2aafa0f

Browse files
author
duke
committed
Automatic merge of jdk:master into master
2 parents a18f4d6 + 1e9a432 commit 2aafa0f

File tree

2 files changed

+84
-57
lines changed

2 files changed

+84
-57
lines changed

test/jdk/sun/security/tools/jarsigner/PosixPermissionsTest.java

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,21 @@
3232
*/
3333

3434
import java.net.URI;
35-
import java.nio.file.*;
35+
import java.nio.file.FileSystem;
36+
import java.nio.file.FileSystems;
37+
import java.nio.file.Files;
38+
import java.nio.file.Path;
39+
import java.nio.file.StandardCopyOption;
3640
import java.nio.file.attribute.PosixFilePermission;
3741
import java.nio.file.attribute.PosixFilePermissions;
38-
import java.util.*;
42+
import java.util.HashMap;
43+
import java.util.List;
44+
import java.util.Map;
45+
import java.util.Set;
3946

4047
import jdk.test.lib.SecurityTools;
4148

4249
public class PosixPermissionsTest {
43-
4450
private static List<String> perms = List.of(
4551
"---------",
4652
"r--------",
@@ -77,16 +83,13 @@ public class PosixPermissionsTest {
7783
"protected by the signature.";
7884

7985
public static void main(String[] args) throws Exception {
80-
if (!FileSystems.getDefault().supportedFileAttributeViews().contains("posix")) {
81-
System.out.println("No posix support. Skipping");
82-
return;
83-
}
84-
8586
createFiles();
87+
8688
// check permissions before signing
8789
verifyFilePermissions(ZIPURI, true);
8890
verifyFilePermissions(JARURI, false);
8991

92+
// generate key for signing
9093
SecurityTools.keytool(
9194
"-genkey",
9295
"-keyalg", "RSA",
@@ -98,6 +101,7 @@ public static void main(String[] args) throws Exception {
98101
"-validity", "365")
99102
.shouldHaveExitValue(0);
100103

104+
// sign zip file - expect warning
101105
SecurityTools.jarsigner(
102106
"-keystore", "examplekeystore",
103107
"-verbose", ZIPFILENAME,
@@ -107,31 +111,35 @@ public static void main(String[] args) throws Exception {
107111
.shouldHaveExitValue(0)
108112
.shouldContain(WARNING_MSG);
109113

110-
// zip file now signed. Recheck file permissions
114+
// recheck permissions after signing
111115
verifyFilePermissions(ZIPURI, true);
112116

113-
// sign jar file - no posix warning message expected
114-
SecurityTools.jarsigner("-keystore", "examplekeystore",
117+
// sign jar file - expect no warning
118+
SecurityTools.jarsigner(
119+
"-keystore", "examplekeystore",
115120
"-verbose", JARFILENAME,
116121
"-storepass", "password",
117122
"-keypass", "password",
118123
"examplekey")
119124
.shouldHaveExitValue(0)
120125
.shouldNotContain(WARNING_MSG);
121126

122-
// default attributes expected
127+
// recheck permissions after signing
123128
verifyFilePermissions(JARURI, false);
124129

125-
SecurityTools.jarsigner("-keystore", "examplekeystore",
130+
// verify zip file - expect warning
131+
SecurityTools.jarsigner(
132+
"-keystore", "examplekeystore",
126133
"-storepass", "password",
127134
"-keypass", "password",
128135
"-verbose",
129136
"-verify", ZIPFILENAME)
130137
.shouldHaveExitValue(0)
131138
.shouldContain(WARNING_MSG);
132139

133-
// no warning expected for regular jar file
134-
SecurityTools.jarsigner("-keystore", "examplekeystore",
140+
// verify jar file - expect no warning
141+
SecurityTools.jarsigner(
142+
"-keystore", "examplekeystore",
135143
"-storepass", "password",
136144
"-keypass", "password",
137145
"-verbose",

test/jdk/sun/security/tools/jarsigner/SymLinkTest.java

Lines changed: 61 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,35 @@
3131
* @run main/othervm SymLinkTest
3232
*/
3333

34-
import java.io.*;
35-
import java.net.URI;
36-
import java.nio.file.*;
34+
import java.io.FileInputStream;
35+
import java.io.IOException;
36+
import java.nio.file.Files;
37+
import java.nio.file.Path;
3738
import java.util.Formatter;
3839

3940
import jdk.test.lib.SecurityTools;
4041

4142
public class SymLinkTest {
43+
private final static int BYTES_PER_ROW = 8;
4244
private final static String ZIPFILENAME = "8250968-test.zip";
4345
private static final String WARNING_MSG = "POSIX file permission and/or symlink " +
4446
"attributes detected. These attributes are ignored when signing and are not " +
4547
"protected by the signature.";
4648

4749
public static void main(String[] args) throws Exception {
48-
Files.deleteIfExists(Paths.get(ZIPFILENAME));
49-
try (FileOutputStream fos = new FileOutputStream(ZIPFILENAME)) {
50-
fos.write(ZIPBYTES);
50+
// call main with an argument to print the prepared zipfile as byte array declaration
51+
if (args.length > 0) {
52+
System.out.println("Bytes of " + ZIPFILENAME + ":");
53+
System.out.println(createByteArray(Files.readAllBytes(Path.of(ZIPFILENAME)), "ZIPBYTES"));
54+
System.exit(0);
5155
}
5256

53-
// check permissions before signing
57+
Files.write(Path.of(ZIPFILENAME), ZIPBYTES);
58+
59+
// check attributes before signing
5460
verifyExtraAttrs(ZIPFILENAME);
5561

62+
// generate key for signing
5663
SecurityTools.keytool(
5764
"-genkey",
5865
"-keyalg", "RSA",
@@ -64,6 +71,7 @@ public static void main(String[] args) throws Exception {
6471
"-validity", "365")
6572
.shouldHaveExitValue(0);
6673

74+
// sign zip file - expect warning
6775
SecurityTools.jarsigner(
6876
"-keystore", "examplekeystore",
6977
"-verbose", ZIPFILENAME,
@@ -73,10 +81,12 @@ public static void main(String[] args) throws Exception {
7381
.shouldHaveExitValue(0)
7482
.shouldContain(WARNING_MSG);
7583

76-
// zip file now signed. Recheck attributes
84+
// recheck attributes after signing
7785
verifyExtraAttrs(ZIPFILENAME);
7886

79-
SecurityTools.jarsigner("-keystore", "examplekeystore",
87+
// verify zip file - expect warning
88+
SecurityTools.jarsigner(
89+
"-keystore", "examplekeystore",
8090
"-storepass", "password",
8191
"-keypass", "password",
8292
"-verbose",
@@ -114,48 +124,57 @@ private static void verifyExtraAttrs(String zipFileName) throws IOException {
114124
* @param name Name to be used in the byte array declaration
115125
* @return The formatted byte array declaration
116126
*/
117-
public static String createByteArray(byte[] bytes, String name) {
118-
StringBuilder sb = new StringBuilder(bytes.length * 5);
119-
Formatter fmt = new Formatter(sb);
120-
fmt.format(" public static byte[] %s = {", name);
121-
final int linelen = 8;
122-
for (int i = 0; i < bytes.length; i++) {
123-
if (i % linelen == 0) {
124-
fmt.format("%n ");
127+
private static String createByteArray(byte[] bytes, String name) {
128+
StringBuilder sb = new StringBuilder();
129+
try (Formatter fmt = new Formatter(sb)) {
130+
fmt.format(" public final static byte[] %s = {", name);
131+
for (int i = 0; i < bytes.length; i++) {
132+
int mod = i % BYTES_PER_ROW;
133+
if (mod == 0) {
134+
fmt.format("%n ");
135+
} else {
136+
fmt.format(" ");
137+
}
138+
fmt.format("(byte)0x%02x", bytes[i]);
139+
if (i != bytes.length - 1) {
140+
fmt.format(",");
141+
}
125142
}
126-
fmt.format(" (byte) 0x%x,", bytes[i] & 0xff);
143+
fmt.format("%n };%n");
127144
}
128-
fmt.format("%n };%n");
129145
return sb.toString();
130146
}
131147

132148
/*
133-
* Created using the createByteArray utility method.
134-
* The zipfile itself was created via this example:
149+
* The zipfile itself was created like this:
150+
* $ ln -s ../z z
135151
* $ ls -l z
136152
* lrwxrwxrwx 1 test test 4 Aug 27 18:33 z -> ../z
137-
* $ zip -ry test.zip z
153+
* $ zip -ry 8250968-test.zip z
154+
*
155+
* The byte array representation was generated using the createByteArray utility method:
156+
* $ java SymLinkTest generate
138157
*/
139158
public final static byte[] ZIPBYTES = {
140-
(byte) 0x50, (byte) 0x4b, (byte) 0x3, (byte) 0x4, (byte) 0xa, (byte) 0x0, (byte) 0x0, (byte) 0x0,
141-
(byte) 0x0, (byte) 0x0, (byte) 0x2e, (byte) 0x94, (byte) 0x1b, (byte) 0x51, (byte) 0xb4, (byte) 0xcc,
142-
(byte) 0xb6, (byte) 0xf1, (byte) 0x4, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x4, (byte) 0x0,
143-
(byte) 0x0, (byte) 0x0, (byte) 0x1, (byte) 0x0, (byte) 0x1c, (byte) 0x0, (byte) 0x7a, (byte) 0x55,
144-
(byte) 0x54, (byte) 0x9, (byte) 0x0, (byte) 0x3, (byte) 0x77, (byte) 0xfc, (byte) 0x47, (byte) 0x5f,
145-
(byte) 0x78, (byte) 0xfc, (byte) 0x47, (byte) 0x5f, (byte) 0x75, (byte) 0x78, (byte) 0xb, (byte) 0x0,
146-
(byte) 0x1, (byte) 0x4, (byte) 0xec, (byte) 0x3, (byte) 0x0, (byte) 0x0, (byte) 0x4, (byte) 0xec,
147-
(byte) 0x3, (byte) 0x0, (byte) 0x0, (byte) 0x2e, (byte) 0x2e, (byte) 0x2f, (byte) 0x7a, (byte) 0x50,
148-
(byte) 0x4b, (byte) 0x1, (byte) 0x2, (byte) 0x1e, (byte) 0x3, (byte) 0xa, (byte) 0x0, (byte) 0x0,
149-
(byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x2e, (byte) 0x94, (byte) 0x1b, (byte) 0x51, (byte) 0xb4,
150-
(byte) 0xcc, (byte) 0xb6, (byte) 0xf1, (byte) 0x4, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x4,
151-
(byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x1, (byte) 0x0, (byte) 0x18, (byte) 0x0, (byte) 0x0,
152-
(byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0xff,
153-
(byte) 0xa1, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x7a, (byte) 0x55, (byte) 0x54,
154-
(byte) 0x5, (byte) 0x0, (byte) 0x3, (byte) 0x77, (byte) 0xfc, (byte) 0x47, (byte) 0x5f, (byte) 0x75,
155-
(byte) 0x78, (byte) 0xb, (byte) 0x0, (byte) 0x1, (byte) 0x4, (byte) 0xec, (byte) 0x3, (byte) 0x0,
156-
(byte) 0x0, (byte) 0x4, (byte) 0xec, (byte) 0x3, (byte) 0x0, (byte) 0x0, (byte) 0x50, (byte) 0x4b,
157-
(byte) 0x5, (byte) 0x6, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x1, (byte) 0x0,
158-
(byte) 0x1, (byte) 0x0, (byte) 0x47, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x3f, (byte) 0x0,
159-
(byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0,
159+
(byte)0x50, (byte)0x4b, (byte)0x03, (byte)0x04, (byte)0x0a, (byte)0x00, (byte)0x00, (byte)0x00,
160+
(byte)0x00, (byte)0x00, (byte)0x2e, (byte)0x94, (byte)0x1b, (byte)0x51, (byte)0xb4, (byte)0xcc,
161+
(byte)0xb6, (byte)0xf1, (byte)0x04, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x04, (byte)0x00,
162+
(byte)0x00, (byte)0x00, (byte)0x01, (byte)0x00, (byte)0x1c, (byte)0x00, (byte)0x7a, (byte)0x55,
163+
(byte)0x54, (byte)0x09, (byte)0x00, (byte)0x03, (byte)0x77, (byte)0xfc, (byte)0x47, (byte)0x5f,
164+
(byte)0x78, (byte)0xfc, (byte)0x47, (byte)0x5f, (byte)0x75, (byte)0x78, (byte)0x0b, (byte)0x00,
165+
(byte)0x01, (byte)0x04, (byte)0xec, (byte)0x03, (byte)0x00, (byte)0x00, (byte)0x04, (byte)0xec,
166+
(byte)0x03, (byte)0x00, (byte)0x00, (byte)0x2e, (byte)0x2e, (byte)0x2f, (byte)0x7a, (byte)0x50,
167+
(byte)0x4b, (byte)0x01, (byte)0x02, (byte)0x1e, (byte)0x03, (byte)0x0a, (byte)0x00, (byte)0x00,
168+
(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x2e, (byte)0x94, (byte)0x1b, (byte)0x51, (byte)0xb4,
169+
(byte)0xcc, (byte)0xb6, (byte)0xf1, (byte)0x04, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x04,
170+
(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x00, (byte)0x18, (byte)0x00, (byte)0x00,
171+
(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xff,
172+
(byte)0xa1, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x7a, (byte)0x55, (byte)0x54,
173+
(byte)0x05, (byte)0x00, (byte)0x03, (byte)0x77, (byte)0xfc, (byte)0x47, (byte)0x5f, (byte)0x75,
174+
(byte)0x78, (byte)0x0b, (byte)0x00, (byte)0x01, (byte)0x04, (byte)0xec, (byte)0x03, (byte)0x00,
175+
(byte)0x00, (byte)0x04, (byte)0xec, (byte)0x03, (byte)0x00, (byte)0x00, (byte)0x50, (byte)0x4b,
176+
(byte)0x05, (byte)0x06, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x00,
177+
(byte)0x01, (byte)0x00, (byte)0x47, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x3f, (byte)0x00,
178+
(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00
160179
};
161180
}

0 commit comments

Comments
 (0)