Java Code Examples for org.apache.xml.security.keys.content.X509Data#lengthCertificate()

The following examples show how to use org.apache.xml.security.keys.content.X509Data#lengthCertificate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: X509DataExctractor.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public List<X509Certificate> extract(KeyInfo keyInfo) throws XMLSecurityException {
   List<X509Certificate> result = new ArrayList();

   for(int i = 0; i < keyInfo.lengthX509Data(); ++i) {
      X509Data data = keyInfo.itemX509Data(i);

      for(int j = 0; j < data.lengthCertificate(); ++j) {
         result.add(data.itemCertificate(j).getX509Certificate());
      }
   }

   return result;
}
 
Example 2
Source File: X509DataExctractor.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public List<X509Certificate> extract(KeyInfo keyInfo) throws XMLSecurityException {
   List<X509Certificate> result = new ArrayList();

   for(int i = 0; i < keyInfo.lengthX509Data(); ++i) {
      X509Data data = keyInfo.itemX509Data(i);

      for(int j = 0; j < data.lengthCertificate(); ++j) {
         result.add(data.itemCertificate(j).getX509Certificate());
      }
   }

   return result;
}
 
Example 3
Source File: X509DataExctractor.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public List<X509Certificate> extract(KeyInfo keyInfo) throws XMLSecurityException {
   List<X509Certificate> result = new ArrayList();

   for(int i = 0; i < keyInfo.lengthX509Data(); ++i) {
      X509Data data = keyInfo.itemX509Data(i);

      for(int j = 0; j < data.lengthCertificate(); ++j) {
         result.add(data.itemCertificate(j).getX509Certificate());
      }
   }

   return result;
}
 
Example 4
Source File: X509DataExctractor.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public List<X509Certificate> extract(KeyInfo keyInfo) throws XMLSecurityException {
   List<X509Certificate> result = new ArrayList();

   for(int i = 0; i < keyInfo.lengthX509Data(); ++i) {
      X509Data data = keyInfo.itemX509Data(i);

      for(int j = 0; j < data.lengthCertificate(); ++j) {
         result.add(data.itemCertificate(j).getX509Certificate());
      }
   }

   return result;
}
 
Example 5
Source File: X509DataExctractor.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public List<X509Certificate> extract(KeyInfo keyInfo) throws XMLSecurityException {
   List<X509Certificate> result = new ArrayList();

   for(int i = 0; i < keyInfo.lengthX509Data(); ++i) {
      X509Data data = keyInfo.itemX509Data(i);

      for(int j = 0; j < data.lengthCertificate(); ++j) {
         result.add(data.itemCertificate(j).getX509Certificate());
      }
   }

   return result;
}
 
Example 6
Source File: KeyInfoProcessor.java    From xades4j with GNU Lesser General Public License v3.0 4 votes vote down vote up
static KeyInfoRes process(
        KeyInfo keyInfo, CertRef signingCertRef, X500NameStyleProvider x500NameStyleProvider) throws CertificateValidationException
{
    if (null == keyInfo || !keyInfo.containsX509Data())
    {
        return tryUseSigningCertificateReference(signingCertRef, x500NameStyleProvider);
    }
    
    List<X509Certificate> keyInfoCerts = new ArrayList<X509Certificate>(1);
    XMLX509IssuerSerial issuerSerial = null;
    X509CertSelector certSelector = new X509CertSelector();

    // XML-DSIG 4.4.4: "Any X509IssuerSerial, X509SKI, and X509SubjectName elements
    // that appear MUST refer to the certificate or certificates containing the
    // validation key."
    // "All certificates appearing in an X509Data element MUST relate to the
    // validation key by either containing it or being part of a certification
    // chain that terminates in a certificate containing the validation key".

    // Scan ds:X509Data to find ds:IssuerSerial or ds:SubjectName elements. The
    // first to be found is used to select the leaf certificate. If none of those
    // elements is present, the first ds:X509Certificate is assumed as the signing
    // certificate.
    boolean hasSelectionCriteria = false;

    try
    {
        for (int i = 0; i < keyInfo.lengthX509Data(); ++i)
        {
            X509Data x509Data = keyInfo.itemX509Data(i);

            if (!hasSelectionCriteria)
            {
                if (x509Data.containsIssuerSerial())
                {
                    issuerSerial = x509Data.itemIssuerSerial(0);
                    certSelector.setIssuer(x500NameStyleProvider.fromString(issuerSerial.getIssuerName()));
                    certSelector.setSerialNumber(issuerSerial.getSerialNumber());
                    hasSelectionCriteria = true;
                }
                else if (x509Data.containsSubjectName())
                {
                    certSelector.setSubject(x500NameStyleProvider.fromString(x509Data.itemSubjectName(0).getSubjectName()));
                    hasSelectionCriteria = true;
                }
            }

            // Collect all certificates as they may be needed to build the cert path.
            if (x509Data.containsCertificate())
            {
                for (int j = 0; j < x509Data.lengthCertificate(); ++j)
                {
                    keyInfoCerts.add(x509Data.itemCertificate(j).getX509Certificate());
                }
            }
        }

        if (!hasSelectionCriteria)
        {
            if (keyInfoCerts.isEmpty())
            {
                return tryUseSigningCertificateReference(signingCertRef, x500NameStyleProvider);
            }

            certSelector.setCertificate(keyInfoCerts.get(0));
        }
    }
    catch (XMLSecurityException ex)
    {
        throw new InvalidKeyInfoDataException("Cannot process X509Data", ex);
    }

    return new KeyInfoRes(certSelector, keyInfoCerts, issuerSerial);
}