Search in sources :

Example 16 with OutputAnalyzer

use of jdk.testlibrary.OutputAnalyzer in project jdk8u_jdk by JetBrains.

the class HasExpiredCertTest method start.

private void start() throws Throwable {
    // create a jar file that contains one class file
    Utils.createFiles(FIRST_FILE);
    JarUtils.createJar(UNSIGNED_JARFILE, FIRST_FILE);
    // create key pair for jar signing
    ProcessTools.executeCommand(KEYTOOL, "-genkey", "-alias", KEY_ALIAS, "-keyalg", KEY_ALG, "-keysize", Integer.toString(KEY_SIZE), "-keystore", KEYSTORE, "-storepass", PASSWORD, "-keypass", PASSWORD, "-dname", "CN=Test", "-startdate", "-" + SHORT_VALIDITY * 2 + "d", "-validity", Integer.toString(SHORT_VALIDITY)).shouldHaveExitValue(0);
    // sign jar
    OutputAnalyzer analyzer = ProcessTools.executeCommand(JARSIGNER, "-keystore", KEYSTORE, "-storepass", PASSWORD, "-keypass", PASSWORD, "-signedjar", SIGNED_JARFILE, UNSIGNED_JARFILE, KEY_ALIAS);
    checkSigning(analyzer, HAS_EXPIRED_CERT_SIGNING_WARNING);
    // verify signed jar
    analyzer = ProcessTools.executeCommand(JARSIGNER, "-verify", "-verbose", "-keystore", KEYSTORE, "-storepass", PASSWORD, "-keypass", PASSWORD, SIGNED_JARFILE);
    checkVerifying(analyzer, 0, HAS_EXPIRED_CERT_VERIFYING_WARNING);
    analyzer = ProcessTools.executeCommand(JARSIGNER, "-verify", "-strict", "-keystore", KEYSTORE, "-storepass", PASSWORD, "-keypass", PASSWORD, SIGNED_JARFILE);
    checkVerifying(analyzer, HAS_EXPIRED_CERT_EXIT_CODE, HAS_EXPIRED_CERT_VERIFYING_WARNING);
    System.out.println("Test passed");
}
Also used : OutputAnalyzer(jdk.testlibrary.OutputAnalyzer)

Example 17 with OutputAnalyzer

use of jdk.testlibrary.OutputAnalyzer in project jdk8u_jdk by JetBrains.

the class HasExpiringCertTest method start.

private void start() throws Throwable {
    // create a jar file that contains one class file
    Utils.createFiles(FIRST_FILE);
    JarUtils.createJar(UNSIGNED_JARFILE, FIRST_FILE);
    // create key pair for jar signing
    ProcessTools.executeCommand(KEYTOOL, "-genkey", "-alias", KEY_ALIAS, "-keyalg", KEY_ALG, "-keysize", Integer.toString(KEY_SIZE), "-keystore", KEYSTORE, "-storepass", PASSWORD, "-keypass", PASSWORD, "-dname", "CN=Test", "-validity", Integer.toString(SHORT_VALIDITY)).shouldHaveExitValue(0);
    // sign jar
    OutputAnalyzer analyzer = ProcessTools.executeCommand(JARSIGNER, "-keystore", KEYSTORE, "-verbose", "-storepass", PASSWORD, "-keypass", PASSWORD, "-signedjar", SIGNED_JARFILE, UNSIGNED_JARFILE, KEY_ALIAS);
    checkSigning(analyzer, HAS_EXPIRING_CERT_SIGNING_WARNING);
    // verify signed jar
    analyzer = ProcessTools.executeCommand(JARSIGNER, "-verify", "-verbose", "-keystore", KEYSTORE, "-storepass", PASSWORD, "-keypass", PASSWORD, SIGNED_JARFILE, KEY_ALIAS);
    checkVerifying(analyzer, 0, HAS_EXPIRING_CERT_VERIFYING_WARNING);
    // verify signed jar in strict mode
    analyzer = ProcessTools.executeCommand(JARSIGNER, "-verify", "-verbose", "-strict", "-keystore", KEYSTORE, "-storepass", PASSWORD, "-keypass", PASSWORD, SIGNED_JARFILE, KEY_ALIAS);
    checkVerifying(analyzer, 0, HAS_EXPIRING_CERT_VERIFYING_WARNING);
    System.out.println("Test passed");
}
Also used : OutputAnalyzer(jdk.testlibrary.OutputAnalyzer)

Example 18 with OutputAnalyzer

use of jdk.testlibrary.OutputAnalyzer in project jdk8u_jdk by JetBrains.

the class BadNetscapeCertTypeTest method start.

private void start() throws Throwable {
    // create a jar file that contains one class file
    Utils.createFiles(FIRST_FILE);
    JarUtils.createJar(UNSIGNED_JARFILE, FIRST_FILE);
    // sign jar
    OutputAnalyzer analyzer = ProcessTools.executeCommand(JARSIGNER, "-verbose", "-keystore", NETSCAPE_KEYSTORE, "-storepass", PASSWORD, "-keypass", PASSWORD, "-signedjar", SIGNED_JARFILE, UNSIGNED_JARFILE, KEY_ALIAS);
    checkSigning(analyzer, BAD_NETSCAPE_CERT_TYPE_SIGNING_WARNING);
    // verify signed jar
    analyzer = ProcessTools.executeCommand(JARSIGNER, "-verify", "-verbose", "-keystore", NETSCAPE_KEYSTORE, "-storepass", PASSWORD, "-keypass", PASSWORD, SIGNED_JARFILE);
    checkVerifying(analyzer, 0, BAD_NETSCAPE_CERT_TYPE_VERIFYING_WARNING);
    // verify signed jar in strict mode
    analyzer = ProcessTools.executeCommand(JARSIGNER, "-verify", "-verbose", "-strict", "-keystore", NETSCAPE_KEYSTORE, "-storepass", PASSWORD, "-keypass", PASSWORD, SIGNED_JARFILE);
    checkVerifying(analyzer, BAD_NETSCAPE_CERT_TYPE_EXIT_CODE, BAD_NETSCAPE_CERT_TYPE_VERIFYING_WARNING);
    System.out.println("Test passed");
}
Also used : OutputAnalyzer(jdk.testlibrary.OutputAnalyzer)

Example 19 with OutputAnalyzer

use of jdk.testlibrary.OutputAnalyzer in project jdk8u_jdk by JetBrains.

the class TsacertOptionTest method start.

void start() throws Throwable {
    // create a jar file that contains one file
    Utils.createFiles(FILENAME);
    JarUtils.createJar(UNSIGNED_JARFILE, FILENAME);
    // look for free network port for TSA service
    int port = jdk.testlibrary.Utils.getFreePort();
    String host = jdk.testlibrary.Utils.getHostname();
    String tsaUrl = "http://" + host + ":" + port;
    // create key pair for jar signing
    ProcessTools.executeCommand(KEYTOOL, "-genkey", "-alias", SIGNING_KEY_ALIAS, "-keyalg", KEY_ALG, "-keysize", Integer.toString(KEY_SIZE), "-keystore", KEYSTORE, "-storepass", PASSWORD, "-keypass", PASSWORD, "-dname", "CN=Test", "-validity", Integer.toString(VALIDITY)).shouldHaveExitValue(0);
    // create key pair for TSA service
    // SubjectInfoAccess extension contains URL to TSA service
    ProcessTools.executeCommand(KEYTOOL, "-genkey", "-v", "-alias", TSA_KEY_ALIAS, "-keyalg", KEY_ALG, "-keysize", Integer.toString(KEY_SIZE), "-keystore", KEYSTORE, "-storepass", PASSWORD, "-keypass", PASSWORD, "-dname", "CN=TSA", "-ext", "ExtendedkeyUsage:critical=timeStamping", "-ext", "SubjectInfoAccess=timeStamping:URI:" + tsaUrl, "-validity", Integer.toString(VALIDITY)).shouldHaveExitValue(0);
    try (TimestampCheck.Handler tsa = TimestampCheck.Handler.init(port, KEYSTORE)) {
        // start TSA
        tsa.start();
        // sign jar file
        // specify -tsadigestalg option because
        // TSA server uses SHA-1 digest algorithm
        OutputAnalyzer analyzer = ProcessTools.executeCommand(JARSIGNER, "-J-Dhttp.proxyHost=", "-J-Dhttp.proxyPort=", "-J-Djava.net.useSystemProxies=", "-verbose", "-keystore", KEYSTORE, "-storepass", PASSWORD, "-keypass", PASSWORD, "-signedjar", SIGNED_JARFILE, "-tsacert", TSA_KEY_ALIAS, "-tsadigestalg", "SHA-1", UNSIGNED_JARFILE, SIGNING_KEY_ALIAS);
        analyzer.shouldHaveExitValue(0);
        analyzer.stdoutShouldNotContain(WARNING);
        analyzer.shouldContain(JAR_SIGNED);
        // verify signed jar
        analyzer = ProcessTools.executeCommand(JARSIGNER, "-verbose", "-verify", "-keystore", KEYSTORE, "-storepass", PASSWORD, SIGNED_JARFILE);
        analyzer.shouldHaveExitValue(0);
        analyzer.stdoutShouldNotContain(WARNING);
        analyzer.shouldContain(JAR_VERIFIED);
    }
    System.out.println("Test passed");
}
Also used : OutputAnalyzer(jdk.testlibrary.OutputAnalyzer)

Example 20 with OutputAnalyzer

use of jdk.testlibrary.OutputAnalyzer in project jdk8u_jdk by JetBrains.

the class AliasNotInStoreTest method start.

private void start() throws Throwable {
    Utils.createFiles(FIRST_FILE, SECOND_FILE);
    System.out.println(String.format("Create a %s that contains %s", new Object[] { UNSIGNED_JARFILE, FIRST_FILE }));
    JarUtils.createJar(UNSIGNED_JARFILE, FIRST_FILE);
    // create first key pair for signing
    ProcessTools.executeCommand(KEYTOOL, "-genkey", "-alias", FIRST_KEY_ALIAS, "-keyalg", KEY_ALG, "-keysize", Integer.toString(KEY_SIZE), "-keystore", BOTH_KEYS_KEYSTORE, "-storepass", PASSWORD, "-keypass", PASSWORD, "-dname", "CN=First", "-validity", Integer.toString(VALIDITY)).shouldHaveExitValue(0);
    // create second key pair for signing
    ProcessTools.executeCommand(KEYTOOL, "-genkey", "-alias", SECOND_KEY_ALIAS, "-keyalg", KEY_ALG, "-keysize", Integer.toString(KEY_SIZE), "-keystore", BOTH_KEYS_KEYSTORE, "-storepass", PASSWORD, "-keypass", PASSWORD, "-dname", "CN=Second", "-validity", Integer.toString(VALIDITY)).shouldHaveExitValue(0);
    // sign jar with first key
    OutputAnalyzer analyzer = ProcessTools.executeCommand(JARSIGNER, "-keystore", BOTH_KEYS_KEYSTORE, "-storepass", PASSWORD, "-keypass", PASSWORD, "-signedjar", SIGNED_JARFILE, UNSIGNED_JARFILE, FIRST_KEY_ALIAS);
    checkSigning(analyzer);
    System.out.println(String.format("Copy %s to %s, and add %s", new Object[] { SIGNED_JARFILE, UPDATED_SIGNED_JARFILE, SECOND_FILE }));
    JarUtils.updateJar(SIGNED_JARFILE, UPDATED_SIGNED_JARFILE, SECOND_FILE);
    // sign jar with second key
    analyzer = ProcessTools.executeCommand(JARSIGNER, "-keystore", BOTH_KEYS_KEYSTORE, "-storepass", PASSWORD, "-keypass", PASSWORD, UPDATED_SIGNED_JARFILE, SECOND_KEY_ALIAS);
    checkSigning(analyzer);
    // create keystore that contains only first key
    ProcessTools.executeCommand(KEYTOOL, "-importkeystore", "-srckeystore", BOTH_KEYS_KEYSTORE, "-srcalias", FIRST_KEY_ALIAS, "-srcstorepass", PASSWORD, "-srckeypass", PASSWORD, "-destkeystore", FIRST_KEY_KEYSTORE, "-destalias", FIRST_KEY_ALIAS, "-deststorepass", PASSWORD, "-destkeypass", PASSWORD).shouldHaveExitValue(0);
    // verify jar with keystore that contains only first key in strict mode,
    // so there is signed entry (FirstClass.class) that is not signed
    // by any alias in the keystore
    analyzer = ProcessTools.executeCommand(JARSIGNER, "-verify", "-verbose", "-keystore", FIRST_KEY_KEYSTORE, "-storepass", PASSWORD, "-keypass", PASSWORD, UPDATED_SIGNED_JARFILE);
    checkVerifying(analyzer, 0, CHAIN_NOT_VALIDATED_VERIFYING_WARNING, ALIAS_NOT_IN_STORE_VERIFYING_WARNING);
    // verify jar with keystore that contains only first key in strict mode
    analyzer = ProcessTools.executeCommand(JARSIGNER, "-verify", "-verbose", "-strict", "-keystore", FIRST_KEY_KEYSTORE, "-storepass", PASSWORD, "-keypass", PASSWORD, UPDATED_SIGNED_JARFILE);
    int expectedExitCode = ALIAS_NOT_IN_STORE_EXIT_CODE + CHAIN_NOT_VALIDATED_EXIT_CODE;
    checkVerifying(analyzer, expectedExitCode, CHAIN_NOT_VALIDATED_VERIFYING_WARNING, ALIAS_NOT_IN_STORE_VERIFYING_WARNING);
    System.out.println("Test passed");
}
Also used : OutputAnalyzer(jdk.testlibrary.OutputAnalyzer)

Aggregations

OutputAnalyzer (jdk.testlibrary.OutputAnalyzer)54 File (java.io.File)5 JDKToolLauncher (jdk.testlibrary.JDKToolLauncher)5 ArrayList (java.util.ArrayList)4 PortUnreachableException (java.net.PortUnreachableException)1 LocateRegistry (java.rmi.registry.LocateRegistry)1 Registry (java.rmi.registry.Registry)1 KeyStore (java.security.KeyStore)1 X509Certificate (java.security.cert.X509Certificate)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 MissingResourceException (java.util.MissingResourceException)1 ProcessThread (jdk.testlibrary.ProcessThread)1