Add new provider classes for JCA Compliance.

This commit is contained in:
nicolson%netscape.com 2001-12-14 20:01:33 +00:00
parent ec44bb325c
commit 6f91bb1b97
9 changed files with 683 additions and 0 deletions

View File

@ -0,0 +1,72 @@
#! gmake
# 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 Netscape are
# Copyright (C) 1998-2000 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the
# terms of the GNU General Public License Version 2 or later (the
# "GPL"), in which case the provisions of the GPL are applicable
# instead of those above. If you wish to allow use of your
# version of this file only under the terms of the GPL and not to
# allow others to use your version of this file under the MPL,
# indicate your decision by deleting the provisions above and
# replace them with the notice and other provisions required by
# the GPL. If you do not delete the provisions above, a recipient
# may use your version of this file under either the MPL or the
# GPL.
#
#######################################################################
# (1) Include initial platform-independent assignments (MANDATORY). #
#######################################################################
include manifest.mn
#######################################################################
# (2) Include "global" configuration information. (OPTIONAL) #
#######################################################################
include $(CORE_DEPTH)/coreconf/config.mk
#######################################################################
# (3) Include "component" configuration information. (OPTIONAL) #
#######################################################################
include $(CORE_DEPTH)/$(MODULE)/config/config.mk
#######################################################################
# (4) Include "local" platform-dependent assignments (OPTIONAL). #
#######################################################################
include config.mk
#######################################################################
# (5) Execute "global" rules. (OPTIONAL) #
#######################################################################
include $(CORE_DEPTH)/coreconf/rules.mk
#######################################################################
# (6) Execute "component" rules. (OPTIONAL) #
#######################################################################
#######################################################################
# (7) Execute "local" rules. (OPTIONAL). #
#######################################################################

View File

@ -0,0 +1,37 @@
#
# 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 Netscape are
# Copyright (C) 1998-2000 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the
# terms of the GNU General Public License Version 2 or later (the
# "GPL"), in which case the provisions of the GPL are applicable
# instead of those above. If you wish to allow use of your
# version of this file only under the terms of the GPL and not to
# allow others to use your version of this file under the MPL,
# indicate your decision by deleting the provisions above and
# replace them with the notice and other provisions required by
# the GPL. If you do not delete the provisions above, a recipient
# may use your version of this file under either the MPL or the
# GPL.
#
TARGETS=$(LIBRARY)
SHARED_LIBRARY=
IMPORT_LIBRARY=
NO_MD_RELEASE = 1

View File

@ -0,0 +1,40 @@
#
# 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 Netscape are
# Copyright (C) 1998-2000 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the
# terms of the GNU General Public License Version 2 or later (the
# "GPL"), in which case the provisions of the GPL are applicable
# instead of those above. If you wish to allow use of your
# version of this file only under the terms of the GPL and not to
# allow others to use your version of this file under the MPL,
# indicate your decision by deleting the provisions above and
# replace them with the notice and other provisions required by
# the GPL. If you do not delete the provisions above, a recipient
# may use your version of this file under either the MPL or the
# GPL.
#
CORE_DEPTH = ../../../../../..
MODULE = jss
NS_USE_JDK = 1
DIRS = security $(NULL)

View File

@ -0,0 +1,187 @@
/* ***** 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 Network Security Services for Java.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2001
* 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.provider.java.security;
import java.security.PublicKey;
import java.security.spec.*;
import org.mozilla.jss.crypto.InvalidKeyFormatException;
import org.mozilla.jss.crypto.PrivateKey;
import org.mozilla.jss.crypto.TokenSupplierManager;
import org.mozilla.jss.asn1.*;
import org.mozilla.jss.pkcs11.PK11PubKey;
import org.mozilla.jss.pkcs11.PK11PrivKey;
import org.mozilla.jss.pkix.primitive.*;
import java.security.Key;
import java.security.InvalidKeyException;
public class KeyFactorySpi1_2 extends java.security.KeyFactorySpi
{
protected PublicKey engineGeneratePublic(KeySpec keySpec)
throws InvalidKeySpecException
{
if( keySpec instanceof RSAPublicKeySpec ) {
RSAPublicKeySpec spec = (RSAPublicKeySpec) keySpec;
// Generate a DER RSA public key
SEQUENCE seq = new SEQUENCE();
seq.addElement( new INTEGER(spec.getModulus()));
seq.addElement( new INTEGER(spec.getPublicExponent()));
return PK11PubKey.fromRaw( PrivateKey.RSA, ASN1Util.encode(seq) );
} else if( keySpec instanceof DSAPublicKeySpec ) {
DSAPublicKeySpec spec = (DSAPublicKeySpec) keySpec;
// Generate a DER DSA public key
INTEGER pubval = new INTEGER( spec.getY() );
return PK11PubKey.fromRaw( PrivateKey.DSA, ASN1Util.encode(pubval));
} else if( keySpec instanceof X509EncodedKeySpec ) {
//
// SubjectPublicKeyInfo
//
X509EncodedKeySpec spec = (X509EncodedKeySpec) keySpec;
return PK11PubKey.fromSPKI( spec.getEncoded() );
}
throw new InvalidKeySpecException("Unsupported KeySpec type: " +
keySpec.getClass().getName());
}
/**
* We don't support RSAPrivateKeySpec because it doesn't have enough
* information. You need to provide an RSAPrivateCrtKeySpec.
*/
protected java.security.PrivateKey engineGeneratePrivate(KeySpec keySpec)
throws InvalidKeySpecException
{
if( keySpec instanceof RSAPrivateCrtKeySpec ) {
//
// PKCS #1 RSAPrivateKey
//
RSAPrivateCrtKeySpec spec = (RSAPrivateCrtKeySpec) keySpec;
SEQUENCE privKey = new SEQUENCE();
privKey.addElement( new INTEGER(0) ) ; // version
privKey.addElement( new INTEGER(spec.getModulus()) );
privKey.addElement( new INTEGER(spec.getPublicExponent()) );
privKey.addElement( new INTEGER(spec.getPrivateExponent()) );
privKey.addElement( new INTEGER(spec.getPrimeP()) );
privKey.addElement( new INTEGER(spec.getPrimeQ()) );
privKey.addElement( new INTEGER(spec.getPrimeExponentP()) );
privKey.addElement( new INTEGER(spec.getPrimeExponentQ()) );
privKey.addElement( new INTEGER(spec.getCrtCoefficient()) );
AlgorithmIdentifier algID =
new AlgorithmIdentifier( PrivateKey.RSA.toOID(), null );
OCTET_STRING encodedPrivKey = new OCTET_STRING(
ASN1Util.encode(privKey) );
PrivateKeyInfo pki = new PrivateKeyInfo(
new INTEGER(0), // version
algID,
encodedPrivKey,
(SET)null // OPTIONAL SET OF Attribute
);
return PK11PrivKey.fromPrivateKeyInfo( ASN1Util.encode(pki),
TokenSupplierManager.getTokenSupplier().getThreadToken() );
} else if( keySpec instanceof DSAPrivateKeySpec ) {
DSAPrivateKeySpec spec = (DSAPrivateKeySpec) keySpec;
SEQUENCE pqgParams = new SEQUENCE();
pqgParams.addElement(new INTEGER(spec.getP()));
pqgParams.addElement(new INTEGER(spec.getQ()));
pqgParams.addElement(new INTEGER(spec.getG()));
AlgorithmIdentifier algID =
new AlgorithmIdentifier( PrivateKey.DSA.toOID(), pqgParams );
OCTET_STRING privateKey = new OCTET_STRING(
ASN1Util.encode(new INTEGER(spec.getX())) );
PrivateKeyInfo pki = new PrivateKeyInfo(
new INTEGER(0), // version
algID,
privateKey,
null // OPTIONAL SET OF Attribute
);
return PK11PrivKey.fromPrivateKeyInfo( ASN1Util.encode(pki),
TokenSupplierManager.getTokenSupplier().getThreadToken() );
} else if( keySpec instanceof PKCS8EncodedKeySpec ) {
return PK11PrivKey.fromPrivateKeyInfo(
(PKCS8EncodedKeySpec)keySpec,
TokenSupplierManager.getTokenSupplier().getThreadToken() );
}
throw new InvalidKeySpecException("Unsupported KeySpec type: " +
keySpec.getClass().getName());
}
protected KeySpec engineGetKeySpec(Key key, Class keySpec)
throws InvalidKeySpecException
{
throw new InvalidKeySpecException(
"Exporting raw key data is not supported. Wrap the key instead.");
}
/**
* Translates key by calling getEncoded() to get its encoded form,
* then importing the key from its encoding. Two formats are supported:
* "SubjectPublicKeyInfo", which is decoded with an X509EncodedKeySpec;
* and "PrivateKeyInfo", which is decoded with a PKCS8EncodedKeySpec.
*
* <p>This method is not well standardized: the documentation is very vague
* about how the key is supposed to be translated. It is better
* to move keys around by wrapping and unwrapping them; or by manually
* translating to a KeySpec, then manually translating back to a Key.
*/
protected Key engineTranslateKey(Key key)
throws InvalidKeyException
{
byte[] encoded = key.getEncoded();
String format = key.getFormat();
try {
if( format.equals("SubjectPublicKeyInfo") ) {
X509EncodedKeySpec spec = new X509EncodedKeySpec(encoded);
return engineGeneratePublic(spec);
} else if( format.equals("PrivateKeyInfo") ) {
PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(encoded);
return engineGeneratePrivate(spec);
}
} catch(InvalidKeySpecException e) {
throw new InvalidKeyException(e.getMessage());
}
throw new InvalidKeyException(
"Unsupported encoding format: " + format);
}
}

View File

@ -0,0 +1,85 @@
/* ***** 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 Network Security Services for Java.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2001
* 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.provider.java.security;
import java.security.PublicKey;
import java.security.spec.*;
import org.mozilla.jss.crypto.InvalidKeyFormatException;
import org.mozilla.jss.crypto.PrivateKey;
import org.mozilla.jss.asn1.*;
import org.mozilla.jss.pkcs11.PK11PubKey;
import java.security.Key;
import java.security.InvalidKeyException;
import javax.crypto.spec.DHPublicKeySpec;
public class KeyFactorySpi1_4 extends KeyFactorySpi1_2
{
protected PublicKey engineGeneratePublic(KeySpec keySpec)
throws InvalidKeySpecException
{
if( keySpec instanceof DHPublicKeySpec ) {
DHPublicKeySpec spec = (DHPublicKeySpec) keySpec;
// Generate a DER DH public key
INTEGER pubval = new INTEGER( spec.getY() );
return PK11PubKey.fromRaw( PrivateKey.DiffieHellman,
ASN1Util.encode(pubval));
} else {
return super.engineGeneratePublic(keySpec);
}
}
protected java.security.PrivateKey engineGeneratePrivate(KeySpec keySpec)
throws InvalidKeySpecException
{
return null;
}
protected KeySpec engineGetKeySpec(Key key, Class keySpec)
throws InvalidKeySpecException
{
return null;
}
protected Key engineTranslateKey(Key key)
throws InvalidKeyException
{
return null;
}
}

View File

@ -0,0 +1,74 @@
/* ***** 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 Network Security Services for Java.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2001
* 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.provider.java.security;
class GenericKeyPairGeneratorSpi
extends java.security.KeyPairGeneratorSpi
{
private KeyPairGenerator kpg;
private GenericKeyPairGeneratorSpi() { super(); }
public GenericKeyPairGeneratorSpi(String algName)
throws java.security.NoSuchAlgorithmException
{
super();
this(KeyPairAlgorithm.fromString(algName));
}
public GenericKeyPairGeneratorSpi(KeyPairAlgorithm alg) {
super();
CryptoToken token =
TokenSupplierManager.getTokenSupplier().getThreadToken();
kpg = token.getKeyPairGenerator(alg)
}
public void initialize(AlgorithmParameterSpec params,
SecureRandom random) throws InvalidAlgorithmParameterSpecException
{
kpg.initialize(params, random);
}
public void initialize(int keysize, SecureRandom random) {
kpg.initialize(keysize, random);
}
}

View File

@ -0,0 +1,72 @@
#! gmake
# 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 Netscape are
# Copyright (C) 1998-2000 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the
# terms of the GNU General Public License Version 2 or later (the
# "GPL"), in which case the provisions of the GPL are applicable
# instead of those above. If you wish to allow use of your
# version of this file only under the terms of the GPL and not to
# allow others to use your version of this file under the MPL,
# indicate your decision by deleting the provisions above and
# replace them with the notice and other provisions required by
# the GPL. If you do not delete the provisions above, a recipient
# may use your version of this file under either the MPL or the
# GPL.
#
#######################################################################
# (1) Include initial platform-independent assignments (MANDATORY). #
#######################################################################
include manifest.mn
#######################################################################
# (2) Include "global" configuration information. (OPTIONAL) #
#######################################################################
include $(CORE_DEPTH)/coreconf/config.mk
#######################################################################
# (3) Include "component" configuration information. (OPTIONAL) #
#######################################################################
include $(CORE_DEPTH)/$(MODULE)/config/config.mk
#######################################################################
# (4) Include "local" platform-dependent assignments (OPTIONAL). #
#######################################################################
include config.mk
#######################################################################
# (5) Execute "global" rules. (OPTIONAL) #
#######################################################################
include $(CORE_DEPTH)/coreconf/rules.mk
#######################################################################
# (6) Execute "component" rules. (OPTIONAL) #
#######################################################################
#######################################################################
# (7) Execute "local" rules. (OPTIONAL). #
#######################################################################

View File

@ -0,0 +1,37 @@
#
# 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 Netscape are
# Copyright (C) 1998-2000 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the
# terms of the GNU General Public License Version 2 or later (the
# "GPL"), in which case the provisions of the GPL are applicable
# instead of those above. If you wish to allow use of your
# version of this file only under the terms of the GPL and not to
# allow others to use your version of this file under the MPL,
# indicate your decision by deleting the provisions above and
# replace them with the notice and other provisions required by
# the GPL. If you do not delete the provisions above, a recipient
# may use your version of this file under either the MPL or the
# GPL.
#
TARGETS=$(LIBRARY)
SHARED_LIBRARY=
IMPORT_LIBRARY=
NO_MD_RELEASE = 1

View File

@ -0,0 +1,79 @@
#
# 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 Netscape are
# Copyright (C) 1998-2000 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the
# terms of the GNU General Public License Version 2 or later (the
# "GPL"), in which case the provisions of the GPL are applicable
# instead of those above. If you wish to allow use of your
# version of this file only under the terms of the GPL and not to
# allow others to use your version of this file under the MPL,
# indicate your decision by deleting the provisions above and
# replace them with the notice and other provisions required by
# the GPL. If you do not delete the provisions above, a recipient
# may use your version of this file under either the MPL or the
# GPL.
#
CORE_DEPTH = ../../../../../../..
MODULE = jss
NS_USE_JDK = 1
REQUIRES = nspr20 security
PACKAGE = org/mozilla/jss/
JNI_GEN = \
$(NULL)
PRIVATE_EXPORTS = \
$(NULL)
CLASSES = \
org.mozilla.jss.provider.java.security.KeyFactorySpi1_2 \
$(NULL)
PRIVATE_CLASSES = \
$(NULL)
JSRCS = \
KeyFactorySpi1_2.java \
$(NULL)
ifdef JDK_1_4
CLASSES += \
org.mozilla.jss.provider.java.security.KeyFactorySpi1_4 \
$(NULL)
JSRCS += \
KeyFactorySpi1_4.java \
$(NULL)
endif
PRIVATE_JSRCS = \
$(NULL)
CSRCS = \
$(NULL)
LIBRARY_NAME =