📄 x509certificateobject.java
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: X509CertificateObject.java
package org.bouncycastle.jce.provider;
import java.io.*;
import java.math.BigInteger;
import java.security.*;
import java.security.cert.*;
import java.util.*;
import javax.security.auth.x500.X500Principal;
import org.bouncycastle.asn1.*;
import org.bouncycastle.asn1.misc.*;
import org.bouncycastle.asn1.util.ASN1Dump;
import org.bouncycastle.asn1.x509.*;
import org.bouncycastle.jce.X509Principal;
import org.bouncycastle.jce.interfaces.PKCS12BagAttributeCarrier;
import org.bouncycastle.util.encoders.Hex;
// Referenced classes of package org.bouncycastle.jce.provider:
// JDKKeyFactory
public class X509CertificateObject extends X509Certificate
implements PKCS12BagAttributeCarrier
{
private X509CertificateStructure c;
private Hashtable pkcs12Attributes;
private Vector pkcs12Ordering;
public X509CertificateObject(X509CertificateStructure c)
{
pkcs12Attributes = new Hashtable();
pkcs12Ordering = new Vector();
this.c = c;
}
public void checkValidity()
throws CertificateExpiredException, CertificateNotYetValidException
{
checkValidity(new Date());
}
public void checkValidity(Date date)
throws CertificateExpiredException, CertificateNotYetValidException
{
if (date.after(getNotAfter()))
throw new CertificateExpiredException((new StringBuilder()).append("certificate expired on ").append(c.getEndDate().getTime()).toString());
if (date.before(getNotBefore()))
throw new CertificateNotYetValidException((new StringBuilder()).append("certificate not valid till ").append(c.getStartDate().getTime()).toString());
else
return;
}
public int getVersion()
{
return c.getVersion();
}
public BigInteger getSerialNumber()
{
return c.getSerialNumber().getValue();
}
public Principal getIssuerDN()
{
return new X509Principal(c.getIssuer());
}
public X500Principal getIssuerX500Principal()
{
ByteArrayOutputStream bOut;
bOut = new ByteArrayOutputStream();
ASN1OutputStream aOut = new ASN1OutputStream(bOut);
aOut.writeObject(c.getIssuer());
return new X500Principal(bOut.toByteArray());
IOException e;
e;
throw new IllegalStateException("can't encode issuer DN");
}
public Principal getSubjectDN()
{
return new X509Principal(c.getSubject());
}
public X500Principal getSubjectX500Principal()
{
ByteArrayOutputStream bOut;
bOut = new ByteArrayOutputStream();
ASN1OutputStream aOut = new ASN1OutputStream(bOut);
aOut.writeObject(c.getSubject());
return new X500Principal(bOut.toByteArray());
IOException e;
e;
throw new IllegalStateException("can't encode issuer DN");
}
public Date getNotBefore()
{
return c.getStartDate().getDate();
}
public Date getNotAfter()
{
return c.getEndDate().getDate();
}
public byte[] getTBSCertificate()
throws CertificateEncodingException
{
ByteArrayOutputStream bOut;
DEROutputStream dOut;
bOut = new ByteArrayOutputStream();
dOut = new DEROutputStream(bOut);
dOut.writeObject(c.getTBSCertificate());
return bOut.toByteArray();
IOException e;
e;
throw new CertificateEncodingException(e.toString());
}
public byte[] getSignature()
{
return c.getSignature().getBytes();
}
public String getSigAlgName()
{
Provider prov = Security.getProvider("BC");
String algName = prov.getProperty((new StringBuilder()).append("Alg.Alias.Signature.").append(getSigAlgOID()).toString());
if (algName != null)
return algName;
Provider provs[] = Security.getProviders();
for (int i = 0; i != provs.length; i++)
{
algName = provs[i].getProperty((new StringBuilder()).append("Alg.Alias.Signature.").append(getSigAlgOID()).toString());
if (algName != null)
return algName;
}
return getSigAlgOID();
}
public String getSigAlgOID()
{
return c.getSignatureAlgorithm().getObjectId().getId();
}
public byte[] getSigAlgParams()
{
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
if (c.getSignatureAlgorithm().getParameters() != null)
{
try
{
DEROutputStream dOut = new DEROutputStream(bOut);
dOut.writeObject(c.getSignatureAlgorithm().getParameters());
}
catch (Exception e)
{
throw new RuntimeException((new StringBuilder()).append("exception getting sig parameters ").append(e).toString());
}
return bOut.toByteArray();
} else
{
return null;
}
}
public boolean[] getIssuerUniqueID()
{
DERBitString id = c.getTBSCertificate().getIssuerUniqueId();
if (id != null)
{
byte bytes[] = id.getBytes();
boolean boolId[] = new boolean[bytes.length * 8 - id.getPadBits()];
for (int i = 0; i != boolId.length; i++)
boolId[i] = (bytes[i / 8] & 128 >>> i % 8) != 0;
return boolId;
} else
{
return null;
}
}
public boolean[] getSubjectUniqueID()
{
DERBitString id = c.getTBSCertificate().getSubjectUniqueId();
if (id != null)
{
byte bytes[] = id.getBytes();
boolean boolId[] = new boolean[bytes.length * 8 - id.getPadBits()];
for (int i = 0; i != boolId.length; i++)
boolId[i] = (bytes[i / 8] & 128 >>> i % 8) != 0;
return boolId;
} else
{
return null;
}
}
public boolean[] getKeyUsage()
{
byte bytes[] = getExtensionBytes("2.5.29.15");
int length = 0;
if (bytes != null)
{
try
{
DERInputStream dIn = new DERInputStream(new ByteArrayInputStream(bytes));
DERBitString bits = (DERBitString)dIn.readObject();
bytes = bits.getBytes();
length = bytes.length * 8 - bits.getPadBits();
}
catch (Exception e)
{
throw new RuntimeException("error processing key usage extension");
}
boolean keyUsage[] = new boolean[length >= 9 ? length : 9];
for (int i = 0; i != length; i++)
keyUsage[i] = (bytes[i / 8] & 128 >>> i % 8) != 0;
return keyUsage;
} else
{
return null;
}
}
public int getBasicConstraints()
{
byte bytes[];
bytes = getExtensionBytes("2.5.29.19");
if (bytes == null)
break MISSING_BLOCK_LABEL_128;
ASN1Sequence seq;
DERInputStream dIn = new DERInputStream(new ByteArrayInputStream(bytes));
seq = (ASN1Sequence)dIn.readObject();
if (seq.size() != 2)
break MISSING_BLOCK_LABEL_74;
if (((DERBoolean)seq.getObjectAt(0)).isTrue())
return ((DERInteger)seq.getObjectAt(1)).getValue().intValue();
return -1;
if (seq.size() != 1)
break MISSING_BLOCK_LABEL_128;
if (!(seq.getObjectAt(0) instanceof DERBoolean))
break MISSING_BLOCK_LABEL_112;
if (((DERBoolean)seq.getObjectAt(0)).isTrue())
return 0x7fffffff;
return -1;
return -1;
Exception e;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -