1 | /* | |
2 | * Copyright 2004 by Paulo Soares. | |
3 | * | |
4 | * The contents of this file are subject to the Mozilla Public License Version 1.1 | |
5 | * (the "License"); you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at http://www.mozilla.org/MPL/ | |
7 | * | |
8 | * Software distributed under the License is distributed on an "AS IS" basis, | |
9 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | |
10 | * for the specific language governing rights and limitations under the License. | |
11 | * | |
12 | * The Original Code is 'iText, a free JAVA-PDF library'. | |
13 | * | |
14 | * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by | |
15 | * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie. | |
16 | * All Rights Reserved. | |
17 | * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer | |
18 | * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved. | |
19 | * | |
20 | * Contributor(s): all the names of the contributors are added in the source code | |
21 | * where applicable. | |
22 | * | |
23 | * Alternatively, the contents of this file may be used under the terms of the | |
24 | * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the | |
25 | * provisions of LGPL are applicable instead of those above. If you wish to | |
26 | * allow use of your version of this file only under the terms of the LGPL | |
27 | * License and not to allow others to use your version of this file under | |
28 | * the MPL, indicate your decision by deleting the provisions above and | |
29 | * replace them with the notice and other provisions required by the LGPL. | |
30 | * If you do not delete the provisions above, a recipient may use your version | |
31 | * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE. | |
32 | * | |
33 | * This library is free software; you can redistribute it and/or modify it | |
34 | * under the terms of the MPL as stated above or under the terms of the GNU | |
35 | * Library General Public License as published by the Free Software Foundation; | |
36 | * either version 2 of the License, or any later version. | |
37 | * | |
38 | * This library is distributed in the hope that it will be useful, but WITHOUT | |
39 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
40 | * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more | |
41 | * details. | |
42 | * | |
43 | * If you didn't download this code from the following link, you should check if | |
44 | * you aren't using an obsolete version: | |
45 | * http://www.lowagie.com/iText/ | |
46 | */ | |
47 | package com.lowagie.text.pdf; | |
48 | ||
49 | import com.lowagie.text.ExceptionConverter; | |
50 | import com.lowagie.text.error_messages.MessageLocalization; | |
51 | import org.bouncycastle.asn1.*; | |
52 | import org.bouncycastle.asn1.cms.Attribute; | |
53 | import org.bouncycastle.asn1.cms.AttributeTable; | |
54 | import org.bouncycastle.asn1.cms.ContentInfo; | |
55 | import org.bouncycastle.asn1.ocsp.BasicOCSPResponse; | |
56 | import org.bouncycastle.asn1.ocsp.OCSPObjectIdentifiers; | |
57 | import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers; | |
58 | import org.bouncycastle.asn1.tsp.MessageImprint; | |
59 | import org.bouncycastle.cert.jcajce.JcaX509CertificateHolder; | |
60 | import org.bouncycastle.cert.ocsp.BasicOCSPResp; | |
61 | import org.bouncycastle.cert.ocsp.CertificateID; | |
62 | import org.bouncycastle.cert.ocsp.SingleResp; | |
63 | import org.bouncycastle.jcajce.provider.asymmetric.x509.CertificateFactory; | |
64 | import org.bouncycastle.jce.provider.X509CRLParser; | |
65 | import org.bouncycastle.operator.DigestCalculatorProvider; | |
66 | import org.bouncycastle.operator.jcajce.JcaDigestCalculatorProviderBuilder; | |
67 | import org.bouncycastle.tsp.TimeStampToken; | |
68 | ||
69 | import javax.annotation.Nonnull; | |
70 | import javax.annotation.Nullable; | |
71 | import java.io.*; | |
72 | import java.math.BigInteger; | |
73 | import java.nio.charset.StandardCharsets; | |
74 | import java.security.*; | |
75 | import java.security.cert.CRL; | |
76 | import java.security.cert.Certificate; | |
77 | import java.security.cert.X509CRL; | |
78 | import java.security.cert.X509Certificate; | |
79 | import java.util.*; | |
80 | ||
81 | import static org.bouncycastle.asn1.x509.Extension.authorityInfoAccess; | |
82 | ||
83 | /** | |
84 | * This class does all the processing related to signing and verifying a PKCS#7 | |
85 | * signature. | |
86 | * <p> | |
87 | * It's based in code found at org.bouncycastle. | |
88 | */ | |
89 | public class PdfPKCS7 { | |
90 | ||
91 | private byte[] sigAttr; | |
92 | private byte[] digestAttr; | |
93 | private int version, signerversion; | |
94 | private Set<String> digestalgos; | |
95 | private List<Certificate> certs, signCerts; | |
96 | private List<CRL> crls; | |
97 | private X509Certificate signCert; | |
98 | private byte[] digest; | |
99 | private MessageDigest messageDigest; | |
100 | private String digestAlgorithm, digestEncryptionAlgorithm; | |
101 | private Signature sig; | |
102 | private transient PrivateKey privKey; | |
103 | private byte[] RSAdata; | |
104 | private boolean verified; | |
105 | private boolean verifyResult; | |
106 | private byte[] externalDigest; | |
107 | private byte[] externalRSAdata; | |
108 | private String provider; | |
109 | ||
110 | private static final String ID_PKCS7_DATA = "1.2.840.113549.1.7.1"; | |
111 | private static final String ID_PKCS7_SIGNED_DATA = "1.2.840.113549.1.7.2"; | |
112 | private static final String ID_RSA = "1.2.840.113549.1.1.1"; | |
113 | private static final String ID_DSA = "1.2.840.10040.4.1"; | |
114 | private static final String ID_CONTENT_TYPE = "1.2.840.113549.1.9.3"; | |
115 | private static final String ID_MESSAGE_DIGEST = "1.2.840.113549.1.9.4"; | |
116 | private static final String ID_SIGNING_TIME = "1.2.840.113549.1.9.5"; | |
117 | private static final String ID_ADBE_REVOCATION = "1.2.840.113583.1.1.8"; | |
118 | /** | |
119 | * Holds value of property reason. | |
120 | */ | |
121 | private String reason; | |
122 | ||
123 | /** | |
124 | * Holds value of property location. | |
125 | */ | |
126 | private String location; | |
127 | ||
128 | /** | |
129 | * Holds value of property signDate. | |
130 | */ | |
131 | private Calendar signDate; | |
132 | ||
133 | /** | |
134 | * Holds value of property signName. | |
135 | */ | |
136 | private String signName; | |
137 | ||
138 | private TimeStampToken timeStampToken; | |
139 | ||
140 | private static final Map<String, String> digestNames = new HashMap<>(); | |
141 | private static final Map<String, String> algorithmNames = new HashMap<>(); | |
142 | private static final Map<String, String> allowedDigests = new HashMap<>(); | |
143 | ||
144 | static { | |
145 | digestNames.put("1.2.840.113549.2.5", "MD5"); | |
146 | digestNames.put("1.2.840.113549.2.2", "MD2"); | |
147 | digestNames.put("1.3.14.3.2.26", "SHA1"); | |
148 | digestNames.put("2.16.840.1.101.3.4.2.4", "SHA224"); | |
149 | digestNames.put("2.16.840.1.101.3.4.2.1", "SHA256"); | |
150 | digestNames.put("2.16.840.1.101.3.4.2.2", "SHA384"); | |
151 | digestNames.put("2.16.840.1.101.3.4.2.3", "SHA512"); | |
152 | digestNames.put("1.3.36.3.2.2", "RIPEMD128"); | |
153 | digestNames.put("1.3.36.3.2.1", "RIPEMD160"); | |
154 | digestNames.put("1.3.36.3.2.3", "RIPEMD256"); | |
155 | digestNames.put("1.2.840.113549.1.1.4", "MD5"); | |
156 | digestNames.put("1.2.840.113549.1.1.2", "MD2"); | |
157 | digestNames.put("1.2.840.113549.1.1.5", "SHA1"); | |
158 | digestNames.put("1.2.840.113549.1.1.14", "SHA224"); | |
159 | digestNames.put("1.2.840.113549.1.1.11", "SHA256"); | |
160 | digestNames.put("1.2.840.113549.1.1.12", "SHA384"); | |
161 | digestNames.put("1.2.840.113549.1.1.13", "SHA512"); | |
162 | digestNames.put("1.2.840.10040.4.3", "SHA1"); // TODO: bug - duplicate key - overwrites this with DSA | |
163 | digestNames.put("2.16.840.1.101.3.4.3.1", "SHA224"); // TODO: bug - duplicate key - overwrites this with DSA | |
164 | digestNames.put("2.16.840.1.101.3.4.3.2", "SHA256"); | |
165 | digestNames.put("2.16.840.1.101.3.4.3.3", "SHA384"); | |
166 | digestNames.put("2.16.840.1.101.3.4.3.4", "SHA512"); | |
167 | digestNames.put("1.3.36.3.3.1.3", "RIPEMD128"); | |
168 | digestNames.put("1.3.36.3.3.1.2", "RIPEMD160"); | |
169 | digestNames.put("1.3.36.3.3.1.4", "RIPEMD256"); | |
170 | ||
171 | algorithmNames.put("1.2.840.113549.1.1.1", "RSA"); | |
172 | algorithmNames.put("1.2.840.10040.4.1", "DSA"); | |
173 | algorithmNames.put("1.2.840.113549.1.1.2", "RSA"); | |
174 | algorithmNames.put("1.2.840.113549.1.1.4", "RSA"); | |
175 | algorithmNames.put("1.2.840.113549.1.1.5", "RSA"); | |
176 | algorithmNames.put("1.2.840.113549.1.1.14", "RSA"); | |
177 | algorithmNames.put("1.2.840.113549.1.1.11", "RSA"); | |
178 | algorithmNames.put("1.2.840.113549.1.1.12", "RSA"); | |
179 | algorithmNames.put("1.2.840.113549.1.1.13", "RSA"); | |
180 | algorithmNames.put("1.2.840.10040.4.3", "DSA"); | |
181 | algorithmNames.put("2.16.840.1.101.3.4.3.1", "DSA"); | |
182 | algorithmNames.put("2.16.840.1.101.3.4.3.2", "DSA"); | |
183 | algorithmNames.put("1.3.36.3.3.1.3", "RSA"); | |
184 | algorithmNames.put("1.3.36.3.3.1.2", "RSA"); | |
185 | algorithmNames.put("1.3.36.3.3.1.4", "RSA"); | |
186 | ||
187 | allowedDigests.put("MD5", "1.2.840.113549.2.5"); | |
188 | allowedDigests.put("MD2", "1.2.840.113549.2.2"); | |
189 | allowedDigests.put("SHA1", "1.3.14.3.2.26"); | |
190 | allowedDigests.put("SHA224", "2.16.840.1.101.3.4.2.4"); | |
191 | allowedDigests.put("SHA256", "2.16.840.1.101.3.4.2.1"); | |
192 | allowedDigests.put("SHA384", "2.16.840.1.101.3.4.2.2"); | |
193 | allowedDigests.put("SHA512", "2.16.840.1.101.3.4.2.3"); | |
194 | allowedDigests.put("MD-5", "1.2.840.113549.2.5"); | |
195 | allowedDigests.put("MD-2", "1.2.840.113549.2.2"); | |
196 | allowedDigests.put("SHA-1", "1.3.14.3.2.26"); | |
197 | allowedDigests.put("SHA-224", "2.16.840.1.101.3.4.2.4"); | |
198 | allowedDigests.put("SHA-256", "2.16.840.1.101.3.4.2.1"); | |
199 | allowedDigests.put("SHA-384", "2.16.840.1.101.3.4.2.2"); | |
200 | allowedDigests.put("SHA-512", "2.16.840.1.101.3.4.2.3"); | |
201 | allowedDigests.put("RIPEMD128", "1.3.36.3.2.2"); | |
202 | allowedDigests.put("RIPEMD-128", "1.3.36.3.2.2"); | |
203 | allowedDigests.put("RIPEMD160", "1.3.36.3.2.1"); | |
204 | allowedDigests.put("RIPEMD-160", "1.3.36.3.2.1"); | |
205 | allowedDigests.put("RIPEMD256", "1.3.36.3.2.3"); | |
206 | allowedDigests.put("RIPEMD-256", "1.3.36.3.2.3"); | |
207 | } | |
208 | ||
209 | /** | |
210 | * Gets the digest name for a certain id | |
211 | * | |
212 | * @param oid an id (for instance "1.2.840.113549.2.5") | |
213 | * @return a digest name (for instance "MD5") | |
214 | * @since 2.1.6 | |
215 | */ | |
216 | public static String getDigest(String oid) { | |
217 |
1
1. getDigest : mutated return of Object value for com/lowagie/text/pdf/PdfPKCS7::getDigest to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return Optional.ofNullable(digestNames.get(oid)) |
218 | .orElse(oid); | |
219 | } | |
220 | ||
221 | /** | |
222 | * Gets the algorithm name for a certain id. | |
223 | * | |
224 | * @param oid an id (for instance "1.2.840.113549.1.1.1") | |
225 | * @return an algorithm name (for instance "RSA") | |
226 | * @since 2.1.6 | |
227 | */ | |
228 | public static String getAlgorithm(String oid) { | |
229 |
1
1. getAlgorithm : mutated return of Object value for com/lowagie/text/pdf/PdfPKCS7::getAlgorithm to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return Optional.ofNullable(algorithmNames.get(oid)) |
230 | .orElse(oid); | |
231 | } | |
232 | ||
233 | /** | |
234 | * Gets the timestamp token if there is one. | |
235 | * | |
236 | * @return the timestamp token or null | |
237 | * @since 2.1.6 | |
238 | */ | |
239 | public TimeStampToken getTimeStampToken() { | |
240 | return timeStampToken; | |
241 | } | |
242 | ||
243 | /** | |
244 | * Gets the timestamp date | |
245 | * | |
246 | * @return a date | |
247 | * @since 2.1.6 | |
248 | */ | |
249 | @Nullable | |
250 | public Calendar getTimeStampDate() { | |
251 |
1
1. getTimeStampDate : negated conditional → NO_COVERAGE |
if (timeStampToken == null) |
252 |
1
1. getTimeStampDate : mutated return of Object value for com/lowagie/text/pdf/PdfPKCS7::getTimeStampDate to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
253 | Calendar cal = new GregorianCalendar(); | |
254 | Date date = timeStampToken.getTimeStampInfo().getGenTime(); | |
255 |
1
1. getTimeStampDate : removed call to java/util/Calendar::setTime → NO_COVERAGE |
cal.setTime(date); |
256 |
1
1. getTimeStampDate : mutated return of Object value for com/lowagie/text/pdf/PdfPKCS7::getTimeStampDate to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return cal; |
257 | } | |
258 | ||
259 | /** | |
260 | * Verifies a signature using the sub-filter adbe.x509.rsa_sha1. | |
261 | * | |
262 | * @param contentsKey the /Contents key | |
263 | * @param certsKey the /Cert key | |
264 | * @param provider the provider or <code>null</code> for the default provider | |
265 | */ | |
266 | public PdfPKCS7(byte[] contentsKey, byte[] certsKey, String provider) { | |
267 | try { | |
268 | this.provider = provider; | |
269 | CertificateFactory certificateFactory = new CertificateFactory(); | |
270 | Collection certificates = certificateFactory.engineGenerateCertificates(new ByteArrayInputStream(certsKey)); | |
271 | certs = new ArrayList<>((Collection<Certificate>) certificates); | |
272 | signCerts = certs; | |
273 | signCert = (X509Certificate) certs.iterator().next(); | |
274 | crls = new ArrayList<>(); | |
275 | ASN1InputStream in = new ASN1InputStream(new ByteArrayInputStream(contentsKey)); | |
276 | digest = ((DEROctetString) in.readObject()).getOctets(); | |
277 |
1
1. |
if (provider == null) { |
278 | sig = Signature.getInstance("SHA1withRSA"); | |
279 | } else { | |
280 | sig = Signature.getInstance("SHA1withRSA", provider); | |
281 | } | |
282 |
1
1. |
sig.initVerify(signCert.getPublicKey()); |
283 | } catch (Exception e) { | |
284 | throw new ExceptionConverter(e); | |
285 | } | |
286 | } | |
287 | ||
288 | private BasicOCSPResp basicResp; | |
289 | ||
290 | /** | |
291 | * Gets the OCSP basic response if there is one. | |
292 | * | |
293 | * @return the OCSP basic response or null | |
294 | * @since 2.1.6 | |
295 | */ | |
296 | public BasicOCSPResp getOcsp() { | |
297 | return basicResp; | |
298 | } | |
299 | ||
300 | private void findOcsp(ASN1Sequence seq) throws IOException { | |
301 | basicResp = null; | |
302 | while ((!(seq.getObjectAt(0) instanceof ASN1ObjectIdentifier)) | |
303 | || !((ASN1ObjectIdentifier) seq.getObjectAt(0)).getId().equals( | |
304 | OCSPObjectIdentifiers.id_pkix_ocsp_basic.getId())) { | |
305 | boolean ret = true; | |
306 | int k = 0; | |
307 | while (k < seq.size()) { | |
308 | if (seq.getObjectAt(k) instanceof ASN1Sequence) { | |
309 | seq = (ASN1Sequence) seq.getObjectAt(0); | |
310 | ret = false; | |
311 | break; | |
312 | } | |
313 | if (seq.getObjectAt(k) instanceof ASN1TaggedObject) { | |
314 | ASN1TaggedObject tag = (ASN1TaggedObject) seq.getObjectAt(k); | |
315 | if (tag.getObject() instanceof ASN1Sequence) { | |
316 | seq = (ASN1Sequence) tag.getObject(); | |
317 | ret = false; | |
318 | break; | |
319 | } else | |
320 | return; | |
321 | } | |
322 |
1
1. findOcsp : Changed increment from 1 to -1 → NO_COVERAGE |
++k; |
323 | } | |
324 |
1
1. findOcsp : negated conditional → NO_COVERAGE |
if (ret) |
325 | return; | |
326 | } | |
327 | DEROctetString os = (DEROctetString) seq.getObjectAt(1); | |
328 | ASN1InputStream inp = new ASN1InputStream(os.getOctets()); | |
329 | BasicOCSPResponse resp = BasicOCSPResponse.getInstance(inp.readObject()); | |
330 | basicResp = new BasicOCSPResp(resp); | |
331 | } | |
332 | ||
333 | /** | |
334 | * Verifies a signature using the sub-filter adbe.pkcs7.detached or | |
335 | * adbe.pkcs7.sha1. | |
336 | * | |
337 | * @param contentsKey the /Contents key | |
338 | * @param provider the provider or <code>null</code> for the default provider | |
339 | */ | |
340 | public PdfPKCS7(byte[] contentsKey, String provider) { | |
341 | try { | |
342 | this.provider = provider; | |
343 | ASN1InputStream din = new ASN1InputStream(new ByteArrayInputStream( | |
344 | contentsKey)); | |
345 | ||
346 | // | |
347 | // Basic checks to make sure it's a PKCS#7 SignedData Object | |
348 | // | |
349 | ASN1Primitive pkcs; | |
350 | ||
351 | try { | |
352 | pkcs = din.readObject(); | |
353 | } catch (IOException e) { | |
354 | throw new IllegalArgumentException( | |
355 | MessageLocalization | |
356 | .getComposedMessage("can.t.decode.pkcs7signeddata.object")); | |
357 | } | |
358 |
1
1. |
if (!(pkcs instanceof ASN1Sequence)) { |
359 | throw new IllegalArgumentException( | |
360 | MessageLocalization | |
361 | .getComposedMessage("not.a.valid.pkcs.7.object.not.a.sequence")); | |
362 | } | |
363 | ASN1Sequence signedData = (ASN1Sequence) pkcs; | |
364 | ASN1ObjectIdentifier objId = (ASN1ObjectIdentifier) signedData | |
365 | .getObjectAt(0); | |
366 | if (!objId.getId().equals(ID_PKCS7_SIGNED_DATA)) | |
367 | throw new IllegalArgumentException( | |
368 | MessageLocalization | |
369 | .getComposedMessage("not.a.valid.pkcs.7.object.not.signed.data")); | |
370 | ASN1Sequence content = (ASN1Sequence) ( | |
371 | (signedData.getObjectAt(1) instanceof BERTaggedObject) ? | |
372 | (BERTaggedObject) signedData.getObjectAt(1) : | |
373 | (DERTaggedObject) signedData.getObjectAt(1)) | |
374 | .getObject(); | |
375 | // the positions that we care are: | |
376 | // 0 - version | |
377 | // 1 - digestAlgorithms | |
378 | // 2 - possible ID_PKCS7_DATA | |
379 | // (the certificates and crls are taken out by other means) | |
380 | // last - signerInfos | |
381 | ||
382 | // the version | |
383 | version = ((ASN1Integer) content.getObjectAt(0)).getValue().intValue(); | |
384 | ||
385 | // the digestAlgorithms | |
386 | digestalgos = new HashSet<>(); | |
387 | Enumeration e = ((ASN1Set) content.getObjectAt(1)).getObjects(); | |
388 |
1
1. |
while (e.hasMoreElements()) { |
389 | ASN1Sequence s = (ASN1Sequence) e.nextElement(); | |
390 | ASN1ObjectIdentifier o = (ASN1ObjectIdentifier) s.getObjectAt(0); | |
391 | digestalgos.add(o.getId()); | |
392 | } | |
393 | ||
394 | // the certificates and crls | |
395 | CertificateFactory certificateFactory = new CertificateFactory(); | |
396 | Collection certificates = certificateFactory.engineGenerateCertificates(new ByteArrayInputStream(contentsKey)); | |
397 | this.certs = new ArrayList<>((Collection<Certificate>) certificates); | |
398 | X509CRLParser cl = new X509CRLParser(); | |
399 | cl.engineInit(new ByteArrayInputStream(contentsKey)); | |
400 | crls = (List<CRL>) cl.engineReadAll(); | |
401 | ||
402 | // the possible ID_PKCS7_DATA | |
403 | ASN1Sequence rsaData = (ASN1Sequence) content.getObjectAt(2); | |
404 | if (rsaData.size() > 1) { | |
405 | DEROctetString rsaDataContent = (DEROctetString) ((DERTaggedObject) rsaData | |
406 | .getObjectAt(1)).getObject(); | |
407 | RSAdata = rsaDataContent.getOctets(); | |
408 | } | |
409 | ||
410 | // the signerInfos | |
411 | int next = 3; | |
412 | while (content.getObjectAt(next) instanceof DERTaggedObject || | |
413 | content.getObjectAt(next) instanceof BERTaggedObject) | |
414 |
1
1. |
++next; |
415 | ASN1Set signerInfos = (ASN1Set) content.getObjectAt(next); | |
416 | if (signerInfos.size() != 1) | |
417 | throw new IllegalArgumentException( | |
418 | MessageLocalization | |
419 | .getComposedMessage("this.pkcs.7.object.has.multiple.signerinfos.only.one.is.supported.at.this.time")); | |
420 | ASN1Sequence signerInfo = (ASN1Sequence) signerInfos.getObjectAt(0); | |
421 | // the positions that we care are | |
422 | // 0 - version | |
423 | // 1 - the signing certificate serial number | |
424 | // 2 - the digest algorithm | |
425 | // 3 or 4 - digestEncryptionAlgorithm | |
426 | // 4 or 5 - encryptedDigest | |
427 | signerversion = ((ASN1Integer) signerInfo.getObjectAt(0)).getValue() | |
428 | .intValue(); | |
429 | // Get the signing certificate | |
430 | ASN1Sequence issuerAndSerialNumber = (ASN1Sequence) signerInfo | |
431 | .getObjectAt(1); | |
432 | BigInteger serialNumber = ((ASN1Integer) issuerAndSerialNumber | |
433 | .getObjectAt(1)).getValue(); | |
434 | for (Object cert1 : this.certs) { | |
435 | X509Certificate cert = (X509Certificate) cert1; | |
436 |
1
1. |
if (serialNumber.equals(cert.getSerialNumber())) { |
437 | signCert = cert; | |
438 | break; | |
439 | } | |
440 | } | |
441 |
1
1. |
if (signCert == null) { |
442 | throw new IllegalArgumentException( | |
443 | MessageLocalization.getComposedMessage( | |
444 | "can.t.find.signing.certificate.with.serial.1", | |
445 | serialNumber.toString(16))); | |
446 | } | |
447 |
1
1. |
signCertificateChain(); |
448 | digestAlgorithm = ((ASN1ObjectIdentifier) ((ASN1Sequence) signerInfo | |
449 | .getObjectAt(2)).getObjectAt(0)).getId(); | |
450 | next = 3; | |
451 | if (signerInfo.getObjectAt(next) instanceof ASN1TaggedObject) { | |
452 | ASN1TaggedObject tagsig = (ASN1TaggedObject) signerInfo | |
453 | .getObjectAt(next); | |
454 | ASN1Set sseq = ASN1Set.getInstance(tagsig, false); | |
455 | sigAttr = sseq.getEncoded(ASN1Encoding.DER); | |
456 | ||
457 | for (int k = 0; k < sseq.size(); ++k) { | |
458 | ASN1Sequence seq2 = (ASN1Sequence) sseq.getObjectAt(k); | |
459 | if (((ASN1ObjectIdentifier) seq2.getObjectAt(0)).getId().equals( | |
460 | ID_MESSAGE_DIGEST)) { | |
461 | ASN1Set set = (ASN1Set) seq2.getObjectAt(1); | |
462 | digestAttr = ((DEROctetString) set.getObjectAt(0)).getOctets(); | |
463 | } else if (((ASN1ObjectIdentifier) seq2.getObjectAt(0)).getId() | |
464 |
1
1. |
.equals(ID_ADBE_REVOCATION)) { |
465 | ASN1Set setout = (ASN1Set) seq2.getObjectAt(1); | |
466 | ASN1Sequence seqout = (ASN1Sequence) setout.getObjectAt(0); | |
467 | for (int j = 0; j < seqout.size(); ++j) { | |
468 | ASN1TaggedObject tg = (ASN1TaggedObject) seqout.getObjectAt(j); | |
469 | if (tg.getTagNo() != 1) | |
470 | continue; | |
471 | ASN1Sequence seqin = (ASN1Sequence) tg.getObject(); | |
472 |
1
1. |
findOcsp(seqin); |
473 | } | |
474 | } | |
475 | } | |
476 |
1
1. |
if (digestAttr == null) |
477 | throw new IllegalArgumentException( | |
478 | MessageLocalization | |
479 | .getComposedMessage("authenticated.attribute.is.missing.the.digest")); | |
480 |
1
1. |
++next; |
481 | } | |
482 |
1
1. |
digestEncryptionAlgorithm = ((ASN1ObjectIdentifier) ((ASN1Sequence) signerInfo |
483 | .getObjectAt(next++)).getObjectAt(0)).getId(); | |
484 | digest = ((DEROctetString) signerInfo.getObjectAt(next++)).getOctets(); | |
485 | if (next < signerInfo.size() | |
486 | && (signerInfo.getObjectAt(next) instanceof DERTaggedObject)) { | |
487 | DERTaggedObject taggedObject = (DERTaggedObject) signerInfo | |
488 | .getObjectAt(next); | |
489 | ASN1Set unat = ASN1Set.getInstance(taggedObject, false); | |
490 | AttributeTable attble = new AttributeTable(unat); | |
491 | Attribute ts = attble | |
492 | .get(PKCSObjectIdentifiers.id_aa_signatureTimeStampToken); | |
493 | if (ts != null && ts.getAttrValues().size() > 0) { | |
494 | ASN1Set attributeValues = ts.getAttrValues(); | |
495 | ASN1Sequence tokenSequence = ASN1Sequence.getInstance(attributeValues | |
496 | .getObjectAt(0)); | |
497 | ContentInfo contentInfo = new ContentInfo(tokenSequence); | |
498 | this.timeStampToken = new TimeStampToken(contentInfo); | |
499 | } | |
500 | } | |
501 |
2
1. 2. |
if (RSAdata != null || digestAttr != null) { |
502 |
2
1. 2. |
if (provider == null || provider.startsWith("SunPKCS11")) |
503 | messageDigest = MessageDigest.getInstance(getHashAlgorithm()); | |
504 | else | |
505 | messageDigest = MessageDigest.getInstance(getHashAlgorithm(), | |
506 | provider); | |
507 | } | |
508 |
1
1. |
if (provider == null) |
509 | sig = Signature.getInstance(getDigestAlgorithm()); | |
510 | else | |
511 | sig = Signature.getInstance(getDigestAlgorithm(), provider); | |
512 |
1
1. |
sig.initVerify(signCert.getPublicKey()); |
513 | } catch (Exception e) { | |
514 | throw new ExceptionConverter(e); | |
515 | } | |
516 | } | |
517 | ||
518 | /** | |
519 | * Generates a signature. | |
520 | * | |
521 | * @param privKey the private key | |
522 | * @param certChain the certificate chain | |
523 | * @param crlList the certificate revocation list | |
524 | * @param hashAlgorithm the hash algorithm | |
525 | * @param provider the provider or <code>null</code> for the default provider | |
526 | * @param hasRSAdata <CODE>true</CODE> if the sub-filter is adbe.pkcs7.sha1 | |
527 | * @throws InvalidKeyException on error | |
528 | * @throws NoSuchProviderException on error | |
529 | * @throws NoSuchAlgorithmException on error | |
530 | */ | |
531 | public PdfPKCS7(PrivateKey privKey, Certificate[] certChain, CRL[] crlList, | |
532 | String hashAlgorithm, String provider, boolean hasRSAdata) | |
533 | throws InvalidKeyException, NoSuchProviderException, | |
534 | NoSuchAlgorithmException { | |
535 | this.privKey = privKey; | |
536 | this.provider = provider; | |
537 | ||
538 | digestAlgorithm = (String) allowedDigests.get(hashAlgorithm.toUpperCase()); | |
539 |
1
1. |
if (digestAlgorithm == null) |
540 | throw new NoSuchAlgorithmException( | |
541 | MessageLocalization.getComposedMessage("unknown.hash.algorithm.1", | |
542 | hashAlgorithm)); | |
543 | ||
544 | version = signerversion = 1; | |
545 | certs = new ArrayList<>(); | |
546 | crls = new ArrayList<>(); | |
547 | digestalgos = new HashSet<>(); | |
548 | digestalgos.add(digestAlgorithm); | |
549 | ||
550 | // | |
551 | // Copy in the certificates and crls used to sign the private key. | |
552 | // | |
553 | signCert = (X509Certificate) certChain[0]; | |
554 | certs.addAll(Arrays.asList(certChain)); | |
555 | ||
556 |
1
1. |
if (crlList != null) { |
557 | crls.addAll(Arrays.asList(crlList)); | |
558 | } | |
559 | ||
560 |
1
1. |
if (privKey != null) { |
561 | // | |
562 | // Now we have private key, find out what the digestEncryptionAlgorithm | |
563 | // is. | |
564 | // | |
565 | digestEncryptionAlgorithm = privKey.getAlgorithm(); | |
566 |
1
1. |
if (digestEncryptionAlgorithm.equals("RSA")) { |
567 | digestEncryptionAlgorithm = ID_RSA; | |
568 |
1
1. |
} else if (digestEncryptionAlgorithm.equals("DSA")) { |
569 | digestEncryptionAlgorithm = ID_DSA; | |
570 | } else { | |
571 | throw new NoSuchAlgorithmException( | |
572 | MessageLocalization.getComposedMessage("unknown.key.algorithm.1", | |
573 | digestEncryptionAlgorithm)); | |
574 | } | |
575 | } | |
576 |
1
1. |
if (hasRSAdata) { |
577 | RSAdata = new byte[0]; | |
578 |
2
1. 2. |
if (provider == null || provider.startsWith("SunPKCS11")) |
579 | messageDigest = MessageDigest.getInstance(getHashAlgorithm()); | |
580 | else | |
581 | messageDigest = MessageDigest.getInstance(getHashAlgorithm(), provider); | |
582 | } | |
583 | ||
584 |
1
1. |
if (privKey != null) { |
585 |
1
1. |
if (provider == null) |
586 | sig = Signature.getInstance(getDigestAlgorithm()); | |
587 | else | |
588 | sig = Signature.getInstance(getDigestAlgorithm(), provider); | |
589 | ||
590 |
1
1. |
sig.initSign(privKey); |
591 | } | |
592 | } | |
593 | ||
594 | /** | |
595 | * Update the digest with the specified bytes. This method is used both for | |
596 | * signing and verifying | |
597 | * | |
598 | * @param buf the data buffer | |
599 | * @param off the offset in the data buffer | |
600 | * @param len the data length | |
601 | * @throws SignatureException on error | |
602 | */ | |
603 | public void update(byte[] buf, int off, int len) throws SignatureException { | |
604 |
2
1. update : negated conditional → NO_COVERAGE 2. update : negated conditional → NO_COVERAGE |
if (RSAdata != null || digestAttr != null) |
605 |
1
1. update : removed call to java/security/MessageDigest::update → NO_COVERAGE |
messageDigest.update(buf, off, len); |
606 | else | |
607 |
1
1. update : removed call to java/security/Signature::update → NO_COVERAGE |
sig.update(buf, off, len); |
608 | } | |
609 | ||
610 | /** | |
611 | * Verify the digest. | |
612 | * | |
613 | * @return <CODE>true</CODE> if the signature checks out, <CODE>false</CODE> | |
614 | * otherwise | |
615 | * @throws SignatureException on error | |
616 | */ | |
617 | public boolean verify() throws SignatureException { | |
618 |
1
1. verify : negated conditional → NO_COVERAGE |
if (verified) |
619 |
1
1. verify : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return verifyResult; |
620 |
1
1. verify : negated conditional → NO_COVERAGE |
if (sigAttr != null) { |
621 |
1
1. verify : removed call to java/security/Signature::update → NO_COVERAGE |
sig.update(sigAttr); |
622 |
1
1. verify : negated conditional → NO_COVERAGE |
if (RSAdata != null) { |
623 | byte[] msd = messageDigest.digest(); | |
624 |
1
1. verify : removed call to java/security/MessageDigest::update → NO_COVERAGE |
messageDigest.update(msd); |
625 | } | |
626 |
1
1. verify : negated conditional → NO_COVERAGE |
verifyResult = (Arrays.equals(messageDigest.digest(), digestAttr) && sig |
627 |
1
1. verify : negated conditional → NO_COVERAGE |
.verify(digest)); |
628 | } else { | |
629 |
1
1. verify : negated conditional → NO_COVERAGE |
if (RSAdata != null) |
630 |
1
1. verify : removed call to java/security/Signature::update → NO_COVERAGE |
sig.update(messageDigest.digest()); |
631 | verifyResult = sig.verify(digest); | |
632 | } | |
633 | verified = true; | |
634 |
1
1. verify : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return verifyResult; |
635 | } | |
636 | ||
637 | /** | |
638 | * Checks if the timestamp refers to this document. | |
639 | * | |
640 | * @return true if it checks false otherwise | |
641 | * @throws java.security.NoSuchAlgorithmException on error | |
642 | * @since 2.1.6 | |
643 | */ | |
644 | public boolean verifyTimestampImprint() throws NoSuchAlgorithmException { | |
645 |
1
1. verifyTimestampImprint : negated conditional → NO_COVERAGE |
if (timeStampToken == null) |
646 |
1
1. verifyTimestampImprint : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return false; |
647 | MessageImprint imprint = timeStampToken.getTimeStampInfo().toASN1Structure() | |
648 | .getMessageImprint(); | |
649 | byte[] md = MessageDigest.getInstance("SHA-1").digest(digest); | |
650 | byte[] imphashed = imprint.getHashedMessage(); | |
651 |
1
1. verifyTimestampImprint : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return Arrays.equals(md, imphashed); |
652 | } | |
653 | ||
654 | /** | |
655 | * Get all the X.509 certificates associated with this PKCS#7 object in no | |
656 | * particular order. Other certificates, from OCSP for example, will also be | |
657 | * included. | |
658 | * | |
659 | * @return the X.509 certificates associated with this PKCS#7 object | |
660 | */ | |
661 | public Certificate[] getCertificates() { | |
662 |
1
1. getCertificates : mutated return of Object value for com/lowagie/text/pdf/PdfPKCS7::getCertificates to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return certs.toArray(new Certificate[0]); |
663 | } | |
664 | ||
665 | /** | |
666 | * Get the X.509 sign certificate chain associated with this PKCS#7 object. | |
667 | * Only the certificates used for the main signature will be returned, with | |
668 | * the signing certificate first. | |
669 | * | |
670 | * @return the X.509 certificates associated with this PKCS#7 object | |
671 | * @since 2.1.6 | |
672 | */ | |
673 | public Certificate[] getSignCertificateChain() { | |
674 |
1
1. getSignCertificateChain : mutated return of Object value for com/lowagie/text/pdf/PdfPKCS7::getSignCertificateChain to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return signCerts.toArray(new X509Certificate[0]); |
675 | } | |
676 | ||
677 | private void signCertificateChain() { | |
678 | List<Certificate> cc = new ArrayList<>(); | |
679 | cc.add(signCert); | |
680 | List<Certificate> oc = new ArrayList<>(certs); | |
681 |
2
1. signCertificateChain : changed conditional boundary → NO_COVERAGE 2. signCertificateChain : negated conditional → NO_COVERAGE |
for (int k = 0; k < oc.size(); ++k) { |
682 |
1
1. signCertificateChain : negated conditional → NO_COVERAGE |
if (signCert.getSerialNumber().equals( |
683 | ((X509Certificate) oc.get(k)).getSerialNumber())) { | |
684 | oc.remove(k); | |
685 |
1
1. signCertificateChain : Changed increment from -1 to 1 → NO_COVERAGE |
--k; |
686 | } | |
687 | } | |
688 | boolean found = true; | |
689 |
1
1. signCertificateChain : negated conditional → NO_COVERAGE |
while (found) { |
690 |
1
1. signCertificateChain : Replaced integer subtraction with addition → NO_COVERAGE |
X509Certificate v = (X509Certificate) cc.get(cc.size() - 1); |
691 | found = false; | |
692 |
3
1. signCertificateChain : changed conditional boundary → NO_COVERAGE 2. signCertificateChain : Changed increment from 1 to -1 → NO_COVERAGE 3. signCertificateChain : negated conditional → NO_COVERAGE |
for (int k = 0; k < oc.size(); ++k) { |
693 | try { | |
694 |
1
1. signCertificateChain : negated conditional → NO_COVERAGE |
if (provider == null) |
695 |
1
1. signCertificateChain : removed call to java/security/cert/X509Certificate::verify → NO_COVERAGE |
v.verify(oc.get(k).getPublicKey()); |
696 | else | |
697 |
1
1. signCertificateChain : removed call to java/security/cert/X509Certificate::verify → NO_COVERAGE |
v.verify(oc.get(k).getPublicKey(), provider); |
698 | found = true; | |
699 | cc.add(oc.get(k)); | |
700 | oc.remove(k); | |
701 | break; | |
702 | } catch (Exception ignored) { | |
703 | } | |
704 | } | |
705 | } | |
706 | signCerts = cc; | |
707 | } | |
708 | ||
709 | /** | |
710 | * Get the X.509 certificate revocation lists associated with this PKCS#7 | |
711 | * object | |
712 | * | |
713 | * @return the X.509 certificate revocation lists associated with this PKCS#7 | |
714 | * object | |
715 | */ | |
716 | public Collection getCRLs() { | |
717 | return crls; | |
718 | } | |
719 | ||
720 | /** | |
721 | * Get the X.509 certificate actually used to sign the digest. | |
722 | * | |
723 | * @return the X.509 certificate actually used to sign the digest | |
724 | */ | |
725 | public X509Certificate getSigningCertificate() { | |
726 | return signCert; | |
727 | } | |
728 | ||
729 | /** | |
730 | * Get the version of the PKCS#7 object. Always 1 | |
731 | * | |
732 | * @return the version of the PKCS#7 object. Always 1 | |
733 | */ | |
734 | public int getVersion() { | |
735 | return version; | |
736 | } | |
737 | ||
738 | /** | |
739 | * Get the version of the PKCS#7 "SignerInfo" object. Always 1 | |
740 | * | |
741 | * @return the version of the PKCS#7 "SignerInfo" object. Always 1 | |
742 | */ | |
743 | public int getSigningInfoVersion() { | |
744 | return signerversion; | |
745 | } | |
746 | ||
747 | /** | |
748 | * Get the algorithm used to calculate the message digest | |
749 | * | |
750 | * @return the algorithm used to calculate the message digest | |
751 | */ | |
752 | public String getDigestAlgorithm() { | |
753 | String dea = getAlgorithm(digestEncryptionAlgorithm); | |
754 |
1
1. getDigestAlgorithm : negated conditional → NO_COVERAGE |
if (dea == null) |
755 | dea = digestEncryptionAlgorithm; | |
756 | ||
757 |
1
1. getDigestAlgorithm : mutated return of Object value for com/lowagie/text/pdf/PdfPKCS7::getDigestAlgorithm to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return getHashAlgorithm() + "with" + dea; |
758 | } | |
759 | ||
760 | /** | |
761 | * Returns the algorithm. | |
762 | * | |
763 | * @return the digest algorithm | |
764 | */ | |
765 | public String getHashAlgorithm() { | |
766 |
1
1. getHashAlgorithm : mutated return of Object value for com/lowagie/text/pdf/PdfPKCS7::getHashAlgorithm to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return getDigest(digestAlgorithm); |
767 | } | |
768 | ||
769 | /** | |
770 | * Loads the default root certificates at | |
771 | * <java.home>/lib/security/cacerts with the default provider. | |
772 | * | |
773 | * @return a <CODE>KeyStore</CODE> | |
774 | */ | |
775 | public static KeyStore loadCacertsKeyStore() { | |
776 |
1
1. loadCacertsKeyStore : mutated return of Object value for com/lowagie/text/pdf/PdfPKCS7::loadCacertsKeyStore to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return loadCacertsKeyStore(null); |
777 | } | |
778 | ||
779 | /** | |
780 | * Loads the default root certificates at | |
781 | * <java.home>/lib/security/cacerts. | |
782 | * | |
783 | * @param provider the provider or <code>null</code> for the default provider | |
784 | * @return a <CODE>KeyStore</CODE> | |
785 | */ | |
786 | public static KeyStore loadCacertsKeyStore(String provider) { | |
787 | File file = new File(System.getProperty("java.home"), "lib"); | |
788 | file = new File(file, "security"); | |
789 | file = new File(file, "cacerts"); | |
790 | try (FileInputStream fin = new FileInputStream(file)) { | |
791 | KeyStore k; | |
792 |
1
1. loadCacertsKeyStore : negated conditional → NO_COVERAGE |
if (provider == null) |
793 | k = KeyStore.getInstance("JKS"); | |
794 | else | |
795 | k = KeyStore.getInstance("JKS", provider); | |
796 |
1
1. loadCacertsKeyStore : removed call to java/security/KeyStore::load → NO_COVERAGE |
k.load(fin, null); |
797 |
1
1. loadCacertsKeyStore : mutated return of Object value for com/lowagie/text/pdf/PdfPKCS7::loadCacertsKeyStore to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return k; |
798 | } catch (Exception e) { | |
799 | throw new ExceptionConverter(e); | |
800 | } | |
801 | } | |
802 | ||
803 | /** | |
804 | * Verifies a single certificate. | |
805 | * | |
806 | * @param cert the certificate to verify | |
807 | * @param crls the certificate revocation list or <CODE>null</CODE> | |
808 | * @param calendar the date or <CODE>null</CODE> for the current date | |
809 | * @return a <CODE>String</CODE> with the error description or | |
810 | * <CODE>null</CODE> if no error | |
811 | */ | |
812 | public static String verifyCertificate(X509Certificate cert, Collection crls, | |
813 | Calendar calendar) { | |
814 |
1
1. verifyCertificate : negated conditional → NO_COVERAGE |
if (calendar == null) |
815 | calendar = new GregorianCalendar(); | |
816 |
1
1. verifyCertificate : negated conditional → NO_COVERAGE |
if (cert.hasUnsupportedCriticalExtension()) |
817 |
1
1. verifyCertificate : mutated return of Object value for com/lowagie/text/pdf/PdfPKCS7::verifyCertificate to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return "Has unsupported critical extension"; |
818 | try { | |
819 |
1
1. verifyCertificate : removed call to java/security/cert/X509Certificate::checkValidity → NO_COVERAGE |
cert.checkValidity(calendar.getTime()); |
820 | } catch (Exception e) { | |
821 |
1
1. verifyCertificate : mutated return of Object value for com/lowagie/text/pdf/PdfPKCS7::verifyCertificate to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return e.getMessage(); |
822 | } | |
823 |
1
1. verifyCertificate : negated conditional → NO_COVERAGE |
if (crls != null) { |
824 | for (Object crl : crls) { | |
825 |
1
1. verifyCertificate : negated conditional → NO_COVERAGE |
if (((CRL) crl).isRevoked(cert)) |
826 |
1
1. verifyCertificate : mutated return of Object value for com/lowagie/text/pdf/PdfPKCS7::verifyCertificate to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return "Certificate revoked"; |
827 | } | |
828 | } | |
829 |
1
1. verifyCertificate : mutated return of Object value for com/lowagie/text/pdf/PdfPKCS7::verifyCertificate to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
830 | } | |
831 | ||
832 | /** | |
833 | * Verifies a certificate chain against a KeyStore. | |
834 | * | |
835 | * @param certs the certificate chain | |
836 | * @param keystore the <CODE>KeyStore</CODE> | |
837 | * @param crls the certificate revocation list or <CODE>null</CODE> | |
838 | * @param calendar the date or <CODE>null</CODE> for the current date | |
839 | * @return <CODE>null</CODE> if the certificate chain could be validated or a | |
840 | * <CODE>Object[]{cert,error}</CODE> where <CODE>cert</CODE> is the | |
841 | * failed certificate and <CODE>error</CODE> is the error message | |
842 | */ | |
843 | public static Object[] verifyCertificates(Certificate[] certs, | |
844 | KeyStore keystore, Collection crls, Calendar calendar) { | |
845 |
1
1. verifyCertificates : negated conditional → NO_COVERAGE |
if (calendar == null) |
846 | calendar = new GregorianCalendar(); | |
847 |
3
1. verifyCertificates : changed conditional boundary → NO_COVERAGE 2. verifyCertificates : Changed increment from 1 to -1 → NO_COVERAGE 3. verifyCertificates : negated conditional → NO_COVERAGE |
for (int k = 0; k < certs.length; ++k) { |
848 | X509Certificate cert = (X509Certificate) certs[k]; | |
849 | String err = verifyCertificate(cert, crls, calendar); | |
850 |
1
1. verifyCertificates : negated conditional → NO_COVERAGE |
if (err != null) |
851 |
1
1. verifyCertificates : mutated return of Object value for com/lowagie/text/pdf/PdfPKCS7::verifyCertificates to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new Object[]{cert, err}; |
852 | try { | |
853 | for (Enumeration aliases = keystore.aliases(); aliases | |
854 |
1
1. verifyCertificates : negated conditional → NO_COVERAGE |
.hasMoreElements(); ) { |
855 | try { | |
856 | String alias = (String) aliases.nextElement(); | |
857 |
1
1. verifyCertificates : negated conditional → NO_COVERAGE |
if (!keystore.isCertificateEntry(alias)) |
858 | continue; | |
859 | X509Certificate certStoreX509 = (X509Certificate) keystore | |
860 | .getCertificate(alias); | |
861 |
1
1. verifyCertificates : negated conditional → NO_COVERAGE |
if (verifyCertificate(certStoreX509, crls, calendar) != null) |
862 | continue; | |
863 | try { | |
864 |
1
1. verifyCertificates : removed call to java/security/cert/X509Certificate::verify → NO_COVERAGE |
cert.verify(certStoreX509.getPublicKey()); |
865 |
1
1. verifyCertificates : mutated return of Object value for com/lowagie/text/pdf/PdfPKCS7::verifyCertificates to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
866 | } catch (Exception ignored) { | |
867 | } | |
868 | } catch (Exception ignored) { | |
869 | } | |
870 | } | |
871 | } catch (Exception ignored) { | |
872 | } | |
873 | int j; | |
874 |
2
1. verifyCertificates : changed conditional boundary → NO_COVERAGE 2. verifyCertificates : negated conditional → NO_COVERAGE |
for (j = 0; j < certs.length; ++j) { |
875 |
1
1. verifyCertificates : negated conditional → NO_COVERAGE |
if (j == k) |
876 | continue; | |
877 | X509Certificate certNext = (X509Certificate) certs[j]; | |
878 | try { | |
879 |
1
1. verifyCertificates : removed call to java/security/cert/X509Certificate::verify → NO_COVERAGE |
cert.verify(certNext.getPublicKey()); |
880 | break; | |
881 | } catch (Exception ignored) { | |
882 | } | |
883 | } | |
884 |
1
1. verifyCertificates : negated conditional → NO_COVERAGE |
if (j == certs.length) |
885 |
1
1. verifyCertificates : mutated return of Object value for com/lowagie/text/pdf/PdfPKCS7::verifyCertificates to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new Object[]{cert, |
886 | "Cannot be verified against the KeyStore or the certificate chain"}; | |
887 | } | |
888 |
1
1. verifyCertificates : mutated return of Object value for com/lowagie/text/pdf/PdfPKCS7::verifyCertificates to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new Object[]{null, |
889 | "Invalid state. Possible circular certificate chain"}; | |
890 | } | |
891 | ||
892 | // OJO... Modificacion de | |
893 | // Felix-------------------------------------------------- | |
894 | // Sin uso | |
895 | // /** | |
896 | // * Verifies an OCSP response against a KeyStore. | |
897 | // * @param ocsp the OCSP response | |
898 | // * @param keystore the <CODE>KeyStore</CODE> | |
899 | // * @param provider the provider or <CODE>null</CODE> to use the BouncyCastle | |
900 | // provider | |
901 | // * @return <CODE>true</CODE> is a certificate was found | |
902 | // * @since 2.1.6 | |
903 | // */ | |
904 | // public static boolean verifyOcspCertificates(BasicOCSPResp ocsp, KeyStore | |
905 | // keystore, String provider) { | |
906 | // if (provider == null) | |
907 | // provider = "BC"; | |
908 | // try { | |
909 | // for (Enumeration aliases = keystore.aliases(); aliases.hasMoreElements();) | |
910 | // { | |
911 | // try { | |
912 | // String alias = (String)aliases.nextElement(); | |
913 | // if (!keystore.isCertificateEntry(alias)) | |
914 | // continue; | |
915 | // X509Certificate certStoreX509 = | |
916 | // (X509Certificate)keystore.getCertificate(alias); | |
917 | // if (ocsp.verify(certStoreX509.getPublicKey(), provider)) | |
918 | // return true; | |
919 | // } | |
920 | // catch (Exception ex) { | |
921 | // } | |
922 | // } | |
923 | // } | |
924 | // catch (Exception e) { | |
925 | // } | |
926 | // return false; | |
927 | // } | |
928 | // | |
929 | // /** | |
930 | // * Verifies a timestamp against a KeyStore. | |
931 | // * @param ts the timestamp | |
932 | // * @param keystore the <CODE>KeyStore</CODE> | |
933 | // * @param provider the provider or <CODE>null</CODE> to use the BouncyCastle | |
934 | // provider | |
935 | // * @return <CODE>true</CODE> is a certificate was found | |
936 | // * @since 2.1.6 | |
937 | // */ | |
938 | // public static boolean verifyTimestampCertificates(TimeStampToken ts, | |
939 | // KeyStore keystore, String provider) { | |
940 | // if (provider == null) | |
941 | // provider = "BC"; | |
942 | // try { | |
943 | // for (Enumeration aliases = keystore.aliases(); aliases.hasMoreElements();) | |
944 | // { | |
945 | // try { | |
946 | // String alias = (String)aliases.nextElement(); | |
947 | // if (!keystore.isCertificateEntry(alias)) | |
948 | // continue; | |
949 | // X509Certificate certStoreX509 = | |
950 | // (X509Certificate)keystore.getCertificate(alias); | |
951 | // ts.validate(certStoreX509, provider); | |
952 | // return true; | |
953 | // } | |
954 | // catch (Exception ex) { | |
955 | // } | |
956 | // } | |
957 | // } | |
958 | // catch (Exception e) { | |
959 | // } | |
960 | // return false; | |
961 | // } | |
962 | // ****************************************************************************** | |
963 | ||
964 | /** | |
965 | * Retrieves the OCSP URL from the given certificate. | |
966 | * | |
967 | * @param certificate the certificate | |
968 | * @return the URL or null | |
969 | * @since 2.1.6 | |
970 | */ | |
971 | public static String getOCSPURL(X509Certificate certificate) { | |
972 | try { | |
973 | ASN1Primitive obj = getExtensionValue(certificate, authorityInfoAccess.getId()); | |
974 |
1
1. getOCSPURL : negated conditional → NO_COVERAGE |
if (obj == null) { |
975 |
1
1. getOCSPURL : mutated return of Object value for com/lowagie/text/pdf/PdfPKCS7::getOCSPURL to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
976 | } | |
977 | ||
978 | ASN1Sequence AccessDescriptions = (ASN1Sequence) obj; | |
979 | for (int i = 0; i < AccessDescriptions.size(); i++) { | |
980 | ASN1Sequence AccessDescription = (ASN1Sequence) AccessDescriptions | |
981 | .getObjectAt(i); | |
982 | if (AccessDescription.size() == 2) { | |
983 | if ((AccessDescription.getObjectAt(0) instanceof ASN1ObjectIdentifier) | |
984 | && ((ASN1ObjectIdentifier) AccessDescription.getObjectAt(0)) | |
985 | .getId().equals("1.3.6.1.5.5.7.48.1")) { | |
986 |
1
1. getOCSPURL : mutated return of Object value for com/lowagie/text/pdf/PdfPKCS7::getOCSPURL to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return getStringFromGeneralName((ASN1Primitive) AccessDescription |
987 | .getObjectAt(1)); | |
988 | } | |
989 | } | |
990 | } | |
991 | } catch (Exception ignored) { | |
992 | } | |
993 |
1
1. getOCSPURL : mutated return of Object value for com/lowagie/text/pdf/PdfPKCS7::getOCSPURL to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
994 | } | |
995 | ||
996 | /** | |
997 | * Checks if OCSP revocation refers to the document signing certificate. | |
998 | * | |
999 | * @return true if it checks false otherwise | |
1000 | * @since 2.1.6 | |
1001 | */ | |
1002 | public boolean isRevocationValid() { | |
1003 |
1
1. isRevocationValid : negated conditional → NO_COVERAGE |
if (basicResp == null) |
1004 |
1
1. isRevocationValid : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return false; |
1005 |
2
1. isRevocationValid : changed conditional boundary → NO_COVERAGE 2. isRevocationValid : negated conditional → NO_COVERAGE |
if (signCerts.size() < 2) |
1006 |
1
1. isRevocationValid : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return false; |
1007 | try { | |
1008 | X509Certificate[] cs = (X509Certificate[]) getSignCertificateChain(); | |
1009 | SingleResp sr = basicResp.getResponses()[0]; | |
1010 | CertificateID cid = sr.getCertID(); | |
1011 | X509Certificate sigcer = getSigningCertificate(); | |
1012 | X509Certificate isscer = cs[1]; | |
1013 | // OJO... Modificacion de | |
1014 | // Felix-------------------------------------------------- | |
1015 | // CertificateID tis = new CertificateID(CertificateID.HASH_SHA1, isscer, | |
1016 | // sigcer.getSerialNumber()); | |
1017 | DigestCalculatorProvider digCalcProv = new JcaDigestCalculatorProviderBuilder() | |
1018 | .setProvider(provider).build(); | |
1019 | CertificateID id = new CertificateID( | |
1020 | digCalcProv.get(CertificateID.HASH_SHA1), | |
1021 | new JcaX509CertificateHolder(isscer), sigcer.getSerialNumber()); | |
1022 | ||
1023 | return id.equals(cid); | |
1024 | // ****************************************************************************** | |
1025 | } catch (Exception ignored) { | |
1026 | } | |
1027 |
1
1. isRevocationValid : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return false; |
1028 | } | |
1029 | ||
1030 | @Nullable | |
1031 | private static ASN1Primitive getExtensionValue(X509Certificate cert, | |
1032 | String oid) throws IOException { | |
1033 | byte[] bytes = cert.getExtensionValue(oid); | |
1034 |
1
1. getExtensionValue : negated conditional → NO_COVERAGE |
if (bytes == null) { |
1035 |
1
1. getExtensionValue : mutated return of Object value for com/lowagie/text/pdf/PdfPKCS7::getExtensionValue to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
1036 | } | |
1037 | ASN1InputStream aIn = new ASN1InputStream(new ByteArrayInputStream(bytes)); | |
1038 | ASN1OctetString octs = (ASN1OctetString) aIn.readObject(); | |
1039 | aIn = new ASN1InputStream(new ByteArrayInputStream(octs.getOctets())); | |
1040 | return aIn.readObject(); | |
1041 | } | |
1042 | ||
1043 | @Nonnull | |
1044 | private static String getStringFromGeneralName(ASN1Primitive names) { | |
1045 | DERTaggedObject taggedObject = (DERTaggedObject) names; | |
1046 | return new String(ASN1OctetString.getInstance(taggedObject, false) | |
1047 | .getOctets(), StandardCharsets.ISO_8859_1); | |
1048 | } | |
1049 | ||
1050 | /** | |
1051 | * Get the "issuer" from the TBSCertificate bytes that are passed in | |
1052 | * | |
1053 | * @param enc a TBSCertificate in a byte array | |
1054 | * @return a ASN1Primitive | |
1055 | */ | |
1056 | private static ASN1Primitive getIssuer(byte[] enc) { | |
1057 | try { | |
1058 | ASN1InputStream in = new ASN1InputStream(new ByteArrayInputStream(enc)); | |
1059 | ASN1Sequence seq = (ASN1Sequence) in.readObject(); | |
1060 |
1
1. getIssuer : mutated return of Object value for com/lowagie/text/pdf/PdfPKCS7::getIssuer to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return (ASN1Primitive) seq |
1061 | .getObjectAt(seq.getObjectAt(0) instanceof DERTaggedObject ? 3 : 2); | |
1062 | } catch (IOException e) { | |
1063 | throw new ExceptionConverter(e); | |
1064 | } | |
1065 | } | |
1066 | ||
1067 | /** | |
1068 | * Get the "subject" from the TBSCertificate bytes that are passed in | |
1069 | * | |
1070 | * @param enc A TBSCertificate in a byte array | |
1071 | * @return a ASN1Primitive | |
1072 | */ | |
1073 | private static ASN1Primitive getSubject(byte[] enc) { | |
1074 | try { | |
1075 | ASN1InputStream in = new ASN1InputStream(new ByteArrayInputStream(enc)); | |
1076 | ASN1Sequence seq = (ASN1Sequence) in.readObject(); | |
1077 |
1
1. getSubject : mutated return of Object value for com/lowagie/text/pdf/PdfPKCS7::getSubject to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return (ASN1Primitive) seq |
1078 | .getObjectAt(seq.getObjectAt(0) instanceof DERTaggedObject ? 5 : 4); | |
1079 | } catch (IOException e) { | |
1080 | throw new ExceptionConverter(e); | |
1081 | } | |
1082 | } | |
1083 | ||
1084 | /** | |
1085 | * Get the issuer fields from an X509 Certificate | |
1086 | * | |
1087 | * @param cert an X509Certificate | |
1088 | * @return an X509Name | |
1089 | */ | |
1090 | public static X509Name getIssuerFields(X509Certificate cert) { | |
1091 | try { | |
1092 |
1
1. getIssuerFields : mutated return of Object value for com/lowagie/text/pdf/PdfPKCS7::getIssuerFields to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new X509Name((ASN1Sequence) getIssuer(cert.getTBSCertificate())); |
1093 | } catch (Exception e) { | |
1094 | throw new ExceptionConverter(e); | |
1095 | } | |
1096 | } | |
1097 | ||
1098 | /** | |
1099 | * Get the subject fields from an X509 Certificate | |
1100 | * | |
1101 | * @param cert an X509Certificate | |
1102 | * @return an X509Name | |
1103 | */ | |
1104 | public static X509Name getSubjectFields(X509Certificate cert) { | |
1105 | try { | |
1106 |
1
1. getSubjectFields : mutated return of Object value for com/lowagie/text/pdf/PdfPKCS7::getSubjectFields to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new X509Name((ASN1Sequence) getSubject(cert.getTBSCertificate())); |
1107 | } catch (Exception e) { | |
1108 | throw new ExceptionConverter(e); | |
1109 | } | |
1110 | } | |
1111 | ||
1112 | /** | |
1113 | * Gets the bytes for the PKCS#1 object. | |
1114 | * | |
1115 | * @return a byte array | |
1116 | */ | |
1117 | public byte[] getEncodedPKCS1() { | |
1118 | try { | |
1119 |
1
1. getEncodedPKCS1 : negated conditional → NO_COVERAGE |
if (externalDigest != null) |
1120 | digest = externalDigest; | |
1121 | else | |
1122 | digest = sig.sign(); | |
1123 | ByteArrayOutputStream bOut = new ByteArrayOutputStream(); | |
1124 | ||
1125 | ASN1OutputStream dout = new ASN1OutputStream(bOut); | |
1126 | dout.writeObject(new DEROctetString(digest)); | |
1127 | dout.close(); | |
1128 | ||
1129 |
1
1. getEncodedPKCS1 : mutated return of Object value for com/lowagie/text/pdf/PdfPKCS7::getEncodedPKCS1 to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return bOut.toByteArray(); |
1130 | } catch (Exception e) { | |
1131 | throw new ExceptionConverter(e); | |
1132 | } | |
1133 | } | |
1134 | ||
1135 | /** | |
1136 | * Sets the digest/signature to an external calculated value. | |
1137 | * | |
1138 | * @param digest the digest. This is the actual signature | |
1139 | * @param RSAdata the extra data that goes into the data tag in PKCS#7 | |
1140 | * @param digestEncryptionAlgorithm the encryption algorithm. It may must be <CODE>null</CODE> if the | |
1141 | * <CODE>digest</CODE> is also <CODE>null</CODE>. If the | |
1142 | * <CODE>digest</CODE> is not <CODE>null</CODE> then it may be "RSA" | |
1143 | * or "DSA" | |
1144 | */ | |
1145 | public void setExternalDigest(byte[] digest, byte[] RSAdata, | |
1146 | String digestEncryptionAlgorithm) { | |
1147 | externalDigest = digest; | |
1148 | externalRSAdata = RSAdata; | |
1149 |
1
1. setExternalDigest : negated conditional → NO_COVERAGE |
if (digestEncryptionAlgorithm != null) { |
1150 |
1
1. setExternalDigest : negated conditional → NO_COVERAGE |
if (digestEncryptionAlgorithm.equals("RSA")) { |
1151 | this.digestEncryptionAlgorithm = ID_RSA; | |
1152 |
1
1. setExternalDigest : negated conditional → NO_COVERAGE |
} else if (digestEncryptionAlgorithm.equals("DSA")) { |
1153 | this.digestEncryptionAlgorithm = ID_DSA; | |
1154 | } else | |
1155 | throw new ExceptionConverter(new NoSuchAlgorithmException( | |
1156 | MessageLocalization.getComposedMessage("unknown.key.algorithm.1", | |
1157 | digestEncryptionAlgorithm))); | |
1158 | } | |
1159 | } | |
1160 | ||
1161 | /** | |
1162 | * Gets the bytes for the PKCS7SignedData object. | |
1163 | * | |
1164 | * @return the bytes for the PKCS7SignedData object | |
1165 | */ | |
1166 | public byte[] getEncodedPKCS7() { | |
1167 |
1
1. getEncodedPKCS7 : mutated return of Object value for com/lowagie/text/pdf/PdfPKCS7::getEncodedPKCS7 to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return getEncodedPKCS7(null, null, null, null); |
1168 | } | |
1169 | ||
1170 | /** | |
1171 | * Gets the bytes for the PKCS7SignedData object. Optionally the | |
1172 | * authenticatedAttributes in the signerInfo can also be set. If either of the | |
1173 | * parameters is <CODE>null</CODE>, none will be used. | |
1174 | * | |
1175 | * @param secondDigest the digest in the authenticatedAttributes | |
1176 | * @param signingTime the signing time in the authenticatedAttributes | |
1177 | * @return the bytes for the PKCS7SignedData object | |
1178 | */ | |
1179 | public byte[] getEncodedPKCS7(byte[] secondDigest, Calendar signingTime) { | |
1180 |
1
1. getEncodedPKCS7 : mutated return of Object value for com/lowagie/text/pdf/PdfPKCS7::getEncodedPKCS7 to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return getEncodedPKCS7(secondDigest, signingTime, null, null); |
1181 | } | |
1182 | ||
1183 | /** | |
1184 | * Gets the bytes for the PKCS7SignedData object. Optionally the | |
1185 | * authenticatedAttributes in the signerInfo can also be set, OR a | |
1186 | * time-stamp-authority client may be provided. | |
1187 | * | |
1188 | * @param secondDigest the digest in the authenticatedAttributes | |
1189 | * @param signingTime the signing time in the authenticatedAttributes | |
1190 | * @param tsaClient TSAClient - null or an optional time stamp authority client | |
1191 | * @return byte[] the bytes for the PKCS7SignedData object | |
1192 | * @since 2.1.6 | |
1193 | */ | |
1194 | public byte[] getEncodedPKCS7(byte[] secondDigest, Calendar signingTime, | |
1195 | TSAClient tsaClient, byte[] ocsp) { | |
1196 | try { | |
1197 |
1
1. getEncodedPKCS7 : negated conditional → NO_COVERAGE |
if (externalDigest != null) { |
1198 | digest = externalDigest; | |
1199 |
1
1. getEncodedPKCS7 : negated conditional → NO_COVERAGE |
if (RSAdata != null) |
1200 | RSAdata = externalRSAdata; | |
1201 |
2
1. getEncodedPKCS7 : negated conditional → NO_COVERAGE 2. getEncodedPKCS7 : negated conditional → NO_COVERAGE |
} else if (externalRSAdata != null && RSAdata != null) { |
1202 | RSAdata = externalRSAdata; | |
1203 |
1
1. getEncodedPKCS7 : removed call to java/security/Signature::update → NO_COVERAGE |
sig.update(RSAdata); |
1204 | digest = sig.sign(); | |
1205 | } else { | |
1206 |
1
1. getEncodedPKCS7 : negated conditional → NO_COVERAGE |
if (RSAdata != null) { |
1207 | RSAdata = messageDigest.digest(); | |
1208 |
1
1. getEncodedPKCS7 : removed call to java/security/Signature::update → NO_COVERAGE |
sig.update(RSAdata); |
1209 | } | |
1210 | digest = sig.sign(); | |
1211 | } | |
1212 | ||
1213 | // Create the set of Hash algorithms | |
1214 | ASN1EncodableVector digestAlgorithms = new ASN1EncodableVector(); | |
1215 | for (String digestalgo : digestalgos) { | |
1216 | ASN1EncodableVector algos = new ASN1EncodableVector(); | |
1217 | algos.add(new ASN1ObjectIdentifier(digestalgo)); | |
1218 | algos.add(DERNull.INSTANCE); | |
1219 | digestAlgorithms.add(new DERSequence(algos)); | |
1220 | } | |
1221 | ||
1222 | // Create the contentInfo. | |
1223 | ASN1EncodableVector v = new ASN1EncodableVector(); | |
1224 | v.add(new ASN1ObjectIdentifier(ID_PKCS7_DATA)); | |
1225 |
1
1. getEncodedPKCS7 : negated conditional → NO_COVERAGE |
if (RSAdata != null) |
1226 | v.add(new DERTaggedObject(0, new DEROctetString(RSAdata))); | |
1227 | DERSequence contentinfo = new DERSequence(v); | |
1228 | ||
1229 | // Get all the certificates | |
1230 | // | |
1231 | v = new ASN1EncodableVector(); | |
1232 | for (Object cert : certs) { | |
1233 | ASN1InputStream tempstream = new ASN1InputStream( | |
1234 | new ByteArrayInputStream(((X509Certificate) cert).getEncoded())); | |
1235 | v.add(tempstream.readObject()); | |
1236 | } | |
1237 | ||
1238 | DERSet dercertificates = new DERSet(v); | |
1239 | ||
1240 | // Create signerinfo structure. | |
1241 | // | |
1242 | ASN1EncodableVector signerinfo = new ASN1EncodableVector(); | |
1243 | ||
1244 | // Add the signerInfo version | |
1245 | // | |
1246 | signerinfo.add(new ASN1Integer(signerversion)); | |
1247 | ||
1248 | v = new ASN1EncodableVector(); | |
1249 | v.add(getIssuer(signCert.getTBSCertificate())); | |
1250 | v.add(new ASN1Integer(signCert.getSerialNumber())); | |
1251 | signerinfo.add(new DERSequence(v)); | |
1252 | ||
1253 | // Add the digestAlgorithm | |
1254 | v = new ASN1EncodableVector(); | |
1255 | v.add(new ASN1ObjectIdentifier(digestAlgorithm)); | |
1256 | v.add(DERNull.INSTANCE); | |
1257 | signerinfo.add(new DERSequence(v)); | |
1258 | ||
1259 | // add the authenticated attribute if present | |
1260 |
2
1. getEncodedPKCS7 : negated conditional → NO_COVERAGE 2. getEncodedPKCS7 : negated conditional → NO_COVERAGE |
if (secondDigest != null && signingTime != null) { |
1261 | signerinfo.add(new DERTaggedObject(false, 0, | |
1262 | getAuthenticatedAttributeSet(secondDigest, signingTime, ocsp))); | |
1263 | } | |
1264 | // Add the digestEncryptionAlgorithm | |
1265 | v = new ASN1EncodableVector(); | |
1266 | v.add(new ASN1ObjectIdentifier(digestEncryptionAlgorithm)); | |
1267 | v.add(DERNull.INSTANCE); | |
1268 | signerinfo.add(new DERSequence(v)); | |
1269 | ||
1270 | // Add the digest | |
1271 | signerinfo.add(new DEROctetString(digest)); | |
1272 | ||
1273 | // When requested, go get and add the timestamp. May throw an exception. | |
1274 | // Added by Martin Brunecky, 07/12/2007 folowing Aiken Sam, 2006-11-15 | |
1275 | // Sam found Adobe expects time-stamped SHA1-1 of the encrypted digest | |
1276 |
1
1. getEncodedPKCS7 : negated conditional → NO_COVERAGE |
if (tsaClient != null) { |
1277 | byte[] tsImprint = MessageDigest.getInstance("SHA-1").digest(digest); | |
1278 | byte[] tsToken = tsaClient.getTimeStampToken(this, tsImprint); | |
1279 |
1
1. getEncodedPKCS7 : negated conditional → NO_COVERAGE |
if (tsToken != null) { |
1280 | ASN1EncodableVector unauthAttributes = buildUnauthenticatedAttributes(tsToken); | |
1281 |
1
1. getEncodedPKCS7 : negated conditional → NO_COVERAGE |
if (unauthAttributes != null) { |
1282 | signerinfo.add(new DERTaggedObject(false, 1, new DERSet( | |
1283 | unauthAttributes))); | |
1284 | } | |
1285 | } | |
1286 | } | |
1287 | ||
1288 | // Finally build the body out of all the components above | |
1289 | ASN1EncodableVector body = new ASN1EncodableVector(); | |
1290 | body.add(new ASN1Integer(version)); | |
1291 | body.add(new DERSet(digestAlgorithms)); | |
1292 | body.add(contentinfo); | |
1293 | body.add(new DERTaggedObject(false, 0, dercertificates)); | |
1294 | ||
1295 | // Only allow one signerInfo | |
1296 | body.add(new DERSet(new DERSequence(signerinfo))); | |
1297 | ||
1298 | // Now we have the body, wrap it in it's PKCS7Signed shell | |
1299 | // and return it | |
1300 | // | |
1301 | ASN1EncodableVector whole = new ASN1EncodableVector(); | |
1302 | whole.add(new ASN1ObjectIdentifier(ID_PKCS7_SIGNED_DATA)); | |
1303 | whole.add(new DERTaggedObject(0, new DERSequence(body))); | |
1304 | ||
1305 | ByteArrayOutputStream bOut = new ByteArrayOutputStream(); | |
1306 | ||
1307 | ASN1OutputStream dout = new ASN1OutputStream(bOut); | |
1308 | dout.writeObject(new DERSequence(whole)); | |
1309 | dout.close(); | |
1310 | ||
1311 |
1
1. getEncodedPKCS7 : mutated return of Object value for com/lowagie/text/pdf/PdfPKCS7::getEncodedPKCS7 to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return bOut.toByteArray(); |
1312 | } catch (Exception e) { | |
1313 | throw new ExceptionConverter(e); | |
1314 | } | |
1315 | } | |
1316 | ||
1317 | /** | |
1318 | * Added by Aiken Sam, 2006-11-15, modifed by Martin Brunecky 07/12/2007 to | |
1319 | * start with the timeStampToken (signedData 1.2.840.113549.1.7.2). Token is | |
1320 | * the TSA response without response status, which is usually handled by the | |
1321 | * (vendor supplied) TSA request/response interface). | |
1322 | * | |
1323 | * @param timeStampToken byte[] - time stamp token, DER encoded signedData | |
1324 | * @return ASN1EncodableVector | |
1325 | * @throws IOException | |
1326 | */ | |
1327 | private ASN1EncodableVector buildUnauthenticatedAttributes( | |
1328 | byte[] timeStampToken) throws IOException { | |
1329 |
1
1. buildUnauthenticatedAttributes : negated conditional → NO_COVERAGE |
if (timeStampToken == null) |
1330 |
1
1. buildUnauthenticatedAttributes : mutated return of Object value for com/lowagie/text/pdf/PdfPKCS7::buildUnauthenticatedAttributes to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
1331 | ||
1332 | // @todo: move this together with the rest of the defintions | |
1333 | String ID_TIME_STAMP_TOKEN = "1.2.840.113549.1.9.16.2.14"; // RFC 3161 | |
1334 | // id-aa-timeStampToken | |
1335 | ||
1336 | ASN1InputStream tempstream = new ASN1InputStream(new ByteArrayInputStream( | |
1337 | timeStampToken)); | |
1338 | ASN1EncodableVector unauthAttributes = new ASN1EncodableVector(); | |
1339 | ||
1340 | ASN1EncodableVector v = new ASN1EncodableVector(); | |
1341 | v.add(new ASN1ObjectIdentifier(ID_TIME_STAMP_TOKEN)); // id-aa-timeStampToken | |
1342 | ASN1Sequence seq = (ASN1Sequence) tempstream.readObject(); | |
1343 | v.add(new DERSet(seq)); | |
1344 | ||
1345 | unauthAttributes.add(new DERSequence(v)); | |
1346 |
1
1. buildUnauthenticatedAttributes : mutated return of Object value for com/lowagie/text/pdf/PdfPKCS7::buildUnauthenticatedAttributes to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return unauthAttributes; |
1347 | } | |
1348 | ||
1349 | /** | |
1350 | * When using authenticatedAttributes the authentication process is different. | |
1351 | * The document digest is generated and put inside the attribute. The signing | |
1352 | * is done over the DER encoded authenticatedAttributes. This method provides | |
1353 | * that encoding and the parameters must be exactly the same as in | |
1354 | * {@link #getEncodedPKCS7(byte[], Calendar)}. | |
1355 | * <p> | |
1356 | * A simple example: | |
1357 | * <p> | |
1358 | * | |
1359 | * <pre> | |
1360 | * Calendar cal = Calendar.getInstance(); | |
1361 | * PdfPKCS7 pk7 = new PdfPKCS7(key, chain, null, "SHA1", null, false); | |
1362 | * MessageDigest messageDigest = MessageDigest.getInstance("SHA1"); | |
1363 | * byte buf[] = new byte[8192]; | |
1364 | * int n; | |
1365 | * InputStream inp = sap.getRangeStream(); | |
1366 | * while ((n = inp.read(buf)) > 0) { | |
1367 | * messageDigest.update(buf, 0, n); | |
1368 | * } | |
1369 | * byte hash[] = messageDigest.digest(); | |
1370 | * byte sh[] = pk7.getAuthenticatedAttributeBytes(hash, cal); | |
1371 | * pk7.update(sh, 0, sh.length); | |
1372 | * byte sg[] = pk7.getEncodedPKCS7(hash, cal); | |
1373 | * </pre> | |
1374 | * | |
1375 | * @param secondDigest the content digest | |
1376 | * @param signingTime the signing time | |
1377 | * @return the byte array representation of the authenticatedAttributes ready | |
1378 | * to be signed | |
1379 | */ | |
1380 | public byte[] getAuthenticatedAttributeBytes(byte[] secondDigest, | |
1381 | Calendar signingTime, byte[] ocsp) { | |
1382 | try { | |
1383 |
1
1. getAuthenticatedAttributeBytes : mutated return of Object value for com/lowagie/text/pdf/PdfPKCS7::getAuthenticatedAttributeBytes to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return getAuthenticatedAttributeSet(secondDigest, signingTime, ocsp) |
1384 | .getEncoded(ASN1Encoding.DER); | |
1385 | } catch (Exception e) { | |
1386 | throw new ExceptionConverter(e); | |
1387 | } | |
1388 | } | |
1389 | ||
1390 | private DERSet getAuthenticatedAttributeSet(byte[] secondDigest, | |
1391 | Calendar signingTime, byte[] ocsp) { | |
1392 | try { | |
1393 | ASN1EncodableVector attribute = new ASN1EncodableVector(); | |
1394 | ASN1EncodableVector v = new ASN1EncodableVector(); | |
1395 | v.add(new ASN1ObjectIdentifier(ID_CONTENT_TYPE)); | |
1396 | v.add(new DERSet(new ASN1ObjectIdentifier(ID_PKCS7_DATA))); | |
1397 | attribute.add(new DERSequence(v)); | |
1398 | v = new ASN1EncodableVector(); | |
1399 | v.add(new ASN1ObjectIdentifier(ID_SIGNING_TIME)); | |
1400 | v.add(new DERSet(new DERUTCTime(signingTime.getTime()))); | |
1401 | attribute.add(new DERSequence(v)); | |
1402 | v = new ASN1EncodableVector(); | |
1403 | v.add(new ASN1ObjectIdentifier(ID_MESSAGE_DIGEST)); | |
1404 | v.add(new DERSet(new DEROctetString(secondDigest))); | |
1405 | attribute.add(new DERSequence(v)); | |
1406 |
1
1. getAuthenticatedAttributeSet : negated conditional → NO_COVERAGE |
if (ocsp != null) { |
1407 | v = new ASN1EncodableVector(); | |
1408 | v.add(new ASN1ObjectIdentifier(ID_ADBE_REVOCATION)); | |
1409 | DEROctetString doctet = new DEROctetString(ocsp); | |
1410 | ASN1EncodableVector vo1 = new ASN1EncodableVector(); | |
1411 | ASN1EncodableVector v2 = new ASN1EncodableVector(); | |
1412 | v2.add(OCSPObjectIdentifiers.id_pkix_ocsp_basic); | |
1413 | v2.add(doctet); | |
1414 | ASN1Enumerated den = new ASN1Enumerated(0); | |
1415 | ASN1EncodableVector v3 = new ASN1EncodableVector(); | |
1416 | v3.add(den); | |
1417 | v3.add(new DERTaggedObject(true, 0, new DERSequence(v2))); | |
1418 | vo1.add(new DERSequence(v3)); | |
1419 | v.add(new DERSet(new DERSequence(new DERTaggedObject(true, 1, | |
1420 | new DERSequence(vo1))))); | |
1421 | attribute.add(new DERSequence(v)); | |
1422 |
1
1. getAuthenticatedAttributeSet : negated conditional → NO_COVERAGE |
} else if (!crls.isEmpty()) { |
1423 | v = new ASN1EncodableVector(); | |
1424 | v.add(new ASN1ObjectIdentifier(ID_ADBE_REVOCATION)); | |
1425 | ASN1EncodableVector v2 = new ASN1EncodableVector(); | |
1426 | for (Object crl : crls) { | |
1427 | ASN1InputStream t = new ASN1InputStream(new ByteArrayInputStream( | |
1428 | ((X509CRL) crl).getEncoded())); | |
1429 | v2.add(t.readObject()); | |
1430 | } | |
1431 | v.add(new DERSet(new DERSequence(new DERTaggedObject(true, 0, | |
1432 | new DERSequence(v2))))); | |
1433 | attribute.add(new DERSequence(v)); | |
1434 | } | |
1435 | return new DERSet(attribute); | |
1436 | } catch (Exception e) { | |
1437 | throw new ExceptionConverter(e); | |
1438 | } | |
1439 | } | |
1440 | ||
1441 | /** | |
1442 | * Getter for property reason. | |
1443 | * | |
1444 | * @return Value of property reason. | |
1445 | */ | |
1446 | public String getReason() { | |
1447 | return this.reason; | |
1448 | } | |
1449 | ||
1450 | /** | |
1451 | * Setter for property reason. | |
1452 | * | |
1453 | * @param reason New value of property reason. | |
1454 | */ | |
1455 | public void setReason(String reason) { | |
1456 | this.reason = reason; | |
1457 | } | |
1458 | ||
1459 | /** | |
1460 | * Getter for property location. | |
1461 | * | |
1462 | * @return Value of property location. | |
1463 | */ | |
1464 | public String getLocation() { | |
1465 | return this.location; | |
1466 | } | |
1467 | ||
1468 | /** | |
1469 | * Setter for property location. | |
1470 | * | |
1471 | * @param location New value of property location. | |
1472 | */ | |
1473 | public void setLocation(String location) { | |
1474 | this.location = location; | |
1475 | } | |
1476 | ||
1477 | /** | |
1478 | * Getter for property signDate. | |
1479 | * | |
1480 | * @return Value of property signDate. | |
1481 | */ | |
1482 | public Calendar getSignDate() { | |
1483 | return this.signDate; | |
1484 | } | |
1485 | ||
1486 | /** | |
1487 | * Setter for property signDate. | |
1488 | * | |
1489 | * @param signDate New value of property signDate. | |
1490 | */ | |
1491 | public void setSignDate(Calendar signDate) { | |
1492 | this.signDate = signDate; | |
1493 | } | |
1494 | ||
1495 | /** | |
1496 | * Getter for property sigName. | |
1497 | * | |
1498 | * @return Value of property sigName. | |
1499 | */ | |
1500 | public String getSignName() { | |
1501 | return this.signName; | |
1502 | } | |
1503 | ||
1504 | /** | |
1505 | * Setter for property sigName. | |
1506 | * | |
1507 | * @param signName New value of property sigName. | |
1508 | */ | |
1509 | public void setSignName(String signName) { | |
1510 | this.signName = signName; | |
1511 | } | |
1512 | ||
1513 | /** | |
1514 | * a class that holds an X509 name | |
1515 | */ | |
1516 | public static class X509Name { | |
1517 | /** | |
1518 | * country code - StringType(SIZE(2)) | |
1519 | */ | |
1520 | public static final ASN1ObjectIdentifier C = new ASN1ObjectIdentifier( | |
1521 | "2.5.4.6"); | |
1522 | ||
1523 | /** | |
1524 | * organization - StringType(SIZE(1..64)) | |
1525 | */ | |
1526 | public static final ASN1ObjectIdentifier O = new ASN1ObjectIdentifier( | |
1527 | "2.5.4.10"); | |
1528 | ||
1529 | /** | |
1530 | * organizational unit name - StringType(SIZE(1..64)) | |
1531 | */ | |
1532 | public static final ASN1ObjectIdentifier OU = new ASN1ObjectIdentifier( | |
1533 | "2.5.4.11"); | |
1534 | ||
1535 | /** | |
1536 | * Title | |
1537 | */ | |
1538 | public static final ASN1ObjectIdentifier T = new ASN1ObjectIdentifier( | |
1539 | "2.5.4.12"); | |
1540 | ||
1541 | /** | |
1542 | * common name - StringType(SIZE(1..64)) | |
1543 | */ | |
1544 | public static final ASN1ObjectIdentifier CN = new ASN1ObjectIdentifier( | |
1545 | "2.5.4.3"); | |
1546 | ||
1547 | /** | |
1548 | * device serial number name - StringType(SIZE(1..64)) | |
1549 | */ | |
1550 | public static final ASN1ObjectIdentifier SN = new ASN1ObjectIdentifier( | |
1551 | "2.5.4.5"); | |
1552 | ||
1553 | /** | |
1554 | * locality name - StringType(SIZE(1..64)) | |
1555 | */ | |
1556 | public static final ASN1ObjectIdentifier L = new ASN1ObjectIdentifier( | |
1557 | "2.5.4.7"); | |
1558 | ||
1559 | /** | |
1560 | * state, or province name - StringType(SIZE(1..64)) | |
1561 | */ | |
1562 | public static final ASN1ObjectIdentifier ST = new ASN1ObjectIdentifier( | |
1563 | "2.5.4.8"); | |
1564 | ||
1565 | /** | |
1566 | * Naming attribute of type X520name | |
1567 | */ | |
1568 | public static final ASN1ObjectIdentifier SURNAME = new ASN1ObjectIdentifier( | |
1569 | "2.5.4.4"); | |
1570 | /** | |
1571 | * Naming attribute of type X520name | |
1572 | */ | |
1573 | public static final ASN1ObjectIdentifier GIVENNAME = new ASN1ObjectIdentifier( | |
1574 | "2.5.4.42"); | |
1575 | /** | |
1576 | * Naming attribute of type X520name | |
1577 | */ | |
1578 | public static final ASN1ObjectIdentifier INITIALS = new ASN1ObjectIdentifier( | |
1579 | "2.5.4.43"); | |
1580 | /** | |
1581 | * Naming attribute of type X520name | |
1582 | */ | |
1583 | public static final ASN1ObjectIdentifier GENERATION = new ASN1ObjectIdentifier( | |
1584 | "2.5.4.44"); | |
1585 | /** | |
1586 | * Naming attribute of type X520name | |
1587 | */ | |
1588 | public static final ASN1ObjectIdentifier UNIQUE_IDENTIFIER = new ASN1ObjectIdentifier( | |
1589 | "2.5.4.45"); | |
1590 | ||
1591 | /** | |
1592 | * Email address (RSA PKCS#9 extension) - IA5String. | |
1593 | * <p> | |
1594 | * Note: if you're trying to be ultra orthodox, don't use this! It shouldn't | |
1595 | * be in here. | |
1596 | */ | |
1597 | public static final ASN1ObjectIdentifier EmailAddress = new ASN1ObjectIdentifier( | |
1598 | "1.2.840.113549.1.9.1"); | |
1599 | ||
1600 | /** | |
1601 | * email address in Verisign certificates | |
1602 | */ | |
1603 | public static final ASN1ObjectIdentifier E = EmailAddress; | |
1604 | ||
1605 | /** | |
1606 | * object identifier | |
1607 | */ | |
1608 | public static final ASN1ObjectIdentifier DC = new ASN1ObjectIdentifier( | |
1609 | "0.9.2342.19200300.100.1.25"); | |
1610 | ||
1611 | /** | |
1612 | * LDAP User id. | |
1613 | */ | |
1614 | public static final ASN1ObjectIdentifier UID = new ASN1ObjectIdentifier( | |
1615 | "0.9.2342.19200300.100.1.1"); | |
1616 | ||
1617 | /** | |
1618 | * A HashMap with default symbols | |
1619 | */ | |
1620 | public static Map<ASN1Encodable, String> defaultSymbols = new HashMap<>(); | |
1621 | ||
1622 | static { | |
1623 | defaultSymbols.put(C, "C"); | |
1624 | defaultSymbols.put(O, "O"); | |
1625 | defaultSymbols.put(T, "T"); | |
1626 | defaultSymbols.put(OU, "OU"); | |
1627 | defaultSymbols.put(CN, "CN"); | |
1628 | defaultSymbols.put(L, "L"); | |
1629 | defaultSymbols.put(ST, "ST"); | |
1630 | defaultSymbols.put(SN, "SN"); | |
1631 | defaultSymbols.put(EmailAddress, "E"); | |
1632 | defaultSymbols.put(DC, "DC"); | |
1633 | defaultSymbols.put(UID, "UID"); | |
1634 | defaultSymbols.put(SURNAME, "SURNAME"); | |
1635 | defaultSymbols.put(GIVENNAME, "GIVENNAME"); | |
1636 | defaultSymbols.put(INITIALS, "INITIALS"); | |
1637 | defaultSymbols.put(GENERATION, "GENERATION"); | |
1638 | } | |
1639 | ||
1640 | /** | |
1641 | * A HashMap with values | |
1642 | */ | |
1643 | public Map<String, List<String>> values = new HashMap<>(); | |
1644 | ||
1645 | /** | |
1646 | * Constructs an X509 name | |
1647 | * | |
1648 | * @param seq an ASN1 Sequence | |
1649 | */ | |
1650 | public X509Name(ASN1Sequence seq) { | |
1651 | Enumeration e = seq.getObjects(); | |
1652 | ||
1653 |
1
1. |
while (e.hasMoreElements()) { |
1654 | ASN1Set set = (ASN1Set) e.nextElement(); | |
1655 | ||
1656 | for (int i = 0; i < set.size(); i++) { | |
1657 | ASN1Sequence s = (ASN1Sequence) set.getObjectAt(i); | |
1658 | ASN1Encodable encodable = s.getObjectAt(0); | |
1659 | String id = defaultSymbols.get(encodable); | |
1660 |
1
1. |
if (id == null) |
1661 | continue; | |
1662 | List<String> vs = values.computeIfAbsent(id, k -> new ArrayList<>()); | |
1663 | vs.add(((ASN1String) s.getObjectAt(1)).getString()); | |
1664 | } | |
1665 | } | |
1666 | } | |
1667 | ||
1668 | /** | |
1669 | * Constructs an X509 name | |
1670 | * | |
1671 | * @param dirName a directory name | |
1672 | */ | |
1673 | public X509Name(String dirName) { | |
1674 | X509NameTokenizer nTok = new X509NameTokenizer(dirName); | |
1675 | ||
1676 |
1
1. |
while (nTok.hasMoreTokens()) { |
1677 | String token = nTok.nextToken(); | |
1678 | int index = token.indexOf('='); | |
1679 | ||
1680 |
1
1. |
if (index == -1) { |
1681 | throw new IllegalArgumentException( | |
1682 | MessageLocalization | |
1683 | .getComposedMessage("badly.formated.directory.string")); | |
1684 | } | |
1685 | ||
1686 | String id = token.substring(0, index).toUpperCase(); | |
1687 |
1
1. |
String value = token.substring(index + 1); |
1688 | List<String> vs = values.computeIfAbsent(id, k -> new ArrayList<>()); | |
1689 | vs.add(value); | |
1690 | } | |
1691 | ||
1692 | } | |
1693 | ||
1694 | @Nullable | |
1695 | public String getField(String name) { | |
1696 | List<String> vs = values.get(name); | |
1697 |
2
1. getField : negated conditional → NO_COVERAGE 2. getField : mutated return of Object value for com/lowagie/text/pdf/PdfPKCS7$X509Name::getField to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return vs == null ? null : vs.get(0); |
1698 | } | |
1699 | ||
1700 | /** | |
1701 | * gets a field array from the values Hashmap | |
1702 | * | |
1703 | * @param name | |
1704 | * @return an ArrayList | |
1705 | */ | |
1706 | public List<String> getFieldArray(String name) { | |
1707 |
1
1. getFieldArray : mutated return of Object value for com/lowagie/text/pdf/PdfPKCS7$X509Name::getFieldArray to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return values.get(name); |
1708 | } | |
1709 | ||
1710 | /** | |
1711 | * getter for values | |
1712 | * | |
1713 | * @return a HashMap with the fields of the X509 name | |
1714 | */ | |
1715 | public Map<String, List<String>> getFields() { | |
1716 | return values; | |
1717 | } | |
1718 | ||
1719 | /** | |
1720 | * @return values string representation | |
1721 | * @see java.lang.Object#toString() | |
1722 | */ | |
1723 | @Override | |
1724 | public String toString() { | |
1725 | return values.toString(); | |
1726 | } | |
1727 | } | |
1728 | ||
1729 | /** | |
1730 | * class for breaking up an X500 Name into it's component tokens, ala | |
1731 | * java.util.StringTokenizer. We need this class as some of the lightweight | |
1732 | * Java environment don't support classes like StringTokenizer. | |
1733 | */ | |
1734 | public static class X509NameTokenizer { | |
1735 | private final String oid; | |
1736 | private int index; | |
1737 | private final StringBuffer buf = new StringBuffer(); | |
1738 | ||
1739 | public X509NameTokenizer(String oid) { | |
1740 | this.oid = oid; | |
1741 | this.index = -1; | |
1742 | } | |
1743 | ||
1744 | public boolean hasMoreTokens() { | |
1745 |
2
1. hasMoreTokens : negated conditional → NO_COVERAGE 2. hasMoreTokens : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return (index != oid.length()); |
1746 | } | |
1747 | ||
1748 | public String nextToken() { | |
1749 |
1
1. nextToken : negated conditional → NO_COVERAGE |
if (index == oid.length()) { |
1750 |
1
1. nextToken : mutated return of Object value for com/lowagie/text/pdf/PdfPKCS7$X509NameTokenizer::nextToken to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
1751 | } | |
1752 | ||
1753 |
1
1. nextToken : Replaced integer addition with subtraction → NO_COVERAGE |
int end = index + 1; |
1754 | boolean quoted = false; | |
1755 | boolean escaped = false; | |
1756 | ||
1757 |
1
1. nextToken : removed call to java/lang/StringBuffer::setLength → NO_COVERAGE |
buf.setLength(0); |
1758 | ||
1759 |
1
1. nextToken : negated conditional → NO_COVERAGE |
while (end != oid.length()) { |
1760 | char c = oid.charAt(end); | |
1761 | ||
1762 |
1
1. nextToken : negated conditional → NO_COVERAGE |
if (c == '"') { |
1763 |
1
1. nextToken : negated conditional → NO_COVERAGE |
if (!escaped) { |
1764 |
1
1. nextToken : negated conditional → NO_COVERAGE |
quoted = !quoted; |
1765 | } else { | |
1766 | buf.append(c); | |
1767 | } | |
1768 | escaped = false; | |
1769 | } else { | |
1770 |
2
1. nextToken : negated conditional → NO_COVERAGE 2. nextToken : negated conditional → NO_COVERAGE |
if (escaped || quoted) { |
1771 | buf.append(c); | |
1772 | escaped = false; | |
1773 |
1
1. nextToken : negated conditional → NO_COVERAGE |
} else if (c == '\\') { |
1774 | escaped = true; | |
1775 |
1
1. nextToken : negated conditional → NO_COVERAGE |
} else if (c == ',') { |
1776 | break; | |
1777 | } else { | |
1778 | buf.append(c); | |
1779 | } | |
1780 | } | |
1781 |
1
1. nextToken : Changed increment from 1 to -1 → NO_COVERAGE |
end++; |
1782 | } | |
1783 | ||
1784 | index = end; | |
1785 |
1
1. nextToken : mutated return of Object value for com/lowagie/text/pdf/PdfPKCS7$X509NameTokenizer::nextToken to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return buf.toString().trim(); |
1786 | } | |
1787 | } | |
1788 | } | |
Mutations | ||
217 |
1.1 |
|
229 |
1.1 |
|
251 |
1.1 |
|
252 |
1.1 |
|
255 |
1.1 |
|
256 |
1.1 |
|
277 |
1.1 |
|
282 |
1.1 |
|
322 |
1.1 |
|
324 |
1.1 |
|
358 |
1.1 |
|
388 |
1.1 |
|
414 |
1.1 |
|
436 |
1.1 |
|
441 |
1.1 |
|
447 |
1.1 |
|
464 |
1.1 |
|
472 |
1.1 |
|
476 |
1.1 |
|
480 |
1.1 |
|
482 |
1.1 |
|
501 |
1.1 2.2 |
|
502 |
1.1 2.2 |
|
508 |
1.1 |
|
512 |
1.1 |
|
539 |
1.1 |
|
556 |
1.1 |
|
560 |
1.1 |
|
566 |
1.1 |
|
568 |
1.1 |
|
576 |
1.1 |
|
578 |
1.1 2.2 |
|
584 |
1.1 |
|
585 |
1.1 |
|
590 |
1.1 |
|
604 |
1.1 2.2 |
|
605 |
1.1 |
|
607 |
1.1 |
|
618 |
1.1 |
|
619 |
1.1 |
|
620 |
1.1 |
|
621 |
1.1 |
|
622 |
1.1 |
|
624 |
1.1 |
|
626 |
1.1 |
|
627 |
1.1 |
|
629 |
1.1 |
|
630 |
1.1 |
|
634 |
1.1 |
|
645 |
1.1 |
|
646 |
1.1 |
|
651 |
1.1 |
|
662 |
1.1 |
|
674 |
1.1 |
|
681 |
1.1 2.2 |
|
682 |
1.1 |
|
685 |
1.1 |
|
689 |
1.1 |
|
690 |
1.1 |
|
692 |
1.1 2.2 3.3 |
|
694 |
1.1 |
|
695 |
1.1 |
|
697 |
1.1 |
|
754 |
1.1 |
|
757 |
1.1 |
|
766 |
1.1 |
|
776 |
1.1 |
|
792 |
1.1 |
|
796 |
1.1 |
|
797 |
1.1 |
|
814 |
1.1 |
|
816 |
1.1 |
|
817 |
1.1 |
|
819 |
1.1 |
|
821 |
1.1 |
|
823 |
1.1 |
|
825 |
1.1 |
|
826 |
1.1 |
|
829 |
1.1 |
|
845 |
1.1 |
|
847 |
1.1 2.2 3.3 |
|
850 |
1.1 |
|
851 |
1.1 |
|
854 |
1.1 |
|
857 |
1.1 |
|
861 |
1.1 |
|
864 |
1.1 |
|
865 |
1.1 |
|
874 |
1.1 2.2 |
|
875 |
1.1 |
|
879 |
1.1 |
|
884 |
1.1 |
|
885 |
1.1 |
|
888 |
1.1 |
|
974 |
1.1 |
|
975 |
1.1 |
|
986 |
1.1 |
|
993 |
1.1 |
|
1003 |
1.1 |
|
1004 |
1.1 |
|
1005 |
1.1 2.2 |
|
1006 |
1.1 |
|
1027 |
1.1 |
|
1034 |
1.1 |
|
1035 |
1.1 |
|
1060 |
1.1 |
|
1077 |
1.1 |
|
1092 |
1.1 |
|
1106 |
1.1 |
|
1119 |
1.1 |
|
1129 |
1.1 |
|
1149 |
1.1 |
|
1150 |
1.1 |
|
1152 |
1.1 |
|
1167 |
1.1 |
|
1180 |
1.1 |
|
1197 |
1.1 |
|
1199 |
1.1 |
|
1201 |
1.1 2.2 |
|
1203 |
1.1 |
|
1206 |
1.1 |
|
1208 |
1.1 |
|
1225 |
1.1 |
|
1260 |
1.1 2.2 |
|
1276 |
1.1 |
|
1279 |
1.1 |
|
1281 |
1.1 |
|
1311 |
1.1 |
|
1329 |
1.1 |
|
1330 |
1.1 |
|
1346 |
1.1 |
|
1383 |
1.1 |
|
1406 |
1.1 |
|
1422 |
1.1 |
|
1653 |
1.1 |
|
1660 |
1.1 |
|
1676 |
1.1 |
|
1680 |
1.1 |
|
1687 |
1.1 |
|
1697 |
1.1 2.2 |
|
1707 |
1.1 |
|
1745 |
1.1 2.2 |
|
1749 |
1.1 |
|
1750 |
1.1 |
|
1753 |
1.1 |
|
1757 |
1.1 |
|
1759 |
1.1 |
|
1762 |
1.1 |
|
1763 |
1.1 |
|
1764 |
1.1 |
|
1770 |
1.1 2.2 |
|
1773 |
1.1 |
|
1775 |
1.1 |
|
1781 |
1.1 |
|
1785 |
1.1 |