org.bouncycastle.asn1.x509.PolicyInformation Java Examples
The following examples show how to use
org.bouncycastle.asn1.x509.PolicyInformation.
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 File: DCertificatePolicies.java From keystore-explorer with GNU General Public License v3.0 | 6 votes |
private void okPressed() { List<PolicyInformation> policyInformation = jpiCertificatePolicies.getPolicyInformation(); if (policyInformation.isEmpty()) { JOptionPane.showMessageDialog(this, res.getString("DCertificatePolicies.ValueReq.message"), getTitle(), JOptionPane.WARNING_MESSAGE); return; } CertificatePolicies certificatePolicies = new CertificatePolicies(policyInformation.toArray( new PolicyInformation[policyInformation.size()])); try { value = certificatePolicies.getEncoded(ASN1Encoding.DER); } catch (IOException e) { DError.displayError(this, e); return; } closeDialog(); }
Example #2
Source File: PolicyInformationTableCellRend.java From keystore-explorer with GNU General Public License v3.0 | 6 votes |
/** * Returns the rendered cell. * * @param jtPolicyInformation * The JTable * @param value * The value to assign to the cell * @param isSelected * True if cell is selected * @param row * The row of the cell to render * @param col * The column of the cell to render * @param hasFocus * If true, render cell appropriately * @return The renderered cell */ @Override public Component getTableCellRendererComponent(JTable jtPolicyInformation, Object value, boolean isSelected, boolean hasFocus, int row, int col) { JLabel cell = (JLabel) super.getTableCellRendererComponent(jtPolicyInformation, value, isSelected, hasFocus, row, col); PolicyInformation policyInformation = (PolicyInformation) value; try { String policyInformationStr = PolicyInformationUtil.toString(policyInformation); cell.setText(policyInformationStr); cell.setToolTipText(policyInformationStr); } catch (IOException ex) { throw new RuntimeException(ex); // We build this data so should not // happen } cell.setHorizontalAlignment(LEFT); cell.setBorder(new EmptyBorder(0, 5, 0, 5)); return cell; }
Example #3
Source File: DPolicyInformationChooser.java From keystore-explorer with GNU General Public License v3.0 | 6 votes |
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<PolicyQualifierInfo>(); for (int i = 0; i < policyQualifierInfoSeq.size(); i++) { PolicyQualifierInfo policyQualInfo = PolicyQualifierInfo.getInstance( policyQualifierInfoSeq.getObjectAt(i)); policyQualifierInfo.add(policyQualInfo); } jpqPolicyQualifiers.setPolicyQualifierInfo(policyQualifierInfo); } } }
Example #4
Source File: PolicyInformationTableModel.java From keystore-explorer with GNU General Public License v3.0 | 6 votes |
/** * Load the PolicyInformationTableModel with policy information. * * @param policyInformation * The policy information */ public void load(List<PolicyInformation> policyInformation) { PolicyInformation[] policyInformationArray = policyInformation.toArray(new PolicyInformation[policyInformation .size()]); Arrays.sort(policyInformationArray, new PolicyInformationComparator()); data = new Object[policyInformation.size()][1]; int i = 0; for (PolicyInformation policyInfo : policyInformationArray) { data[i][0] = policyInfo; i++; } fireTableDataChanged(); }
Example #5
Source File: CertificatePoliciesImpl.java From SecuritySample with Apache License 2.0 | 5 votes |
public CertificatePoliciesImpl(X509Certificate cert) throws IOException { certificatePolicyIds = new ArrayList<>(); byte[] extVal = cert.getExtensionValue(Extension.certificatePolicies.getId()); if (extVal == null) return; org.bouncycastle.asn1.x509.CertificatePolicies cf = org.bouncycastle.asn1.x509.CertificatePolicies .getInstance(X509ExtensionUtil.fromExtensionValue(extVal)); PolicyInformation[] information = cf.getPolicyInformation(); for (PolicyInformation p : information) { ASN1ObjectIdentifier aIdentifier = p.getPolicyIdentifier(); certificatePolicyIds.add(aIdentifier.getId()); } }
Example #6
Source File: PolicyInformationUtil.java From keystore-explorer with GNU General Public License v3.0 | 5 votes |
/** * 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 { StringBuffer sbPolicyInformation = new StringBuffer(); ASN1ObjectIdentifier policyIdentifier = policyInformation.getPolicyIdentifier(); sbPolicyInformation.append(MessageFormat.format(res.getString("PolicyInformationUtil.PolicyIdentifier"), policyIdentifier.getId())); ASN1Sequence policyQualifiers = policyInformation.getPolicyQualifiers(); if (policyQualifiers != null) { sbPolicyInformation.append(", "); StringBuffer sbPolicyQualifiers = new StringBuffer(); 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(); }
Example #7
Source File: DCertificatePolicies.java From keystore-explorer with GNU General Public License v3.0 | 5 votes |
private void prepopulateWithValue(byte[] value) throws IOException { CertificatePolicies certificatePolicies = CertificatePolicies.getInstance(value); List<PolicyInformation> accessDescriptionList = new ArrayList<>(Arrays.asList(certificatePolicies.getPolicyInformation())); jpiCertificatePolicies.setPolicyInformation(accessDescriptionList); }
Example #8
Source File: DSSASN1Utils.java From dss with GNU Lesser General Public License v2.1 | 5 votes |
public static List<CertificatePolicy> getCertificatePolicies(final CertificateToken certToken) { List<CertificatePolicy> certificatePolicies = new ArrayList<>(); final byte[] certificatePoliciesBinaries = certToken.getCertificate().getExtensionValue(Extension.certificatePolicies.getId()); if (Utils.isArrayNotEmpty(certificatePoliciesBinaries)) { try { ASN1Sequence seq = getAsn1SequenceFromDerOctetString(certificatePoliciesBinaries); for (int ii = 0; ii < seq.size(); ii++) { CertificatePolicy cp = new CertificatePolicy(); final PolicyInformation policyInfo = PolicyInformation.getInstance(seq.getObjectAt(ii)); cp.setOid(policyInfo.getPolicyIdentifier().getId()); ASN1Sequence policyQualifiersSeq = policyInfo.getPolicyQualifiers(); if (policyQualifiersSeq != null) { for (int jj = 0; jj < policyQualifiersSeq.size(); jj++) { PolicyQualifierInfo pqi = PolicyQualifierInfo.getInstance(policyQualifiersSeq.getObjectAt(jj)); if (PolicyQualifierId.id_qt_cps.equals(pqi.getPolicyQualifierId())) { cp.setCpsUrl(getString(pqi.getQualifier())); } } } certificatePolicies.add(cp); } } catch (Exception e) { LOG.warn("Unable to parse the certificatePolicies extension '{}' : {}", Utils.toBase64(certificatePoliciesBinaries), e.getMessage(), e); } } return certificatePolicies; }
Example #9
Source File: PolicyInformationTableModel.java From keystore-explorer with GNU General Public License v3.0 | 5 votes |
@Override public int compare(PolicyInformation policyInformation1, PolicyInformation policyInformation2) { try { return PolicyInformationUtil.toString(policyInformation1).compareToIgnoreCase( PolicyInformationUtil.toString(policyInformation2)); } catch (IOException ex) { throw new RuntimeException(ex); // We build this data so should // not happen } }
Example #10
Source File: JPolicyInformation.java From keystore-explorer with GNU General Public License v3.0 | 5 votes |
private void selectPolicyInformationInTable(PolicyInformation policyInfo) { for (int i = 0; i < jtPolicyInformation.getRowCount(); i++) { if (policyInfo.equals(jtPolicyInformation.getValueAt(i, 0))) { jtPolicyInformation.changeSelection(i, 0, false, false); return; } } }
Example #11
Source File: JPolicyInformation.java From keystore-explorer with GNU General Public License v3.0 | 5 votes |
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); } }
Example #12
Source File: JPolicyInformation.java From keystore-explorer with GNU General Public License v3.0 | 5 votes |
private void removeSelectedPolicyInformation() { int selectedRow = jtPolicyInformation.getSelectedRow(); if (selectedRow != -1) { PolicyInformation policyInfo = (PolicyInformation) jtPolicyInformation.getValueAt(selectedRow, 0); policyInformation.remove(policyInfo); reloadPolicyInformationTable(); selectFirstPolicyInformationInTable(); updateButtonControls(); } }
Example #13
Source File: BasicCertificate.java From signer with GNU Lesser General Public License v3.0 | 4 votes |
/** * returns the ICP-BRASIL Certificate Level(A1, A2, A3, A4, S1, S2, S3, * S4).<br> * DOC-ICP-04 Returns the <b>null</b> value if the CertificatePolicies is * NOT present. * * @return String Certificate level */ public String getCertificateLevel() { try { DLSequence sequence = (DLSequence) getExtensionValue(Extension.certificatePolicies.getId()); if (sequence != null) { for (int pos = 0; pos < sequence.size(); pos++) { DLSequence sequence2 = (DLSequence) sequence.getObjectAt(pos); ASN1ObjectIdentifier policyIdentifier = (ASN1ObjectIdentifier) sequence2.getObjectAt(0); PolicyInformation policyInformation = new PolicyInformation(policyIdentifier); String id = policyInformation.getPolicyIdentifier().getId(); if (id == null) { continue; } if (id.startsWith(OID_A1_CERTIFICATE)) { return "A1"; } if (id.startsWith(OID_A2_CERTIFICATE)) { return "A2"; } if (id.startsWith(OID_A3_CERTIFICATE)) { return "A3"; } if (id.startsWith(OID_A4_CERTIFICATE)) { return "A4"; } if (id.startsWith(OID_S1_CERTIFICATE)) { return "S1"; } if (id.startsWith(OID_S2_CERTIFICATE)) { return "S2"; } if (id.startsWith(OID_S3_CERTIFICATE)) { return "S3"; } if (id.startsWith(OID_S4_CERTIFICATE)) { return "S4"; } } } return null; } catch (Exception e) { logger.info(e.getMessage()); e.printStackTrace(); return null; } }
Example #14
Source File: ExtensionsChecker.java From xipki with Apache License 2.0 | 4 votes |
private void checkExtnCertificatePolicies(StringBuilder failureMsg, byte[] extensionValue, Extensions requestedExtns, ExtensionControl extControl) { CertificatePolicies conf = certificatePolicies; if (conf == null) { checkConstantExtnValue(Extension.certificatePolicies, failureMsg, extensionValue, requestedExtns, extControl); return; } Map<String, CertificatePolicyInformationType> expPoliciesMap = new HashMap<>(); for (CertificatePolicyInformationType cp : conf.getCertificatePolicyInformations()) { expPoliciesMap.put(cp.getPolicyIdentifier().getOid(), cp); } Set<String> expPolicyIds = new HashSet<>(expPoliciesMap.keySet()); 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(); expPolicyIds.remove(isPolicyId.getId()); CertificatePolicyInformationType expCp = expPoliciesMap.get(isPolicyId.getId()); if (expCp == null) { failureMsg.append("certificate policy '").append(isPolicyId).append("' is not expected; "); continue; } List<PolicyQualifier> expCpPq = expCp.getPolicyQualifiers(); if (CollectionUtil.isEmpty(expCpPq)) { 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.getInstance(isPolicyQualifiers.getObjectAt(i)); ASN1ObjectIdentifier isPolicyQualifierId = isPolicyQualifierInfo.getPolicyQualifierId(); ASN1Encodable isQualifier = isPolicyQualifierInfo.getQualifier(); if (PolicyQualifierId.id_qt_cps.equals(isPolicyQualifierId)) { String isCpsUri = DERIA5String.getInstance(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()); } } } for (PolicyQualifier qualifierInfo : expCpPq) { String value = qualifierInfo.getValue(); switch (qualifierInfo.getType()) { case cpsUri: if (!isCpsUris.contains(value)) { failureMsg.append("CPSUri '").append(value).append("' is absent but is required; "); } continue; case userNotice: if (!isUserNotices.contains(value)) { failureMsg.append("userNotice '").append(value) .append("' is absent but is required; "); } continue; default: throw new IllegalStateException("should not reach here"); } } } for (String policyId : expPolicyIds) { failureMsg.append("certificate policy '").append(policyId) .append("' is absent but is required; "); } }
Example #15
Source File: JPolicyInformation.java From keystore-explorer with GNU General Public License v3.0 | 4 votes |
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); } } }
Example #16
Source File: JPolicyInformation.java From keystore-explorer with GNU General Public License v3.0 | 2 votes |
/** * Set policy information. * * @param policyInformation * Policy information */ public void setPolicyInformation(List<PolicyInformation> policyInformation) { this.policyInformation = policyInformation; populate(); }
Example #17
Source File: JPolicyInformation.java From keystore-explorer with GNU General Public License v3.0 | 2 votes |
/** * Get policy information. * * @return Policy information */ public List<PolicyInformation> getPolicyInformation() { return policyInformation; }
Example #18
Source File: PolicyInformationTableModel.java From keystore-explorer with GNU General Public License v3.0 | 2 votes |
/** * Get the class at of the cells at the given column position. * * @param col * The column position * @return The column cells' class */ @Override public Class<?> getColumnClass(int col) { return PolicyInformation.class; }
Example #19
Source File: DPolicyInformationChooser.java From keystore-explorer with GNU General Public License v3.0 | 2 votes |
/** * Get selected policy information. * * @return Policy information, or null if none */ public PolicyInformation getPolicyInformation() { return policyInformation; }
Example #20
Source File: DPolicyInformationChooser.java From keystore-explorer with GNU General Public License v3.0 | 2 votes |
/** * Constructs a new DPolicyInformationChooser dialog. * * @param parent * The parent dialog * @param title * The dialog title * @param policyInformation * Policy information * @throws IOException * If policy information could not be decoded */ public DPolicyInformationChooser(JDialog parent, String title, PolicyInformation policyInformation) throws IOException { super(parent, title, Dialog.ModalityType.DOCUMENT_MODAL); initComponents(policyInformation); }
Example #21
Source File: DPolicyInformationChooser.java From keystore-explorer with GNU General Public License v3.0 | 2 votes |
/** * Constructs a new DPolicyInformationChooser dialog. * * @param parent * The parent frame * @param title * The dialog title * @param policyInformation * Policy information * @throws IOException * If policy information could not be decoded */ public DPolicyInformationChooser(JFrame parent, String title, PolicyInformation policyInformation) throws IOException { super(parent, title, ModalityType.DOCUMENT_MODAL); initComponents(policyInformation); }