Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * @(#) $Id: $
   * 
   * Copyright 2009/2010 by sIT Solutions, A-1110 Wien, Geiselbergstr.21-25. All rights reserved.
   */
  package at.spardat.xma.boot.comp.data;
  
 import java.util.List;
 
Holds information about ssl restrictions (aka certificate pinning)
 
 public class XMASSLRestriction {
 
     private String hostname;
     private List<Stringsubject = new ArrayList<String>();
     private List<Stringissuer = new ArrayList<String>();

    
Returns, whether the given attributes match the subject.

Parameters:
attributes A comma separated list of X.509 attributes
Returns:
true if the attributes match
 
     public boolean matchesSubject(String attributes) {
         return matches(attributes);
     }

    
Returns, whether the given attributes match the issuer.

Parameters:
attributes A comma separated list of X.509 attributes
Returns:
true if the attributes match
 
     public boolean matchesIssuer(String attributes) {
         return matches(attributes);
     }

    
Returns whether the given X.509 certificate attributes match the restrictions. A match is found if all entries of the restriction list are present in the attribute string. If the attribute string contains values which are not present in the restriction list, they are ignored.

An empty restriction list matches any attribute parameter.

Example:
Given the restriction is a list of:
  • CN=Sample Cert
  • O=Company Ltd.
  • C=IE
A match would be found for the following X.509 attributes:
  • CN=Sample Cert, O=Company Ltd., C=IE
  • CN=Sample Cert, O=Company Ltd., OU=Dept C=IE
No match would be found for e.g.:
  • CN=Sample Cert, O=Other Company Ltd., C=IE (not matching O=Other Company Ltd.)
  • CN=Sample Cert, C=IE (not containing O=Copmany Ltd.)

Parameters:
attributes A comma separated list of X.509 attributes
Returns:
true if the attributes match
 
     private boolean matches(String attributesList<Stringrestrictions) {
         List<StringattributesSplit = splitDN(attributes);
         for (String string : restrictions) {
             if (!attributesSplit.contains(string)) {
                 return false;
             }
         }
         return true;
     }
 
     void setSubject(String s) {
         .clear();
         .addAll(splitDN(s));
 
     }
 
     void setIssuer(String s) {
         .clear();
         .addAll(splitDN(s));
 
     }
 
     private List<StringsplitDN(String s) {
         List<Stringlist = new ArrayList<String>();
         for (String item : s.trim().split(",")) {
            list.add(item.trim());
        }
        return list;
    }
    public String getHostname() {
        return ;
    }
    void setHostname(String hostname) {
        this. = hostname;
    }
    public void writeXML(PrintStream ps) {
        ps.print("   " + . + .);
        if ( != null && .length() > 0) {
                    + .);
        }
        ps.println(.);
        ps.println("      " + . + . + .);
        printTag(ps.);
        printTag(ps.);
        ps.println("      " + . + . + . + .);
    }
    private void printTag(PrintStream psString tagnameList<Stringlist) {
        Iterator<Stringiterator = list.iterator();
        if (iterator.hasNext()) {
            ps.print("         " + . + tagname + .);
            ps.print(iterator.next());
            while (iterator.hasNext()) {
                ps.print(", ");
                ps.print(iterator.next());
            }
            ps.println(. + . + tagname + .);
        }
    }
    @Override
    public String toString() {
        return "hostname=" +  + ", subject=" +  + ", issuer=" + ;
    }
New to GrepCode? Check out our FAQ X