зеркало из https://github.com/mozilla/pjs.git
171027 removed deprecated code from tests ran by all.pl sr=sandeep
This commit is contained in:
Родитель
371be6ce7f
Коммит
ec898fad19
|
@ -39,26 +39,73 @@ import java.io.*;
|
|||
import org.mozilla.jss.CryptoManager;
|
||||
import org.mozilla.jss.util.Password;
|
||||
import org.mozilla.jss.util.Debug;
|
||||
import org.mozilla.jss.crypto.*;
|
||||
import org.mozilla.jss.crypto.CryptoToken;
|
||||
import java.security.MessageDigest;
|
||||
|
||||
public class DigestTest {
|
||||
public static boolean messageDigest(String alg, byte[] toBeDigested)
|
||||
throws Exception {
|
||||
byte[] nsdigestOut;
|
||||
byte[] sundigestOut;
|
||||
|
||||
java.security.MessageDigest nsdigest =
|
||||
java.security.MessageDigest.getInstance(alg, "Mozilla-JSS");
|
||||
java.security.MessageDigest sundigest =
|
||||
java.security.MessageDigest.getInstance(alg, "SUN");
|
||||
|
||||
nsdigestOut = nsdigest.digest(toBeDigested);
|
||||
sundigestOut = sundigest.digest(toBeDigested);
|
||||
|
||||
if( MessageDigest.isEqual(nsdigestOut, sundigestOut) ) {
|
||||
System.out.println("Sun and Mozilla give same " + alg + " hash");
|
||||
} else {
|
||||
throw new Exception("ERROR: Sun and Mozilla give different "+
|
||||
alg + " hashes");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean testJSSDigest(String alg, byte[] toBeDigested)
|
||||
throws Exception {
|
||||
byte[] nsdigestOut;
|
||||
byte[] sundigestOut;
|
||||
|
||||
java.security.MessageDigest nsdigest =
|
||||
java.security.MessageDigest.getInstance(alg, "Mozilla-JSS");
|
||||
|
||||
nsdigestOut = nsdigest.digest(toBeDigested);
|
||||
|
||||
System.out.println("Provider " + nsdigest.getProvider());
|
||||
System.out.println("algorithm " + nsdigest.getAlgorithm());
|
||||
System.out.println("length of digest " + nsdigest.getDigestLength());
|
||||
|
||||
if( nsdigestOut.length == nsdigest.getDigestLength() ) {
|
||||
System.out.println("digest output size is " + nsdigestOut.length);
|
||||
} else {
|
||||
throw new Exception("ERROR: digest output size is "+
|
||||
nsdigestOut.length + ", should be "+nsdigest.getDigestLength() );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void main(String []argv) {
|
||||
|
||||
try {
|
||||
|
||||
if( argv.length != 2 ) {
|
||||
System.out.println("Usage: DigestTest <dbdir> <infile>");
|
||||
System.exit(0);
|
||||
System.out.println(
|
||||
"Usage: java org.mozilla.jss.tests.DigestTest " +
|
||||
"<dbdir> <File>");
|
||||
System.exit(1);
|
||||
}
|
||||
String dbdir = argv[0];
|
||||
FileInputStream fis = new FileInputStream(argv[1]);
|
||||
byte[] toBeDigested = new byte[ fis.available() ];
|
||||
int read = fis.read( toBeDigested );
|
||||
System.out.println(read + " bytes to be digested");
|
||||
byte[] nsdigestOut;
|
||||
byte[] sundigestOut;
|
||||
|
||||
CryptoManager.initialize(dbdir);
|
||||
|
||||
|
@ -69,73 +116,29 @@ public class DigestTest {
|
|||
java.security.Security.addProvider(new sun.security.provider.Sun() );
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Test SHA-1
|
||||
// Test all available algorithms
|
||||
/////////////////////////////////////////////////////////////
|
||||
java.security.MessageDigest nsdigest =
|
||||
java.security.MessageDigest.getInstance("SHA-1", "Mozilla-JSS");
|
||||
java.security.MessageDigest sundigest =
|
||||
java.security.MessageDigest.getInstance("SHA-1", "SUN");
|
||||
|
||||
nsdigestOut = nsdigest.digest(toBeDigested);
|
||||
sundigestOut = sundigest.digest(toBeDigested);
|
||||
|
||||
if( MessageDigest.isEqual(nsdigestOut, sundigestOut) ) {
|
||||
System.out.println("Sun and Mozilla give same SHA-1 hash");
|
||||
} else {
|
||||
throw new Exception("ERROR: Sun and Mozilla give different"+
|
||||
" SHA-1 hashes");
|
||||
String javaVersion = System.getProperty("java.version");
|
||||
System.out.println("the java version is: " + javaVersion);
|
||||
messageDigest("SHA1", toBeDigested);
|
||||
if ( javaVersion.indexOf("1.4") == -1) {
|
||||
// JDK 1.5 or greater
|
||||
messageDigest("MD2", toBeDigested);
|
||||
} else {
|
||||
System.out.println("JDK 1.4 does not implement MD2");
|
||||
testJSSDigest("MD2", toBeDigested);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Test MD5
|
||||
/////////////////////////////////////////////////////////////
|
||||
nsdigest = java.security.MessageDigest.getInstance("MD5", "Mozilla-JSS");
|
||||
sundigest = java.security.MessageDigest.getInstance("MD5", "SUN");
|
||||
|
||||
nsdigestOut = nsdigest.digest(toBeDigested);
|
||||
sundigestOut = sundigest.digest(toBeDigested);
|
||||
|
||||
if( MessageDigest.isEqual(nsdigestOut, sundigestOut) ) {
|
||||
System.out.println("Sun and Mozilla give same MD5 hash");
|
||||
} else {
|
||||
throw new Exception("ERROR: Sun and Mozilla give different"+
|
||||
" MD5 hashes");
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Test SHA-1 HMAC
|
||||
/////////////////////////////////////////////////////////////
|
||||
CryptoManager cm = CryptoManager.getInstance();
|
||||
CryptoToken token = cm.getInternalCryptoToken();
|
||||
Password pass = new Password("password".toCharArray());
|
||||
byte[] salt = { 0, 1, 2, 3,4 ,5 ,6 ,7 };
|
||||
PBEKeyGenParams pbe = new PBEKeyGenParams(
|
||||
pass,
|
||||
salt,
|
||||
1 );
|
||||
pass.clear();
|
||||
KeyGenerator kg = token.getKeyGenerator(
|
||||
PBEAlgorithm.PBE_SHA1_DES3_CBC );
|
||||
kg.initialize(pbe);
|
||||
SymmetricKey symkey = kg.generate();
|
||||
pbe.clear();
|
||||
org.mozilla.jss.crypto.JSSMessageDigest digest =
|
||||
token.getDigestContext( HMACAlgorithm.SHA1 );
|
||||
digest.initHMAC(symkey);
|
||||
digest.update(toBeDigested);
|
||||
byte[] digestOut = digest.digest();
|
||||
if( digestOut.length == digest.getOutputSize() ) {
|
||||
System.out.println("digest output size is " + digestOut.length);
|
||||
} else {
|
||||
throw new Exception("ERROR: digest output size is "+
|
||||
digestOut.length + ", should be "+digest.getOutputSize() );
|
||||
}
|
||||
System.exit(0);
|
||||
|
||||
|
||||
messageDigest("MD5", toBeDigested);
|
||||
messageDigest("SHA-256", toBeDigested);
|
||||
messageDigest("SHA-384", toBeDigested);
|
||||
messageDigest("SHA-512", toBeDigested);
|
||||
|
||||
//HMAC examples in org.mozilla.jss.tests.HMACTest
|
||||
|
||||
} catch( Exception e ) {
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,6 @@ package org.mozilla.jss.tests;
|
|||
import org.mozilla.jss.CryptoManager;
|
||||
import org.mozilla.jss.ssl.*;
|
||||
import org.mozilla.jss.crypto.*;
|
||||
import org.mozilla.jss.crypto.KeyPairGenerator;
|
||||
import org.mozilla.jss.asn1.*;
|
||||
import org.mozilla.jss.pkix.primitive.*;
|
||||
import org.mozilla.jss.pkix.cert.*;
|
||||
|
@ -73,54 +72,66 @@ public class GenerateTestCert {
|
|||
*/
|
||||
private void doIt(String[] args) throws Exception {
|
||||
|
||||
CryptoManager.initialize(args[0]);
|
||||
CryptoManager cm = CryptoManager.getInstance();
|
||||
if ( args.length != 2 ) {
|
||||
System.out.println("Usage: java org.mozilla.jss.tests." +
|
||||
"GenerateTestCert <dbdir> <passwordFile>");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
CryptoToken tok = cm.getInternalKeyStorageToken();
|
||||
try {
|
||||
CryptoManager.initialize(args[0]);
|
||||
CryptoManager cm = CryptoManager.getInstance();
|
||||
|
||||
PasswordCallback cb = new FilePasswordCallback(args[1]);
|
||||
tok.login(cb);
|
||||
CryptoToken tok = cm.getInternalKeyStorageToken();
|
||||
|
||||
SecureRandom rng= SecureRandom.getInstance("pkcs11prng",
|
||||
PasswordCallback cb = new FilePasswordCallback(args[1]);
|
||||
tok.login(cb);
|
||||
|
||||
SecureRandom rng= SecureRandom.getInstance("pkcs11prng",
|
||||
"Mozilla-JSS");
|
||||
int rand = 24022402;
|
||||
int rand = 24022402;
|
||||
|
||||
// generate CA cert
|
||||
KeyPairGenerator kpg = tok.getKeyPairGenerator(KeyPairAlgorithm.RSA);
|
||||
kpg.initialize(512);
|
||||
KeyPair caPair = kpg.genKeyPair();
|
||||
// generate CA cert
|
||||
java.security.KeyPairGenerator kpg =
|
||||
java.security.KeyPairGenerator.getInstance("RSA", "Mozilla-JSS");
|
||||
kpg.initialize(512);
|
||||
KeyPair caPair = kpg.genKeyPair();
|
||||
|
||||
SEQUENCE extensions = new SEQUENCE();
|
||||
extensions.addElement(makeBasicConstraintsExtension());
|
||||
Certificate caCert = makeCert("CACert", "CACert", 1,
|
||||
SEQUENCE extensions = new SEQUENCE();
|
||||
extensions.addElement(makeBasicConstraintsExtension());
|
||||
Certificate caCert = makeCert("CACert", "CACert", 1,
|
||||
caPair.getPrivate(), caPair.getPublic(), rand, extensions);
|
||||
X509Certificate nssCaCert = cm.importUserCACertPackage(
|
||||
X509Certificate nssCaCert = cm.importUserCACertPackage(
|
||||
ASN1Util.encode(caCert), "JSSCATestCert");
|
||||
InternalCertificate intern = (InternalCertificate)nssCaCert;
|
||||
intern.setSSLTrust(
|
||||
InternalCertificate intern = (InternalCertificate)nssCaCert;
|
||||
intern.setSSLTrust(
|
||||
InternalCertificate.TRUSTED_CA |
|
||||
InternalCertificate.TRUSTED_CLIENT_CA |
|
||||
InternalCertificate.VALID_CA);
|
||||
|
||||
// generate server cert
|
||||
kpg.initialize(512);
|
||||
KeyPair serverPair = kpg.genKeyPair();
|
||||
Certificate serverCert = makeCert("CACert", "localhost", 2,
|
||||
// generate server cert
|
||||
kpg.initialize(512);
|
||||
KeyPair serverPair = kpg.genKeyPair();
|
||||
Certificate serverCert = makeCert("CACert", "localhost", 2,
|
||||
caPair.getPrivate(), serverPair.getPublic(), rand, null);
|
||||
serverCertNick = "JSSCATestServerCert";
|
||||
nssServerCert = cm.importCertPackage(
|
||||
serverCertNick = "JSSCATestServerCert";
|
||||
nssServerCert = cm.importCertPackage(
|
||||
ASN1Util.encode(serverCert), serverCertNick);
|
||||
|
||||
// generate client auth cert
|
||||
kpg.initialize(512);
|
||||
KeyPair clientPair = kpg.genKeyPair();
|
||||
Certificate clientCert = makeCert("CACert", "ClientCert", 3,
|
||||
// generate client auth cert
|
||||
kpg.initialize(512);
|
||||
KeyPair clientPair = kpg.genKeyPair();
|
||||
Certificate clientCert = makeCert("CACert", "ClientCert", 3,
|
||||
caPair.getPrivate(), clientPair.getPublic(), rand, null);
|
||||
clientCertNick = "JSSCATestClientCert";
|
||||
nssClientCert = cm.importCertPackage(
|
||||
clientCertNick = "JSSCATestClientCert";
|
||||
nssClientCert = cm.importCertPackage(
|
||||
ASN1Util.encode(clientCert), clientCertNick);
|
||||
|
||||
System.out.println("Exiting main()");
|
||||
System.out.println("Exiting main()");
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,140 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is the Netscape Security Services for Java.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998-2000
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
package org.mozilla.jss.tests;
|
||||
|
||||
import java.io.*;
|
||||
import org.mozilla.jss.CryptoManager;
|
||||
import org.mozilla.jss.util.Password;
|
||||
import org.mozilla.jss.util.Debug;
|
||||
import java.security.Security;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.Provider;
|
||||
import java.security.*;
|
||||
import javax.crypto.*;
|
||||
import javax.crypto.spec.*;
|
||||
import org.mozilla.jss.crypto.SecretKeyFacade;
|
||||
|
||||
public class HMACTest {
|
||||
|
||||
public static void doHMAC(SecretKeyFacade sk, String alg)
|
||||
throws Exception {
|
||||
|
||||
String clearText = new String("Hi There");
|
||||
|
||||
//Get the Mozilla-JSS HMAC
|
||||
Mac macJSS = Mac.getInstance(alg, "Mozilla-JSS");
|
||||
macJSS.init(sk);
|
||||
macJSS.update(clearText.getBytes());
|
||||
byte[] resultJSS = macJSS.doFinal(clearText.getBytes());
|
||||
|
||||
//Get the SunJCE HMAC
|
||||
Mac macSunJCE = Mac.getInstance(alg, "SunJCE");
|
||||
macSunJCE.init(sk);
|
||||
macSunJCE.update(clearText.getBytes());
|
||||
byte[] resultSunJCE = macSunJCE.doFinal(clearText.getBytes());
|
||||
|
||||
//Check to see if HMACs are equal
|
||||
if ( java.util.Arrays.equals(resultJSS, resultSunJCE) ) {
|
||||
System.out.println("Sun and Mozilla give same " + alg);
|
||||
} else {
|
||||
throw new Exception("ERROR: Sun and Mozilla give different "+ alg );
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String []argv) {
|
||||
|
||||
try {
|
||||
if ( argv.length != 2 ) {
|
||||
System.out.println(
|
||||
"Usage: java org.mozilla.jss.tests.HMACTest " +
|
||||
"<dbdir> <passwordFile>");
|
||||
System.exit(1);
|
||||
}
|
||||
String dbdir = argv[0];
|
||||
FileInputStream fis = new FileInputStream(argv[1]);
|
||||
byte[] toBeDigested = new byte[ fis.available() ];
|
||||
int read = fis.read( toBeDigested );
|
||||
System.out.println(read + " bytes to be digested");
|
||||
CryptoManager.initialize(dbdir);
|
||||
|
||||
Debug.setLevel(Debug.ERROR);
|
||||
Provider[] providers = Security.getProviders();
|
||||
for ( int i=0; i < providers.length; i++ ) {
|
||||
System.out.println("Provider "+i+": "+providers[i].getName());
|
||||
}
|
||||
|
||||
//The secret key must be a JSS key. That is, it must be an
|
||||
//instanceof org.mozilla.jss.crypto.SecretKeyFacade.
|
||||
|
||||
//Generate the secret key using PKCS # 5 password Based Encryption
|
||||
//we have to specify a salt and an iteration count.
|
||||
|
||||
PBEKeySpec pbeKeySpec;
|
||||
SecretKeyFactory keyFac;
|
||||
SecretKeyFacade sk;
|
||||
byte[] salt = {
|
||||
(byte)0x0a, (byte)0x6d, (byte)0x07, (byte)0xba,
|
||||
(byte)0x1e, (byte)0xbd, (byte)0x72, (byte)0xf1
|
||||
};
|
||||
int iterationCount = 7;
|
||||
|
||||
pbeKeySpec = new PBEKeySpec("password".toCharArray(),
|
||||
salt, iterationCount);
|
||||
keyFac = SecretKeyFactory.getInstance("PBEWithSHA1AndDESede",
|
||||
"Mozilla-JSS");
|
||||
sk = (SecretKeyFacade) keyFac.generateSecret(pbeKeySpec);
|
||||
|
||||
//caculate HMAC
|
||||
doHMAC(sk, "HmacSHA1");
|
||||
|
||||
//need to do bug https://bugzilla.mozilla.org/show_bug.cgi?id=263544
|
||||
//to support
|
||||
//doHMAC(sk, "HmacSHA256");
|
||||
//doHMAC(sk, "HmacSHA384");
|
||||
//doHMAC(sk, "HmacSHA512");
|
||||
//also we should add HmacMD2 and HmacMD5
|
||||
//doHMAC(sk, "HmacMD2");
|
||||
//doHMAC(sk, "HmacMD5");
|
||||
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
|
@ -62,6 +62,11 @@ public class JCASigTest {
|
|||
Provider provider = signer.getProvider();
|
||||
System.out.println("The provider used for the signer "
|
||||
+ provider.getName() + " and the algorithm was " + alg);
|
||||
if (provider.getName().equalsIgnoreCase("Mozilla-JSS") == false) {
|
||||
System.out.println("Mozilla-JSS is supposed to be the " +
|
||||
"default provider for JCASigTest");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
signer.initSign(
|
||||
(org.mozilla.jss.crypto.PrivateKey)keyPair.getPrivate());
|
||||
|
@ -83,6 +88,7 @@ public class JCASigTest {
|
|||
}
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -93,7 +99,7 @@ public class JCASigTest {
|
|||
|
||||
if ( args.length != 2 ) {
|
||||
usage();
|
||||
return;
|
||||
System.exit(1);
|
||||
}
|
||||
String dbdir = args[0];
|
||||
String file = args[1];
|
||||
|
@ -106,7 +112,6 @@ public class JCASigTest {
|
|||
manager.setPasswordCallback( new FilePasswordCallback(file) );
|
||||
|
||||
Debug.setLevel(Debug.OBNOXIOUS);
|
||||
|
||||
Provider[] providers = Security.getProviders();
|
||||
for ( int i=0; i < providers.length; i++ ) {
|
||||
System.out.println("Provider "+i+": "+providers[i].getName());
|
||||
|
@ -121,6 +126,12 @@ public class JCASigTest {
|
|||
System.out.println("The provider used to Generate the Keys was "
|
||||
+ provider.getName() );
|
||||
System.out.println("provider info " + provider.getInfo() );
|
||||
|
||||
if (provider.getName().equalsIgnoreCase("Mozilla-JSS") == false) {
|
||||
System.out.println("Mozilla-JSS is supposed to be the " +
|
||||
"default provider for JCASigTest");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
sigTest("MD5/RSA", keyPair);
|
||||
sigTest("MD2/RSA", keyPair);
|
||||
|
@ -129,9 +140,10 @@ public class JCASigTest {
|
|||
sigTest("SHA-384/RSA", keyPair);
|
||||
sigTest("SHA-512/RSA", keyPair);
|
||||
|
||||
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,7 +54,11 @@ public class JSSPackageTest {
|
|||
try {
|
||||
try {
|
||||
certDbPath = (String)args[0];
|
||||
} catch (Exception e) { }
|
||||
} catch (Exception e) {
|
||||
System.out.println("Exception caught : " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
CryptoManager.initialize(certDbPath);
|
||||
|
||||
Package pkg = Package.getPackage("org.mozilla.jss");
|
||||
|
|
|
@ -40,8 +40,8 @@ import java.security.*;
|
|||
import java.security.spec.*;
|
||||
import org.mozilla.jss.CryptoManager;
|
||||
import org.mozilla.jss.crypto.CryptoToken;
|
||||
import org.mozilla.jss.util.ConsolePasswordCallback;
|
||||
import java.util.Iterator;
|
||||
import org.mozilla.jss.util.PasswordCallback;
|
||||
|
||||
abstract class TestValues {
|
||||
protected TestValues(String keyGenAlg, String sigAlg,
|
||||
|
@ -78,16 +78,21 @@ class DSATestValues extends TestValues {
|
|||
|
||||
public class KeyFactoryTest {
|
||||
|
||||
|
||||
public static void main(String argv[]) {
|
||||
try {
|
||||
|
||||
if( argv.length < 1 ) {
|
||||
System.out.println("Usage: java KeyFactoryTest <dbdir>\n");
|
||||
if( argv.length < 2 ) {
|
||||
System.out.println(
|
||||
"Usage: java org.mozilla.jss.tests.KeyFactoryTest " +
|
||||
"<dbdir> <passwordFile>");
|
||||
System.exit(1);
|
||||
}
|
||||
CryptoManager.initialize(argv[0]);
|
||||
CryptoToken tok = CryptoManager.getInstance().getInternalKeyStorageToken();
|
||||
tok.login( new ConsolePasswordCallback() );
|
||||
PasswordCallback cb = new FilePasswordCallback(argv[1]);
|
||||
tok.login(cb);
|
||||
|
||||
Provider []provs = Security.getProviders();
|
||||
for( int i=0; i < provs.length; ++i) {
|
||||
System.out.println("======");
|
||||
|
@ -97,36 +102,31 @@ public class KeyFactoryTest {
|
|||
}
|
||||
|
||||
(new KeyFactoryTest()).doTest();
|
||||
|
||||
System.exit(0);
|
||||
|
||||
} catch(Throwable e) {
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
public void doTest() throws Throwable {
|
||||
RSATestValues rsa = new RSATestValues();
|
||||
DSATestValues dsa = new DSATestValues();
|
||||
|
||||
//
|
||||
// Generate private key from spec
|
||||
//
|
||||
// Generate RSA private key from spec
|
||||
genPrivKeyFromSpec(rsa);
|
||||
|
||||
// importing DSA private keys doesn't work
|
||||
// http://bugzilla.mozilla.org/show_bug.cgi?id=150720
|
||||
// genPrivKeyFromSpec(dsa);
|
||||
// Generate DSA private key from spec
|
||||
genPrivKeyFromSpec(dsa);
|
||||
|
||||
//
|
||||
// Generate public key from spec
|
||||
//
|
||||
// translate RSA key
|
||||
genPubKeyFromSpec(rsa);
|
||||
genPubKeyFromSpec(dsa);
|
||||
|
||||
//
|
||||
// translate key
|
||||
//
|
||||
genPubKeyFromSpec(dsa);
|
||||
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
public void genPrivKeyFromSpec(TestValues vals) throws Throwable {
|
||||
|
|
|
@ -6,17 +6,28 @@ import org.mozilla.jss.crypto.*;
|
|||
public class ListCACerts {
|
||||
|
||||
public static void main(String args[]) throws Exception {
|
||||
CryptoManager.initialize(args[0]);
|
||||
CryptoManager cm = CryptoManager.getInstance();
|
||||
if( args.length != 1 ) {
|
||||
System.out.println(
|
||||
"Usage: java org.mozilla.jss.tests.ListCACerts <dbdir>");
|
||||
System.exit(1);
|
||||
}
|
||||
try {
|
||||
CryptoManager.initialize(args[0]);
|
||||
CryptoManager cm = CryptoManager.getInstance();
|
||||
|
||||
X509Certificate[] certs = cm.getCACerts();
|
||||
X509Certificate[] certs = cm.getCACerts();
|
||||
|
||||
for(int i=0; i < certs.length; ++i ) {
|
||||
System.out.println(certs[i].getSubjectDN().toString());
|
||||
InternalCertificate ic = (InternalCertificate) certs[i];
|
||||
System.out.println("SSL: " + ic.getSSLTrust() + ", Email: " +
|
||||
ic.getEmailTrust() + ", Object Signing: " +
|
||||
ic.getObjectSigningTrust());
|
||||
}
|
||||
for(int i=0; i < certs.length; ++i ) {
|
||||
System.out.println(certs[i].getSubjectDN().toString());
|
||||
InternalCertificate ic = (InternalCertificate) certs[i];
|
||||
System.out.println("SSL: " + ic.getSSLTrust() + ", Email: " +
|
||||
ic.getEmailTrust() + ", Object Signing: " +
|
||||
ic.getObjectSigningTrust());
|
||||
}
|
||||
} catch(Throwable e) {
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ package org.mozilla.jss.tests;
|
|||
import org.mozilla.jss.CryptoManager;
|
||||
import org.mozilla.jss.ssl.*;
|
||||
import org.mozilla.jss.crypto.*;
|
||||
import org.mozilla.jss.crypto.KeyPairGenerator;
|
||||
import java.security.*;
|
||||
import org.mozilla.jss.asn1.*;
|
||||
import org.mozilla.jss.pkix.primitive.*;
|
||||
import org.mozilla.jss.pkix.cert.*;
|
||||
|
@ -51,6 +51,10 @@ import java.security.PrivateKey;
|
|||
import java.net.InetAddress;
|
||||
import java.io.InputStream;
|
||||
import java.io.EOFException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.*;
|
||||
|
||||
public class SSLClientAuth implements Runnable {
|
||||
|
||||
|
@ -103,8 +107,15 @@ public class SSLClientAuth implements Runnable {
|
|||
private X509Certificate nssServerCert, nssClientCert;
|
||||
private String serverCertNick, clientCertNick;
|
||||
|
||||
|
||||
public void doIt(String[] args) throws Exception {
|
||||
|
||||
if ( args.length != 2 ) {
|
||||
System.out.println("Usage: java org.mozilla.jss.tests." +
|
||||
"SSLClientAuth <dbdir> <passwordFile>");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
CryptoManager.initialize(args[0]);
|
||||
CryptoManager cm = CryptoManager.getInstance();
|
||||
|
||||
|
@ -117,8 +128,11 @@ public class SSLClientAuth implements Runnable {
|
|||
"Mozilla-JSS");
|
||||
int rand = nextRandInt(rng);
|
||||
|
||||
|
||||
// generate CA cert
|
||||
KeyPairGenerator kpg = tok.getKeyPairGenerator(KeyPairAlgorithm.RSA);
|
||||
// 512-bit RSA Key with default exponent
|
||||
java.security.KeyPairGenerator kpg =
|
||||
java.security.KeyPairGenerator.getInstance("RSA", "Mozilla-JSS");
|
||||
kpg.initialize(512);
|
||||
KeyPair caPair = kpg.genKeyPair();
|
||||
|
||||
|
|
|
@ -45,7 +45,8 @@ public class SetupDBs {
|
|||
public static void main(String args[]) {
|
||||
try {
|
||||
if( args.length != 2 ) {
|
||||
System.err.println("Invalid number of arguments");
|
||||
System.err.println("Usage: java org.mozilla.jss.tests.SetupDBs " +
|
||||
"<dbdir> <passwordFile>");
|
||||
System.exit(1);
|
||||
}
|
||||
String dbdir = args[0];
|
||||
|
|
|
@ -36,6 +36,9 @@
|
|||
|
||||
|
||||
/* This program demonstrates how to sign data with keys from JSS
|
||||
*
|
||||
* Most of this code is deprecated look at JCASigTest.java
|
||||
*
|
||||
* The token name can be either the name of a hardware token, or
|
||||
* one of the internal tokens:
|
||||
* Internal Crypto Services Token
|
||||
|
|
|
@ -71,10 +71,9 @@ public class TestKeyGen {
|
|||
Base64OutputStream base64;
|
||||
|
||||
if(args.length != 2) {
|
||||
System.err.println(
|
||||
"Usage: java org.mozilla.jss.pkcs11.TestKeyGen <dbdir> <pwfile>");
|
||||
System.err.println("Usage: java org.mozilla.jss.pkcs11." +
|
||||
"TestKeyGen <dbdir> <pwfile>");
|
||||
System.exit(1);
|
||||
return;
|
||||
}
|
||||
|
||||
CryptoManager.initialize(args[0]);
|
||||
|
|
|
@ -125,5 +125,6 @@ public class TestSDR {
|
|||
"Good: failed to decrypt plaintext with deleted key");
|
||||
|
||||
System.out.println("TestSDR: Success");
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -256,6 +256,16 @@ $result >>=8;
|
|||
$result and print "TestKeyGen returned $result\n";
|
||||
print_case_result ($result,"Key generation");
|
||||
|
||||
|
||||
# test KeyFactory
|
||||
#
|
||||
print "============= test KeyFactory\n";
|
||||
$result = system("$java org.mozilla.jss.tests.KeyFactoryTest $testdir $pwfile");
|
||||
$result >>=8;
|
||||
$result and print "KeyFactoryTest returned $result\n";
|
||||
print_case_result ($result,"KeyFactoryTest");
|
||||
|
||||
|
||||
# test digesting
|
||||
#
|
||||
print "============= test digesting\n";
|
||||
|
@ -264,6 +274,16 @@ $result >>=8;
|
|||
$result and print "DigestTest returned $result\n";
|
||||
print_case_result ($result,"Digesting");
|
||||
|
||||
|
||||
# test HMAC
|
||||
#
|
||||
print "============= test HMAC\n";
|
||||
$result = system("$java org.mozilla.jss.tests.HMACTest $testdir $pwfile");
|
||||
$result >>=8;
|
||||
$result and print "HMACTest returned $result\n";
|
||||
print_case_result ($result,"HMACTest");
|
||||
|
||||
|
||||
# test signing
|
||||
#
|
||||
print "============= test signing\n";
|
||||
|
@ -274,11 +294,11 @@ print_case_result ($result,"Signing");
|
|||
|
||||
# test JCA Sig Test
|
||||
#
|
||||
print "============= test Mozilla-JSS SigatureSPI JCASitTest\n";
|
||||
print "============= test Mozilla-JSS SigatureSPI JCASigTest\n";
|
||||
$result = system("$java org.mozilla.jss.tests.JCASigTest $testdir $pwfile");
|
||||
$result >>=8;
|
||||
$result and print "TestJCASigTest returned $result\n";
|
||||
print_case_result ($result,"Mozilla-JSS SigatureSPI JCASitTest");
|
||||
print_case_result ($result,"Mozilla-JSS SigatureSPI JCASigTest");
|
||||
|
||||
# test Secret Decoder Ring
|
||||
#
|
||||
|
|
Загрузка…
Ссылка в новой задаче