📄 x509certificateobject.java
字号:
e;
throw new RuntimeException("error processing key usage extension");
return -1;
}
public Set getCriticalExtensionOIDs()
{
if (getVersion() == 3)
{
HashSet set = new HashSet();
X509Extensions extensions = c.getTBSCertificate().getExtensions();
if (extensions != null)
{
Enumeration e = extensions.oids();
do
{
if (!e.hasMoreElements())
break;
DERObjectIdentifier oid = (DERObjectIdentifier)e.nextElement();
X509Extension ext = extensions.getExtension(oid);
if (ext.isCritical())
set.add(oid.getId());
} while (true);
return set;
}
}
return null;
}
private byte[] getExtensionBytes(String oid)
{
X509Extensions exts = c.getTBSCertificate().getExtensions();
if (exts != null)
{
X509Extension ext = exts.getExtension(new DERObjectIdentifier(oid));
if (ext != null)
return ext.getValue().getOctets();
}
return null;
}
public byte[] getExtensionValue(String oid)
{
X509Extension ext;
ByteArrayOutputStream bOut;
DEROutputStream dOut;
X509Extensions exts = c.getTBSCertificate().getExtensions();
if (exts == null)
break MISSING_BLOCK_LABEL_100;
ext = exts.getExtension(new DERObjectIdentifier(oid));
if (ext == null)
break MISSING_BLOCK_LABEL_100;
bOut = new ByteArrayOutputStream();
dOut = new DEROutputStream(bOut);
dOut.writeObject(ext.getValue());
return bOut.toByteArray();
Exception e;
e;
throw new RuntimeException((new StringBuilder()).append("error encoding ").append(e.toString()).toString());
return null;
}
public Set getNonCriticalExtensionOIDs()
{
if (getVersion() == 3)
{
HashSet set = new HashSet();
X509Extensions extensions = c.getTBSCertificate().getExtensions();
if (extensions != null)
{
Enumeration e = extensions.oids();
do
{
if (!e.hasMoreElements())
break;
DERObjectIdentifier oid = (DERObjectIdentifier)e.nextElement();
X509Extension ext = extensions.getExtension(oid);
if (!ext.isCritical())
set.add(oid.getId());
} while (true);
return set;
}
}
return null;
}
public boolean hasUnsupportedCriticalExtension()
{
label0:
{
if (getVersion() != 3)
break label0;
X509Extensions extensions = c.getTBSCertificate().getExtensions();
if (extensions == null)
break label0;
Enumeration e = extensions.oids();
X509Extension ext;
do
{
DERObjectIdentifier oid;
do
{
if (!e.hasMoreElements())
break label0;
oid = (DERObjectIdentifier)e.nextElement();
} while (oid.getId().equals("2.5.29.15") || oid.getId().equals("2.5.29.19"));
ext = extensions.getExtension(oid);
} while (!ext.isCritical());
return true;
}
return false;
}
public PublicKey getPublicKey()
{
return JDKKeyFactory.createPublicKeyFromPublicKeyInfo(c.getSubjectPublicKeyInfo());
}
public byte[] getEncoded()
throws CertificateEncodingException
{
ByteArrayOutputStream bOut;
DEROutputStream dOut;
bOut = new ByteArrayOutputStream();
dOut = new DEROutputStream(bOut);
dOut.writeObject(c);
return bOut.toByteArray();
IOException e;
e;
throw new CertificateEncodingException(e.toString());
}
public void setBagAttribute(DERObjectIdentifier oid, DEREncodable attribute)
{
pkcs12Attributes.put(oid, attribute);
pkcs12Ordering.addElement(oid);
}
public DEREncodable getBagAttribute(DERObjectIdentifier oid)
{
return (DEREncodable)pkcs12Attributes.get(oid);
}
public Enumeration getBagAttributeKeys()
{
return pkcs12Ordering.elements();
}
public String toString()
{
StringBuffer buf = new StringBuffer();
String nl = System.getProperty("line.separator");
buf.append((new StringBuilder()).append(" [0] Version: ").append(getVersion()).append(nl).toString());
buf.append((new StringBuilder()).append(" SerialNumber: ").append(getSerialNumber()).append(nl).toString());
buf.append((new StringBuilder()).append(" IssuerDN: ").append(getIssuerDN()).append(nl).toString());
buf.append((new StringBuilder()).append(" Start Date: ").append(getNotBefore()).append(nl).toString());
buf.append((new StringBuilder()).append(" Final Date: ").append(getNotAfter()).append(nl).toString());
buf.append((new StringBuilder()).append(" SubjectDN: ").append(getSubjectDN()).append(nl).toString());
buf.append((new StringBuilder()).append(" Public Key: ").append(getPublicKey()).append(nl).toString());
buf.append((new StringBuilder()).append(" Signature Algorithm: ").append(getSigAlgName()).append(nl).toString());
byte sig[] = getSignature();
buf.append((new StringBuilder()).append(" Signature: ").append(new String(Hex.encode(sig, 0, 20))).append(nl).toString());
for (int i = 20; i < sig.length; i += 20)
if (i < sig.length - 20)
buf.append((new StringBuilder()).append(" ").append(new String(Hex.encode(sig, i, 20))).append(nl).toString());
else
buf.append((new StringBuilder()).append(" ").append(new String(Hex.encode(sig, i, sig.length - i))).append(nl).toString());
X509Extensions extensions = c.getTBSCertificate().getExtensions();
if (extensions != null)
{
Enumeration e = extensions.oids();
if (e.hasMoreElements())
buf.append(" Extensions: \n");
while (e.hasMoreElements())
{
DERObjectIdentifier oid = (DERObjectIdentifier)e.nextElement();
X509Extension ext = extensions.getExtension(oid);
if (ext.getValue() != null)
{
byte octs[] = ext.getValue().getOctets();
ByteArrayInputStream bIn = new ByteArrayInputStream(octs);
DERInputStream dIn = new DERInputStream(bIn);
buf.append((new StringBuilder()).append(" critical(").append(ext.isCritical()).append(") ").toString());
try
{
if (oid.equals(X509Extensions.BasicConstraints))
buf.append((new StringBuilder()).append(new BasicConstraints((ASN1Sequence)dIn.readObject())).append(nl).toString());
else
if (oid.equals(X509Extensions.KeyUsage))
buf.append((new StringBuilder()).append(new KeyUsage((DERBitString)dIn.readObject())).append(nl).toString());
else
if (oid.equals(MiscObjectIdentifiers.netscapeCertType))
buf.append((new StringBuilder()).append(new NetscapeCertType((DERBitString)dIn.readObject())).append(nl).toString());
else
if (oid.equals(MiscObjectIdentifiers.netscapeRevocationURL))
buf.append((new StringBuilder()).append(new NetscapeRevocationURL((DERIA5String)dIn.readObject())).append(nl).toString());
else
if (oid.equals(MiscObjectIdentifiers.verisignCzagExtension))
{
buf.append((new StringBuilder()).append(new VerisignCzagExtension((DERIA5String)dIn.readObject())).append(nl).toString());
} else
{
buf.append(oid.getId());
buf.append((new StringBuilder()).append(" value = ").append(ASN1Dump.dumpAsString(dIn.readObject())).append(nl).toString());
}
}
catch (Exception ex)
{
buf.append(oid.getId());
buf.append((new StringBuilder()).append(" value = *****").append(nl).toString());
}
} else
{
buf.append(nl);
}
}
}
return buf.toString();
}
public final void verify(PublicKey key)
throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException
{
Signature signature = null;
if (!c.getSignatureAlgorithm().equals(c.getTBSCertificate().getSignature()))
throw new CertificateException("signature algorithm in TBS cert not same as outer cert");
try
{
signature = Signature.getInstance(c.getSignatureAlgorithm().getObjectId().getId(), "BC");
}
catch (Exception e)
{
signature = Signature.getInstance(c.getSignatureAlgorithm().getObjectId().getId());
}
signature.initVerify(key);
signature.update(getTBSCertificate());
if (!signature.verify(getSignature()))
throw new InvalidKeyException("Public key presented not for certificate signature");
else
return;
}
public final void verify(PublicKey key, String sigProvider)
throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException
{
Signature signature = Signature.getInstance(c.getSignatureAlgorithm().getObjectId().getId(), sigProvider);
signature.initVerify(key);
signature.update(getTBSCertificate());
if (!signature.verify(getSignature()))
throw new InvalidKeyException("Public key presented not for certificate signature");
else
return;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -