use of com.github.zhenwei.core.asn1.DERIA5String in project keystore-explorer by kaikramer.
the class DSelectStandardExtensionTemplate method addSAN.
private void addSAN(X509ExtensionSet extensionSet, X500Name subjectDN) throws IOException {
GeneralName[] generalNames = new GeneralName[1];
if (subjectDN == null) {
// add extension but without value so we can remind the user later to add a value
generalNames[0] = new GeneralName(GeneralName.dNSName, new DERIA5String(""));
} else {
// if subject DN already exists, we use value of CN
String cn = X500NameUtils.extractCN(subjectDN);
if (cn == "") {
generalNames[0] = new GeneralName(GeneralName.dNSName, new DERIA5String(""));
} else {
if (IPAddress.isValid(cn)) {
generalNames[0] = new GeneralName(GeneralName.iPAddress, cn);
} else {
generalNames[0] = new GeneralName(GeneralName.dNSName, new DERIA5String(cn));
}
}
}
byte[] sanEncoded = X509Ext.wrapInOctetString(new GeneralNames(generalNames).getEncoded());
extensionSet.addExtension(X509ExtensionType.SUBJECT_ALTERNATIVE_NAME.oid(), false, sanEncoded);
}
use of com.github.zhenwei.core.asn1.DERIA5String in project keystore-explorer by kaikramer.
the class DPolicyQualifierInfoChooser method okPressed.
private void okPressed() {
PolicyQualifierInfo newPolicyQualifierInfo = null;
try {
if (jrbCps.isSelected()) {
String cps = jtfCps.getText().trim();
if (cps.length() == 0) {
JOptionPane.showMessageDialog(this, res.getString("DPolicyQualifierInfoChooser.CpsValueReq.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
}
newPolicyQualifierInfo = new PolicyQualifierInfo(new ASN1ObjectIdentifier(PKIX_CPS_POINTER_QUALIFIER.oid()), (new DERIA5String(cps)).toASN1Primitive());
} else {
UserNotice userNotice = junUserNotice.getUserNotice();
if (userNotice == null) {
JOptionPane.showMessageDialog(this, res.getString("DPolicyQualifierInfoChooser.UserNoticeValueReq.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
}
newPolicyQualifierInfo = new PolicyQualifierInfo(new ASN1ObjectIdentifier(PKIX_USER_NOTICE_QUALIFIER.oid()), userNotice);
}
} catch (Exception e) {
DError.displayError(this, e);
return;
}
policyQualifierInfo = newPolicyQualifierInfo;
closeDialog();
}
use of com.github.zhenwei.core.asn1.DERIA5String in project signer by demoiselle.
the class IdSigningPolicy method getValue.
/**
* org.bouncycastle.asn1.ASN1ObjectIdentifier sigPolicyId
* org.bouncycastle.asn1.esf.OtherHashAlgAndValue sigPolicyHash
* List<org.bouncycastle.asn1.esf.SigPolicyQualifierInfo> sigPolicyQualifierInfos
*/
@Override
public Attribute getValue() {
// Atributo 1
ASN1ObjectIdentifier sigPolicyId = new ASN1ObjectIdentifier(signaturePolicy.getSignPolicyInfo().getSignPolicyIdentifier().getValue());
// Atributo 2
OtherHashAlgAndValue sigPolicyHash = new OtherHashAlgAndValue(new AlgorithmIdentifier(new ASN1ObjectIdentifier(signaturePolicy.getSignPolicyHashAlg().getAlgorithm().getValue())), signaturePolicy.getSignPolicyHash().getDerOctetString());
// Atributo 3
List<SigPolicyQualifierInfo> sigPolicyQualifierInfos = new ArrayList<SigPolicyQualifierInfo>();
ASN1ObjectIdentifier sigPolicyQualifierId = new ASN1ObjectIdentifier("1.2.840.113549.1.9.16.5.1");
DERIA5String sigQualifier = new DERIA5String(signaturePolicy.getSignPolicyURI());
SigPolicyQualifierInfo bcSigPolicyQualifierInfo = new SigPolicyQualifierInfo(sigPolicyQualifierId, sigQualifier);
sigPolicyQualifierInfos.add(bcSigPolicyQualifierInfo);
SigPolicyQualifiers sigPolicyQualifiers = new SigPolicyQualifiers(sigPolicyQualifierInfos.toArray(new SigPolicyQualifierInfo[] {}));
SignaturePolicyId signaturePolicyId = new SignaturePolicyId(sigPolicyId, sigPolicyHash, sigPolicyQualifiers);
return new Attribute(identifier, new DERSet(signaturePolicyId));
}
use of com.github.zhenwei.core.asn1.DERIA5String in project signer by demoiselle.
the class PolicyInfo method parse.
@Override
public void parse(ASN1Primitive primitive) {
ASN1Sequence sequence1 = ASN1Object.getDERSequence(primitive);
this.signingPeriod = new SigningPeriod();
this.signingPeriod.parse(sequence1.getObjectAt(0).toASN1Primitive());
int indice = 2;
ASN1Primitive secondObject = sequence1.getObjectAt(1).toASN1Primitive();
if (secondObject instanceof ASN1ObjectIdentifier) {
indice = 1;
}
if (indice == 2) {
this.revocationDate = new GeneralizedTime();
this.revocationDate.parse(secondObject);
}
this.policyOID = new ObjectIdentifier();
this.policyOID.parse(sequence1.getObjectAt(indice).toASN1Primitive());
DERIA5String policyURI = (DERIA5String) sequence1.getObjectAt(indice + 1);
this.policyURI = policyURI.getString();
ASN1Primitive policyDigest = sequence1.getObjectAt(indice + 2).toASN1Primitive();
ASN1Sequence sequence2 = ASN1Sequence.getInstance(policyDigest);
DEROctetString derOctetString = (DEROctetString) sequence2.getObjectAt(1).toASN1Primitive();
ASN1Sequence sequence3 = ASN1Object.getDERSequence(sequence2.getObjectAt(0).toASN1Primitive());
ASN1ObjectIdentifier objectIdentifier = (ASN1ObjectIdentifier) sequence3.getObjectAt(0).toASN1Primitive();
AlgorithmIdentifier algorithmIdentifier = new AlgorithmIdentifier(objectIdentifier);
this.policyDigest = new OtherHashAlgAndValue(algorithmIdentifier, derOctetString);
}
use of com.github.zhenwei.core.asn1.DERIA5String in project signer by demoiselle.
the class OIDGeneric method getInstance.
/**
* Instance for OIDGeneric.
*
* @param data Set of bytes with the contents of the certificate.
* @return Object GenericOID
* @throws IOException exception of input/output
* @throws Exception general exception
*/
public static OIDGeneric getInstance(byte[] data) throws IOException, Exception {
is = new ASN1InputStream(data);
DLSequence sequence = (DLSequence) is.readObject();
ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier) sequence.getObjectAt(0);
DERTaggedObject taggedObject = (DERTaggedObject) sequence.getObjectAt(1);
DERTaggedObject taggedObject2 = (DERTaggedObject) taggedObject.getObject();
DEROctetString octet = null;
DERPrintableString print = null;
DERUTF8String utf8 = null;
DERIA5String ia5 = null;
try {
octet = (DEROctetString) taggedObject2.getObject();
} catch (Exception e) {
try {
print = (DERPrintableString) taggedObject2.getObject();
} catch (Exception e1) {
try {
utf8 = (DERUTF8String) taggedObject2.getObject();
} catch (Exception e2) {
ia5 = (DERIA5String) taggedObject2.getObject();
}
}
}
String className = getPackageName() + oid.getId().replaceAll("[.]", "_");
OIDGeneric oidGenerico;
try {
oidGenerico = (OIDGeneric) Class.forName(className).newInstance();
} catch (InstantiationException e) {
throw new Exception(coreMessagesBundle.getString("error.class.instance", className), e);
} catch (IllegalAccessException e) {
throw new Exception(coreMessagesBundle.getString("error.class.illegal.access", className), e);
} catch (ClassNotFoundException e) {
oidGenerico = new OIDGeneric();
}
oidGenerico.oid = oid.getId();
if (octet != null) {
oidGenerico.data = new String(octet.getOctets());
} else {
if (print != null) {
oidGenerico.data = print.getString();
} else {
if (utf8 != null) {
oidGenerico.data = utf8.getString();
} else {
oidGenerico.data = ia5.getString();
}
}
}
oidGenerico.initialize();
return oidGenerico;
}
Aggregations