use of com.github.zhenwei.core.asn1.x509.PolicyInformation in project xipki by xipki.
the class ExtensionsChecker method checkExtensionCertificatePolicies.
// method checkExtensionTlsFeature
private void checkExtensionCertificatePolicies(StringBuilder failureMsg, byte[] extensionValue, Extensions requestedExtensions, ExtensionControl extControl) {
QaCertificatePolicies conf = certificatePolicies;
if (conf == null) {
byte[] expected = getExpectedExtValue(Extension.certificatePolicies, requestedExtensions, extControl);
if (!Arrays.equals(expected, extensionValue)) {
addViolation(failureMsg, "extension values", hex(extensionValue), (expected == null) ? "not present" : hex(expected));
}
return;
}
org.bouncycastle.asn1.x509.CertificatePolicies asn1 = org.bouncycastle.asn1.x509.CertificatePolicies.getInstance(extensionValue);
PolicyInformation[] isPolicyInformations = asn1.getPolicyInformation();
for (PolicyInformation isPolicyInformation : isPolicyInformations) {
ASN1ObjectIdentifier isPolicyId = isPolicyInformation.getPolicyIdentifier();
QaCertificatePolicyInformation expCp = conf.getPolicyInformation(isPolicyId.getId());
if (expCp == null) {
failureMsg.append("certificate policy '").append(isPolicyId).append("' is not expected; ");
continue;
}
QaPolicyQualifiers expCpPq = expCp.getPolicyQualifiers();
if (expCpPq == null) {
continue;
}
ASN1Sequence isPolicyQualifiers = isPolicyInformation.getPolicyQualifiers();
List<String> isCpsUris = new LinkedList<>();
List<String> isUserNotices = new LinkedList<>();
int size = isPolicyQualifiers.size();
for (int i = 0; i < size; i++) {
PolicyQualifierInfo isPolicyQualifierInfo = (PolicyQualifierInfo) isPolicyQualifiers.getObjectAt(i);
ASN1ObjectIdentifier isPolicyQualifierId = isPolicyQualifierInfo.getPolicyQualifierId();
ASN1Encodable isQualifier = isPolicyQualifierInfo.getQualifier();
if (PolicyQualifierId.id_qt_cps.equals(isPolicyQualifierId)) {
String isCpsUri = ((DERIA5String) isQualifier).getString();
isCpsUris.add(isCpsUri);
} else if (PolicyQualifierId.id_qt_unotice.equals(isPolicyQualifierId)) {
UserNotice isUserNotice = UserNotice.getInstance(isQualifier);
if (isUserNotice.getExplicitText() != null) {
isUserNotices.add(isUserNotice.getExplicitText().getString());
}
}
}
List<QaPolicyQualifierInfo> qualifierInfos = expCpPq.getPolicyQualifiers();
for (QaPolicyQualifierInfo qualifierInfo : qualifierInfos) {
if (qualifierInfo instanceof QaCpsUriPolicyQualifier) {
String value = ((QaCpsUriPolicyQualifier) qualifierInfo).getCpsUri();
if (!isCpsUris.contains(value)) {
failureMsg.append("CPSUri '").append(value).append("' is absent but is required; ");
}
} else if (qualifierInfo instanceof QaUserNoticePolicyQualifierInfo) {
String value = ((QaUserNoticePolicyQualifierInfo) qualifierInfo).getUserNotice();
if (!isUserNotices.contains(value)) {
failureMsg.append("userNotice '").append(value).append("' is absent but is required; ");
}
} else {
throw new RuntimeException("should not reach here");
}
}
}
for (QaCertificatePolicyInformation cp : conf.getPolicyInformations()) {
boolean present = false;
for (PolicyInformation isPolicyInformation : isPolicyInformations) {
if (isPolicyInformation.getPolicyIdentifier().getId().equals(cp.getPolicyId())) {
present = true;
break;
}
}
if (present) {
continue;
}
failureMsg.append("certificate policy '").append(cp.getPolicyId()).append("' is absent but is required; ");
}
}
use of com.github.zhenwei.core.asn1.x509.PolicyInformation in project keystore-explorer by kaikramer.
the class PolicyInformationUtil method toString.
/**
* Get string representation of policy information.
*
* @param policyInformation Policy information
* @return String representation of policy information
* @throws IOException If policy information is invalid
*/
public static String toString(PolicyInformation policyInformation) throws IOException {
StringBuilder sbPolicyInformation = new StringBuilder();
ASN1ObjectIdentifier policyIdentifier = policyInformation.getPolicyIdentifier();
sbPolicyInformation.append(MessageFormat.format(res.getString("PolicyInformationUtil.PolicyIdentifier"), policyIdentifier.getId()));
ASN1Sequence policyQualifiers = policyInformation.getPolicyQualifiers();
if (policyQualifiers != null) {
sbPolicyInformation.append(", ");
StringBuilder sbPolicyQualifiers = new StringBuilder();
for (int i = 0; i < policyQualifiers.size(); i++) {
PolicyQualifierInfo policyQualifierInfo = PolicyQualifierInfo.getInstance(policyQualifiers.getObjectAt(i));
sbPolicyQualifiers.append(toString(policyQualifierInfo));
if ((i + 1) < policyQualifiers.size()) {
sbPolicyQualifiers.append(", ");
}
}
sbPolicyInformation.append(MessageFormat.format(res.getString("PolicyInformationUtil.PolicyQualifiers"), sbPolicyQualifiers));
}
return sbPolicyInformation.toString();
}
use of com.github.zhenwei.core.asn1.x509.PolicyInformation in project keystore-explorer by kaikramer.
the class DPolicyInformationChooser method populate.
private void populate(PolicyInformation policyInformation) throws IOException {
if (policyInformation != null) {
joiPolicyIdentifier.setObjectId(policyInformation.getPolicyIdentifier());
ASN1Sequence policyQualifierInfoSeq = policyInformation.getPolicyQualifiers();
if (policyQualifierInfoSeq != null) {
List<PolicyQualifierInfo> policyQualifierInfo = new ArrayList<>();
for (int i = 0; i < policyQualifierInfoSeq.size(); i++) {
PolicyQualifierInfo policyQualInfo = PolicyQualifierInfo.getInstance(policyQualifierInfoSeq.getObjectAt(i));
policyQualifierInfo.add(policyQualInfo);
}
jpqPolicyQualifiers.setPolicyQualifierInfo(policyQualifierInfo);
}
}
}
use of com.github.zhenwei.core.asn1.x509.PolicyInformation in project keystore-explorer by kaikramer.
the class JPolicyInformation method editSelectedPolicyInformation.
private void editSelectedPolicyInformation() {
int selectedRow = jtPolicyInformation.getSelectedRow();
if (selectedRow != -1) {
PolicyInformation policyInfo = (PolicyInformation) jtPolicyInformation.getValueAt(selectedRow, 0);
Container container = getTopLevelAncestor();
try {
DPolicyInformationChooser dPolicyNameChooser = null;
if (container instanceof JDialog) {
dPolicyNameChooser = new DPolicyInformationChooser((JDialog) container, title, policyInfo);
} else {
dPolicyNameChooser = new DPolicyInformationChooser((JFrame) container, title, policyInfo);
}
dPolicyNameChooser.setLocationRelativeTo(container);
dPolicyNameChooser.setVisible(true);
PolicyInformation newPolicyInfo = dPolicyNameChooser.getPolicyInformation();
if (newPolicyInfo == null) {
return;
}
policyInformation.remove(policyInfo);
policyInformation.add(newPolicyInfo);
populate();
selectPolicyInformationInTable(newPolicyInfo);
} catch (IOException ex) {
DError dError = null;
if (container instanceof JDialog) {
dError = new DError((JDialog) container, ex);
} else {
dError = new DError((JFrame) container, ex);
}
dError.setLocationRelativeTo(container);
dError.setVisible(true);
}
}
}
use of com.github.zhenwei.core.asn1.x509.PolicyInformation in project keystore-explorer by kaikramer.
the class JPolicyInformation method addPressed.
private void addPressed() {
Container container = getTopLevelAncestor();
try {
DPolicyInformationChooser dPolicyInformationChooser = null;
if (container instanceof JDialog) {
dPolicyInformationChooser = new DPolicyInformationChooser((JDialog) container, title, null);
} else {
dPolicyInformationChooser = new DPolicyInformationChooser((JFrame) container, title, null);
}
dPolicyInformationChooser.setLocationRelativeTo(container);
dPolicyInformationChooser.setVisible(true);
PolicyInformation newPolicyInfo = dPolicyInformationChooser.getPolicyInformation();
if (newPolicyInfo == null) {
return;
}
policyInformation.add(newPolicyInfo);
populate();
selectPolicyInformationInTable(newPolicyInfo);
} catch (IOException ex) {
DError dError = null;
if (container instanceof JDialog) {
dError = new DError((JDialog) container, ex);
} else {
dError = new DError((JFrame) container, ex);
}
dError.setLocationRelativeTo(container);
dError.setVisible(true);
}
}
Aggregations