Java Code Examples for org.bouncycastle.asn1.x500.DirectoryString

The following examples show how to use org.bouncycastle.asn1.x500.DirectoryString. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: signer   Source File: PolicyInfo.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void parse(ASN1Primitive derObject) {
    ASN1Sequence derSequence = ASN1Object.getDERSequence(derObject);
    ASN1Primitive firstObject = derSequence.getObjectAt(0).toASN1Primitive();
    this.policyName = new DirectoryString(firstObject.toString());
    ASN1Primitive secondObject = derSequence.getObjectAt(1).toASN1Primitive();
    String fieldOfApplication = secondObject.toString();
    this.fieldOfApplication = new DirectoryString(fieldOfApplication);
    this.signingPeriod = new SigningPeriod();
    this.signingPeriod.parse(derSequence.getObjectAt(2).toASN1Primitive());

    int indice = 3;
    ASN1Primitive revocationObject = derSequence.getObjectAt(indice).toASN1Primitive();
    if (!(secondObject instanceof DERTaggedObject)) {
        indice = 4;
    }
    if (indice == 3) {
        this.revocationDate = new Time();
        this.revocationDate.parse(revocationObject);
    }
}
 
Example 2
Source Project: keystore-explorer   Source File: X509Ext.java    License: GNU General Public License v3.0 5 votes vote down vote up
private String getAttributeValueString(ASN1ObjectIdentifier attributeType, ASN1Encodable attributeValue)
		throws IOException {

	/* AttributeValue ::= ANY  */

	// Get value string for recognized attribute types
	AttributeTypeType attributeTypeType = AttributeTypeType.resolveOid(attributeType.getId());

	switch (attributeTypeType) {
	case DATE_OF_BIRTH:
		return getGeneralizedTimeString(ASN1GeneralizedTime.getInstance(attributeValue));
	case SERIAL_NUMBER:
	case UNSTRUCTURED_ADDRESS:
	case COUNTRY_NAME:
	case GENDER:
	case COUNTRY_OF_CITIZENSHIP:
	case COUNTRY_OF_RESIDENCE:
		return DERPrintableString.getInstance(attributeValue).getString();
	case COMMON_NAME:
	case LOCALITY_NAME:
	case STATE_NAME:
	case STREET_ADDRESS:
	case ORGANIZATION_NAME:
	case ORGANIZATIONAL_UNIT:
	case TITLE:
	case USER_ID:
	case PLACE_OF_BIRTH:
		return DirectoryString.getInstance(attributeValue).getString();
	case MAIL:
	case EMAIL_ADDRESS:
	case UNSTRUCTURED_NAME:
	case DOMAIN_COMPONENT:
		return DERIA5String.getInstance(attributeValue).getString();
	default:
		// Attribute type not recognized - return hex string for value
		return HexUtil.getHexString(attributeValue.toASN1Primitive().getEncoded());
	}
}
 
Example 3
Source Project: keystore-explorer   Source File: X509Ext.java    License: GNU General Public License v3.0 5 votes vote down vote up
private String getNamingAuthorityStringValue(NamingAuthority namingAuthority, int indentLevel)
		throws IOException {
	// @formatter:off
	/*
	     NamingAuthority ::= SEQUENCE
	     {
	       namingAuthorityId OBJECT IDENTIFIER OPTIONAL,
	       namingAuthorityUrl IA5String OPTIONAL,
	       namingAuthorityText DirectoryString(SIZE(1..128)) OPTIONAL
	     }
	 */
	// @formatter:on

	StringBuilder sb = new StringBuilder();

	ASN1ObjectIdentifier namingAuthorityId = namingAuthority.getNamingAuthorityId();
	String namingAuthorityUrl = namingAuthority.getNamingAuthorityUrl();
	DirectoryString namingAuthorityText = namingAuthority.getNamingAuthorityText();

	if (namingAuthorityId != null) {
		sb.append(INDENT.toString(indentLevel));
		sb.append(MessageFormat.format(res.getString("Admission.NamingAuthorityOID"), namingAuthorityId.getId()));
		sb.append(NEWLINE);
	}

	if (namingAuthorityUrl != null) {
		sb.append(INDENT.toString(indentLevel));
		sb.append(MessageFormat.format(res.getString("Admission.NamingAuthorityURL"), namingAuthorityUrl));
		sb.append(NEWLINE);
	}

	if (namingAuthorityText != null) {
		sb.append(INDENT.toString(indentLevel));
		sb.append(MessageFormat.format(res.getString("Admission.NamingAuthorityText"),
				namingAuthorityText.toString()));
		sb.append(NEWLINE);
	}

	return sb.toString();
}
 
Example 4
Source Project: xipki   Source File: ExtensionType.java    License: Apache License 2.0 5 votes vote down vote up
private static NamingAuthority buildNamingAuthority(NamingAuthorityType value) {
  ASN1ObjectIdentifier oid = (value.getOid() == null) ? null
      : new ASN1ObjectIdentifier(value.getOid().getOid());
  String url = StringUtil.isBlank(value.getUrl()) ? null : value.getUrl();
  DirectoryString text = StringUtil.isBlank(value.getText()) ? null
      : new DirectoryString(value.getText());
  return new NamingAuthority(oid, url, text);
}
 
Example 5
Source Project: signer   Source File: PolicyInfo.java    License: GNU Lesser General Public License v3.0 4 votes vote down vote up
public DirectoryString getPolicyName() {
    return policyName;
}
 
Example 6
Source Project: signer   Source File: PolicyInfo.java    License: GNU Lesser General Public License v3.0 4 votes vote down vote up
public void setPolicyName(DirectoryString policyName) {
    this.policyName = policyName;
}
 
Example 7
Source Project: signer   Source File: PolicyInfo.java    License: GNU Lesser General Public License v3.0 4 votes vote down vote up
public DirectoryString getFieldOfApplication() {
    return fieldOfApplication;
}
 
Example 8
Source Project: signer   Source File: PolicyInfo.java    License: GNU Lesser General Public License v3.0 4 votes vote down vote up
public void setFieldOfApplication(DirectoryString fieldOfApplication) {
    this.fieldOfApplication = fieldOfApplication;
}
 
Example 9
Source Project: keystore-explorer   Source File: X509Ext.java    License: GNU General Public License v3.0 4 votes vote down vote up
private String getProcurationStringValue(byte[] octets) throws IOException {

		// @formatter:off

		/*
			ProcurationSyntax ::= SEQUENCE
			{
				country [1] EXPLICIT PrintableString(SIZE(2)) OPTIONAL,
				typeOfSubstitution [2] EXPLICIT DirectoryString(SIZE(1..128)) OPTIONAL,
				signingFor [3] EXPLICIT SigningFor
			}

			SigningFor ::= CHOICE
			{
				thirdPerson GeneralName,
				certRef IssuerSerial
			}
		 */

		// @formatter:on

		StringBuilder sb = new StringBuilder();

		ProcurationSyntax procurationSyntax = ProcurationSyntax.getInstance(octets);
		String country = procurationSyntax.getCountry();
		DirectoryString typeOfSubstitution = procurationSyntax.getTypeOfSubstitution();
		GeneralName thirdPerson = procurationSyntax.getThirdPerson();
		IssuerSerial certRef = procurationSyntax.getCertRef();

		if (country != null) {
			sb.append(MessageFormat.format(res.getString("Procuration.Country"), country));
			sb.append(NEWLINE);
		}

		if (typeOfSubstitution != null) {
			sb.append(MessageFormat.format(res.getString("Procuration.TypeOfSubstitution"),
					typeOfSubstitution.toString()));
			sb.append(NEWLINE);
		}

		if (thirdPerson != null) {
			sb.append(MessageFormat.format(res.getString("Procuration.ThirdPerson"),
					GeneralNameUtil.toString(thirdPerson)));
			sb.append(NEWLINE);
		}

		if (certRef != null) {
			sb.append(res.getString("Procuration.CertRef"));
			sb.append(NEWLINE);

			sb.append(INDENT);
			sb.append(res.getString("Procuration.CertRef.Issuer"));
			for (GeneralName generalName : certRef.getIssuer().getNames()) {
				sb.append(INDENT);
				sb.append(INDENT);
				sb.append(GeneralNameUtil.toString(generalName));
				sb.append(NEWLINE);
			}
			sb.append(NEWLINE);

			sb.append(INDENT);
			sb.append(MessageFormat.format(res.getString("Procuration.CertRef.SN"),
					HexUtil.getHexString(certRef.getSerial().getValue())));
			sb.append(NEWLINE);
		}

		return sb.toString();
	}
 
Example 10
Source Project: dss   Source File: CAdESSignature.java    License: GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public SignatureProductionPlace getSignatureProductionPlace() {
	Attribute signatureProductionPlaceAttr = getSignedAttribute(PKCSObjectIdentifiers.id_aa_ets_signerLocation);
	if (signatureProductionPlaceAttr == null) {
		return null;
	}

	final ASN1Encodable asn1Encodable = signatureProductionPlaceAttr.getAttrValues().getObjectAt(0);
	SignerLocation signerLocation = null;
	try {
		signerLocation = SignerLocation.getInstance(asn1Encodable);
	} catch (Exception e) {
		LOG.error(e.getMessage(), e);
	}
	if (signerLocation == null) {
		return null;
	}
	final SignatureProductionPlace signatureProductionPlace = new SignatureProductionPlace();
	final DirectoryString countryName = signerLocation.getCountry();
	if (countryName != null) {
		signatureProductionPlace.setCountryName(countryName.getString());
	}
	final DirectoryString localityName = signerLocation.getLocality();
	if (localityName != null) {
		signatureProductionPlace.setCity(localityName.getString());
	}
	final StringBuilder address = new StringBuilder();
	final ASN1Sequence seq = signerLocation.getPostalAddress();
	if (seq != null) {

		for (int ii = 0; ii < seq.size(); ii++) {

			if (seq.getObjectAt(ii) instanceof DEROctetString) {
				if (address.length() > 0) {
					address.append(" / ");
				}
				// TODO: getOctets returns an array
				address.append(new String(((DEROctetString) seq.getObjectAt(ii)).getOctets()));
			} else if (seq.getObjectAt(ii) instanceof DERUTF8String) {

				if (address.length() > 0) {
					address.append(" / ");
				}
				final DERUTF8String derutf8String = (DERUTF8String) seq.getObjectAt(ii);
				address.append(derutf8String.getString());
			}
		}
	}
	signatureProductionPlace.setStreetAddress(address.toString());
	// This property is not used in CAdES version of signature
	// signatureProductionPlace.setStateOrProvince(stateOrProvince);
	return signatureProductionPlace;
}
 
Example 11
Source Project: keystore-explorer   Source File: X509Ext.java    License: GNU General Public License v3.0 2 votes vote down vote up
private String getRestrictionStringValue(byte[] octets) throws IOException {

		/*	RestrictionSyntax ::= DirectoryString (SIZE(1..1024)) */

		return DirectoryString.getInstance(ASN1Primitive.fromByteArray(octets)).toString();
	}
 
Example 12
Source Project: keystore-explorer   Source File: X509Ext.java    License: GNU General Public License v3.0 2 votes vote down vote up
private String getAdditionalInformationStringValue(byte[] octets) throws IOException {

		/*	AdditionalInformationSyntax ::= DirectoryString (SIZE(1..2048)) */

		return DirectoryString.getInstance(ASN1Primitive.fromByteArray(octets)).toString();
	}