Package com.lowagie.text.pdf

Examples of com.lowagie.text.pdf.PdfPKCS7


      for (String name : tmpNames) {
        final SignatureVerification tmpVerif = new SignatureVerification(name);
        tmpVerif.setWholeDocument(tmpAcroFields.signatureCoversWholeDocument(name));
        tmpVerif.setRevision(tmpAcroFields.getRevision(name));
        final PdfPKCS7 pk = tmpAcroFields.verifySignature(name);
        tmpVerif.setDate(pk.getSignDate());
        tmpVerif.setLocation(pk.getLocation());
        tmpVerif.setReason(pk.getReason());
        tmpVerif.setSignName(pk.getSignName());
        final Certificate pkc[] = pk.getCertificates();
        final X509Name tmpX509Name = PdfPKCS7.getSubjectFields(pk.getSigningCertificate());
        // TODO read more details from X509Name ?
        tmpVerif.setSubject(tmpX509Name.toString());
        tmpVerif.setModified(!pk.verify());
        // TODO revocation list and date to which should be verified?
        tmpVerif.setFails(PdfPKCS7.verifyCertificates(pkc, kall, null, tmpVerif.getDate()));
        tmpResult.addVerification(tmpVerif);
      }
    } catch (Exception e) {
View Full Code Here


      final int contentEstimated = (int) (Constants.DEFVAL_SIG_SIZE + 2L * crlInfo.getByteCount());
      HashMap exc = new HashMap();
      exc.put(PdfName.CONTENTS, new Integer(contentEstimated * 2 + 2));
      sap.preClose(exc);

      PdfPKCS7 sgn = new PdfPKCS7(key, chain, crlInfo.getCrls(), hashAlgorithm.getAlgorithmName(), null, false);
      InputStream data = sap.getRangeStream();
      final MessageDigest messageDigest = MessageDigest.getInstance(hashAlgorithm.getAlgorithmName());
      byte buf[] = new byte[8192];
      int n;
      while ((n = data.read(buf)) > 0) {
        messageDigest.update(buf, 0, n);
      }
      byte hash[] = messageDigest.digest();
      Calendar cal = Calendar.getInstance();
      byte[] ocsp = null;
      if (options.isOcspEnabledX() && chain.length >= 2) {
        options.log("console.getOCSPURL");
        String url = PdfPKCS7.getOCSPURL((X509Certificate) chain[0]);
        if (url != null && url.length() > 0) {
          options.log("console.readingOCSP");
          final OcspClientBouncyCastle ocspClient = new OcspClientBouncyCastle((X509Certificate) chain[0],
              (X509Certificate) chain[1], url);
          ocspClient.setProxy(tmpProxy);
          ocsp = ocspClient.getEncoded();
        }
      }
      byte sh[] = sgn.getAuthenticatedAttributeBytes(hash, cal, ocsp);
      sgn.update(sh, 0, sh.length);

      TSAClientBouncyCastle tsc = null;
      if (options.isTimestampX() && !StringUtils.isEmpty(options.getTsaUrl())) {
        options.log("console.creatingTsaClient");
        tsc = new TSAClientBouncyCastle(options.getTsaUrl(), StringUtils.emptyNull(options.getTsaUser()),
            StringUtils.emptyNull(options.getTsaPasswd()));
        tsc.setProxy(tmpProxy);
        final String policyOid = options.getTsaPolicy();
        if (StringUtils.hasLength(policyOid)) {
          options.log("console.settingTsaPolicy", policyOid);
          tsc.setPolicy(policyOid);
        }
      }
      byte[] encodedSig = sgn.getEncodedPKCS7(hash, cal, tsc, ocsp);

      if (contentEstimated + 2 < encodedSig.length) {
        System.err.println("SigSize - contentEstimated=" + contentEstimated + ", sigLen=" + encodedSig.length);
        throw new Exception("Not enough space");
      }
View Full Code Here

        tmpVerif.setDate(pk.getSignDate());
        tmpVerif.setLocation(pk.getLocation());
        tmpVerif.setReason(pk.getReason());
        tmpVerif.setSignName(pk.getSignName());
        final Certificate pkc[] = pk.getCertificates();
        final X509Name tmpX509Name = PdfPKCS7.getSubjectFields(pk.getSigningCertificate());
        // TODO read more details from X509Name ?
        tmpVerif.setSubject(tmpX509Name.toString());
        tmpVerif.setModified(!pk.verify());
        // TODO revocation list and date to which should be verified?
        tmpVerif.setFails(PdfPKCS7.verifyCertificates(pkc, kall, null, tmpVerif.getDate()));
        tmpResult.addVerification(tmpVerif);
      }
View Full Code Here

TOP

Related Classes of com.lowagie.text.pdf.PdfPKCS7

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.