66 * JCA getInstance() model, so it return the implementation from the
67 * provider with the highest precedence, which may be this class.
68 */
69 static Signature getInstance() throws NoSuchAlgorithmException {
70 return JsseJce.getSignature(JsseJce.SIGNATURE_SSLRSA);
71 }
72
73 /**
74 * Get an internal implementation for the RSA signature. Used for RSA
75 * client authentication, which needs the ability to set the digests
76 * to externally provided values via the setHashes() method.
77 */
78 static Signature getInternalInstance()
79 throws NoSuchAlgorithmException, NoSuchProviderException {
80 return Signature.getInstance(JsseJce.SIGNATURE_SSLRSA, "SunJSSE");
81 }
82
83 /**
84 * Set the MD5 and SHA hashes to the provided objects.
85 */
86 static void setHashes(Signature sig, MessageDigest md5, MessageDigest sha) {
87 sig.setParameter("hashes", new MessageDigest[] {md5, sha});
88 }
89
90 /**
91 * Reset the MessageDigests unless they are already reset.
92 */
93 private void reset() {
94 if (isReset == false) {
95 md5.reset();
96 sha.reset();
97 isReset = true;
98 }
99 }
100
101 private static void checkNull(Key key) throws InvalidKeyException {
102 if (key == null) {
103 throw new InvalidKeyException("Key must not be null");
104 }
105 }
166
167 @Override
168 protected byte[] engineSign() throws SignatureException {
169 rawRsa.update(getDigest());
170 return rawRsa.sign();
171 }
172
173 @Override
174 protected boolean engineVerify(byte[] sigBytes) throws SignatureException {
175 return engineVerify(sigBytes, 0, sigBytes.length);
176 }
177
178 @Override
179 protected boolean engineVerify(byte[] sigBytes, int offset, int length)
180 throws SignatureException {
181 rawRsa.update(getDigest());
182 return rawRsa.verify(sigBytes, offset, length);
183 }
184
185 @Override
186 protected void engineSetParameter(String param, Object value)
187 throws InvalidParameterException {
188 if (param.equals("hashes") == false) {
189 throw new InvalidParameterException
190 ("Parameter not supported: " + param);
191 }
192 if (value instanceof MessageDigest[] == false) {
193 throw new InvalidParameterException
194 ("value must be MessageDigest[]");
195 }
196 MessageDigest[] digests = (MessageDigest[])value;
197 md5 = digests[0];
198 sha = digests[1];
199 }
200
201 @Override
202 protected Object engineGetParameter(String param)
203 throws InvalidParameterException {
204 throw new InvalidParameterException("Parameters not supported");
205 }
206
207 }
|
66 * JCA getInstance() model, so it return the implementation from the
67 * provider with the highest precedence, which may be this class.
68 */
69 static Signature getInstance() throws NoSuchAlgorithmException {
70 return JsseJce.getSignature(JsseJce.SIGNATURE_SSLRSA);
71 }
72
73 /**
74 * Get an internal implementation for the RSA signature. Used for RSA
75 * client authentication, which needs the ability to set the digests
76 * to externally provided values via the setHashes() method.
77 */
78 static Signature getInternalInstance()
79 throws NoSuchAlgorithmException, NoSuchProviderException {
80 return Signature.getInstance(JsseJce.SIGNATURE_SSLRSA, "SunJSSE");
81 }
82
83 /**
84 * Set the MD5 and SHA hashes to the provided objects.
85 */
86 @SuppressWarnings("deprecation")
87 static void setHashes(Signature sig, MessageDigest md5, MessageDigest sha) {
88 sig.setParameter("hashes", new MessageDigest[] {md5, sha});
89 }
90
91 /**
92 * Reset the MessageDigests unless they are already reset.
93 */
94 private void reset() {
95 if (isReset == false) {
96 md5.reset();
97 sha.reset();
98 isReset = true;
99 }
100 }
101
102 private static void checkNull(Key key) throws InvalidKeyException {
103 if (key == null) {
104 throw new InvalidKeyException("Key must not be null");
105 }
106 }
167
168 @Override
169 protected byte[] engineSign() throws SignatureException {
170 rawRsa.update(getDigest());
171 return rawRsa.sign();
172 }
173
174 @Override
175 protected boolean engineVerify(byte[] sigBytes) throws SignatureException {
176 return engineVerify(sigBytes, 0, sigBytes.length);
177 }
178
179 @Override
180 protected boolean engineVerify(byte[] sigBytes, int offset, int length)
181 throws SignatureException {
182 rawRsa.update(getDigest());
183 return rawRsa.verify(sigBytes, offset, length);
184 }
185
186 @Override
187 @SuppressWarnings("deprecation")
188 protected void engineSetParameter(String param, Object value)
189 throws InvalidParameterException {
190 if (param.equals("hashes") == false) {
191 throw new InvalidParameterException
192 ("Parameter not supported: " + param);
193 }
194 if (value instanceof MessageDigest[] == false) {
195 throw new InvalidParameterException
196 ("value must be MessageDigest[]");
197 }
198 MessageDigest[] digests = (MessageDigest[])value;
199 md5 = digests[0];
200 sha = digests[1];
201 }
202
203 @Override
204 @SuppressWarnings("deprecation")
205 protected Object engineGetParameter(String param)
206 throws InvalidParameterException {
207 throw new InvalidParameterException("Parameters not supported");
208 }
209
210 }
|