test/org/openjdk/jigsaw/cli/TimestampTest.java

Print this page




  61 // copied from test/sun/security/tools/jarsigner and adapted for use with
  62 // jigsaw signed modules
  63 public class TimestampTest {
  64     private static final String BASE_DIR = System.getProperty("test.src", ".");
  65     private static final String MNAME = "test.security";
  66     private int port;
  67     private String[] jsignArgs = {
  68         "-v",
  69         "--keystore",
  70         "keystore.jks"
  71     };
  72 
  73     private String[] jmodArgs = {
  74         "-L",
  75         "z.lib",
  76         "install",
  77         MNAME + "@0.1.jmod"
  78     };
  79 
  80     private String[] jpkgArgs = {
  81         "-L",
  82         "z.lib",
  83         "-m",
  84         "z.modules/" + MNAME,
  85         "jmod",
  86         MNAME
  87     };
  88 
  89     private File moduleDir = new File("z.lib", MNAME);
  90 
  91     public static void main(String[] args) throws Exception {
  92         new TimestampTest().run();
  93     }
  94 
  95     void run() throws Exception {
  96 
  97         Handler h = new Handler();
  98         HttpServer server = HttpServer.create(new InetSocketAddress(0), 0);
  99         port = server.getAddress().getPort();
 100         HttpContext ctx = server.createContext("/", h);
 101         server.start();
 102 


 129         sign("expired-signer", 0);
 130         try {
 131             install();
 132             throw new Exception("Expected SignatureException");
 133         } catch (Exception e) {
 134             if (!(e.getCause() instanceof SignatureException))
 135                 throw e;
 136             System.out.println(e.getCause());
 137         }
 138     }
 139 
 140     void testExpiredWithValidTimestamp() throws Exception {
 141         reset();
 142         sign("expired-signer", 1);
 143         install();
 144     }
 145 
 146     void reset() {
 147         if (moduleDir.exists())
 148             deleteAll(moduleDir);



 149     }

 150 
 151     /**
 152      * Delete a file or a directory (including all its contents).
 153      */
 154     boolean deleteAll(File file) {
 155         if (file.isDirectory()) {
 156             for (File f: file.listFiles())
 157                 deleteAll(f);
 158         }
 159         return file.delete();
 160     }
 161 
 162     void sign(String alias, int type) throws Exception {
 163         List<String> args = new ArrayList<>();
 164         args.addAll(Arrays.asList(jpkgArgs));
 165         Packager.run(args.toArray(new String[0]));
 166         args = new ArrayList<>();
 167         args.addAll(Arrays.asList(jsignArgs));
 168         args.add("--tsa");
 169         args.add("http://localhost:" + port + "/" + type);




  61 // copied from test/sun/security/tools/jarsigner and adapted for use with
  62 // jigsaw signed modules
  63 public class TimestampTest {
  64     private static final String BASE_DIR = System.getProperty("test.src", ".");
  65     private static final String MNAME = "test.security";
  66     private int port;
  67     private String[] jsignArgs = {
  68         "-v",
  69         "--keystore",
  70         "keystore.jks"
  71     };
  72 
  73     private String[] jmodArgs = {
  74         "-L",
  75         "z.lib",
  76         "install",
  77         MNAME + "@0.1.jmod"
  78     };
  79 
  80     private String[] jpkgArgs = {


  81         "-m",
  82         "z.modules/" + MNAME,
  83         "jmod",
  84         MNAME
  85     };
  86 
  87     private File moduleDir = new File("z.lib", MNAME);
  88 
  89     public static void main(String[] args) throws Exception {
  90         new TimestampTest().run();
  91     }
  92 
  93     void run() throws Exception {
  94 
  95         Handler h = new Handler();
  96         HttpServer server = HttpServer.create(new InetSocketAddress(0), 0);
  97         port = server.getAddress().getPort();
  98         HttpContext ctx = server.createContext("/", h);
  99         server.start();
 100 


 127         sign("expired-signer", 0);
 128         try {
 129             install();
 130             throw new Exception("Expected SignatureException");
 131         } catch (Exception e) {
 132             if (!(e.getCause() instanceof SignatureException))
 133                 throw e;
 134             System.out.println(e.getCause());
 135         }
 136     }
 137 
 138     void testExpiredWithValidTimestamp() throws Exception {
 139         reset();
 140         sign("expired-signer", 1);
 141         install();
 142     }
 143 
 144     void reset() {
 145         if (moduleDir.exists())
 146             deleteAll(moduleDir);
 147 
 148         if (moduleDir.exists()) {
 149             System.err.println("WARNING: removal of " + moduleDir + " failed.");
 150         }
 151     }
 152 
 153     /**
 154      * Delete a file or a directory (including all its contents).
 155      */
 156     boolean deleteAll(File file) {
 157         if (file.isDirectory()) {
 158             for (File f: file.listFiles())
 159                 deleteAll(f);
 160         }
 161         return file.delete();
 162     }
 163 
 164     void sign(String alias, int type) throws Exception {
 165         List<String> args = new ArrayList<>();
 166         args.addAll(Arrays.asList(jpkgArgs));
 167         Packager.run(args.toArray(new String[0]));
 168         args = new ArrayList<>();
 169         args.addAll(Arrays.asList(jsignArgs));
 170         args.add("--tsa");
 171         args.add("http://localhost:" + port + "/" + type);