/** * Return a control value of the specified type. * * @param type the type OID for the control value we are checking for. * @return the control value if present, null otherwise. */ public Control getControl(ASN1ObjectIdentifier type) { AttributeTypeAndValue found = findControl(type); if (found != null) { if (found.getType().equals(CRMFObjectIdentifiers.id_regCtrl_pkiArchiveOptions)) { return new PKIArchiveControl(PKIArchiveOptions.getInstance(found.getValue())); } if (found.getType().equals(CRMFObjectIdentifiers.id_regCtrl_regToken)) { return new RegTokenControl(DERUTF8String.getInstance(found.getValue())); } if (found.getType().equals(CRMFObjectIdentifiers.id_regCtrl_authenticator)) { return new AuthenticatorControl(DERUTF8String.getInstance(found.getValue())); } } return null; }
public SignerLocation( DERUTF8String countryName, DERUTF8String localityName, ASN1Sequence postalAddress) { if (postalAddress != null && postalAddress.size() > 6) { throw new IllegalArgumentException("postal address must contain less than 6 strings"); } if (countryName != null) { this.countryName = DERUTF8String.getInstance(countryName.toASN1Primitive()); } if (localityName != null) { this.localityName = DERUTF8String.getInstance(localityName.toASN1Primitive()); } if (postalAddress != null) { this.postalAddress = ASN1Sequence.getInstance(postalAddress.toASN1Primitive()); } }
private EncKeyWithID(ASN1Sequence seq) { this.privKeyInfo = PrivateKeyInfo.getInstance(seq.getObjectAt(0)); if (seq.size() > 1) { if (!(seq.getObjectAt(1) instanceof DERUTF8String)) { this.identifier = GeneralName.getInstance(seq.getObjectAt(1)); } else { this.identifier = (ASN1Encodable)seq.getObjectAt(1); } } else { this.identifier = null; } }
private MetaData(ASN1Sequence seq) { this.hashProtected = ASN1Boolean.getInstance(seq.getObjectAt(0)); int index = 1; if (index < seq.size() && seq.getObjectAt(index) instanceof DERUTF8String) { this.fileName = DERUTF8String.getInstance(seq.getObjectAt(index++)); } if (index < seq.size() && seq.getObjectAt(index) instanceof DERIA5String) { this.mediaType = DERIA5String.getInstance(seq.getObjectAt(index++)); } if (index < seq.size()) { this.otherMetaData = Attributes.getInstance(seq.getObjectAt(index++)); } }
@Override public ASN1Primitive toASN1Primitive() { ASN1EncodableVector vector = new ASN1EncodableVector(); vector.add(new Asn1P11SlotIdentifier(slotId)); vector.add(new DERUTF8String(label)); vector.add(new ASN1Integer(keysize)); if (publicExponent != null) { vector.add(new ASN1Integer(publicExponent)); } return new DERSequence(vector); }
private static Pair<String, String> parseOtherName(byte[] otherName) { try { ASN1Primitive asn1Primitive = ASN1Primitive.fromByteArray(otherName); if (asn1Primitive instanceof DERTaggedObject) { ASN1Primitive inner = ((DERTaggedObject) asn1Primitive).getObject(); if (inner instanceof DLSequence) { DLSequence sequence = (DLSequence) inner; if (sequence.size() >= 2 && sequence.getObjectAt(1) instanceof DERTaggedObject) { String oid = sequence.getObjectAt(0).toString(); ASN1Primitive value = ((DERTaggedObject) sequence.getObjectAt(1)).getObject(); if (value instanceof DERUTF8String) { return new Pair<>(oid, ((DERUTF8String) value).getString()); } else if (value instanceof DERIA5String) { return new Pair<>(oid, ((DERIA5String) value).getString()); } } } } return null; } catch (IOException e) { return null; } }
private void checkConstruction( ContentHints hints, ASN1ObjectIdentifier contentType, DERUTF8String description) throws IOException { checkValues(hints, contentType, description); hints = ContentHints.getInstance(hints); checkValues(hints, contentType, description); ASN1InputStream aIn = new ASN1InputStream(hints.toASN1Primitive().getEncoded()); ASN1Sequence seq = (ASN1Sequence)aIn.readObject(); hints = ContentHints.getInstance(seq); checkValues(hints, contentType, description); }
private static OtherName parseOtherName(byte[] otherName) { try { ASN1Primitive asn1Primitive = ASN1Primitive.fromByteArray(otherName); if (asn1Primitive instanceof DERTaggedObject) { ASN1Primitive inner = ((DERTaggedObject) asn1Primitive).getObject(); if (inner instanceof DLSequence) { DLSequence sequence = (DLSequence) inner; if (sequence.size() >= 2 && sequence.getObjectAt(1) instanceof DERTaggedObject) { String oid = sequence.getObjectAt(0).toString(); ASN1Primitive value = ((DERTaggedObject) sequence.getObjectAt(1)).getObject(); if (value instanceof DERUTF8String) { return new OtherName(oid, ((DERUTF8String) value).getString()); } else if (value instanceof DERIA5String) { return new OtherName(oid, ((DERIA5String) value).getString()); } } } } return null; } catch (IOException e) { return null; } }
static void verifyCertificateCommonName(X500Name subject, String commonName) { List<AttributeTypeAndValue> attributesAndValues = Arrays.stream(subject.getRDNs()) .flatMap(rdn -> rdn.isMultiValued() ? Stream.of(rdn.getTypesAndValues()) : Stream.of(rdn.getFirst())) .filter(attr -> attr.getType() == BCStyle.CN) .collect(Collectors.toList()); if (attributesAndValues.size() != 1) { throw new IllegalArgumentException("Only 1 common name should be set"); } String actualCommonName = DERUTF8String.getInstance(attributesAndValues.get(0).getValue()).getString(); if (! actualCommonName.equals(commonName)) { throw new IllegalArgumentException("Expected common name to be " + commonName + ", but was " + actualCommonName); } }
CertificateTrustBlock(byte[] encoded) { ASN1Sequence seq = ASN1Sequence.getInstance(encoded); for (Enumeration en = seq.getObjects(); en.hasMoreElements();) { ASN1Encodable obj = (ASN1Encodable)en.nextElement(); if (obj instanceof ASN1Sequence) { this.uses = ASN1Sequence.getInstance(obj); } else if (obj instanceof ASN1TaggedObject) { this.prohibitions = ASN1Sequence.getInstance((ASN1TaggedObject)obj, false); } else if (obj instanceof DERUTF8String) { this.alias = DERUTF8String.getInstance(obj).getString(); } } }
ASN1Sequence toASN1Sequence() { ASN1EncodableVector v = new ASN1EncodableVector(); if (uses != null) { v.add(uses); } if (prohibitions != null) { v.add(new DERTaggedObject(false, 0, prohibitions)); } if (alias != null) { v.add(new DERUTF8String(alias)); } return new DERSequence(v); }
private static void populateTextField(Attribute[] attrs, JTextField textField, ASN1ObjectIdentifier pkcs9Attr) { if (attrs != null) { for (Attribute attribute : attrs) { ASN1ObjectIdentifier attributeOid = attribute.getAttrType(); if (attributeOid.equals(pkcs9Attr)) { ASN1Encodable challenge = attribute.getAttributeValues()[0]; // data type can be one of IA5String or UTF8String if (challenge instanceof DERPrintableString) { textField.setText(((DERPrintableString) challenge).getString()); } else if (challenge instanceof DERUTF8String) { textField.setText(((DERUTF8String) challenge).getString()); } textField.setCaretPosition(0); } } } }
ASN1Primitive toASN1Primitive(boolean includeChecksum) { DEROctetString checksumEncodable = includeChecksum ? new DEROctetString(checksum()) : null; ASN1Integer flagsEncodable = flags.map(ASN1Integer::new) .orElse(null); ASN1EncodableVector vector = DER.vector( new DERUTF8String(name), DER.toSet(keys), DER.toSet(serviceKeyIDs), checksumEncodable, flagsEncodable, signatureInfo.orElse(null)); DERSequence sequence = new DERSequence(vector); return DER.toApplicationSpecific(APPLICATION_TAG, sequence); }
@Override public ASN1Primitive toASN1Primitive() { ASN1EncodableVector v = new ASN1EncodableVector(); v.add(new DERUTF8String(boardName)); v.add(new DERUTF8String(host)); v.add(new ASN1Integer(messageCount)); if (backupHost != null) { v.add(new DERUTF8String(backupHost)); } return new DERSequence(v); }
@Override public ASN1Primitive toASN1Primitive() { ASN1EncodableVector out = new ASN1EncodableVector(); Iterator<Map.Entry<String, Object>> it = values.entrySet().iterator(); while (it.hasNext()) { ASN1EncodableVector pair = new ASN1EncodableVector(); Map.Entry<String, Object> entry = it.next(); pair.add(new DERUTF8String(entry.getKey())); pair.add(objToASNType(entry.getValue())); out.add(new DERSequence(pair)); } return new DERSequence(out); }
@Override public ASN1Primitive toASN1Primitive() { ASN1EncodableVector v = new ASN1EncodableVector(); v.add(new DERUTF8String(boardName)); ASN1EncodableVector dataV = new ASN1EncodableVector(); for (int i = 0; i != data.length; i++) { dataV.add(new DEROctetString(data[i])); } v.add(new DERSequence(dataV)); return new DERSequence(v); }
@Override public ASN1Primitive toASN1Primitive() { ASN1EncodableVector v = new ASN1EncodableVector(); ASN1EncodableVector mv = new ASN1EncodableVector(); for (byte[] message : messages) { mv.add(new DEROctetString(message)); } v.add(new DERUTF8String(keyID)); v.add(new DERSequence(mv)); return new DERSequence(v); }
private PermuteAndMoveMessage(ASN1Sequence seq) { this.operationNumber = ASN1Integer.getInstance(seq.getObjectAt(0)).getValue().longValue(); this.boardName = DERUTF8String.getInstance(seq.getObjectAt(1)).getString(); this.stepNumber = ASN1Integer.getInstance(seq.getObjectAt(2)).getValue().intValue(); this.transformName = DERUTF8String.getInstance(seq.getObjectAt(3)).getString(); if (seq.size() == 6) { this.keyID = DERUTF8String.getInstance(seq.getObjectAt(4)).getString(); this.nodeName = DERUTF8String.getInstance(seq.getObjectAt(5)).getString(); } else { this.keyID = null; this.nodeName = DERUTF8String.getInstance(seq.getObjectAt(4)).getString(); } }
@Override public ASN1Primitive toASN1Primitive() { ASN1EncodableVector v = new ASN1EncodableVector(); v.add(new ASN1Integer(BigInteger.valueOf(operationNumber))); v.add(new DERUTF8String(boardName)); v.add(new ASN1Integer(BigInteger.valueOf(stepNumber))); v.add(new DERUTF8String(transformName)); if (keyID != null) { v.add(new DERUTF8String(keyID)); } v.add(new DERUTF8String(nodeName)); return new DERSequence(v); }
@Override public ASN1Primitive toASN1Primitive() { ASN1EncodableVector v = new ASN1EncodableVector(); v.add(new ASN1Integer(queryID)); v.add(new DERUTF8String(boardName)); ASN1EncodableVector stepV = new ASN1EncodableVector(); for (int i = 0; i != stepNos.length; i++) { stepV.add(new ASN1Integer(stepNos[i])); } v.add(new DERSequence(stepV)); return new DERSequence(v); }
/** * Get UPN String. * * @param seq ASN1Sequence abstraction representing subject alternative name. * First element is the object identifier, second is the object itself. * * @return UPN string or null */ private String getUPNStringFromSequence(final ASN1Sequence seq) { if (seq != null) { // First in sequence is the object identifier, that we must check final DERObjectIdentifier id = DERObjectIdentifier.getInstance(seq.getObjectAt(0)); if (id != null && UPN_OBJECTID.equals(id.getId())) { final ASN1TaggedObject obj = (ASN1TaggedObject) seq.getObjectAt(1); final DERUTF8String str = DERUTF8String.getInstance(obj.getObject()); return str.getString(); } } return null; }
/** * Creates a new <code>DisplayText</code> instance. * * @param text the text to encapsulate. Strings longer than 200 * characters are truncated. */ public DisplayText(String text) { // by default use UTF8String if (text.length() > DISPLAY_TEXT_MAXIMUM_SIZE) { text = text.substring(0, DISPLAY_TEXT_MAXIMUM_SIZE); } contentType = CONTENT_TYPE_UTF8STRING; contents = new DERUTF8String(text); }
/** * Apply default coversion for the given value depending on the oid * and the character range of the value. * * @param oid the object identifier for the DN entry * @param value the value associated with it * @return the ASN.1 equivalent for the string value. */ public ASN1Primitive getConvertedValue( ASN1ObjectIdentifier oid, String value) { if (value.length() != 0 && value.charAt(0) == '#') { try { return convertHexEncoded(value, 1); } catch (IOException e) { throw new RuntimeException("can't recode value for oid " + oid.getId()); } } else { if (value.length() != 0 && value.charAt(0) == '\\') { value = value.substring(1); } if (oid.equals(X509Name.EmailAddress) || oid.equals(X509Name.DC)) { return new DERIA5String(value); } else if (oid.equals(X509Name.DATE_OF_BIRTH)) // accept time string as well as # (for compatibility) { return new DERGeneralizedTime(value); } else if (oid.equals(X509Name.C) || oid.equals(X509Name.SN) || oid.equals(X509Name.DN_QUALIFIER) || oid.equals(X509Name.TELEPHONE_NUMBER)) { return new DERPrintableString(value); } } return new DERUTF8String(value); }
private SignerLocation( ASN1Sequence seq) { Enumeration e = seq.getObjects(); while (e.hasMoreElements()) { DERTaggedObject o = (DERTaggedObject)e.nextElement(); switch (o.getTagNo()) { case 0: DirectoryString countryNameDirectoryString = DirectoryString.getInstance(o, true); this.countryName = new DERUTF8String(countryNameDirectoryString.getString()); break; case 1: DirectoryString localityNameDirectoryString = DirectoryString.getInstance(o, true); this.localityName = new DERUTF8String(localityNameDirectoryString.getString()); break; case 2: if (o.isExplicit()) { this.postalAddress = ASN1Sequence.getInstance(o, true); } else // handle erroneous implicitly tagged sequences { this.postalAddress = ASN1Sequence.getInstance(o, false); } if (postalAddress != null && postalAddress.size() > 6) { throw new IllegalArgumentException("postal address must contain less than 6 strings"); } break; default: throw new IllegalArgumentException("illegal tag"); } } }
public MetaData( ASN1Boolean hashProtected, DERUTF8String fileName, DERIA5String mediaType, Attributes otherMetaData) { this.hashProtected = hashProtected; this.fileName = fileName; this.mediaType = mediaType; this.otherMetaData = otherMetaData; }
private PKIFreeText( ASN1Sequence seq) { Enumeration e = seq.getObjects(); while (e.hasMoreElements()) { if (!(e.nextElement() instanceof DERUTF8String)) { throw new IllegalArgumentException("attempt to insert non UTF8 STRING into PKIFreeText"); } } strings = seq; }