1 /* |
1 /* |
2 * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
24 */ |
24 */ |
25 |
25 |
26 package sun.security.mscapi; |
26 package sun.security.mscapi; |
27 |
27 |
28 import java.nio.ByteBuffer; |
28 import java.nio.ByteBuffer; |
29 import java.security.PublicKey; |
29 import java.security.*; |
30 import java.security.PrivateKey; |
30 import java.security.spec.AlgorithmParameterSpec; |
31 import java.security.InvalidKeyException; |
|
32 import java.security.InvalidParameterException; |
|
33 import java.security.KeyStoreException; |
|
34 import java.security.NoSuchAlgorithmException; |
|
35 import java.security.ProviderException; |
|
36 import java.security.MessageDigest; |
|
37 import java.security.SignatureException; |
|
38 import java.math.BigInteger; |
31 import java.math.BigInteger; |
39 |
32 |
40 import sun.security.rsa.RSAKeyFactory; |
33 import sun.security.rsa.RSAKeyFactory; |
41 |
34 |
42 /** |
35 /** |
228 super("MD2"); |
221 super("MD2"); |
229 } |
222 } |
230 } |
223 } |
231 |
224 |
232 // initialize for signing. See JCA doc |
225 // initialize for signing. See JCA doc |
|
226 @Override |
233 protected void engineInitVerify(PublicKey key) |
227 protected void engineInitVerify(PublicKey key) |
234 throws InvalidKeyException |
228 throws InvalidKeyException |
235 { |
229 { |
236 // This signature accepts only RSAPublicKey |
230 // This signature accepts only RSAPublicKey |
237 if ((key instanceof java.security.interfaces.RSAPublicKey) == false) { |
231 if ((key instanceof java.security.interfaces.RSAPublicKey) == false) { |
278 this.privateKey = null; |
272 this.privateKey = null; |
279 resetDigest(); |
273 resetDigest(); |
280 } |
274 } |
281 |
275 |
282 // initialize for signing. See JCA doc |
276 // initialize for signing. See JCA doc |
|
277 @Override |
283 protected void engineInitSign(PrivateKey key) throws InvalidKeyException |
278 protected void engineInitSign(PrivateKey key) throws InvalidKeyException |
284 { |
279 { |
285 // This signature accepts only RSAPrivateKey |
280 // This signature accepts only RSAPrivateKey |
286 if ((key instanceof sun.security.mscapi.RSAPrivateKey) == false) { |
281 if ((key instanceof sun.security.mscapi.RSAPrivateKey) == false) { |
287 throw new InvalidKeyException("Key type not supported"); |
282 throw new InvalidKeyException("Key type not supported"); |
341 * @param len the number of bytes to use, starting at offset |
337 * @param len the number of bytes to use, starting at offset |
342 * |
338 * |
343 * @exception SignatureException if the engine is not initialized |
339 * @exception SignatureException if the engine is not initialized |
344 * properly |
340 * properly |
345 */ |
341 */ |
|
342 @Override |
346 protected void engineUpdate(byte[] b, int off, int len) |
343 protected void engineUpdate(byte[] b, int off, int len) |
347 throws SignatureException |
344 throws SignatureException |
348 { |
345 { |
349 messageDigest.update(b, off, len); |
346 messageDigest.update(b, off, len); |
350 needsReset = true; |
347 needsReset = true; |
354 * Updates the data to be signed or verified, using the |
351 * Updates the data to be signed or verified, using the |
355 * specified ByteBuffer. |
352 * specified ByteBuffer. |
356 * |
353 * |
357 * @param input the ByteBuffer |
354 * @param input the ByteBuffer |
358 */ |
355 */ |
|
356 @Override |
359 protected void engineUpdate(ByteBuffer input) |
357 protected void engineUpdate(ByteBuffer input) |
360 { |
358 { |
361 messageDigest.update(input); |
359 messageDigest.update(input); |
362 needsReset = true; |
360 needsReset = true; |
363 } |
361 } |
372 * |
370 * |
373 * @exception SignatureException if the engine is not |
371 * @exception SignatureException if the engine is not |
374 * initialized properly or if this signature algorithm is unable to |
372 * initialized properly or if this signature algorithm is unable to |
375 * process the input data provided. |
373 * process the input data provided. |
376 */ |
374 */ |
|
375 @Override |
377 protected byte[] engineSign() throws SignatureException { |
376 protected byte[] engineSign() throws SignatureException { |
378 |
377 |
379 byte[] hash = getDigestValue(); |
378 byte[] hash = getDigestValue(); |
380 |
379 |
381 // Omit the hash OID when generating a Raw signature |
380 // Omit the hash OID when generating a Raw signature |
433 * @exception SignatureException if the engine is not |
432 * @exception SignatureException if the engine is not |
434 * initialized properly, the passed-in signature is improperly |
433 * initialized properly, the passed-in signature is improperly |
435 * encoded or of the wrong type, if this signature algorithm is unable to |
434 * encoded or of the wrong type, if this signature algorithm is unable to |
436 * process the input data provided, etc. |
435 * process the input data provided, etc. |
437 */ |
436 */ |
|
437 @Override |
438 protected boolean engineVerify(byte[] sigBytes) |
438 protected boolean engineVerify(byte[] sigBytes) |
439 throws SignatureException |
439 throws SignatureException |
440 { |
440 { |
441 byte[] hash = getDigestValue(); |
441 byte[] hash = getDigestValue(); |
442 |
442 |
468 * |
468 * |
469 * @deprecated Replaced by {@link |
469 * @deprecated Replaced by {@link |
470 * #engineSetParameter(java.security.spec.AlgorithmParameterSpec) |
470 * #engineSetParameter(java.security.spec.AlgorithmParameterSpec) |
471 * engineSetParameter}. |
471 * engineSetParameter}. |
472 */ |
472 */ |
|
473 @Override |
473 @Deprecated |
474 @Deprecated |
474 protected void engineSetParameter(String param, Object value) |
475 protected void engineSetParameter(String param, Object value) |
475 throws InvalidParameterException |
476 throws InvalidParameterException |
476 { |
477 { |
477 throw new InvalidParameterException("Parameter not supported"); |
478 throw new InvalidParameterException("Parameter not supported"); |
478 } |
479 } |
479 |
480 |
|
481 /** |
|
482 * Sets this signature engine with the specified algorithm parameter. |
|
483 * |
|
484 * @param params the parameters |
|
485 * |
|
486 * @exception InvalidAlgorithmParameterException if the given |
|
487 * parameter is invalid |
|
488 */ |
|
489 @Override |
|
490 protected void engineSetParameter(AlgorithmParameterSpec params) |
|
491 throws InvalidAlgorithmParameterException |
|
492 { |
|
493 if (params != null) { |
|
494 throw new InvalidAlgorithmParameterException("No parameter accepted"); |
|
495 } |
|
496 } |
480 |
497 |
481 /** |
498 /** |
482 * Gets the value of the specified algorithm parameter. |
499 * Gets the value of the specified algorithm parameter. |
483 * This method supplies a general-purpose mechanism through which it |
500 * This method supplies a general-purpose mechanism through which it |
484 * is possible to get the various parameters of this object. A parameter |
501 * is possible to get the various parameters of this object. A parameter |
498 * invalid parameter for this engine, or another exception occurs while |
515 * invalid parameter for this engine, or another exception occurs while |
499 * trying to get this parameter. |
516 * trying to get this parameter. |
500 * |
517 * |
501 * @deprecated |
518 * @deprecated |
502 */ |
519 */ |
|
520 @Override |
503 @Deprecated |
521 @Deprecated |
504 protected Object engineGetParameter(String param) |
522 protected Object engineGetParameter(String param) |
505 throws InvalidParameterException |
523 throws InvalidParameterException |
506 { |
524 { |
507 throw new InvalidParameterException("Parameter not supported"); |
525 throw new InvalidParameterException("Parameter not supported"); |
|
526 } |
|
527 |
|
528 /** |
|
529 * Gets the algorithm parameter from this signature engine. |
|
530 * |
|
531 * @return the parameter, or null if no parameter is used. |
|
532 */ |
|
533 @Override |
|
534 protected AlgorithmParameters engineGetParameters() { |
|
535 return null; |
508 } |
536 } |
509 |
537 |
510 /** |
538 /** |
511 * Generates a public-key BLOB from a key's components. |
539 * Generates a public-key BLOB from a key's components. |
512 */ |
540 */ |