< prev index next >

test/jdk/sun/security/pkcs11/Signature/TestDSA.java

Print this page
rev 59383 : [mq]: final
   1 /*
   2  * Copyright (c) 2003, 2018, 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  */


 104         if (r != result) {
 105             throw new Exception("Result mismatch, actual: " + r);
 106         }
 107         s.update(data);
 108         r = s.verify(sig);
 109         if (r != result) {
 110             throw new Exception("Result mismatch, actual: " + r);
 111         }
 112         System.out.println("Passed");
 113     }
 114 
 115     public static void main(String[] args) throws Exception {
 116         main(new TestDSA(), args);
 117     }
 118 
 119     @Override
 120     public void main(Provider provider) throws Exception {
 121         long start = System.currentTimeMillis();
 122 
 123         System.out.println("Testing provider " + provider + "...");
 124 
 125         /*
 126          * Use Solaris SPARC 11.2 or later to avoid an intermittent failure
 127          * when running SunPKCS11-Solaris (8044554)
 128          */
 129         if (provider.getName().equals("SunPKCS11-Solaris") &&
 130             props.getProperty("os.name").equals("SunOS") &&
 131             props.getProperty("os.arch").equals("sparcv9") &&
 132             props.getProperty("os.version").compareTo("5.11") <= 0 &&
 133             getDistro().compareTo("11.2") < 0) {
 134 
 135             System.out.println("SunPKCS11-Solaris provider requires " +
 136                 "Solaris SPARC 11.2 or later, skipping");
 137             return;
 138         }
 139 
 140         if (provider.getService("Signature", "SHA1withDSA") == null) {
 141             System.out.println("DSA not supported, skipping");
 142             return;
 143         }
 144 
 145         KeyFactory kf = KeyFactory.getInstance("DSA", provider);
 146         DSAPrivateKeySpec privSpec = new DSAPrivateKeySpec(x, p, q, g);
 147         DSAPublicKeySpec pubSpec = new DSAPublicKeySpec(y, p, q, g);
 148         PrivateKey privateKey = kf.generatePrivate(privSpec);
 149         PublicKey publicKey = kf.generatePublic(pubSpec);
 150 
 151         // verify known-good and known-bad signatures using SHA1withDSA and RawDSA
 152         verify(provider, "SHA1withDSA", publicKey, data1Raw, sig1a, true);
 153         verify(provider, "SHA1withDSA", publicKey, data1Raw, sig1b, true);
 154         verify(provider, "SHA1withDSA", publicKey, data2Raw, sig1a, false);
 155         verify(provider, "SHA1withDSA", publicKey, data2Raw, sig1b, false);
 156 
 157         verify(provider, "RawDSA", publicKey, data1SHA, sig1a, true);
 158         verify(provider, "RawDSA", publicKey, data1SHA, sig1b, true);


   1 /*
   2  * Copyright (c) 2003, 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  */


 104         if (r != result) {
 105             throw new Exception("Result mismatch, actual: " + r);
 106         }
 107         s.update(data);
 108         r = s.verify(sig);
 109         if (r != result) {
 110             throw new Exception("Result mismatch, actual: " + r);
 111         }
 112         System.out.println("Passed");
 113     }
 114 
 115     public static void main(String[] args) throws Exception {
 116         main(new TestDSA(), args);
 117     }
 118 
 119     @Override
 120     public void main(Provider provider) throws Exception {
 121         long start = System.currentTimeMillis();
 122 
 123         System.out.println("Testing provider " + provider + "...");















 124 
 125         if (provider.getService("Signature", "SHA1withDSA") == null) {
 126             System.out.println("DSA not supported, skipping");
 127             return;
 128         }
 129 
 130         KeyFactory kf = KeyFactory.getInstance("DSA", provider);
 131         DSAPrivateKeySpec privSpec = new DSAPrivateKeySpec(x, p, q, g);
 132         DSAPublicKeySpec pubSpec = new DSAPublicKeySpec(y, p, q, g);
 133         PrivateKey privateKey = kf.generatePrivate(privSpec);
 134         PublicKey publicKey = kf.generatePublic(pubSpec);
 135 
 136         // verify known-good and known-bad signatures using SHA1withDSA and RawDSA
 137         verify(provider, "SHA1withDSA", publicKey, data1Raw, sig1a, true);
 138         verify(provider, "SHA1withDSA", publicKey, data1Raw, sig1b, true);
 139         verify(provider, "SHA1withDSA", publicKey, data2Raw, sig1a, false);
 140         verify(provider, "SHA1withDSA", publicKey, data2Raw, sig1b, false);
 141 
 142         verify(provider, "RawDSA", publicKey, data1SHA, sig1a, true);
 143         verify(provider, "RawDSA", publicKey, data1SHA, sig1b, true);


< prev index next >