Пример #1
0
  /**
   * Returns the (alias) name of the first keystore entry whose certificate matches the given
   * certificate.
   *
   * <p>This method attempts to match the given certificate with each keystore entry. If the entry
   * being considered is a <i>trusted certificate entry</i>, the given certificate is compared to
   * that entry's certificate. If the entry being considered is a <i>key entry</i>, the given
   * certificate is compared to the first element of that entry's certificate chain (if a chain
   * exists).
   *
   * @param cert the certificate to match with.
   * @return the (alias) name of the first entry with matching certificate, or null if no such entry
   *     exists in this keystore.
   */
  public String engineGetCertificateAlias(Certificate cert) {

    try {

      String alias = null;
      for (KeyStore keystore : keystores.values()) {
        if ((alias = keystore.getCertificateAlias(cert)) != null) {
          break;
        }
      }
      return alias;

    } catch (KeyStoreException e) {
      throw new IllegalStateException(e);
    }
  }