List of usage examples for org.bouncycastle.asn1.x509 GeneralSubtree getBase
public GeneralName getBase()
From source file:net.sf.keystore_explorer.crypto.x509.X509Ext.java
License:Open Source License
private String getNameConstraintsStringValue(byte[] value) throws IOException { // @formatter:off /*//from w ww . ja v a2 s .com * NameConstraints ::= ASN1Sequence { permittedSubtrees [0] * GeneralSubtrees OPTIONAL, excludedSubtrees [1] GeneralSubtrees * OPTIONAL } * * GeneralSubtrees ::= ASN1Sequence SIZE (1..MAX) OF GeneralSubtree * * GeneralSubtree ::= ASN1Sequence { base GeneralName, minimum [0] * BaseDistance DEFAULT nodistance, maximum [1] BaseDistance OPTIONAL } * * BaseDistance ::= ASN1Integer {nodistance(0) } (0..MAX) */ // @formatter:on StringBuilder sb = new StringBuilder(); NameConstraints nameConstraints = NameConstraints.getInstance(value); GeneralSubtrees permittedSubtrees = null; if (nameConstraints.getPermittedSubtrees() != null && nameConstraints.getPermittedSubtrees().length != 0) { permittedSubtrees = new GeneralSubtrees(nameConstraints.getPermittedSubtrees()); } sb.append(res.getString("PermittedSubtrees")); if (permittedSubtrees == null) { sb.append(" ").append(res.getString("NoValue")); sb.append(NEWLINE); } else { sb.append(NEWLINE); int permitted = 0; for (GeneralSubtree permittedSubtree : permittedSubtrees.getGeneralSubtrees()) { permitted++; sb.append(INDENT); sb.append(MessageFormat.format(res.getString("PermittedSubtree"), permitted)); sb.append(NEWLINE); sb.append(INDENT); sb.append(INDENT); sb.append(res.getString("Base")); sb.append(NEWLINE); GeneralName base = permittedSubtree.getBase(); sb.append(INDENT); sb.append(INDENT); sb.append(INDENT); sb.append(GeneralNameUtil.toString(base)); sb.append(NEWLINE); BigInteger minimum = permittedSubtree.getMinimum(); int minimumInt = 0; // Default 'nodistance' value if (minimum != null) { minimumInt = minimum.intValue(); } sb.append(INDENT); sb.append(INDENT); sb.append(MessageFormat.format(res.getString("Minimum"), minimumInt)); sb.append(NEWLINE); BigInteger maximum = permittedSubtree.getMaximum(); if (maximum != null) { int maximumInt = maximum.intValue(); sb.append(INDENT); sb.append(INDENT); sb.append(MessageFormat.format(res.getString("Maximum"), maximumInt)); sb.append(NEWLINE); } } } GeneralSubtree[] excludedSubtreeArray = nameConstraints.getExcludedSubtrees(); sb.append(res.getString("ExcludedSubtrees")); if (excludedSubtreeArray == null) { // Optional sb.append(" ").append(res.getString("NoValue")); sb.append(NEWLINE); } else { GeneralSubtrees excludedSubtrees = new GeneralSubtrees(excludedSubtreeArray); sb.append(NEWLINE); int excluded = 0; for (GeneralSubtree excludedSubtree : excludedSubtrees.getGeneralSubtrees()) { excluded++; sb.append(INDENT); sb.append(MessageFormat.format(res.getString("ExcludedSubtree"), excluded)); sb.append(NEWLINE); sb.append(INDENT); sb.append(INDENT); sb.append(res.getString("Base")); sb.append(NEWLINE); GeneralName base = excludedSubtree.getBase(); sb.append(INDENT); sb.append(INDENT); sb.append(INDENT); sb.append(GeneralNameUtil.toString(base)); sb.append(NEWLINE); BigInteger minimum = excludedSubtree.getMinimum(); int minimumInt = minimum.intValue(); sb.append(INDENT); sb.append(INDENT); sb.append(MessageFormat.format(res.getString("Minimum"), minimumInt)); sb.append(NEWLINE); BigInteger maximum = excludedSubtree.getMaximum(); if (maximum != null) { int maximumInt = maximum.intValue(); sb.append(INDENT); sb.append(INDENT); sb.append(MessageFormat.format(res.getString("Maximum"), maximumInt)); sb.append(NEWLINE); } } } return sb.toString(); }
From source file:net.sf.keystore_explorer.gui.crypto.generalsubtree.DGeneralSubtreeChooser.java
License:Open Source License
private void populate(GeneralSubtree generalSubtree) { if (generalSubtree != null) { jgnBase.setGeneralName(generalSubtree.getBase()); if (generalSubtree.getMinimum() != null) { jtfMinimum.setText("" + generalSubtree.getMinimum().intValue()); jtfMinimum.setCaretPosition(0); }// w w w . j a v a2 s. co m if (generalSubtree.getMaximum() != null) { jtfMaximum.setText("" + generalSubtree.getMaximum().intValue()); jtfMaximum.setCaretPosition(0); } } }
From source file:net.sf.keystore_explorer.gui.crypto.generalsubtree.GeneralSubtreesTableCellRend.java
License:Open Source License
/** * Returns the rendered cell.//from w w w .j a v a 2 s.com * * @param jtGeneralSubtrees * 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 jtGeneralSubtrees, Object value, boolean isSelected, boolean hasFocus, int row, int col) { JLabel cell = (JLabel) super.getTableCellRendererComponent(jtGeneralSubtrees, value, isSelected, hasFocus, row, col); GeneralSubtree generalSubtree = (GeneralSubtree) value; if (col == 0) { cell.setText(GeneralNameUtil.safeToString(generalSubtree.getBase(), false)); } else if (col == 1) { if (generalSubtree.getMinimum() != null) { String minimumStr = "" + generalSubtree.getMinimum().intValue(); cell.setText(minimumStr); cell.setToolTipText(minimumStr); } else { cell.setText("-"); } } else { if (generalSubtree.getMaximum() != null) { String maximumStr = "" + generalSubtree.getMaximum().intValue(); cell.setText(maximumStr); cell.setToolTipText(maximumStr); } else { cell.setText("-"); } } cell.setBorder(new EmptyBorder(0, 5, 0, 5)); return cell; }
From source file:org.xipki.ca.qa.impl.X509CertprofileQAImpl.java
License:Open Source License
private void checkExtensionNameConstraintsSubtrees(final StringBuilder failureMsg, final String description, final GeneralSubtree[] subtrees, final List<QaGeneralSubtree> expectedSubtrees) { int iSize = subtrees == null ? 0 : subtrees.length; int eSize = expectedSubtrees == null ? 0 : expectedSubtrees.size(); if (iSize != eSize) { failureMsg.append("size of " + description + " is '" + iSize + "' but expected '" + eSize + "'"); failureMsg.append("; "); return;//w ww. j a va 2 s . c om } for (int i = 0; i < iSize; i++) { GeneralSubtree iSubtree = subtrees[i]; QaGeneralSubtree eSubtree = expectedSubtrees.get(i); BigInteger bigInt = iSubtree.getMinimum(); int iMinimum = bigInt == null ? 0 : bigInt.intValue(); Integer _int = eSubtree.getMinimum(); int eMinimum = _int == null ? 0 : _int.intValue(); String desc = description + " [" + i + "]"; if (iMinimum != eMinimum) { failureMsg.append("minimum of " + desc + " is '" + iMinimum + "' but expected '" + eMinimum + "'"); failureMsg.append("; "); } bigInt = iSubtree.getMaximum(); Integer iMaximum = bigInt == null ? null : bigInt.intValue(); Integer eMaximum = eSubtree.getMaximum(); if (iMaximum != eMaximum) { failureMsg.append("maxmum of " + desc + " is '" + iMaximum + "' but expected '" + eMaximum + "'"); failureMsg.append("; "); } GeneralName iBase = iSubtree.getBase(); GeneralName eBase; if (eSubtree.getDirectoryName() != null) { eBase = new GeneralName(X509Util.reverse(new X500Name(eSubtree.getDirectoryName()))); } else if (eSubtree.getDNSName() != null) { eBase = new GeneralName(GeneralName.dNSName, eSubtree.getDNSName()); } else if (eSubtree.getIpAddress() != null) { eBase = new GeneralName(GeneralName.iPAddress, eSubtree.getIpAddress()); } else if (eSubtree.getRfc822Name() != null) { eBase = new GeneralName(GeneralName.rfc822Name, eSubtree.getRfc822Name()); } else if (eSubtree.getUri() != null) { eBase = new GeneralName(GeneralName.uniformResourceIdentifier, eSubtree.getUri()); } else { throw new RuntimeException("should not reach here, unknown child of GeneralName"); } if (iBase.equals(eBase) == false) { failureMsg.append("base of " + desc + " is '" + iBase + "' but expected '" + eBase + "'"); failureMsg.append("; "); } } }
From source file:org.xipki.pki.ca.qa.ExtensionsChecker.java
License:Open Source License
private void checkExtensionNameConstraintsSubtrees(final StringBuilder failureMsg, final String description, final GeneralSubtree[] subtrees, final List<QaGeneralSubtree> expectedSubtrees) { int isSize = (subtrees == null) ? 0 : subtrees.length; int expSize = (expectedSubtrees == null) ? 0 : expectedSubtrees.size(); if (isSize != expSize) { addViolation(failureMsg, "size of " + description, isSize, expSize); return;//from w ww . j a v a 2s.co m } if (subtrees == null || expectedSubtrees == null) { return; } for (int i = 0; i < isSize; i++) { GeneralSubtree isSubtree = subtrees[i]; QaGeneralSubtree expSubtree = expectedSubtrees.get(i); BigInteger bigInt = isSubtree.getMinimum(); int isMinimum = (bigInt == null) ? 0 : bigInt.intValue(); Integer minimum = expSubtree.getMinimum(); int expMinimum = (minimum == null) ? 0 : minimum.intValue(); String desc = description + " [" + i + "]"; if (isMinimum != expMinimum) { addViolation(failureMsg, "minimum of " + desc, isMinimum, expMinimum); } bigInt = isSubtree.getMaximum(); Integer isMaximum = (bigInt == null) ? null : bigInt.intValue(); Integer expMaximum = expSubtree.getMaximum(); if (!CompareUtil.equalsObject(isMaximum, expMaximum)) { addViolation(failureMsg, "maxmum of " + desc, isMaximum, expMaximum); } GeneralName isBase = isSubtree.getBase(); GeneralName expBase; if (expSubtree.getDirectoryName() != null) { expBase = new GeneralName(X509Util.reverse(new X500Name(expSubtree.getDirectoryName()))); } else if (expSubtree.getDnsName() != null) { expBase = new GeneralName(GeneralName.dNSName, expSubtree.getDnsName()); } else if (expSubtree.getIpAddress() != null) { expBase = new GeneralName(GeneralName.iPAddress, expSubtree.getIpAddress()); } else if (expSubtree.getRfc822Name() != null) { expBase = new GeneralName(GeneralName.rfc822Name, expSubtree.getRfc822Name()); } else if (expSubtree.getUri() != null) { expBase = new GeneralName(GeneralName.uniformResourceIdentifier, expSubtree.getUri()); } else { throw new RuntimeException("should not reach here, unknown child of GeneralName"); } if (!isBase.equals(expBase)) { addViolation(failureMsg, "base of " + desc, isBase, expBase); } } }