Extension ext = new Extension(OCSPObjectIdentifiers.id_pkix_ocsp_nonce, true, new DEROctetString(nonce.toByteArray())); requestGenerator.setRequestExtensions(new Extensions(new Extension[]{ext}));
@Override public byte[] getExtensionValue(String oid) { Extension ext = this.extensions.getExtension(new ASN1ObjectIdentifier(oid)); if (ext == null) { return null; } return ext.getExtnValue().getOctets(); }
/** * return the parsed value of the extension represented by the object identifier * passed in. * * @return the parsed value of the extension if it's present, null otherwise. */ public ASN1Encodable getExtensionParsedValue(ASN1ObjectIdentifier oid) { Extension ext = this.getExtension(oid); if (ext != null) { return ext.getParsedValue(); } return null; }
public boolean equals( Object o) { if (!(o instanceof Extension)) { return false; } Extension other = (Extension)o; return other.getExtnId().equals(this.getExtnId()) && other.getExtnValue().equals(this.getExtnValue()) && (other.isCritical() == this.isCritical()); }
public int hashCode() { if (this.isCritical()) { return this.getExtnValue().hashCode() ^ this.getExtnId().hashCode(); } return ~(this.getExtnValue().hashCode() ^ this.getExtnId().hashCode()); }
/** * Creates an X509ExtensionSet object from the extensions in the ASN1 sequence. * * @param extensions Sequence with extensions. */ public X509ExtensionSet(ASN1Sequence extensions) { ASN1Encodable[] asn1Encodables = extensions.toArray(); for (int i = 0; i < asn1Encodables.length; i++) { ASN1Encodable asn1Encodable = asn1Encodables[i]; Extension ext = Extension.getInstance(asn1Encodable); if (ext != null) { try { addExtension(ext.getExtnId().toString(), ext.isCritical(), ext.getExtnValue().getEncoded()); } catch (IOException e) { // ignore exception from getEncoded() } } } }
private Set getExtensionOIDs(boolean critical) { Extensions extensions = c.getExtensions(); if (extensions != null) { Set set = new HashSet(); Enumeration e = extensions.oids(); while (e.hasMoreElements()) { ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier) e.nextElement(); Extension ext = extensions.getExtension(oid); if (critical == ext.isCritical()) { set.add(oid.getId()); } } return set; } return null; }
private Set loadCRLEntries() { Set entrySet = new HashSet(); Enumeration certs = c.getRevokedCertificateEnumeration(); X500Name previousCertificateIssuer = null; // the issuer while (certs.hasMoreElements()) { TBSCertList.CRLEntry entry = (TBSCertList.CRLEntry)certs.nextElement(); X509CRLEntryObject crlEntry = new X509CRLEntryObject(entry, isIndirect, previousCertificateIssuer); entrySet.add(crlEntry); if (isIndirect && entry.hasExtensions()) { Extension currentCaName = entry.getExtensions().getExtension(Extension.certificateIssuer); if (currentCaName != null) { previousCertificateIssuer = X500Name.getInstance(GeneralNames.getInstance(currentCaName.getParsedValue()).getNames()[0].getName()); } } } return entrySet; }
Enumeration e = extensions.oids(); if (e.hasMoreElements()) while (e.hasMoreElements()) ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier)e.nextElement(); Extension ext = extensions.getExtension(oid); if (ext.getExtnValue() != null) byte[] octs = ext.getExtnValue().getOctets(); ASN1InputStream dIn = new ASN1InputStream(octs); buf.append(" critical(").append(ext.isCritical()).append(") "); try if (oid.equals(X509Extension.reasonCode)) else if (oid.equals(X509Extension.certificateIssuer)) buf.append(oid.getId()); buf.append(" value = ").append(ASN1Dump.dumpAsString(dIn.readObject())).append(nl);
/** * Constructor from ASN1Sequence. * <p> * The extensions are a list of constructed sequences, either with (OID, OctetString) or (OID, Boolean, OctetString) * </p> */ private Extensions( ASN1Sequence seq) { Enumeration e = seq.getObjects(); while (e.hasMoreElements()) { Extension ext = Extension.getInstance(e.nextElement()); extensions.put(ext.getExtnId(), ext); ordering.addElement(ext.getExtnId()); } }
@Override public X509ExtensionBuilder addExtensions(X509Extensions extensionSet) throws IOException { if (extensionSet == null) { return this; } // Optimisation if (extensionSet instanceof BcX509Extensions) { Extensions exts = ((BcX509Extensions) extensionSet).getExtensions(); @SuppressWarnings("unchecked") Enumeration<ASN1ObjectIdentifier> oids = exts.oids(); while (oids.hasMoreElements()) { ASN1ObjectIdentifier oid = oids.nextElement(); Extension ext = exts.getExtension(oid); this.extensions.addExtension(ext.getExtnId(), ext.isCritical(), ext.getParsedValue()); } } else { // Fallback for (String oid : extensionSet.getExtensionOID()) { this.extensions.addExtension(new ASN1ObjectIdentifier(oid), extensionSet.isCritical(oid), extensionSet.getExtensionValue(oid)); } } return this; }
Enumeration e = extensions.oids(); while (e.hasMoreElements()) ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier)e.nextElement(); if (oid.equals(Extension.keyUsage) || oid.equals(Extension.certificatePolicies) || oid.equals(Extension.policyMappings) || oid.equals(Extension.inhibitAnyPolicy) || oid.equals(Extension.cRLDistributionPoints) Extension ext = extensions.getExtension(oid); if (ext.isCritical())
.getInstance((ASN1Sequence) targetExtension.getParsedValue()); for (Enumeration e = targetSequence.getObjects(); e.hasMoreElements();) { ASN1Sequence seq = (ASN1Sequence) e.nextElement(); ASN1TaggedObject val = (ASN1TaggedObject) seq.getObjectAt(0); asn1Targets[count++] = Target.getInstance(val);
throws IOException Extension ext = exts.getExtension(oid); if (ext != null) { byte[] extensionData = ext.getExtnValue().getOctets(); ASN1Object asn1Value = binaryToASN1Object(oid, extensionData); ret.put("oid", oid.getId()); ret.put("critical", critical); ret.put("value", asn1ObjToObj(asn1Value));
for (ASN1ObjectIdentifier oid : bcExtensions.getNonCriticalExtensionOIDs()) { certGen.addExtension(oid.getId(), false, bcExtensions.getExtension(oid).getExtnValue().getOctets()); for (ASN1ObjectIdentifier oid : bcExtensions.getCriticalExtensionOIDs()) { certGen.addExtension(oid.getId(), true, bcExtensions.getExtension(oid).getExtnValue().getOctets());
public byte[] getExtensionValue(String oid) { Extensions exts = c.getTBSCertificate().getExtensions(); if (exts != null) { Extension ext = exts.getExtension(new ASN1ObjectIdentifier(oid)); if (ext != null) { try { return ext.getExtnValue().getEncoded(); } catch (Exception e) { throw new IllegalStateException("error parsing " + e.toString()); } } } return null; }
public static byte[] extractSki(org.bouncycastle.asn1.x509.Certificate cert) throws CertificateEncodingException { Args.notNull(cert, "cert"); Extension encodedSkiValue = cert.getTBSCertificate().getExtensions().getExtension( Extension.subjectKeyIdentifier); if (encodedSkiValue == null) { return null; } try { return ASN1OctetString.getInstance(encodedSkiValue.getParsedValue()).getOctets(); } catch (IllegalArgumentException ex) { throw new CertificateEncodingException("invalid extension SubjectKeyIdentifier: " + ex.getMessage()); } }
protected void copyExtension(final ASN1ObjectIdentifier extensionType, X509Certificate issuerCertificate, List<Extension> extensions) { final byte[] encodedAttribute = issuerCertificate.getExtensionValue(extensionType.getId()); ASN1OctetString data = ASN1OctetString.getInstance(encodedAttribute); boolean isCritical = issuerCertificate.getCriticalExtensionOIDs().contains(extensionType.getId()); if (encodedAttribute != null) { extensions.add(new Extension(extensionType, isCritical, data)); } }
private byte[] getExpectedExtValue(final ASN1ObjectIdentifier type, final Extensions requestedExtensions, final ExtensionControl extControl) { if (constantExtensions != null && constantExtensions.containsKey(type)) { return constantExtensions.get(type).value(); } else if (requestedExtensions != null && extControl.isRequest()) { Extension reqExt = requestedExtensions.getExtension(type); if (reqExt != null) { return reqExt.getExtnValue().getOctets(); } } return null; } // getExpectedExtValue
if(ext != null) { if(m_logger.isDebugEnabled()) m_logger.debug("Ext: " + ext.getExtnId() + " val-len: " + ((ext.getExtnValue() != null) ? ext.getExtnValue().getOctets().length : 0)); if(ext.getExtnValue() != null && ext.getExtnValue().getOctets() != null && ext.getExtnValue().getOctets().length == 20) { nonce2 = ext.getExtnValue().getOctets(); m_logger.debug("Raw nonce len: " + ((nonce2 != null) ? nonce2.length : 0)); } else { ASN1Encodable extObj = ext.getParsedValue(); nonce2 = extObj.toASN1Primitive().getEncoded();