Navigation Menu

Skip to content

Commit

Permalink
8281175: Add a -providerPath option to jarsigner
Browse files Browse the repository at this point in the history
Reviewed-by: xuelei, hchao
  • Loading branch information
wangweij committed Feb 7, 2022
1 parent a0f6f24 commit 2ed1f4c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 18 deletions.
Expand Up @@ -824,9 +824,7 @@ void doCommands(PrintStream out) throws Exception {
if (providerClasses != null) {
ClassLoader cl = null;
if (pathlist != null) {
String path = null;
path = PathList.appendPath(
path, System.getProperty("java.class.path"));
String path = System.getProperty("java.class.path");
path = PathList.appendPath(
path, System.getProperty("env.class.path"));
path = PathList.appendPath(path, pathlist);
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -27,6 +27,7 @@

import java.io.*;
import java.net.UnknownHostException;
import java.net.URLClassLoader;
import java.security.cert.CertPathValidatorException;
import java.security.cert.PKIXBuilderParameters;
import java.util.*;
Expand Down Expand Up @@ -59,6 +60,7 @@
import sun.security.provider.certpath.CertPathConstraintsParameters;
import sun.security.timestamp.TimestampToken;
import sun.security.tools.KeyStoreUtil;
import sun.security.tools.PathList;
import sun.security.validator.Validator;
import sun.security.validator.ValidatorException;
import sun.security.x509.*;
Expand Down Expand Up @@ -152,6 +154,7 @@ public static void main(String args[]) throws Exception {
List<String> providerClasses = null; // list of provider classes
// arguments for provider constructors
HashMap<String,String> providerArgs = new HashMap<>();
String pathlist = null;
char[] keypass; // private key password
String sigfile; // name of .SF file
String sigalg; // name of signature algorithm
Expand Down Expand Up @@ -246,7 +249,18 @@ public void run(String args[]) {
}

if (providerClasses != null) {
ClassLoader cl = ClassLoader.getSystemClassLoader();
ClassLoader cl;
if (pathlist != null) {
String path = System.getProperty("java.class.path");
path = PathList.appendPath(
path, System.getProperty("env.class.path"));
path = PathList.appendPath(path, pathlist);

URL[] urls = PathList.pathToURLs(path);
cl = new URLClassLoader(urls);
} else {
cl = ClassLoader.getSystemClassLoader();
}
for (String provClass: providerClasses) {
try {
KeyStoreUtil.loadProviderByClass(provClass,
Expand Down Expand Up @@ -434,6 +448,9 @@ String[] parseArgs(String args[]) throws Exception {
n += 2;
}
}
} else if (collator.compare(flags, "-providerpath") == 0) {
if (++n == args.length) usageNoArg();
pathlist = args[n];
} else if (collator.compare(flags, "-protected") ==0) {
protectedPath = true;
} else if (collator.compare(flags, "-certchain") ==0) {
Expand Down Expand Up @@ -705,6 +722,9 @@ static void fullusage() {
System.out.println(rb.getString
(".providerArg.option.2"));
System.out.println();
System.out.println(rb.getString
(".providerPath.option"));
System.out.println();
System.out.println(rb.getString
(".strict.treat.warnings.as.errors"));
System.out.println();
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -119,6 +119,8 @@ public class Resources extends java.util.ListResourceBundle {
"[-providerClass <class> add security provider by fully-qualified class name"},
{".providerArg.option.2",
" [-providerArg <arg>]] ... configure argument for -providerClass"},
{".providerPath.option",
"[-providerPath <list>] provider classpath"},
{".strict.treat.warnings.as.errors",
"[-strict] treat warnings as errors"},
{".conf.url.specify.a.pre.configured.options.file",
Expand Down
19 changes: 7 additions & 12 deletions test/jdk/sun/security/tools/jarsigner/AltProvider.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -23,7 +23,7 @@

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

// legacy use (-providerPath only supported by keytool)
testKeytool("-providerPath mods/test.dummy " +
"-providerClass org.test.dummy.DummyProvider -providerArg full",
0, "loadProviderByClass: org.test.dummy.DummyProvider");

// legacy, on classpath
testBoth("-J-cp -Jmods/test.dummy " +
testBoth("-providerpath mods/test.dummy " +
"-providerClass org.test.dummy.DummyProvider -providerArg full",
0, "loadProviderByClass: org.test.dummy.DummyProvider");

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

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

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

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

Expand Down

1 comment on commit 2ed1f4c

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.