Provider classes have been moved into the java/security and javax/crypto

subdirectories.
This commit is contained in:
nicolson%netscape.com 2002-07-03 23:48:53 +00:00
Родитель 9c2bde8f9d
Коммит 0254942b89
12 изменённых файлов: 67 добавлений и 1053 удалений

Просмотреть файл

@ -1,117 +0,0 @@
/*
* 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.
*/
package org.mozilla.jss.provider;
import java.security.PrivateKey;
import java.security.SecureRandom;
import java.security.InvalidKeyException;
import java.security.SignatureException;
import java.security.PublicKey;
import java.security.InvalidParameterException;
import org.mozilla.jss.crypto.SignatureAlgorithm;
import java.security.spec.AlgorithmParameterSpec;
import java.security.InvalidAlgorithmParameterException;
public class DSASignature extends java.security.Signature {
protected Signature sig = new Signature();
public DSASignature() {
super("DSA");
}
public void engineInitSign(PrivateKey privateKey, SecureRandom random)
throws InvalidKeyException
{
sig.engineInitSign(privateKey, random,
SignatureAlgorithm.DSASignatureWithSHA1Digest);
}
public void engineInitSign(PrivateKey privateKey)
throws InvalidKeyException
{
sig.engineInitSign(privateKey,
SignatureAlgorithm.DSASignatureWithSHA1Digest);
}
public void engineInitVerify(PublicKey publicKey)
throws InvalidKeyException
{
sig.engineInitVerify(publicKey,
SignatureAlgorithm.DSASignatureWithSHA1Digest);
}
public void engineUpdate(byte b)
throws SignatureException
{
sig.engineUpdate(b);
}
public void engineUpdate(byte[] b, int off, int len)
throws SignatureException
{
sig.engineUpdate(b, off, len);
}
public byte[] engineSign() throws SignatureException {
return sig.engineSign();
}
public int engineSign(byte[] outbuf, int offset, int len)
throws SignatureException
{
return sig.engineSign(outbuf, offset, len);
}
public boolean engineVerify(byte[] sigBytes) throws SignatureException {
return sig.engineVerify(sigBytes);
}
public void engineSetParameter(AlgorithmParameterSpec params)
throws InvalidAlgorithmParameterException
{
sig.engineSetParameter(params);
}
protected void engineSetParameter(String param, Object value)
throws InvalidParameterException
{
throw new InvalidParameterException();
}
protected Object engineGetParameter(String param)
throws InvalidParameterException
{
throw new InvalidParameterException();
}
}

Просмотреть файл

@ -1,50 +0,0 @@
/*
* 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.
*/
package org.mozilla.jss.provider;
import org.mozilla.jss.crypto.DigestAlgorithm;
/**
* The JSS JCA MD2 provider.
*/
public class MD2MessageDigest extends MessageDigest {
public MD2MessageDigest() {
super(DigestAlgorithm.MD2.toString());
}
protected DigestAlgorithm getAlg() {
return DigestAlgorithm.MD2;
}
}

Просмотреть файл

@ -1,117 +0,0 @@
/*
* 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.
*/
package org.mozilla.jss.provider;
import java.security.PrivateKey;
import java.security.SecureRandom;
import java.security.SignatureException;
import java.security.InvalidKeyException;
import java.security.PublicKey;
import java.security.InvalidParameterException;
import org.mozilla.jss.crypto.SignatureAlgorithm;
import java.security.spec.AlgorithmParameterSpec;
import java.security.InvalidAlgorithmParameterException;
public class MD2RSASignature extends java.security.Signature {
protected Signature sig = new Signature();
public MD2RSASignature() {
super("MD2/RSA");
}
public void engineInitSign(PrivateKey privateKey, SecureRandom random)
throws InvalidKeyException
{
sig.engineInitSign(privateKey, random,
SignatureAlgorithm.RSASignatureWithMD2Digest);
}
public void engineInitSign(PrivateKey privateKey)
throws InvalidKeyException
{
sig.engineInitSign(privateKey,
SignatureAlgorithm.RSASignatureWithMD2Digest);
}
public void engineInitVerify(PublicKey publicKey)
throws InvalidKeyException
{
sig.engineInitVerify(publicKey,
SignatureAlgorithm.RSASignatureWithMD2Digest);
}
public void engineUpdate(byte b)
throws SignatureException
{
sig.engineUpdate(b);
}
public void engineUpdate(byte[] b, int off, int len)
throws SignatureException
{
sig.engineUpdate(b, off, len);
}
public byte[] engineSign() throws SignatureException {
return sig.engineSign();
}
public int engineSign(byte[] outbuf, int offset, int len)
throws SignatureException
{
return sig.engineSign(outbuf, offset, len);
}
public boolean engineVerify(byte[] sigBytes) throws SignatureException {
return sig.engineVerify(sigBytes);
}
public void engineSetParameter(AlgorithmParameterSpec params)
throws InvalidAlgorithmParameterException
{
sig.engineSetParameter(params);
}
protected void engineSetParameter(String param, Object value)
throws InvalidParameterException
{
throw new InvalidParameterException();
}
protected Object engineGetParameter(String param)
throws InvalidParameterException
{
throw new InvalidParameterException();
}
}

Просмотреть файл

@ -1,50 +0,0 @@
/*
* 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.
*/
package org.mozilla.jss.provider;
import org.mozilla.jss.crypto.DigestAlgorithm;
/**
* The JSS JCA MD5 provider.
*/
public class MD5MessageDigest extends MessageDigest {
public MD5MessageDigest() {
super(DigestAlgorithm.MD5.toString());
}
protected DigestAlgorithm getAlg() {
return DigestAlgorithm.MD5;
}
}

Просмотреть файл

@ -1,117 +0,0 @@
/*
* 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.
*/
package org.mozilla.jss.provider;
import java.security.PrivateKey;
import java.security.SecureRandom;
import java.security.SignatureException;
import java.security.InvalidKeyException;
import java.security.PublicKey;
import java.security.InvalidParameterException;
import org.mozilla.jss.crypto.SignatureAlgorithm;
import java.security.spec.AlgorithmParameterSpec;
import java.security.InvalidAlgorithmParameterException;
public class MD5RSASignature extends java.security.Signature {
protected Signature sig = new Signature();
public MD5RSASignature() {
super("MD5/RSA");
}
public void engineInitSign(PrivateKey privateKey, SecureRandom random)
throws InvalidKeyException
{
sig.engineInitSign(privateKey, random,
SignatureAlgorithm.RSASignatureWithMD5Digest);
}
public void engineInitSign(PrivateKey privateKey)
throws InvalidKeyException
{
sig.engineInitSign(privateKey,
SignatureAlgorithm.RSASignatureWithMD5Digest);
}
public void engineInitVerify(PublicKey publicKey)
throws InvalidKeyException
{
sig.engineInitVerify(publicKey,
SignatureAlgorithm.RSASignatureWithMD5Digest);
}
public void engineUpdate(byte b)
throws SignatureException
{
sig.engineUpdate(b);
}
public void engineUpdate(byte[] b, int off, int len)
throws SignatureException
{
sig.engineUpdate(b, off, len);
}
public byte[] engineSign() throws SignatureException {
return sig.engineSign();
}
public int engineSign(byte[] outbuf, int offset, int len)
throws SignatureException
{
return sig.engineSign(outbuf, offset, len);
}
public boolean engineVerify(byte[] sigBytes) throws SignatureException {
return sig.engineVerify(sigBytes);
}
public void engineSetParameter(AlgorithmParameterSpec params)
throws InvalidAlgorithmParameterException
{
sig.engineSetParameter(params);
}
protected void engineSetParameter(String param, Object value)
throws InvalidParameterException
{
throw new InvalidParameterException();
}
protected Object engineGetParameter(String param)
throws InvalidParameterException
{
throw new InvalidParameterException();
}
}

Просмотреть файл

@ -1,133 +0,0 @@
/*
* 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.
*/
package org.mozilla.jss.provider;
import org.mozilla.jss.crypto.*;
import org.mozilla.jss.util.Debug;
import org.mozilla.jss.util.Assert;
import java.security.DigestException;
import java.security.NoSuchAlgorithmException;
/**
* A JCA provider of message digesting implemented with
* Netscape Security Services. One big problem is the Sun interface doesn't
* thrown any exceptions, so I can't thrown any exceptions, even though
* lots can go wrong.
*/
abstract class MessageDigest extends java.security.MessageDigest {
private org.mozilla.jss.crypto.JSSMessageDigest md;
/**
* Returns the particular algorithm that the subclass is implementing.
*/
protected abstract DigestAlgorithm getAlg();
/**
* Creates a JSS MessageDigest provider object.
*/
protected MessageDigest(String algName) {
super( algName );
try {
Debug.trace(Debug.OBNOXIOUS, "In JSS JCA message digest constructor");
CryptoToken internal = TokenSupplierManager.getTokenSupplier().
getInternalCryptoToken();
md = internal.getDigestContext( getAlg() );
} catch( java.security.NoSuchAlgorithmException e ) {
Debug.trace(Debug.ERROR, "Unknown message digesting algorithm: "+
algName);
Assert.notReached("Unknown message digesting algorithm");
} catch( DigestException e ) {
Debug.trace(Debug.ERROR, "Digest Exception while creating "+
algName + " digest" );
Assert.notReached("Digest exception creating message digest");
}
}
protected void engineUpdate(byte input) {
try {
Debug.trace(Debug.OBNOXIOUS, "In JSS JCA message digest engineUpdate");
md.update(input);
} catch( DigestException e ) {
Debug.trace(Debug.ERROR, "Digest Exception while updating digest");
Assert.notReached("Digest exception while updating digest");
}
}
protected void engineUpdate(byte[] input, int offset, int len) {
try {
Debug.trace(Debug.OBNOXIOUS, "In JSS JCA message digest engineUpdate");
md.update(input, offset, len);
} catch( DigestException e ) {
Debug.trace(Debug.ERROR, "Digest Exception while updating digest");
Assert.notReached("Digest exception while updating digest");
}
}
protected byte[] engineDigest() {
try {
Debug.trace(Debug.OBNOXIOUS, "In JSS JCA message digest engineDigest");
return md.digest();
} catch( DigestException e ) {
Debug.trace(Debug.ERROR, "Digest Exception while finalizing digest");
Assert.notReached("Digest exception while finalizing digest");
return null;
}
}
protected void engineReset() {
try {
Debug.trace(Debug.OBNOXIOUS, "In JSS JCA message digest engineReset");
md.reset();
} catch( DigestException e ) {
Debug.trace(Debug.ERROR, "Digest Exception while resetting digest");
Assert.notReached("Digest exception while resetting digest");
}
}
/**
* Throws CloneNotSupportedException, because this implementation is
* not clonable.
*/
public Object clone() throws CloneNotSupportedException {
throw new CloneNotSupportedException();
}
}

Просмотреть файл

@ -1,62 +0,0 @@
/*
* 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 Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2001 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.
*/
package org.mozilla.jss.provider;
import org.mozilla.jss.crypto.TokenSupplierManager;
import org.mozilla.jss.crypto.JSSSecureRandom;
public class PKCS11SecureRandom extends java.security.SecureRandomSpi {
JSSSecureRandom engine;
public PKCS11SecureRandom() {
super();
engine = TokenSupplierManager.getTokenSupplier().getSecureRNG();
}
protected byte[]
engineGenerateSeed(int numBytes) {
byte[] bytes = new byte[numBytes];
engine.nextBytes(bytes);
return bytes;
}
protected void
engineNextBytes(byte[] bytes) {
engine.nextBytes(bytes);
}
protected void
engineSetSeed(byte[] seed) {
engine.setSeed(seed);
}
}

Просмотреть файл

@ -1,82 +0,0 @@
/*
* 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.
*/
package org.mozilla.jss.provider;
public class Provider extends java.security.Provider {
public Provider() {
super("Mozilla-JSS", 3.1,
"Provides Signature, Message Digesting, and RNG");
/////////////////////////////////////////////////////////////
// Signature
/////////////////////////////////////////////////////////////
put("Signature.SHA1withDSA", "org.mozilla.jss.provider.DSASignature");
put("Alg.Alias.Signature.DSA", "SHA1withDSA");
put("Alg.Alias.Signature.DSS", "SHA1withDSA");
put("Alg.Alias.Signature.SHA/DSA", "SHA1withDSA");
put("Alg.Alias.Signature.SHA-1/DSA", "SHA1withDSA");
put("Alg.Alias.Signature.SHA1/DSA", "SHA1withDSA");
put("Alg.Alias.Signature.DSAWithSHA1", "SHA1withDSA");
put("Alg.Alias.Signature.SHAwithDSA", "SHA1withDSA");
put("Signature.MD5/RSA", "org.mozilla.jss.provider.MD5RSASignature");
put("Signature.MD2/RSA", "org.mozilla.jss.provider.MD2RSASignature");
put("Signature.SHA-1/RSA",
"org.mozilla.jss.provider.SHA1RSASignature");
put("Alg.Alias.Signature.SHA1/RSA", "SHA-1/RSA");
/////////////////////////////////////////////////////////////
// Message Digesting
/////////////////////////////////////////////////////////////
put("MessageDigest.SHA-1",
"org.mozilla.jss.provider.SHA1MessageDigest");
put("MessageDigest.MD2",
"org.mozilla.jss.provider.MD2MessageDigest");
put("MessageDigest.MD5",
"org.mozilla.jss.provider.MD5MessageDigest");
put("Alg.Alias.MessageDigest.SHA1", "SHA-1");
put("Alg.Alias.MessageDigest.SHA", "SHA-1");
/////////////////////////////////////////////////////////////
// SecureRandom
/////////////////////////////////////////////////////////////
put("SecureRandom.pkcs11prng",
"org.mozilla.jss.provider.PKCS11SecureRandom");
}
}

Просмотреть файл

@ -1,50 +0,0 @@
/*
* 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.
*/
package org.mozilla.jss.provider;
import org.mozilla.jss.crypto.DigestAlgorithm;
/**
* The JSS JCA SHA1 provider.
*/
public class SHA1MessageDigest extends MessageDigest {
public SHA1MessageDigest() {
super(DigestAlgorithm.SHA1.toString());
}
protected DigestAlgorithm getAlg() {
return DigestAlgorithm.SHA1;
}
}

Просмотреть файл

@ -1,117 +0,0 @@
/*
* 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.
*/
package org.mozilla.jss.provider;
import java.security.PrivateKey;
import java.security.SecureRandom;
import java.security.SignatureException;
import java.security.InvalidKeyException;
import java.security.PublicKey;
import java.security.InvalidParameterException;
import org.mozilla.jss.crypto.SignatureAlgorithm;
import java.security.spec.AlgorithmParameterSpec;
import java.security.InvalidAlgorithmParameterException;
public class SHA1RSASignature extends java.security.Signature {
protected Signature sig = new Signature();
public SHA1RSASignature() {
super("SHA-1/RSA");
}
public void engineInitSign(PrivateKey privateKey, SecureRandom random)
throws InvalidKeyException
{
sig.engineInitSign(privateKey, random,
SignatureAlgorithm.RSASignatureWithSHA1Digest);
}
public void engineInitSign(PrivateKey privateKey)
throws InvalidKeyException
{
sig.engineInitSign(privateKey,
SignatureAlgorithm.RSASignatureWithSHA1Digest);
}
public void engineInitVerify(PublicKey publicKey)
throws InvalidKeyException
{
sig.engineInitVerify(publicKey,
SignatureAlgorithm.RSASignatureWithSHA1Digest);
}
public void engineUpdate(byte b)
throws SignatureException
{
sig.engineUpdate(b);
}
public void engineUpdate(byte[] b, int off, int len)
throws SignatureException
{
sig.engineUpdate(b, off, len);
}
public byte[] engineSign() throws SignatureException {
return sig.engineSign();
}
public int engineSign(byte[] outbuf, int offset, int len)
throws SignatureException
{
return sig.engineSign(outbuf, offset, len);
}
public boolean engineVerify(byte[] sigBytes) throws SignatureException {
return sig.engineVerify(sigBytes);
}
public void engineSetParameter(AlgorithmParameterSpec params)
throws InvalidAlgorithmParameterException
{
sig.engineSetParameter(params);
}
protected void engineSetParameter(String param, Object value)
throws InvalidParameterException
{
throw new InvalidParameterException();
}
protected Object engineGetParameter(String param)
throws InvalidParameterException
{
throw new InvalidParameterException();
}
}

Просмотреть файл

@ -1,158 +0,0 @@
/*
* 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.
*/
package org.mozilla.jss.provider;
import java.security.SecureRandom;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.PublicKey;
import org.mozilla.jss.crypto.*;
import java.security.SignatureException;
import java.security.spec.AlgorithmParameterSpec;
import java.security.InvalidAlgorithmParameterException;
public class Signature {
org.mozilla.jss.crypto.Signature sig;
public void engineInitSign(java.security.PrivateKey privateKey,
SecureRandom random, SignatureAlgorithm sigAlg)
throws InvalidKeyException
{
// discard the random
engineInitSign(privateKey, sigAlg);
}
public void engineInitSign(java.security.PrivateKey privateKey,
SignatureAlgorithm sigAlg) throws InvalidKeyException
{
try {
sig = getSigContext(privateKey, sigAlg);
sig.initSign((PrivateKey)privateKey);
} catch(java.security.NoSuchAlgorithmException e) {
throw new InvalidKeyException("Algorithm not supported");
} catch(TokenException e) {
throw new InvalidKeyException("Token exception occurred");
}
}
protected static org.mozilla.jss.crypto.Signature
getSigContext(java.security.PrivateKey privateKey,
SignatureAlgorithm sigAlg)
throws NoSuchAlgorithmException, InvalidKeyException, TokenException
{
CryptoToken token;
PrivateKey privk;
if( ! (privateKey instanceof PrivateKey) ) {
throw new InvalidKeyException();
}
privk = (PrivateKey)privateKey;
token = privk.getOwningToken();
return token.getSignatureContext(sigAlg);
}
public void engineInitVerify(PublicKey publicKey, SignatureAlgorithm sigAlg)
throws InvalidKeyException
{
try {
CryptoToken token =
TokenSupplierManager.getTokenSupplier().getInternalCryptoToken();
sig = token.getSignatureContext(sigAlg);
sig.initVerify(publicKey);
} catch(java.security.NoSuchAlgorithmException e) {
throw new InvalidKeyException("Algorithm not supported");
} catch(TokenException e) {
throw new InvalidKeyException("Token exception occurred");
}
}
public void engineUpdate(byte b)
throws SignatureException
{
try {
sig.update(b);
} catch( TokenException e) {
throw new SignatureException("TokenException: "+e.toString());
}
}
public void engineUpdate(byte[] b, int off, int len)
throws SignatureException
{
try {
sig.update(b, off, len);
} catch( TokenException e) {
throw new SignatureException("TokenException: "+e.toString());
}
}
public byte[] engineSign() throws SignatureException {
try {
return sig.sign();
} catch(TokenException e) {
throw new SignatureException("TokenException: "+e.toString());
}
}
public int engineSign(byte[] outbuf, int offset, int len)
throws SignatureException
{
try {
return sig.sign(outbuf, offset, len);
} catch(TokenException e) {
throw new SignatureException("TokenException: "+e.toString());
}
}
public boolean engineVerify(byte[] sigBytes) throws SignatureException {
try {
return sig.verify(sigBytes);
} catch( TokenException e) {
throw new SignatureException("TokenException: "+e.toString());
}
}
public void engineSetParameter(AlgorithmParameterSpec params)
throws InvalidAlgorithmParameterException
{
try {
sig.setParameter(params);
} catch( TokenException e ) {
throw new InvalidAlgorithmParameterException(
"TokenException: "+e.toString());
}
}
}

Просмотреть файл

@ -0,0 +1,67 @@
/* ***** 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) 2002
* 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 org.mozilla.jss.crypto.TokenSupplierManager;
import org.mozilla.jss.crypto.JSSSecureRandom;
public class JSSSecureRandomSpi extends java.security.SecureRandomSpi {
JSSSecureRandom engine;
public JSSSecureRandomSpi() {
super();
engine = TokenSupplierManager.getTokenSupplier().getSecureRNG();
}
protected byte[]
engineGenerateSeed(int numBytes) {
byte[] bytes = new byte[numBytes];
engine.nextBytes(bytes);
return bytes;
}
protected void
engineNextBytes(byte[] bytes) {
engine.nextBytes(bytes);
}
protected void
engineSetSeed(byte[] seed) {
engine.setSeed(seed);
}
}