Java Code Examples for org.osgi.framework.Bundle#getSignerCertificates()

The following examples show how to use org.osgi.framework.Bundle#getSignerCertificates() . 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: BundleSignerCondition.java    From concierge with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Constructs a Condition that tries to match the passed Bundle's location
 * to the location pattern.
 * 
 * @param bundle The Bundle being evaluated.
 * @param info The ConditionInfo from which to construct the condition. The
 *        ConditionInfo must specify one or two arguments. The first
 *        argument of the ConditionInfo specifies the chain of distinguished
 *        names pattern to match against the signer of the bundle. The
 *        Condition is satisfied if the signer of the bundle matches the
 *        pattern. The second argument of the ConditionInfo is optional. If
 *        a second argument is present and equal to "!", then the
 *        satisfaction of the Condition is negated. That is, the Condition
 *        is satisfied if the signer of the bundle does NOT match the
 *        pattern. If the second argument is present but does not equal "!",
 *        then the second argument is ignored.
 * @return A Condition which checks the signers of the specified bundle.
 */
public static Condition getCondition(final Bundle bundle, final ConditionInfo info) {
	if (!CONDITION_TYPE.equals(info.getType()))
		throw new IllegalArgumentException("ConditionInfo must be of type \"" + CONDITION_TYPE + "\"");
	String[] args = info.getArgs();
	if (args.length != 1 && args.length != 2)
		throw new IllegalArgumentException("Illegal number of args: " + args.length);

	Map<X509Certificate, List<X509Certificate>> signers = bundle.getSignerCertificates(Bundle.SIGNERS_TRUSTED);
	boolean match = false;
	for (List<X509Certificate> signerCerts : signers.values()) {
		List<String> dnChain = new ArrayList<String>(signerCerts.size());
		for (X509Certificate signer : signerCerts) {
			dnChain.add(signer.getSubjectDN().getName());
		}
		if (FrameworkUtil.matchDistinguishedNameChain(args[0], dnChain)) {
			match = true;
			break;
		}
	}

	boolean negate = (args.length == 2) ? "!".equals(args[1]) : false;
	return negate ^ match ? Condition.TRUE : Condition.FALSE;
}
 
Example 2
Source File: BundleSignerCondition.java    From concierge with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Constructs a Condition that tries to match the passed Bundle's location
 * to the location pattern.
 * 
 * @param bundle The Bundle being evaluated.
 * @param info The ConditionInfo from which to construct the condition. The
 *        ConditionInfo must specify one or two arguments. The first
 *        argument of the ConditionInfo specifies the chain of distinguished
 *        names pattern to match against the signer of the bundle. The
 *        Condition is satisfied if the signer of the bundle matches the
 *        pattern. The second argument of the ConditionInfo is optional. If
 *        a second argument is present and equal to "!", then the
 *        satisfaction of the Condition is negated. That is, the Condition
 *        is satisfied if the signer of the bundle does NOT match the
 *        pattern. If the second argument is present but does not equal "!",
 *        then the second argument is ignored.
 * @return A Condition which checks the signers of the specified bundle.
 */
public static Condition getCondition(final Bundle bundle, final ConditionInfo info) {
	if (!CONDITION_TYPE.equals(info.getType()))
		throw new IllegalArgumentException("ConditionInfo must be of type \"" + CONDITION_TYPE + "\"");
	String[] args = info.getArgs();
	if (args.length != 1 && args.length != 2)
		throw new IllegalArgumentException("Illegal number of args: " + args.length);

	Map<X509Certificate, List<X509Certificate>> signers = bundle.getSignerCertificates(Bundle.SIGNERS_TRUSTED);
	boolean match = false;
	for (List<X509Certificate> signerCerts : signers.values()) {
		List<String> dnChain = new ArrayList<String>(signerCerts.size());
		for (X509Certificate signer : signerCerts) {
			dnChain.add(signer.getSubjectDN().getName());
		}
		if (FrameworkUtil.matchDistinguishedNameChain(args[0], dnChain)) {
			match = true;
			break;
		}
	}

	boolean negate = (args.length == 2) ? "!".equals(args[1]) : false;
	return negate ^ match ? Condition.TRUE : Condition.FALSE;
}
 
Example 3
Source File: CoordinationPermission.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Used by the filter matching algorithm. This methods does NOT satisfy the
 * normal equals contract. Since the class is only used in filter expression
 * evaluations, it only needs to support comparing an instance created with
 * a Bundle to an instance created with a pattern string from the filter
 * expression.
 * 
 * @param o SignerProperty to compare against.
 * @return true if the DN name chain matches the pattern.
 */
@Override
public boolean equals(Object o) {
	if (!(o instanceof SignerProperty))
		return false;
	SignerProperty other = (SignerProperty) o;
	Bundle matchBundle = bundle != null ? bundle : other.bundle;
	String matchPattern = bundle != null ? other.pattern : pattern;
	Map<X509Certificate, List<X509Certificate>> signers = matchBundle.getSignerCertificates(Bundle.SIGNERS_TRUSTED);
	for (List<X509Certificate> signerCerts : signers.values()) {
		List<String> dnChain = new ArrayList<String>(signerCerts.size());
		for (X509Certificate signerCert : signerCerts) {
			dnChain.add(signerCert.getSubjectDN().getName());
		}
		try {
			if (FrameworkUtil.matchDistinguishedNameChain(matchPattern, dnChain)) {
				return true;
			}
		} catch (IllegalArgumentException e) {
			continue; // bad pattern
		}
	}
	return false;
}
 
Example 4
Source File: BundleSignerCondition.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Constructs a Condition that tries to match the passed Bundle's location
 * to the location pattern.
 * 
 * @param bundle The Bundle being evaluated.
 * @param info The ConditionInfo from which to construct the condition. The
 *        ConditionInfo must specify one or two arguments. The first
 *        argument of the ConditionInfo specifies the chain of distinguished
 *        names pattern to match against the signer of the bundle. The
 *        Condition is satisfied if the signer of the bundle matches the
 *        pattern. The second argument of the ConditionInfo is optional. If
 *        a second argument is present and equal to "!", then the
 *        satisfaction of the Condition is negated. That is, the Condition
 *        is satisfied if the signer of the bundle does NOT match the
 *        pattern. If the second argument is present but does not equal "!",
 *        then the second argument is ignored.
 * @return A Condition which checks the signers of the specified bundle.
 */
public static Condition getCondition(final Bundle bundle, final ConditionInfo info) {
	if (!CONDITION_TYPE.equals(info.getType()))
		throw new IllegalArgumentException("ConditionInfo must be of type \"" + CONDITION_TYPE + "\"");
	String[] args = info.getArgs();
	if (args.length != 1 && args.length != 2)
		throw new IllegalArgumentException("Illegal number of args: " + args.length);

	Map<X509Certificate, List<X509Certificate>> signers = bundle.getSignerCertificates(Bundle.SIGNERS_TRUSTED);
	boolean match = false;
	for (List<X509Certificate> signerCerts : signers.values()) {
		List<String> dnChain = new ArrayList<String>(signerCerts.size());
		for (X509Certificate signer : signerCerts) {
			dnChain.add(signer.getSubjectDN().getName());
		}
		if (FrameworkUtil.matchDistinguishedNameChain(args[0], dnChain)) {
			match = true;
			break;
		}
	}

	boolean negate = (args.length == 2) ? "!".equals(args[1]) : false;
	return negate ^ match ? Condition.TRUE : Condition.FALSE;
}