Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8266182: Automate manual steps listed in the test jdk/sun/security/pkcs12/ParamsTest.java #4413

Closed
wants to merge 10 commits into from

Conversation

akolarkunnu
Copy link
Contributor

@akolarkunnu akolarkunnu commented Jun 8, 2021

ParamsTest is an interop test between keytool <-> openssl. There are some manual steps listed in jdk/sun/security/pkcs12/params/README to perform after the execution of jtreg execution. So this test is to perform that manual steps.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8266182: Automate manual steps listed in the test jdk/sun/security/pkcs12/ParamsTest.java

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/4413/head:pull/4413
$ git checkout pull/4413

Update a local copy of the PR:
$ git checkout pull/4413
$ git pull https://git.openjdk.java.net/jdk pull/4413/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 4413

View PR using the GUI difftool:
$ git pr show -t 4413

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/4413.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 8, 2021

👋 Welcome back akolarkunnu! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label Jun 8, 2021
@openjdk
Copy link

openjdk bot commented Jun 8, 2021

@akolarkunnu The following label will be automatically applied to this pull request:

  • security

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the security security-dev@openjdk.org label Jun 8, 2021
@mlbridge
Copy link

mlbridge bot commented Jun 8, 2021

* @run shell/manual KeytoolOpensslInterop.sh
*/

public class KeytoolOpensslInteropTest {
Copy link
Member

Choose a reason for hiding this comment

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

This file is not necessary and the shell script can have @run tag instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, corrected that way. Removed this file and done everything in the shell script.

#

# Use OpenSSL 1.1.0i or above versions, earlier versions may generate different
# info and test fail.
Copy link
Member

Choose a reason for hiding this comment

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

It will be more helpful, if some instruction given about finding openssl, any pre-post requirement and any specific way to validate the result after execution for this manual Test execution.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added more details.

@openjdk
Copy link

openjdk bot commented Jun 22, 2021

@akolarkunnu This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8266182: Automate manual steps listed in the test jdk/sun/security/pkcs12/ParamsTest.java

Reviewed-by: hchao, ssahoo, xuelei, weijun

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 912 new commits pushed to the master branch:

  • 0e3fde6: 8264274: Block tags in overview.html are ignored
  • c5c84b8: 8270312: Error: Not a test or directory containing tests: java/awt/print/PrinterJob/XparColor.java
  • df1427b: 8272446: C1: Raw version of UnsafeGet generates load barriers
  • 989f39f: 8272552: mark hotspot runtime/cds tests which ignore external VM flags
  • ee8bf10: 8272327: Shenandoah: Avoid enqueuing duplicate string candidates
  • 3fb1927: 8271227: Missing {@code } in com.sun.source.*
  • a5ad772: 8272342: [TEST_BUG] java/awt/print/PrinterJob/PageDialogMarginTest.java catches all exceptions
  • ae45592: 8272374: doclint should report missing "body" comments
  • b2c272d: 8272305: several hotspot runtime/modules don't check exit codes
  • 8268825: 8272297: FileInputStream should override transferTo() for better performance
  • ... and 902 more: https://git.openjdk.java.net/jdk/compare/341f676066ab807d433f0f0b6c8356d2ad0e1cc9...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jun 22, 2021
@bridgekeeper
Copy link

bridgekeeper bot commented Jul 20, 2021

@akolarkunnu This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@rhalade
Copy link
Member

rhalade commented Jul 21, 2021

@akolarkunnu This is ready for a while now. Can you please integrate?

@akolarkunnu
Copy link
Contributor Author

I am trying to fully automate this instead of a manual test, because of some other high priority works I had paused that work, will resume it soon.

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Aug 9, 2021
@akolarkunnu akolarkunnu changed the title 8266182: Create a manual test for jdk/sun/security/pkcs12/ParamsTest.java 8266182: Automate manual steps listed in the test jdk/sun/security/pkcs12/ParamsTest.java Aug 9, 2021
@openjdk openjdk bot added the ready Pull request is ready to be integrated label Aug 9, 2021
Copy link
Contributor

@wangweij wangweij left a comment

Choose a reason for hiding this comment

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

Thanks for the fix. Code looks fine. I'm only concerned on the failure when openssl is not found.

*/

import jdk.test.lib.Asserts;
import jdk.test.lib.SecurityTools;
import jdk.test.lib.process.OutputAnalyzer;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Copy link
Contributor

Choose a reason for hiding this comment

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

IntelliJ IDEA shows quite some imports are useless.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed all unused imports

generateInitialKeystores(opensslPath);
testWithJavaCommands();
testWithOpensslCommands(opensslPath);
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

I still think it's better to succeed with a warning when the openssl binary cannot be found. IMHO it's a little unfriendly to force people setting up a system property to let the test pass. It's also dependent on runner machines and the user might have to adjust their scripts or launcher all the time. I would rather keep the old test/data if I want to ensure the test gets run everywhere.

Also, it might also help if the test can search for openssl, maybe simply from /usr/bin/openssl or /usr/local/bin/openssl, but this means you might need to check for the version.

Third, is it OK to let the system property pointing to the binary itself directly? When I was trying out this test I was using the openssl I built and it's not in a bin sub-directory.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, changed openssl selection flow as below:

  1. Check whether test.openssl.path is set and it's the the preferred version(1.1.*) of openssl
  2. If above property doesn't set, then look for already installed openssl (version 1.1.*) in system path /usr/bin/openssl or /usr/local/bin/openssl
  3. if above is also not available try to download openssl from artifactory
    If any of above 3 succeeds then perform all tests, otherwise skip all openssl command dependent tests with a warning.

Kept back all pre-generated keystores. Also kept README without any change, let me know whether I need to delete step2 from README.

Also changed system property to point to binary itself.

throws Throwable {
OutputAnalyzer output = ProcessTools.executeCommand(
opensslPath, "version")
.shouldHaveExitValue(0);
Copy link
Contributor

@wangweij wangweij Aug 9, 2021

Choose a reason for hiding this comment

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

This looks like a good time to ensure the version is 1.1.* or at least 1.* (I haven't tested with 1.0.* versions). Also, when trying out with 3.0.0, there are only 2 failures (line 119 generating weak file failed without -legacy. line 479 succeeded with a warning).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, added version check ProcessTools.executeCommand(path, "version").shouldHaveExitValue(0).shouldMatch("1.1.*");

I tested with 1.0.2a version, test fails because some of the info messages are different.
eg: 'MAC: sha256, Iteration 10000' missing from stdout/stderr
1.0.2a produces output as "MAC Iteration 10000" . ": sha256" is not there.

@@ -450,4 +577,57 @@ private static void check(
static OutputAnalyzer keytool(String s) throws Throwable {
return SecurityTools.keytool(s);
}
}

Copy link
Contributor

@wangweij wangweij Aug 9, 2021

Choose a reason for hiding this comment

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

I feel the lines below should go to a test library.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved fetchOpenssl() API to test/lib/jdk/test/lib/artifacts/OpensslArtifactFetcher.java

Copy link
Contributor

@wangweij wangweij left a comment

Choose a reason for hiding this comment

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

Thanks for the change. The fallback to testWithJavaCommands()-only is fine. Some comments.

try {
ProcessTools.executeCommand(path, "version")
.shouldHaveExitValue(0)
.shouldMatch("1.1.*");
Copy link
Contributor

Choose a reason for hiding this comment

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

Precisely the regex should be 1\\.1\\..*, or maybe you can simply call .shouldContain("1.1.").

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed it in to .shouldContain("1.1.")

// trying to download from artifactory
opensslPath = OpensslArtifactFetcher.fetchOpenssl();
}
if (opensslPath != null && verifyOpensslVerion(opensslPath)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The code here is a little different from your description above. If user provides a non-1.1.* openssl through test.openssl.path then you won't go look into elsewhere.

Also, getSystemOpensslPath() and OpensslArtifactFetcher.fetchOpenssl() already ensure version is 1.1.* so the check above is duplicated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Though I had kept it in intentional like that, to make sure to give proper openssl path if user is supplying it explicitly.
Anyhow I changed it now.

  1. Check whether property test.openssl.path is set and it's the
    preferred version(1.1.*) of openssl, then return that path.
  2. Else look for already installed openssl (version 1.1.*) in system
    path /usr/bin/openssl or /usr/local/bin/openssl, then return that
    path.
  3. Else try to download openssl (version 1.1.*) from the artifactory
    and return that path, if download fails then return null.

* questions.
*/

package jdk.test.lib.artifacts.openssl;
Copy link
Contributor

@wangweij wangweij Aug 13, 2021

Choose a reason for hiding this comment

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

The file is not in this package. Somehow I don't think if it's not worth creating a new package for it. Do you expect we will have more classes here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ya, it was by mistake. I tested from different local workspace, that' why I couldn't catch it in my testing.
Now moved to package jdk.test.lib.artifacts.


public class OpensslArtifactFetcher {

public static String fetchOpenssl() {
Copy link
Contributor

@wangweij wangweij Aug 13, 2021

Choose a reason for hiding this comment

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

Can we rename this to fetchOpenssl1.1.1? Someday we will need to download other versions. If so, you can probably move getSystemOpensslPath, verifyOpensslVersion, and System.getProperty("test.openssl.path") here as well. It's quite likely that they will be used together.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved getSystemOpensslPath, verifyOpensslVersion and System.getProperty("test.openssl.path") to OpensslArtifactFetcher class. And renamed fetchOpenssl to getOpenssl1dot1dotStar.

return null;
}

private static boolean verifyOpensslVerion(String path) {
Copy link
Contributor

@wangweij wangweij Aug 13, 2021

Choose a reason for hiding this comment

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

Oops, a typo in the method name. s/Verion/Version/.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

corrected

Copy link
Contributor

@wangweij wangweij left a comment

Choose a reason for hiding this comment

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

Approved. There's a tiny style issue. Fix it if you have time.

Thanks for the great work. The test is much more complete now.

private static String getDefaultSystemOpensslPath(String version) {
if(verifyOpensslVersion("/usr/bin/openssl", version)) {
return "/usr/bin/openssl";
} else if(verifyOpensslVersion("/usr/local/bin/openssl", version)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a space after if on lines 85 and 87.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

corrected it. Thanks for your detailed review.

@akolarkunnu
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Aug 17, 2021

Going to push as commit ed57cf1.
Since your change was applied there have been 912 commits pushed to the master branch:

  • 0e3fde6: 8264274: Block tags in overview.html are ignored
  • c5c84b8: 8270312: Error: Not a test or directory containing tests: java/awt/print/PrinterJob/XparColor.java
  • df1427b: 8272446: C1: Raw version of UnsafeGet generates load barriers
  • 989f39f: 8272552: mark hotspot runtime/cds tests which ignore external VM flags
  • ee8bf10: 8272327: Shenandoah: Avoid enqueuing duplicate string candidates
  • 3fb1927: 8271227: Missing {@code } in com.sun.source.*
  • a5ad772: 8272342: [TEST_BUG] java/awt/print/PrinterJob/PageDialogMarginTest.java catches all exceptions
  • ae45592: 8272374: doclint should report missing "body" comments
  • b2c272d: 8272305: several hotspot runtime/modules don't check exit codes
  • 8268825: 8272297: FileInputStream should override transferTo() for better performance
  • ... and 902 more: https://git.openjdk.java.net/jdk/compare/341f676066ab807d433f0f0b6c8356d2ad0e1cc9...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot closed this Aug 17, 2021
@openjdk openjdk bot added integrated Pull request has been integrated and removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Aug 17, 2021
@openjdk
Copy link

openjdk bot commented Aug 17, 2021

@akolarkunnu Pushed as commit ed57cf1.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integrated Pull request has been integrated security security-dev@openjdk.org
6 participants