Path: blob/master/test/jdk/sun/security/pkcs11/SecmodTest.java
41149 views
/*1* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/222324// common infrastructure for Secmod tests2526import java.io.*;2728import java.security.Provider;2930public class SecmodTest extends PKCS11Test {3132static String LIBPATH;33static String DBDIR;34static char[] password = "test12".toCharArray();35static String keyAlias = "mykey";36static boolean useSqlite = false;3738static void useSqlite(boolean b) {39useSqlite = b;40}4142static boolean initSecmod() throws Exception {43useNSS();44LIBPATH = getNSSLibDir();45if (LIBPATH == null) {46return false;47}48// load all the libraries except libnss3 into memory49if (loadNSPR(LIBPATH) == false) {50return false;51}52safeReload(LIBPATH + System.mapLibraryName("softokn3"));53safeReload(LIBPATH + System.mapLibraryName("nssckbi"));5455DBDIR = System.getProperty("test.classes", ".") + SEP + "tmpdb";56if (useSqlite) {57System.setProperty("pkcs11test.nss.db", "sql:" + DBDIR);58} else {59System.setProperty("pkcs11test.nss.db", DBDIR);60}61File dbdirFile = new File(DBDIR);62if (dbdirFile.exists() == false) {63dbdirFile.mkdir();64}6566if (useSqlite) {67copyFile("key4.db", BASE, DBDIR);68copyFile("cert9.db", BASE, DBDIR);69copyFile("pkcs11.txt", BASE, DBDIR);70} else {71copyFile("secmod.db", BASE, DBDIR);72copyFile("key3.db", BASE, DBDIR);73copyFile("cert8.db", BASE, DBDIR);74}75return true;76}7778private static void copyFile(String name, String srcDir, String dstDir) throws IOException {79InputStream in = new FileInputStream(new File(srcDir, name));80OutputStream out = new FileOutputStream(new File(dstDir, name));81byte[] buf = new byte[2048];82while (true) {83int n = in.read(buf);84if (n < 0) {85break;86}87out.write(buf, 0, n);88}89in.close();90out.close();91}9293public void main(Provider p) throws Exception {94// dummy95}9697}9899100