|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
|
|
package sun.security.ssl; |
|
|
|
import java.security.*; |
|
import java.security.spec.AlgorithmParameterSpec; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public final class RSASignature extends SignatureSpi { |
|
private final Signature rawRsa; |
|
private final MessageDigest mdMD5; |
|
private final MessageDigest mdSHA; |
|
|
|
public RSASignature() throws NoSuchAlgorithmException { |
|
super(); |
|
rawRsa = Signature.getInstance(JsseJce.SIGNATURE_RAWRSA); |
|
this.mdMD5 = MessageDigest.getInstance("MD5"); |
|
this.mdSHA = MessageDigest.getInstance("SHA"); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
static Signature getInstance() throws NoSuchAlgorithmException { |
|
return Signature.getInstance(JsseJce.SIGNATURE_SSLRSA); |
|
} |
|
|
|
@Override |
|
protected void engineInitVerify(PublicKey publicKey) |
|
throws InvalidKeyException { |
|
if (publicKey == null) { |
|
throw new InvalidKeyException("Public key must not be null"); |
|
} |
|
mdMD5.reset(); |
|
mdSHA.reset(); |
|
rawRsa.initVerify(publicKey); |
|
} |
|
|
|
@Override |
|
protected void engineInitSign(PrivateKey privateKey) |
|
throws InvalidKeyException { |
|
engineInitSign(privateKey, null); |
|
} |
|
|
|
@Override |
|
protected void engineInitSign(PrivateKey privateKey, SecureRandom random) |
|
throws InvalidKeyException { |
|
if (privateKey == null) { |
|
throw new InvalidKeyException("Private key must not be null"); |
|
} |
|
mdMD5.reset(); |
|
mdSHA.reset(); |
|
rawRsa.initSign(privateKey, random); |
|
} |
|
|
|
@Override |
|
protected void engineUpdate(byte b) { |
|
mdMD5.update(b); |
|
mdSHA.update(b); |
|
} |
|
|
|
@Override |
|
protected void engineUpdate(byte[] b, int off, int len) { |
|
mdMD5.update(b, off, len); |
|
mdSHA.update(b, off, len); |
|
} |
|
|
|
private byte[] getDigest() throws SignatureException { |
|
try { |
|
byte[] data = new byte[36]; |
|
mdMD5.digest(data, 0, 16); |
|
mdSHA.digest(data, 16, 20); |
|
return data; |
|
} catch (DigestException e) { |
|
|
|
throw new SignatureException(e); |
|
} |
|
} |
|
|
|
@Override |
|
protected byte[] engineSign() throws SignatureException { |
|
rawRsa.update(getDigest()); |
|
return rawRsa.sign(); |
|
} |
|
|
|
@Override |
|
protected boolean engineVerify(byte[] sigBytes) throws SignatureException { |
|
return engineVerify(sigBytes, 0, sigBytes.length); |
|
} |
|
|
|
@Override |
|
protected boolean engineVerify(byte[] sigBytes, int offset, int length) |
|
throws SignatureException { |
|
rawRsa.update(getDigest()); |
|
return rawRsa.verify(sigBytes, offset, length); |
|
} |
|
|
|
@Override |
|
@SuppressWarnings("deprecation") |
|
protected void engineSetParameter(String param, |
|
Object value) throws InvalidParameterException { |
|
throw new InvalidParameterException("Parameters not supported"); |
|
} |
|
|
|
@Override |
|
protected void engineSetParameter(AlgorithmParameterSpec params) |
|
throws InvalidAlgorithmParameterException { |
|
if (params != null) { |
|
throw new InvalidAlgorithmParameterException("No parameters accepted"); |
|
} |
|
} |
|
|
|
@Override |
|
@SuppressWarnings("deprecation") |
|
protected Object engineGetParameter( |
|
String param) throws InvalidParameterException { |
|
throw new InvalidParameterException("Parameters not supported"); |
|
} |
|
|
|
@Override |
|
protected AlgorithmParameters engineGetParameters() { |
|
return null; |
|
} |
|
} |