1 | package com.lowagie.bouncycastle; | |
2 | ||
3 | import com.lowagie.text.ExceptionConverter; | |
4 | import com.lowagie.text.pdf.PdfArray; | |
5 | import com.lowagie.text.pdf.PdfObject; | |
6 | ||
7 | import org.bouncycastle.cert.X509CertificateHolder; | |
8 | import org.bouncycastle.cms.CMSEnvelopedData; | |
9 | import org.bouncycastle.cms.Recipient; | |
10 | import org.bouncycastle.cms.RecipientInformation; | |
11 | import org.bouncycastle.cms.jcajce.JceKeyTransEnvelopedRecipient; | |
12 | ||
13 | import java.io.IOException; | |
14 | import java.security.Key; | |
15 | import java.security.PrivateKey; | |
16 | import java.security.cert.Certificate; | |
17 | import java.security.cert.CertificateEncodingException; | |
18 | import java.util.Collection; | |
19 | import java.util.List; | |
20 | ||
21 | public class BouncyCastleHelper { | |
22 | public static void checkCertificateEncodingOrThrowException(Certificate certificate) { | |
23 | // OJO... | |
24 | try { | |
25 | X509CertificateHolder certificateHolder = new X509CertificateHolder(certificate.getEncoded()); | |
26 | } catch (CertificateEncodingException | IOException f) { | |
27 | throw new ExceptionConverter(f); | |
28 | } | |
29 | // ****************************************************************************** | |
30 | } | |
31 | ||
32 | public static byte[] getEnvelopedData(PdfArray recipients, List<PdfObject> strings, Certificate certificate, Key certificateKey, String certificateKeyProvider) { | |
33 | byte[] envelopedData = null; | |
34 | for (PdfObject recipient : recipients.getElements()) { | |
35 | strings.remove(recipient); | |
36 | try { | |
37 | CMSEnvelopedData data = new CMSEnvelopedData(recipient.getBytes()); | |
38 | ||
39 | final Collection<RecipientInformation> recipientInformations = data.getRecipientInfos().getRecipients(); | |
40 | for (RecipientInformation recipientInfo : recipientInformations) { | |
41 | if (recipientInfo.getRID().match(certificate)) { | |
42 | // OJO... | |
43 | // https://www.bouncycastle.org/docs/pkixdocs1.5on/org/bouncycastle/cms/CMSEnvelopedData.html | |
44 | Recipient rec = new JceKeyTransEnvelopedRecipient( | |
45 | (PrivateKey) certificateKey) | |
46 | .setProvider(certificateKeyProvider); | |
47 | envelopedData = recipientInfo.getContent(rec); | |
48 | // ****************************************************************************** | |
49 | break; | |
50 | } | |
51 | ||
52 | } | |
53 | } catch (Exception f) { | |
54 | throw new ExceptionConverter(f); | |
55 | } | |
56 | } | |
57 |
1
1. getEnvelopedData : mutated return of Object value for com/lowagie/bouncycastle/BouncyCastleHelper::getEnvelopedData to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return envelopedData; |
58 | } | |
59 | } | |
Mutations | ||
57 |
1.1 |