private X509Certificate readLOTLCertificate() throws DSSException {

    X509Certificate lotlCert;
    if (lotlCertificate == null) {

      final String msg =
          "The LOTL signing certificate property must contain a reference to a certificate.";
      diagnosticInfo.put(lotlUrl, msg);
      throw new DSSException(msg);
    }
    InputStream inputStream = null;
    try {

      inputStream = getLotlCertificateInputStream();
      lotlCert = DSSUtils.loadCertificate(inputStream);
    } catch (DSSException e) {

      final String msg = "Cannot read LOTL signing certificate.";
      diagnosticInfo.put(lotlUrl, msg);
      throw e;
    } finally {

      DSSUtils.closeQuietly(inputStream);
    }
    return lotlCert;
  }
  /**
   * Gets the LOTL certificate as an inputStream stream
   *
   * @return the inputStream stream
   * @throws java.io.IOException
   */
  private InputStream getLotlCertificateInputStream() throws DSSException {

    InputStream inputStream = null;
    try {

      if (lotlCertificate.toLowerCase().startsWith(CP)) {

        final String lotlCertificate_ = lotlCertificate.substring(CP.length() - 1);
        inputStream = getClass().getResourceAsStream(lotlCertificate_);
      } else if (lotlCertificate.toLowerCase().startsWith(FILE)) {

        final URL url = new File(lotlCertificate.substring(FILE.length())).toURI().toURL();
        inputStream = url.openStream();
      } else {

        final URL url = new URL(lotlCertificate);
        inputStream = url.openStream();
      }
      return inputStream;
    } catch (Exception e) {

      DSSUtils.closeQuietly(inputStream);
      throw new DSSException(e);
    }
  }
Esempio n. 3
0
  /**
   * This method retrieves data using FTP protocol .
   *
   * @param urlString
   * @return
   */
  protected byte[] ftpGet(final String urlString) {

    InputStream inputStream = null;
    try {

      final URL url = new URL(urlString);
      inputStream = url.openStream();
      return DSSUtils.toByteArray(inputStream);
    } catch (Exception e) {

      LOG.warn(e.getMessage());
    } finally {
      DSSUtils.closeQuietly(inputStream);
    }
    return null;
  }