package org.jscep.client.inspect;

import java.security.cert.CertStore;
import java.security.cert.X509CertSelector;
import java.util.Arrays;
import java.util.Collection;

/**
 * Implementation of the <code>CertStoreInspector</code> for Apache Harmony (Android)
 */
final class HarmonyCertStoreInspector extends AbstractCertStoreInspector implements CertStoreInspector {
    /**
     * @param store
     *            the store to inspect
     */
    HarmonyCertStoreInspector(final CertStore store) {
        super(store);
    }

    /**
     * {@inheritDoc}
     */
	protected Collection<X509CertSelector> getIssuerSelectors() {
		X509CertSelector caSelector = new X509CertSelector();
        caSelector.setBasicConstraints(0);
        
		return Arrays.asList(caSelector);
	}

	/**
     * {@inheritDoc}
     */
	protected Collection<X509CertSelector> getSignerSelectors() {
        X509CertSelector digSigSelector = new X509CertSelector();
        digSigSelector.setBasicConstraints(-2);
        digSigSelector.setKeyUsage(new boolean[] {true});
        
        X509CertSelector caSelector = new X509CertSelector();
        caSelector.setBasicConstraints(0);
        
		return Arrays.asList(digSigSelector, caSelector);
	}

	/**
     * {@inheritDoc}
     */
	protected Collection<X509CertSelector> getRecipientSelectors() {
        X509CertSelector keyEncSelector = new X509CertSelector();
        keyEncSelector.setKeyUsage(new boolean[] {false, false, true});
        
        X509CertSelector dataEncSelector = new X509CertSelector();
        dataEncSelector.setKeyUsage(new boolean[] {false, false, false, true});
        
        X509CertSelector caSelector = new X509CertSelector();
        caSelector.setBasicConstraints(0);
        
		return Arrays.asList(keyEncSelector, dataEncSelector, caSelector);
	}
}

@@ -28,16 +28,44 @@
 spect;%0A%0A
+import java.io.IOException;%0A
 import j
@@ -642,24 +642,40 @@
 erSelectors(
+byte%5B%5D subjectDN
 ) %7B%0A%09%09X509Ce
@@ -757,32 +757,159 @@
 Constraints(0);%0A
+        try %7B%0A            caSelector.setSubject(subjectDN);%0A        %7D catch (IOException e) %7B%0A            // shut up%0A        %7D%0A
         %0A%09%09retur
@@ -1980,8 +1980,9 @@
 );%0A%09%7D%0A%7D%0A
+%0A

Support multiple CA certificates in chain