< prev index next >

test/jdk/java/security/SignedObject/Chain.java

Print this page

  1 /**
  2  * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */

 54         SunRsaSign("SunRsaSign"),
 55         Sun("SUN"),
 56         SunEC("SunEC"),
 57         SunJSSE("SunJSSE"),
 58         SunMSCAPI("SunMSCAPI");
 59 
 60         final String name;
 61 
 62         Provider(String name) {
 63             this.name = name;
 64         }
 65     }
 66 
 67     static enum SigAlg {
 68         MD2withRSA("MD2withRSA"),
 69         MD5withRSA("md5withRSA"),
 70 
 71         SHA1withDSA("SHA1withDSA"),
 72         SHA224withDSA("SHA224withDSA"),
 73         SHA256withDSA("SHA256withDSA"),







 74 
 75         SHA1withRSA("Sha1withrSA"),
 76         SHA224withRSA("SHA224withRSA"),
 77         SHA256withRSA("SHA256withRSA"),
 78         SHA384withRSA("SHA384withRSA"),
 79         SHA512withRSA("SHA512withRSA"),
 80         SHA512_224withRSA("SHA512/224withRSA"),
 81         SHA512_256withRSA("SHA512/256withRSA"),




 82 
 83         SHA1withECDSA("SHA1withECDSA"),
 84         SHA256withECDSA("SHA256withECDSA"),
 85         SHA224withECDSA("SHA224withECDSA"),

 86         SHA384withECDSA("SHA384withECDSA"),
 87         SHA512withECDSA("SHA512withECDSA"),




 88 
 89         MD5andSHA1withRSA("MD5andSHA1withRSA"),
 90 
 91         RSASSA_PSS("RSASSA-PSS");
 92 
 93         final String name;
 94 
 95         SigAlg(String name) {
 96             this.name = name;
 97         }
 98     }
 99 
100     static class Test {
101         final Provider provider;
102         final KeyAlg keyAlg;
103         final SigAlg sigAlg;
104         final int keySize;
105         final AlgorithmParameterSpec sigParams;
106 
107         Test(SigAlg sigAlg, KeyAlg keyAlg, Provider provider) {

130                     p.getSaltLength(), p.getTrailerField());
131             } else if (aps instanceof MGF1ParameterSpec) {
132                 return "MGF1" +
133                     ((MGF1ParameterSpec)aps).getDigestAlgorithm();
134             } else {
135                 return aps.toString();
136             }
137         }
138 
139         public String toString() {
140             return String.format("Test: provider = %s, signature alg = %s, "
141                 + " w/ %s, key alg = %s", provider, sigAlg,
142                 formatParams(sigParams), keyAlg);
143         }
144     }
145 
146     private static final Test[] tests = {
147         new Test(SigAlg.SHA1withDSA, KeyAlg.DSA, Provider.Default, 1024),
148         new Test(SigAlg.MD2withRSA, KeyAlg.RSA, Provider.Default),
149         new Test(SigAlg.MD5withRSA, KeyAlg.RSA, Provider.Default),
150         new Test(SigAlg.SHA1withRSA, KeyAlg.RSA, Provider.Default),



151         new Test(SigAlg.SHA1withDSA, KeyAlg.DSA, Provider.Sun, 1024),
152         new Test(SigAlg.SHA224withDSA, KeyAlg.DSA, Provider.Sun, 2048),
153         new Test(SigAlg.SHA256withDSA, KeyAlg.DSA, Provider.Sun, 2048),
154     };
155 
156     private static final String str = "to-be-signed";
157     private static final int N = 3;
158 
159     public static void main(String argv[]) {
160         boolean result = Arrays.stream(tests).allMatch((test) -> runTest(test));
161         result &= runTestPSS(2048);
162         if (result) {
163             System.out.println("All tests passed");
164         } else {
165             throw new RuntimeException("Some tests failed");
166         }
167     }
168 
169     private static boolean runTestPSS(int keysize) {
170         boolean result = true;

  1 /*
  2  * Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */

 54         SunRsaSign("SunRsaSign"),
 55         Sun("SUN"),
 56         SunEC("SunEC"),
 57         SunJSSE("SunJSSE"),
 58         SunMSCAPI("SunMSCAPI");
 59 
 60         final String name;
 61 
 62         Provider(String name) {
 63             this.name = name;
 64         }
 65     }
 66 
 67     static enum SigAlg {
 68         MD2withRSA("MD2withRSA"),
 69         MD5withRSA("md5withRSA"),
 70 
 71         SHA1withDSA("SHA1withDSA"),
 72         SHA224withDSA("SHA224withDSA"),
 73         SHA256withDSA("SHA256withDSA"),
 74         SHA384withDSA("SHA384withDSA"),
 75         SHA512withDSA("SHA512withDSA"),
 76 
 77         SHA3_224withDSA("SHA3-224withDSA"),
 78         SHA3_256withDSA("SHA3-256withDSA"),
 79         SHA3_384withDSA("SHA3-384withDSA"),
 80         SHA3_512withDSA("SHA3-512withDSA"),
 81 
 82         SHA1withRSA("Sha1withrSA"),
 83         SHA224withRSA("SHA224withRSA"),
 84         SHA256withRSA("SHA256withRSA"),
 85         SHA384withRSA("SHA384withRSA"),
 86         SHA512withRSA("SHA512withRSA"),
 87         SHA512_224withRSA("SHA512/224withRSA"),
 88         SHA512_256withRSA("SHA512/256withRSA"),
 89         SHA3_224withRSA("SHA3-224withRSA"),
 90         SHA3_256withRSA("SHA3-256withRSA"),
 91         SHA3_384withRSA("SHA3-384withRSA"),
 92         SHA3_512withRSA("SHA3-512withRSA"),
 93 
 94         SHA1withECDSA("SHA1withECDSA"),

 95         SHA224withECDSA("SHA224withECDSA"),
 96         SHA256withECDSA("SHA256withECDSA"),
 97         SHA384withECDSA("SHA384withECDSA"),
 98         SHA512withECDSA("SHA512withECDSA"),
 99         SHA3_224withECDSA("SHA3-224withECDSA"),
100         SHA3_256withECDSA("SHA3-256withECDSA"),
101         SHA3_384withECDSA("SHA3-384withECDSA"),
102         SHA3_512withECDSA("SHA3-512withECDSA"),
103 
104         MD5andSHA1withRSA("MD5andSHA1withRSA"),
105 
106         RSASSA_PSS("RSASSA-PSS");
107 
108         final String name;
109 
110         SigAlg(String name) {
111             this.name = name;
112         }
113     }
114 
115     static class Test {
116         final Provider provider;
117         final KeyAlg keyAlg;
118         final SigAlg sigAlg;
119         final int keySize;
120         final AlgorithmParameterSpec sigParams;
121 
122         Test(SigAlg sigAlg, KeyAlg keyAlg, Provider provider) {

145                     p.getSaltLength(), p.getTrailerField());
146             } else if (aps instanceof MGF1ParameterSpec) {
147                 return "MGF1" +
148                     ((MGF1ParameterSpec)aps).getDigestAlgorithm();
149             } else {
150                 return aps.toString();
151             }
152         }
153 
154         public String toString() {
155             return String.format("Test: provider = %s, signature alg = %s, "
156                 + " w/ %s, key alg = %s", provider, sigAlg,
157                 formatParams(sigParams), keyAlg);
158         }
159     }
160 
161     private static final Test[] tests = {
162         new Test(SigAlg.SHA1withDSA, KeyAlg.DSA, Provider.Default, 1024),
163         new Test(SigAlg.MD2withRSA, KeyAlg.RSA, Provider.Default),
164         new Test(SigAlg.MD5withRSA, KeyAlg.RSA, Provider.Default),
165         new Test(SigAlg.SHA3_224withRSA, KeyAlg.RSA, Provider.Default),
166         new Test(SigAlg.SHA3_256withRSA, KeyAlg.RSA, Provider.Default),
167         new Test(SigAlg.SHA3_384withRSA, KeyAlg.RSA, Provider.Default),
168         new Test(SigAlg.SHA3_512withRSA, KeyAlg.RSA, Provider.Default),
169         new Test(SigAlg.SHA1withDSA, KeyAlg.DSA, Provider.Sun, 1024),
170         new Test(SigAlg.SHA224withDSA, KeyAlg.DSA, Provider.Sun, 2048),
171         new Test(SigAlg.SHA256withDSA, KeyAlg.DSA, Provider.Sun, 2048),
172     };
173 
174     private static final String str = "to-be-signed";
175     private static final int N = 3;
176 
177     public static void main(String argv[]) {
178         boolean result = Arrays.stream(tests).allMatch((test) -> runTest(test));
179         result &= runTestPSS(2048);
180         if (result) {
181             System.out.println("All tests passed");
182         } else {
183             throw new RuntimeException("Some tests failed");
184         }
185     }
186 
187     private static boolean runTestPSS(int keysize) {
188         boolean result = true;
< prev index next >