Package com.lowagie.text.pdf

Examples of com.lowagie.text.pdf.PdfPKCS7$X509NameTokenizer


      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

        return null;
      }

      Vector<DERObjectIdentifier> defaultOrdering = new Vector<DERObjectIdentifier>();
      Vector<String> values = new Vector<String>();
      X509NameTokenizer x509NameTokenizer = new X509NameTokenizer(dn);

      while (x509NameTokenizer.hasMoreTokens()) {
        // This is a pair key=val (CN=xx)
      String pair = x509NameTokenizer.nextToken()// Will escape '+' and initial '#' chars
        int index = pair.indexOf('=');

        if (index != -1) {
          String key = pair.substring(0, index).toLowerCase().trim();
          String val = pair.substring(index + 1);
View Full Code Here

      }*/
        boolean ret = false;
        if (dn != null) {
            String first = null;
            String last = null;
            X509NameTokenizer xt = new X509NameTokenizer(dn);
            if (xt.hasMoreTokens()) {
              first = xt.nextToken();
            }
            while (xt.hasMoreTokens()) {
                last = xt.nextToken();
            }
            String[] dNObjects = DnComponents.getDnObjects(true);
            if ( (first != null) && (last != null) ) {
              first = first.substring(0,first.indexOf('='));
              last = last.substring(0,last.indexOf('='));
View Full Code Here

      }
        String part = null;
        if ((dn != null) && (dnpart != null)) {
            String o;
            dnpart += "="; // we search for 'CN=' etc.
            X509NameTokenizer xt = new X509NameTokenizer(dn);
            while (xt.hasMoreTokens()) {
                o = xt.nextToken();
                //log.debug("checking: "+o.substring(0,dnpart.length()));
                if ((o.length() > dnpart.length()) &&
                        o.substring(0, dnpart.length()).equalsIgnoreCase(dnpart)) {
                    part = o.substring(dnpart.length());
View Full Code Here

    }
    ArrayList<String> parts = new ArrayList<String>();
    if ((dn != null) && (dnpart != null)) {
      String o;
      dnpart += "="; // we search for 'CN=' etc.
      X509NameTokenizer xt = new X509NameTokenizer(dn);
      while (xt.hasMoreTokens()) {
        o = xt.nextToken();
        if ((o.length() > dnpart.length()) &&
            o.substring(0, dnpart.length()).equalsIgnoreCase(dnpart)) {
          parts.add(o.substring(dnpart.length()));
        }
      }
View Full Code Here

      log.trace(">getCustomOids: dn:'" + dn);
    }
    ArrayList<String> parts = new ArrayList<String>();
    if (dn != null) {
      String o;
      X509NameTokenizer xt = new X509NameTokenizer(dn);
      while (xt.hasMoreTokens()) {
        o = xt.nextToken();
        // Try to see if it is a valid OID
        try {
          int i = o.indexOf('=');
          // An oid is never shorter than 3 chars and must start with 1.
          if ( (i > 2) && (o.charAt(1) == '.') ) {
View Full Code Here

    public static String insertCNPostfix(String dn, String cnpostfix){
      String newdn = null;
     
      if ((dn != null) && (cnpostfix != null)) {
          String o;         
          X509NameTokenizer xt = new X509NameTokenizer(dn);
          boolean alreadyreplaced = false;
          while (xt.hasMoreTokens()) {
              o = xt.nextToken();            
              if (!alreadyreplaced && (o.length() > 3) &&
                      o.substring(0, 3).equalsIgnoreCase("cn=")) {
                  o += cnpostfix;    
                  alreadyreplaced = true;
              }
View Full Code Here

TOP

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

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.