📄 x509certselector.java
字号:
* @param subjectKeyId The subject key identifier. */ public void setAuthorityKeyIdentifier(byte[] authKeyId) { this.authKeyId = authKeyId != null ? (byte[]) authKeyId.clone() : null; } /** * Returns the date at which certificates must be valid, or <code>null</code> * if this criterion was not set. * * @return The target certificate valitity date. */ public Date getCertificateValid() { if (certValid != null) return (Date) certValid.clone(); else return null; } /** * Sets the date at which certificates must be valid. Specify * <code>null</code> to clear this criterion. * * @param certValid The certificate validity date. */ public void setCertificateValid(Date certValid) { this.certValid = certValid != null ? (Date) certValid.clone() : null; } /** * This method, and its related X.509 certificate extension — the * private key usage period — is not supported under the Internet * PKI for X.509 certificates (PKIX), described in RFC 3280. As such, this * method is not supported either. * * <p>Do not use this method. It is not deprecated, as it is not deprecated * in the Java standard, but it is basically a no-operation and simply * returns <code>null</code>. * * @return Null. */ public Date getPrivateKeyValid() { return null; } /** * This method, and its related X.509 certificate extension — the * private key usage period — is not supported under the Internet * PKI for X.509 certificates (PKIX), described in RFC 3280. As such, this * method is not supported either. * * <p>Do not use this method. It is not deprecated, as it is not deprecated * in the Java standard, but it is basically a no-operation. * * @param UNUSED Is silently ignored. */ public void setPrivateKeyValid(Date UNUSED) { } /** * Returns the public key algorithm ID that matching certificates must have, * or <code>null</code> if this criterion was not set. * * @return The public key algorithm ID. */ public String getSubjectPublicKeyAlgID() { return String.valueOf(sigId); } /** * Sets the public key algorithm ID that matching certificates must have. * Specify <code>null</code> to clear this criterion. * * @param sigId The public key ID. * @throws IOException If the specified ID is not a valid object identifier. */ public void setSubjectPublicKeyAlgID(String sigId) throws IOException { if (sigId != null) { try { OID oid = new OID(sigId); int[] comp = oid.getIDs(); if (!checkOid(comp)) throw new IOException("malformed OID: " + sigId); this.sigId = oid; } catch (IllegalArgumentException iae) { IOException ioe = new IOException("malformed OID: " + sigId); ioe.initCause(iae); throw ioe; } } else this.sigId = null; } /** * Returns the subject public key criterion, or <code>null</code> if this * value is not set. * * @return The subject public key. */ public PublicKey getSubjectPublicKey() { return subjectKey; } /** * Sets the subject public key criterion as an opaque representation. * Specify <code>null</code> to clear this criterion. * * @param key The public key. */ public void setSubjectPublicKey(PublicKey key) { this.subjectKey = key; if (key == null) { subjectKeySpec = null; return; } try { KeyFactory enc = KeyFactory.getInstance("X.509"); subjectKeySpec = (X509EncodedKeySpec) enc.getKeySpec(key, X509EncodedKeySpec.class); } catch (Exception x) { subjectKey = null; subjectKeySpec = null; } } /** * Sets the subject public key criterion as a DER-encoded key. Specify * <code>null</code> to clear this value. * * @param key The DER-encoded key bytes. * @throws IOException If the argument is not a valid DER-encoded key. */ public void setSubjectPublicKey(byte[] key) throws IOException { if (key == null) { subjectKey = null; subjectKeySpec = null; return; } try { subjectKeySpec = new X509EncodedKeySpec(key); KeyFactory enc = KeyFactory.getInstance("X.509"); subjectKey = enc.generatePublic(subjectKeySpec); } catch (Exception x) { subjectKey = null; subjectKeySpec = null; IOException ioe = new IOException(x.getMessage()); ioe.initCause(x); throw ioe; } } /** * Returns the public key usage criterion, or <code>null</code> if this * value is not set. Note that the array is cloned to prevent modification. * * @return The public key usage. */ public boolean[] getKeyUsage() { if (keyUsage != null) return (boolean[]) keyUsage.clone(); else return null; } /** * Sets the public key usage criterion. Specify <code>null</code> to clear * this value. * * @param keyUsage The public key usage. */ public void setKeyUsage(boolean[] keyUsage) { this.keyUsage = keyUsage != null ? (boolean[]) keyUsage.clone() : null; } /** * Returns the set of extended key purpose IDs, as an unmodifiable set * of OID strings. Returns <code>null</code> if this criterion is not * set. * * @return The set of key purpose OIDs (strings). */ public Set getExtendedKeyUsage() { if (keyPurposeSet != null) return Collections.unmodifiableSet(keyPurposeSet); else return null; } /** * Sets the extended key usage criterion, as a set of OID strings. Specify * <code>null</code> to clear this value. * * @param keyPurposeSet The set of key purpose OIDs. * @throws IOException If any element of the set is not a valid OID string. */ public void setExtendedKeyUsage(Set keyPurposeSet) throws IOException { if (keyPurposeSet == null) { this.keyPurposeSet = null; return; } Set s = new HashSet(); for (Iterator it = keyPurposeSet.iterator(); it.hasNext(); ) { Object o = it.next(); if (!(o instanceof String)) throw new IOException("not a string: " + o); try { OID oid = new OID((String) o); int[] comp = oid.getIDs(); if (!checkOid(comp)) throw new IOException("malformed OID: " + o); } catch (IllegalArgumentException iae) { IOException ioe = new IOException("malformed OID: " + o); ioe.initCause(iae); throw ioe; } } this.keyPurposeSet = s; } /** * Returns whether or not all specified alternative names must match. * If false, a certificate is considered a match if <em>one</em> of the * specified alternative names matches. * * @return true if all names must match. */ public boolean getMatchAllSubjectAltNames() { return matchAllNames; } /** * Sets whether or not all subject alternative names must be matched. * If false, then a certificate will be considered a match if one * alternative name matches. * * @param matchAllNames Whether or not all alternative names must be * matched. */ public void setMatchAllSubjectAltNames(boolean matchAllNames) { this.matchAllNames = matchAllNames; } /** * Sets the subject alternative names critertion. Each element of the * argument must be a {@link java.util.List} that contains exactly two * elements: the first an {@link Integer}, representing the type of * name, and the second either a {@link String} or a byte array, * representing the name itself. * * @param altNames The alternative names. * @throws IOException If any element of the argument is invalid. */ public void setSubjectAlternativeNames(Collection altNames) throws IOException { if (altNames == null) { this.altNames = null; return; } List l = new ArrayList(altNames.size()); for (Iterator it = altNames.iterator(); it.hasNext(); ) { Object o = it.next(); if (!(o instanceof List) || ((List) o).size() != 2 || !(((List) o).get(0) instanceof Integer) || !(((List) o).get(1) instanceof String) || !(((List) o).get(1) instanceof byte[])) throw new IOException("illegal alternative name: " + o); Integer i = (Integer) ((List) o).get(0); if (i.intValue() < 0 || i.intValue() > 8) throw new IOException("illegal alternative name: " + o + ", bad id: " + i); l.add(new ArrayList((List) o)); } this.altNames = l; } /** * Add a name to the subject alternative names criterion. * * @param id The type of name this is. Must be in the range [0,8]. * @param name The name. * @throws IOException If the id is out of range, or if the name * is null. */ public void addSubjectAlternativeName(int id, String name) throws IOException { if (id < 0 || id > 8 || name == null) throw new IOException("illegal alternative name"); if (altNames == null) altNames = new LinkedList(); ArrayList l = new ArrayList(2); l.add(new Integer(id)); l.add(name); altNames.add(l); } /** * Add a name, as DER-encoded bytes, to the subject alternative names * criterion. * * @param id The type of name this is. */ public void addSubjectAlternativeName(int id, byte[] name) throws IOException { if (id < 0 || id > 8 || name == null) throw new IOException("illegal alternative name"); if (altNames == null) altNames = new LinkedList(); ArrayList l = new ArrayList(2); l.add(new Integer(id)); l.add(name); altNames.add(l); } /** * Returns the name constraints criterion, or <code>null</code> if this * value is not set. Note that the byte array is cloned to prevent * modification. * * @return The name constraints. */ public byte[] getNameConstraints() { if (nameConstraints != null) return (byte[]) nameConstraints.clone(); else return null; } /** * Sets the name constraints criterion; specify <code>null</code> to
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -