use of com.github.zhenwei.core.asn1.DERIA5String in project keystore-explorer by kaikramer.
the class DGeneralNameChooser method okPressed.
private void okPressed() {
try {
GeneralName newGeneralName = null;
if (jrbDirectoryName.isSelected()) {
X500Name directoryName = jdnDirectoryName.getDistinguishedName();
if (directoryName == null) {
JOptionPane.showMessageDialog(this, res.getString("DGeneralNameChooser.DirectoryNameValueReq.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
}
newGeneralName = new GeneralName(GeneralName.directoryName, directoryName);
} else if (jrbDnsName.isSelected()) {
String dnsName = jtfDnsName.getText().trim();
if (dnsName.length() == 0) {
JOptionPane.showMessageDialog(this, res.getString("DGeneralNameChooser.DnsNameValueReq.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
}
newGeneralName = new GeneralName(GeneralName.dNSName, new DERIA5String(dnsName));
} else if (jrbIpAddress.isSelected()) {
String ipAddress = jtfIpAddress.getText().trim();
if (ipAddress.length() == 0) {
JOptionPane.showMessageDialog(this, res.getString("DGeneralNameChooser.IpAddressValueReq.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
}
if (ipAddress.indexOf('/') == -1) {
if (!IPAddress.isValid(ipAddress)) {
JOptionPane.showMessageDialog(this, res.getString("DGeneralNameChooser.NotAValidIP.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
}
} else {
if (!IPAddress.isValidWithNetMask(ipAddress)) {
JOptionPane.showMessageDialog(this, res.getString("DGeneralNameChooser.NotAValidIP.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
}
}
newGeneralName = new GeneralName(GeneralName.iPAddress, ipAddress);
} else if (jrbRegisteredId.isSelected()) {
ASN1ObjectIdentifier registeredId = joiRegisteredId.getObjectId();
if (registeredId == null) {
JOptionPane.showMessageDialog(this, res.getString("DGeneralNameChooser.RegisteredIdValueReq.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
}
newGeneralName = new GeneralName(GeneralName.registeredID, registeredId);
} else if (jrbRfc822Name.isSelected()) {
String rfc822Name = jtfRfc822Name.getText().trim();
if (rfc822Name.length() == 0) {
JOptionPane.showMessageDialog(this, res.getString("DGeneralNameChooser.Rfc822NameValueReq.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
}
newGeneralName = new GeneralName(GeneralName.rfc822Name, new DERIA5String(rfc822Name));
} else if (jrbUniformResourceIdentifier.isSelected()) {
String uniformResourceIdentifier = jtfUniformResourceIdentifier.getText().trim();
if (uniformResourceIdentifier.length() == 0) {
JOptionPane.showMessageDialog(this, res.getString("DGeneralNameChooser.UniformResourceIdentifierValueReq.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
}
newGeneralName = new GeneralName(GeneralName.uniformResourceIdentifier, new DERIA5String(uniformResourceIdentifier));
} else if (jrbPrincipalName.isSelected()) {
String upnString = jtfPrincipalName.getText().trim();
if (upnString.length() == 0) {
JOptionPane.showMessageDialog(this, res.getString("DGeneralNameChooser.PrincipalNameValueReq.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
}
ASN1EncodableVector asn1Vector = new ASN1EncodableVector();
asn1Vector.add(new ASN1ObjectIdentifier(GeneralNameUtil.UPN_OID));
asn1Vector.add(new DERTaggedObject(true, 0, new DERUTF8String(upnString)));
newGeneralName = new GeneralName(GeneralName.otherName, new DERSequence(asn1Vector));
}
generalName = newGeneralName;
} catch (Exception e) {
DError.displayError(this, e);
return;
}
closeDialog();
}
use of com.github.zhenwei.core.asn1.DERIA5String in project keystore-explorer by kaikramer.
the class X509Ext method getCertificatePoliciesStringValue.
private static String getCertificatePoliciesStringValue(byte[] value) throws IOException {
// @formatter:off
/*
* CertificatePolicies ::= ASN1Sequence SIZE (1..MAX) OF PolicyInformation
*
* PolicyInformation ::= ASN1Sequence
* {
* policyIdentifier CertPolicyId,
* policyQualifiers ASN1Sequence SIZE (1..MAX) OF PolicyQualifierInfo OPTIONAL
* }
*
* CertPolicyId ::= OBJECT IDENTIFIER
*
* PolicyQualifierInfo ::= ASN1Sequence
* {
* policyQualifierId PolicyQualifierId,
* qualifier ANY DEFINED BY policyQualifierId
* }
*
* PolicyQualifierId ::= OBJECT IDENTIFIER ( id-qt-cps | id-qt-unotice )
*
* Qualifier ::= CHOICE
* {
* cPSuri CPSuri,
* userNotice UserNotice
* }
*
* CPSuri ::= DERIA5String
*
* UserNotice ::= ASN1Sequence
* {
* noticeRef NoticeReference OPTIONAL,
* explicitText DisplayText OPTIONAL
* }
*
* NoticeReference ::= ASN1Sequence
* {
* organization DisplayText,
* noticeNumbers ASN1Sequence OF ASN1Integer
* }
*
* DisplayText ::= CHOICE
* {
* ia5String DERIA5String (SIZE (1..200)),
* visibleString VisibleString (SIZE (1..200)),
* bmpString BMPString (SIZE (1..200)),
* utf8String UTF8String (SIZE (1..200))
* }
*/
// @formatter:on
StringBuilder sb = new StringBuilder();
CertificatePolicies certificatePolicies = CertificatePolicies.getInstance(value);
int certPolicy = 0;
for (PolicyInformation policyInformation : certificatePolicies.getPolicyInformation()) {
certPolicy++;
sb.append(MessageFormat.format(res.getString("CertificatePolicy"), certPolicy));
sb.append(NEWLINE);
ASN1ObjectIdentifier policyIdentifier = policyInformation.getPolicyIdentifier();
String policyIdentifierStr = ObjectIdUtil.toString(policyIdentifier);
sb.append(INDENT);
sb.append(MessageFormat.format(res.getString("PolicyIdentifier"), policyIdentifierStr));
sb.append(NEWLINE);
ASN1Sequence policyQualifiers = policyInformation.getPolicyQualifiers();
if (policyQualifiers != null) {
// Optional
int policyQual = 0;
for (ASN1Encodable policyQualifier : policyQualifiers.toArray()) {
ASN1Sequence policyQualifierInfo = (ASN1Sequence) policyQualifier;
sb.append(INDENT.toString(1));
sb.append(MessageFormat.format(res.getString("PolicyQualifierInformation"), certPolicy, ++policyQual));
sb.append(NEWLINE);
ASN1ObjectIdentifier policyQualifierId = (ASN1ObjectIdentifier) policyQualifierInfo.getObjectAt(0);
CertificatePolicyQualifierType certificatePolicyQualifierType = CertificatePolicyQualifierType.resolveOid(policyQualifierId.getId());
if (certificatePolicyQualifierType != null) {
sb.append(INDENT.toString(2));
sb.append(certificatePolicyQualifierType.friendly());
sb.append(NEWLINE);
if (certificatePolicyQualifierType == PKIX_CPS_POINTER_QUALIFIER) {
DERIA5String cpsPointer = (DERIA5String) policyQualifierInfo.getObjectAt(1);
sb.append(INDENT.toString(2));
sb.append(MessageFormat.format(res.getString("CpsPointer"), "<a href=\"" + cpsPointer + "\">" + cpsPointer + "</a>"));
sb.append(NEWLINE);
} else if (certificatePolicyQualifierType == PKIX_USER_NOTICE_QUALIFIER) {
ASN1Encodable userNoticeObj = policyQualifierInfo.getObjectAt(1);
UserNotice userNotice = UserNotice.getInstance(userNoticeObj);
sb.append(INDENT.toString(2));
sb.append(res.getString("UserNotice"));
sb.append(NEWLINE);
NoticeReference noticeReference = userNotice.getNoticeRef();
DisplayText explicitText = userNotice.getExplicitText();
if (noticeReference != null) {
// Optional
sb.append(INDENT.toString(3));
sb.append(res.getString("NoticeReference"));
sb.append(NEWLINE);
DisplayText organization = noticeReference.getOrganization();
String organizationString = organization.getString();
sb.append(INDENT.toString(4));
sb.append(MessageFormat.format(res.getString("Organization"), organizationString));
sb.append(NEWLINE);
ASN1Integer[] noticeNumbers = noticeReference.getNoticeNumbers();
StringBuilder sbNoticeNumbers = new StringBuilder();
for (ASN1Integer noticeNumber : noticeNumbers) {
sbNoticeNumbers.append(noticeNumber.getValue().intValue());
sbNoticeNumbers.append(", ");
}
sbNoticeNumbers.setLength(sbNoticeNumbers.length() - 2);
sb.append(INDENT.toString(4));
sb.append(MessageFormat.format(res.getString("NoticeNumbers"), sbNoticeNumbers.toString()));
sb.append(NEWLINE);
}
if (explicitText != null) {
// Optional
String explicitTextString = explicitText.getString();
sb.append(INDENT.toString(3));
sb.append(MessageFormat.format(res.getString("ExplicitText"), explicitTextString));
sb.append(NEWLINE);
}
}
}
}
}
}
return sb.toString();
}
use of com.github.zhenwei.core.asn1.DERIA5String in project keystore-explorer by kaikramer.
the class PolicyInformationUtil method toString.
/**
* Get string representation of policy qualifier info.
*
* @param policyQualifierInfo Policy qualifier info
* @return String representation of policy qualifier info
* @throws IOException If policy qualifier info is invalid
*/
public static String toString(PolicyQualifierInfo policyQualifierInfo) throws IOException {
StringBuilder sbPolicyQualifier = new StringBuilder();
ASN1ObjectIdentifier policyQualifierId = policyQualifierInfo.getPolicyQualifierId();
CertificatePolicyQualifierType certificatePolicyQualifierType = CertificatePolicyQualifierType.resolveOid(policyQualifierId.getId());
if (certificatePolicyQualifierType == PKIX_CPS_POINTER_QUALIFIER) {
DERIA5String cpsPointer = ((DERIA5String) policyQualifierInfo.getQualifier());
sbPolicyQualifier.append(MessageFormat.format(res.getString("PolicyInformationUtil.CpsPointer"), cpsPointer));
} else if (certificatePolicyQualifierType == PKIX_USER_NOTICE_QUALIFIER) {
ASN1Encodable userNoticeObj = policyQualifierInfo.getQualifier();
UserNotice userNotice = UserNotice.getInstance(userNoticeObj);
sbPolicyQualifier.append(MessageFormat.format(res.getString("PolicyInformationUtil.UserNotice"), toString(userNotice)));
}
return sbPolicyQualifier.toString();
}
use of com.github.zhenwei.core.asn1.DERIA5String in project jruby-openssl by jruby.
the class NetscapeCertRequest method toASN1Primitive.
public ASN1Primitive toASN1Primitive() throws IOException {
ASN1EncodableVector spkac = new ASN1EncodableVector();
ASN1EncodableVector pkac = new ASN1EncodableVector();
try {
pkac.add(getKeySpec());
} catch (IOException e) {
// TODO is this really fine shouldn't it be thrown ?
}
pkac.add(new DERIA5String(challenge));
spkac.add(new DERSequence(pkac));
spkac.add(sigAlg);
spkac.add(new DERBitString(signatureBits));
return new DERSequence(spkac);
}
use of com.github.zhenwei.core.asn1.DERIA5String in project athenz by AthenZ.
the class CryptoTest method testX509CSRrequest.
@Test(dataProvider = "x500Principal")
public void testX509CSRrequest(String x500Principal, boolean badRequest) {
PublicKey publicKey = Crypto.loadPublicKey(rsaPublicKey);
PrivateKey privateKey = Crypto.loadPrivateKey(rsaPrivateKey);
String certRequest = null;
GeneralName otherName1 = new GeneralName(GeneralName.otherName, new DERIA5String("role1"));
GeneralName otherName2 = new GeneralName(GeneralName.otherName, new DERIA5String("role2"));
GeneralName[] sanArray = new GeneralName[] { otherName1, otherName2 };
try {
certRequest = Crypto.generateX509CSR(privateKey, publicKey, x500Principal, sanArray);
} catch (Exception e) {
if (!badRequest) {
fail("Should not have failed to create csr");
}
}
if (!badRequest) {
// Now validate the csr
Crypto.getPKCS10CertRequest(certRequest);
}
}
Aggregations