/* * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
// test pre-JDK1.5 KeyStore throws UnsupportedOperationExceptions // for new methods
KeyStore pre15KS = KeyStore.getInstance("Pre15KeyStore", entry);
testPre15(pre15KS);
// test post-JDK1.5 KeyStore does right thing with new methods
KeyStore post15KS = KeyStore.getInstance("Post15KeyStore", entry);
testPost15(post15KS);
// test post-JDK1.5 KeyStore can throw new UnrecoverableEntryException
KeyStore uKS = KeyStore.getInstance("UnrecoverableKeyStore", entry);
testUnrecoverable(uKS);
}
// TEST load null param
ks.load((KeyStore.LoadStoreParameter)null);
System.out.println("[Pre1.5] test " + tNum++ + " passed");
// TEST load random param try {
ks.load(new FooParameter()); thrownew SecurityException("[Pre1.5] test " + tNum + " failed");
} catch (UnsupportedOperationException uoe) {
System.out.println("[Pre1.5] test " + tNum++ + " passed");
} catch (NoSuchAlgorithmException nsae) {
System.out.println("[Pre1.5] test " + tNum++ + " passed");
}
// TEST load custom param
ks.load(new MyLoadStoreParameter( new KeyStore.PasswordProtection(password)));
System.out.println("[Pre1.5] test " + tNum++ + " passed");
// TEST store random param
ks.load(pre15fis, password);
// setup for later user
KeyStore.Entry pkeNew = ks.getEntry("privkey", new KeyStore.PasswordProtection(password));
KeyStore.Entry tceNew = ks.getEntry("trustedcert", null);
try {
ks.store(new FooParameter()); thrownew SecurityException("[Pre1.5] test " + tNum + " failed");
} catch (UnsupportedOperationException uoe) { // good
System.out.println("[Pre1.5] test " + tNum++ + " passed");
}
// TEST store null param try {
ks.store(null); thrownew SecurityException("[Pre1.5] test " + tNum + " failed");
} catch (UnsupportedOperationException uoe) { // good
System.out.println("[Pre1.5] test " + tNum++ + " passed");
}
// TEST getEntry with alias/protParam - use invalid alias
e = ks.getEntry("notPresent", new KeyStore.PasswordProtection(password)); if (e == null) {
System.out.println("[Pre1.5] test " + tNum++ + " passed");
} else { thrownew SecurityException("[Pre1.5] test " + tNum + " failed - " + "expected null entry returned");
}
// TEST getEntry with alias/null protParam - get private key try {
e = ks.getEntry("privkey", null); thrownew SecurityException("[Pre1.5] test " + tNum + " failed - " + "expected UnrecoverableEntryException");
} catch (UnrecoverableEntryException uee) {
System.out.println("[Pre1.5] test " + tNum++ + " passed");
}
// TEST getEntry with alias/bad password - get private key try {
e = ks.getEntry("privkey", new KeyStore.PasswordProtection(badPwd)); thrownew SecurityException("[Pre1.5] test " + tNum + " failed - " + "expected UnrecoverableEntryException");
} catch (UnrecoverableEntryException uee) {
System.out.println("[Pre1.5] test " + tNum++ + " passed");
}
// TEST getEntry with alias/unknown protection - get private key try {
e = ks.getEntry("privkey", new FooProtect()); thrownew SecurityException("[Pre1.5] test " + tNum + " failed - " + "expected UnsupportedOperationException");
} catch (UnsupportedOperationException uoe) {
System.out.println("[Pre1.5] test " + tNum++ + " passed");
}
// TEST getEntry with alias/protParam - get private key
e = ks.getEntry("privkey", new KeyStore.PasswordProtection(password)); if (e instanceof KeyStore.PrivateKeyEntry) {
System.out.println("[Pre1.5] test " + tNum++ + " passed");
} else { thrownew SecurityException("[Pre1.5] test " + tNum + " failed - " + "expected PrivateKeyEntry");
}
// TEST getEntry with alias/null protParam - get trusted cert
e = ks.getEntry("trustedcert", null); if (e instanceof KeyStore.TrustedCertificateEntry) {
System.out.println("[Pre1.5] test " + tNum++ + " passed");
} else { thrownew SecurityException("[Pre1.5] test " + tNum + " failed");
}
// TEST getEntry with alias/non-null protParam - get trusted cert try {
e = ks.getEntry("trustedcert", new KeyStore.PasswordProtection(password)); thrownew SecurityException("[Pre1.5] test " + tNum + " failed");
} catch (UnsupportedOperationException uoe) {
System.out.println("[Pre1.5] test " + tNum++ + " passed");
}
// TEST setEntry with alias/entry/protParam - use invalid alias try {
ks.setEntry("foo", new FooEntry(), new KeyStore.PasswordProtection(password)); thrownew SecurityException("[Pre1.5] test " + tNum + " failed - " + "expected KeyStoreException");
} catch (KeyStoreException kse) { // good
System.out.println("[Pre1.5] test " + tNum++ + " passed");
}
// TEST setEntry with alias/entry/null protParam - set private key try {
ks.setEntry("newPrivKey", pkeNew, null); thrownew SecurityException("[Pre1.5] test " + tNum + " failed - " + "expected KeyStoreException");
} catch (KeyStoreException kse) {
System.out.println("[Pre1.5] test " + tNum++ + " passed");
}
// TEST setEntry with alias/entry/random protParam - set private key try {
ks.setEntry("newPrivKey", pkeNew, new FooProtect()); thrownew SecurityException("[Pre1.5] test " + tNum + " failed - " + "expected KeyStoreException");
} catch (KeyStoreException kse) {
System.out.println("[Pre1.5] test " + tNum++ + " passed");
}
// TEST setEntry with alias/entry/protParam - set private key
ks.setEntry("newPrivKey", pkeNew, new KeyStore.PasswordProtection(password));
e = ks.getEntry("newPrivKey", new KeyStore.PasswordProtection(password)); if (e instanceof KeyStore.PrivateKeyEntry) {
System.out.println("[Pre1.5] test " + tNum++ + " passed");
} else { thrownew SecurityException("[Pre1.5] test " + tNum + " failed - " + "expected PrivateKeyEntry");
}
// TEST setEntry with alias/entry/non null protParam - set trusted cert try {
ks.setEntry("newTrustedcert", tceNew, new KeyStore.PasswordProtection(password)); thrownew SecurityException("[Pre1.5] test " + tNum + " failed - " + "expected KeyStoreException");
} catch (KeyStoreException kse) { // good
System.out.println("[Pre1.5] test " + tNum++ + " passed");
}
// TEST setEntry with alias/entry/null protParam - set trusted cert
ks.setEntry("newTrustedcert", tceNew, null);
e = ks.getEntry("newTrustedcert", null); if (e instanceof KeyStore.TrustedCertificateEntry) {
System.out.println("[Pre1.5] test " + tNum++ + " passed");
} else { thrownew SecurityException("[Pre1.5] test " + tNum + " failed - " + "expected TrustedCertificateEntry");
}
// TEST entryInstanceOf - invalid alias if (ks.entryInstanceOf("foo", EntryMethods.class) == false) {
System.out.println("[Pre1.5] test " + tNum++ + " passed");
} else { thrownew SecurityException("[Pre1.5] test " + tNum + " failed");
}
// TEST entryInstanceOf - false case if (ks.entryInstanceOf("privkey", EntryMethods.class) == false) {
System.out.println("[Pre1.5] test " + tNum++ + " passed");
} else { thrownew SecurityException("[Pre1.5] test " + tNum + " failed");
}
// TEST entryInstanceOf - true case, trustedcert entry if (ks.entryInstanceOf("trustedcert",
KeyStore.TrustedCertificateEntry.class)) {
System.out.println("[Pre1.5] test " + tNum++ + " passed");
} else { thrownew SecurityException("[Pre1.5] test " + tNum + " failed");
}
// TEST entryInstanceOf - true case, private key entry if (ks.entryInstanceOf("privkey",
KeyStore.PrivateKeyEntry.class)) {
System.out.println("[Pre1.5] test " + tNum++ + " passed");
} else { thrownew SecurityException("[Pre1.5] test " + tNum + " failed");
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.