Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
BEGIN LICENSE BLOCK ***** Version: CPL 1.0/GPL 2.0/LGPL 2.1 The contents of this file are subject to the Common Public License Version 1.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.eclipse.org/legal/cpl-v10.html Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. Copyright (C) 2006 Ola Bini <ola@ologix.com> Alternatively, the contents of this file may be used under the terms of either of the GNU General Public License Version 2 or later (the "GPL"), or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), in which case the provisions of the GPL or the LGPL are applicable instead of those above. If you wish to allow use of your version of this file only under the terms of either the GPL or the LGPL, and not to allow others to use your version of this file under the terms of the CPL, indicate your decision by deleting the provisions above and replace them with the notice and other provisions required by the GPL or the LGPL. If you do not delete the provisions above, a recipient may use your version of this file under the terms of any one of the CPL, the GPL or the LGPL. END LICENSE BLOCK ***
 
 package org.jruby.ext.openssl.x509store;
 
 import java.util.List;

c: X509_TRUST

Author(s):
Ola Bini
 
 public class Trust {
     public static interface Checker extends Function3 {}
     public int trust;
     public int flags;
     public Checker checkTrust;
     public String name;
     public String arg1;
     public Object arg2;
 
     public Trust() {}
 
     public Trust(int tint fChecker ctString nString a1Object a2) {
         this. = t;
         this. = fthis. = ct;
         this. = nthis. = a1;
         this. = a2;
     }

    
c: X509_TRUST_set_default
 
     public static Checker setDefault(Checker trust) {
         Checker old_trust = ;
          = trust;
         return old_trust;
     }
 
     private final static List<Trusttrtable = new ArrayList<Trust>();

    
c: X509_check_trust
 
     public static int checkTrust(X509AuxCertificate xint idint flagsthrows Exception {
         if(id == -1) {
             return 1;
         }
         int idx = getByID(id);
         if(idx == -1) {
             return .call(new Integer(id),x,new Integer(flags));
         }
         Trust pt = getFirst(idx);
         return pt.checkTrust.call(pt,x,new Integer(flags));
     }

    
c: X509_TRUST_get_count
 
     public static int getCount() {
         return .size() + .;
     }

    
c: X509_TRUST_get0
 
     public static Trust getFirst(int idx) {
         if(idx < 0) {
             return null;
         }
         if(idx < .) {
             return [idx];
         }
         return .get(idx - .);
    }

    
c: X509_TRUST_get_by_id
    public static int getByID(int id) {
        if(id >= . && id <= .) {
            return id - .;
        }
        int i = 0;
        for(Trust t : ) {
            if(t.trust == id) {
                return i + .;
            }
        }
        return -1;
    }

    
c: X509_TRUST_set
    public static int set(int[] tint trust) {
        if(getByID(trust) == -1) {
            X509Error.addError(.);
            return 0;
        }
        t[0] = trust;
        return 1;
    }

    
c: X509_TRUST_add
    public static int add(int idint flagsChecker ckString nameString arg1Object arg2) {
        int idx;
        Trust trtmp;
        flags &= ~.;
        flags |= .;
        idx = getByID(id);
        if(idx == -1) {
            trtmp = new Trust();
            trtmp.flags = .;
        } else {
            trtmp = getFirst(idx);
        }
        trtmp.name = name;
        trtmp.flags &= .;
        trtmp.flags |= flags;
        trtmp.trust = id;
        trtmp.checkTrust = ck;
        trtmp.arg1 = arg1;
        trtmp.arg2 = arg2;
        if(idx == -1) {
            .add(trtmp);
        }
        return 1;
    }

    
c: X509_TRUST_cleanup
    public static void cleanup() {
        .clear();
    }
    
    
c: X509_TRUST_get_flags
    public int getFlags() {
	return ;
    }

    
c: X509_TRUST_get0_name
    public String getName() {
	return ;
    }

    
c: X509_TRUST_get_trust
    public int getTrust() {
	return ;
    }

    
c: trust_compat
    public final static Checker trustCompatibe = new Checker() {
            public int call(Object _trustObject _xObject _flagsthrows Exception {
                //X509_TRUST trust = (X509_TRUST)_trust;
                X509AuxCertificate x = (X509AuxCertificate)_x;
                //int flags = ((Integer)_flags).intValue();
                Purpose.checkPurpose(x,-1,0);
                if(x.getIssuerX500Principal().equals(x.getSubjectX500Principal())) { // self signed
                    return .;
                } else {
                    return .;
                }
            }
        };

    
c: trust_1oidany
    public final static Checker trust1OIDAny = new Checker() {
            public int call(Object _trustObject _xObject _flagsthrows Exception {
                Trust trust = (Trust)_trust;
                X509AuxCertificate x = (X509AuxCertificate)_x;
                int flags = ((Integer)_flags).intValue();
                X509Aux ax = x.getAux();
                if(ax != null && (ax.trust.size() > 0 || ax.reject.size() > 0)) {
                    return .call(trust.arg1,x,new Integer(flags));
                }
                return .call(trust,x,new Integer(flags));
            }
        };

    
c: trust_1oid
    public final static Checker trust1OID = new Checker() {
            public int call(Object _trustObject _xObject _flagsthrows Exception {
                Trust trust = (Trust)_trust;
                X509AuxCertificate x = (X509AuxCertificate)_x;
                int flags = ((Integer)_flags).intValue();
                if(x.getAux() != null) {
                    return .call(trust.arg1,x,new Integer(flags));
                }
                return .;
            }
        };

    
c: obj_trust
    public final static Checker objTrust = new Checker() {
            public int call(Object _idObject _xObject _flags) {
                String id = (String)_id;
                X509AuxCertificate x = (X509AuxCertificate)_x;
                //int flags = ((Integer)_flags).intValue();
                
                X509Aux ax = x.getAux();
                if(null == ax) {
                    return .;
                }
                for(String rej : ax.reject) {
                    if(rej.equals(id)) {
                        return .;
                    }
                }
                for(String t : ax.trust) {
                    if(t.equals(id)) {
                        return .;
                    }
                }
                return .;
            }
        };

    
c: default_trust
    public static Checker defaultTrust = ;
    public final static Trust[] trstandard = new Trust[] {
        new Trust(., 0, "compatible"nullnull),
        new Trust(., 0, "SSL Client""1.3.6.1.5.5.7.3.2"null),
        new Trust(., 0, "SSL Server""1.3.6.1.5.5.7.3.1"null),
        new Trust(., 0, "S/MIME email""1.3.6.1.5.5.7.3.4"null),
        new Trust(., 0, "Object Signer""1.3.6.1.5.5.7.3.3"null),
        new Trust(., 0, "OCSP responder""1.3.6.1.5.5.7.3.9"null),
        new Trust(., 0, "OCSP request""1.3.6.1.5.5.7.48.1"null)
    
    };
}// X509_TRUST
New to GrepCode? Check out our FAQ X