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 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 <> 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.Date;
 import java.util.List;
 import java.util.Set;
 import  org.bouncycastle.asn1.ASN1InputStream;
 import  org.bouncycastle.asn1.DERBitString;
 import  org.bouncycastle.asn1.DEROctetString;

Since regular X509Certificate doesn't represent the Aux part of a certification, this class uses composition and extension to contain both pieces of information.

Ola Bini
 public class X509AuxCertificate extends X509Certificate {
     private static final long serialVersionUID = -909543379295427515L;
     private final X509Certificate wrap;
     private final X509Aux aux;
     private boolean valid = false;
     private int ex_flags = 0;
     public X509AuxCertificate(X509Certificate wrap) {
     public X509AuxCertificate(X509Certificate wrapX509Aux aux) {
         this. = wrap;
         this. = aux;
     public X509Aux getAux() {
         return this.;
     public boolean isValid() {
         return ;
     public void setValid(boolean v) {
         this. = v;
     public int getExFlags() {
         return ;
     public void setExFlags(int ex_flags) {
         this. = ex_flags;
    public int 	getBasicConstraints()  { return .getBasicConstraints(); }
    public Principal 	getIssuerDN() { return .getIssuerDN(); }
    public boolean[] 	getIssuerUniqueID() { return .getIssuerUniqueID(); }
    public boolean[] 	getKeyUsage() { return .getKeyUsage(); }
    public Date 	getNotAfter() { return .getNotAfter(); }
    public Date 	getNotBefore() { return .getNotBefore(); }
    public BigInteger 	getSerialNumber() { return .getSerialNumber(); }
    public String 	getSigAlgName() { return .getSigAlgName(); }
    public String 	getSigAlgOID() { return .getSigAlgOID(); }
    public byte[] 	getSigAlgParams() { return .getSigAlgParams(); }
    public byte[] 	getSignature() { return .getSignature(); }
    public Principal 	getSubjectDN() { return .getSubjectDN(); }
    public boolean[] 	getSubjectUniqueID() { return .getSubjectUniqueID(); }
    public byte[] 	getTBSCertificate() throws CertificateEncodingException { return .getTBSCertificate(); }
    public int 	getVersion() { return .getVersion(); }
    public boolean 	equals(Object other) {
        boolean ret = this == other;
        if(!ret && (other instanceof X509AuxCertificate)) {
            X509AuxCertificate o = (X509AuxCertificate)other;
            ret = this..equals(o.wrap) && ((this. == null) ? o.aux == null : this..equals(o.aux));
        return ret;
    public byte[] 	getEncoded() throws CertificateEncodingException { return .getEncoded(); }
    public PublicKey 	getPublicKey(){ return .getPublicKey(); }
    public int 	hashCode() {
        int ret = .hashCode();
        ret += 3 * ( == null ? 1 : .hashCode());
        return ret;
    public String 	toString(){ return .toString(); }
    public  Set<StringgetCriticalExtensionOIDs(){ return .getCriticalExtensionOIDs(); }
    public byte[] 	getExtensionValue(String oid){ return .getExtensionValue(oid); }
    public boolean 	hasUnsupportedCriticalExtension(){ return .hasUnsupportedCriticalExtension(); }
    private static final String NS_CERT_TYPE_OID = "2.16.840.1.113730.1.1";
    public Integer getNsCertType() throws CertificateException {
        byte[] bytes = getExtensionValue();
        if (bytes == null) {
            return null;
        try {
            Object o = new ASN1InputStream(bytes).readObject();
            if (o instanceof DERBitString) {
                return ((DERBitString) o).intValue();
            } else if (o instanceof DEROctetString) {
                // just reads initial object for nsCertType definition and ignores trailing objects.
                ASN1InputStream in = new ASN1InputStream(((DEROctetString) o).getOctets());
                o = in.readObject();
                return ((DERBitString) o).intValue();
            } else {
                throw new CertificateException("unknown type from ASN1InputStream.readObject: " + o);
        } catch (IOException ioe) {
            throw new CertificateEncodingException(ioe.getMessage(), ioe);
}// X509AuxCertificate
New to GrepCode? Check out our FAQ X