Skip to content

Commit 2ed1f4c

Browse files
committed
8281175: Add a -providerPath option to jarsigner
Reviewed-by: xuelei, hchao
1 parent a0f6f24 commit 2ed1f4c

File tree

4 files changed

+33
-18
lines changed

4 files changed

+33
-18
lines changed

src/java.base/share/classes/sun/security/tools/keytool/Main.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -824,9 +824,7 @@ void doCommands(PrintStream out) throws Exception {
824824
if (providerClasses != null) {
825825
ClassLoader cl = null;
826826
if (pathlist != null) {
827-
String path = null;
828-
path = PathList.appendPath(
829-
path, System.getProperty("java.class.path"));
827+
String path = System.getProperty("java.class.path");
830828
path = PathList.appendPath(
831829
path, System.getProperty("env.class.path"));
832830
path = PathList.appendPath(path, pathlist);

src/jdk.jartool/share/classes/sun/security/tools/jarsigner/Main.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -27,6 +27,7 @@
2727

2828
import java.io.*;
2929
import java.net.UnknownHostException;
30+
import java.net.URLClassLoader;
3031
import java.security.cert.CertPathValidatorException;
3132
import java.security.cert.PKIXBuilderParameters;
3233
import java.util.*;
@@ -59,6 +60,7 @@
5960
import sun.security.provider.certpath.CertPathConstraintsParameters;
6061
import sun.security.timestamp.TimestampToken;
6162
import sun.security.tools.KeyStoreUtil;
63+
import sun.security.tools.PathList;
6264
import sun.security.validator.Validator;
6365
import sun.security.validator.ValidatorException;
6466
import sun.security.x509.*;
@@ -152,6 +154,7 @@ public static void main(String args[]) throws Exception {
152154
List<String> providerClasses = null; // list of provider classes
153155
// arguments for provider constructors
154156
HashMap<String,String> providerArgs = new HashMap<>();
157+
String pathlist = null;
155158
char[] keypass; // private key password
156159
String sigfile; // name of .SF file
157160
String sigalg; // name of signature algorithm
@@ -246,7 +249,18 @@ public void run(String args[]) {
246249
}
247250

248251
if (providerClasses != null) {
249-
ClassLoader cl = ClassLoader.getSystemClassLoader();
252+
ClassLoader cl;
253+
if (pathlist != null) {
254+
String path = System.getProperty("java.class.path");
255+
path = PathList.appendPath(
256+
path, System.getProperty("env.class.path"));
257+
path = PathList.appendPath(path, pathlist);
258+
259+
URL[] urls = PathList.pathToURLs(path);
260+
cl = new URLClassLoader(urls);
261+
} else {
262+
cl = ClassLoader.getSystemClassLoader();
263+
}
250264
for (String provClass: providerClasses) {
251265
try {
252266
KeyStoreUtil.loadProviderByClass(provClass,
@@ -434,6 +448,9 @@ String[] parseArgs(String args[]) throws Exception {
434448
n += 2;
435449
}
436450
}
451+
} else if (collator.compare(flags, "-providerpath") == 0) {
452+
if (++n == args.length) usageNoArg();
453+
pathlist = args[n];
437454
} else if (collator.compare(flags, "-protected") ==0) {
438455
protectedPath = true;
439456
} else if (collator.compare(flags, "-certchain") ==0) {
@@ -705,6 +722,9 @@ static void fullusage() {
705722
System.out.println(rb.getString
706723
(".providerArg.option.2"));
707724
System.out.println();
725+
System.out.println(rb.getString
726+
(".providerPath.option"));
727+
System.out.println();
708728
System.out.println(rb.getString
709729
(".strict.treat.warnings.as.errors"));
710730
System.out.println();

src/jdk.jartool/share/classes/sun/security/tools/jarsigner/Resources.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -119,6 +119,8 @@ public class Resources extends java.util.ListResourceBundle {
119119
"[-providerClass <class> add security provider by fully-qualified class name"},
120120
{".providerArg.option.2",
121121
" [-providerArg <arg>]] ... configure argument for -providerClass"},
122+
{".providerPath.option",
123+
"[-providerPath <list>] provider classpath"},
122124
{".strict.treat.warnings.as.errors",
123125
"[-strict] treat warnings as errors"},
124126
{".conf.url.specify.a.pre.configured.options.file",

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

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
2323

2424
/*
2525
* @test
26-
* @bug 4906940 8130302 8194152
26+
* @bug 4906940 8130302 8194152 8281175
2727
* @summary -providerPath, -providerClass, -addprovider, and -providerArg
2828
* @library /test/lib
2929
* @modules java.base/jdk.internal.misc
@@ -81,33 +81,28 @@ public static void main(String[] args) throws Throwable {
8181
// Without new provider
8282
testBoth("", 1, "DUMMYKS not found");
8383

84-
// legacy use (-providerPath only supported by keytool)
85-
testKeytool("-providerPath mods/test.dummy " +
86-
"-providerClass org.test.dummy.DummyProvider -providerArg full",
87-
0, "loadProviderByClass: org.test.dummy.DummyProvider");
88-
8984
// legacy, on classpath
90-
testBoth("-J-cp -Jmods/test.dummy " +
85+
testBoth("-providerpath mods/test.dummy " +
9186
"-providerClass org.test.dummy.DummyProvider -providerArg full",
9287
0, "loadProviderByClass: org.test.dummy.DummyProvider");
9388

9489
// Wrong name
95-
testBoth("-J-cp -Jmods/test.dummy " +
90+
testBoth("-providerpath mods/test.dummy " +
9691
"-providerClass org.test.dummy.Dummy -providerArg full",
9792
1, "Provider \"org.test.dummy.Dummy\" not found");
9893

9994
// Not a provider name
100-
testBoth("-J-cp -Jmods/test.dummy " +
95+
testBoth("-providerpath mods/test.dummy " +
10196
"-providerClass java.lang.Object -providerArg full",
10297
1, "java.lang.Object not a provider");
10398

10499
// without arg
105-
testBoth("-J-cp -Jmods/test.dummy " +
100+
testBoth("-providerpath mods/test.dummy " +
106101
"-providerClass org.test.dummy.DummyProvider",
107102
1, "DUMMYKS not found");
108103

109104
// old -provider still works
110-
testBoth("-J-cp -Jmods/test.dummy " +
105+
testBoth("-providerpath mods/test.dummy " +
111106
"-provider org.test.dummy.DummyProvider -providerArg full",
112107
0, "loadProviderByClass: org.test.dummy.DummyProvider");
113108

0 commit comments

Comments
 (0)