1 /* |
1 /* |
2 * Copyright (c) 1996, 2018, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1996, 2019, 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 |
445 } |
445 } |
446 } |
446 } |
447 |
447 |
448 Signature sig = Signature.getInstance(algname); |
448 Signature sig = Signature.getInstance(algname); |
449 |
449 |
450 sig.initVerify(key); |
|
451 |
|
452 // set parameters after Signature.initSign/initVerify call, |
|
453 // so the deferred provider selections occur when key is set |
|
454 AlgorithmParameters ap = |
450 AlgorithmParameters ap = |
455 digestEncryptionAlgorithmId.getParameters(); |
451 digestEncryptionAlgorithmId.getParameters(); |
456 try { |
452 try { |
457 SignatureUtil.specialSetParameter(sig, ap); |
453 SignatureUtil.initVerifyWithParam(sig, key, |
458 } catch (ProviderException | InvalidAlgorithmParameterException e) { |
454 SignatureUtil.getParamSpec(algname, ap)); |
|
455 } catch (ProviderException | InvalidAlgorithmParameterException | |
|
456 InvalidKeyException e) { |
459 throw new SignatureException(e.getMessage(), e); |
457 throw new SignatureException(e.getMessage(), e); |
460 } |
458 } |
461 |
459 |
462 sig.update(dataSigned); |
460 sig.update(dataSigned); |
463 if (sig.verify(encryptedDigest)) { |
461 if (sig.verify(encryptedDigest)) { |
464 return this; |
462 return this; |
465 } |
463 } |
466 } catch (IOException e) { |
464 } catch (IOException e) { |
467 throw new SignatureException("IO error verifying signature:\n" + |
465 throw new SignatureException("IO error verifying signature:\n" + |
468 e.getMessage()); |
466 e.getMessage()); |
469 } catch (InvalidKeyException e) { |
|
470 throw new SignatureException("InvalidKey: " + e.getMessage()); |
|
471 } |
467 } |
472 return null; |
468 return null; |
473 } |
469 } |
474 |
470 |
475 /* Verify the content of the pkcs7 block. */ |
471 /* Verify the content of the pkcs7 block. */ |