@Override
  protected void doSetUp() throws Exception {
    InputStream resourceStream = IOUtils.getResourceAsStream("cdcatalog-utf-8.xml", getClass());
    srcData = IOUtils.toString(resourceStream, "UTF-8").getBytes("UTF-8");

    resourceStream = IOUtils.getResourceAsStream("cdcatalog-us-ascii.xml", getClass());
    resultData = IOUtils.toString(resourceStream, "US-ASCII");
  }
Ejemplo n.º 2
0
 // @Override
 protected void doSetUp() throws Exception {
   org.dom4j.Document dom4jDoc =
       DocumentHelper.parseText(
           IOUtils.toString(
               IOUtils.getResourceAsStream("cdcatalog-utf-8.xml", getClass()), "UTF-8"));
   srcData = new DOMWriter().write(dom4jDoc);
   resultData =
       IOUtils.toString(
           IOUtils.getResourceAsStream("cdcatalog-us-ascii.xml", getClass()), "US-ASCII");
 }
Ejemplo n.º 3
0
  private void initTrustManagerFactory() throws InitialisationException {
    if (null != trustStoreName) {
      trustStorePassword = null == trustStorePassword ? "" : trustStorePassword;

      KeyStore trustStore;
      try {
        trustStore = KeyStore.getInstance(trustStoreType);
        InputStream is = IOUtils.getResourceAsStream(trustStoreName, getClass());
        if (null == is) {
          throw new FileNotFoundException(
              "Failed to load truststore from classpath or local file: " + trustStoreName);
        }
        trustStore.load(is, trustStorePassword.toCharArray());
      } catch (Exception e) {
        throw new InitialisationException(
            CoreMessages.failedToLoad("TrustStore: " + trustStoreName), e, this);
      }

      try {
        trustManagerFactory = TrustManagerFactory.getInstance(trustManagerAlgorithm);
        trustManagerFactory.init(trustStore);
      } catch (Exception e) {
        throw new InitialisationException(
            CoreMessages.failedToLoad("Trust Manager (" + trustManagerAlgorithm + ")"), e, this);
      }
    }
  }
Ejemplo n.º 4
0
  private void readPrivateKeyBundle() throws Exception {
    InputStream in = IOUtils.getResourceAsStream(secretKeyRingFileName, getClass());

    ExtendedKeyStore ring = (ExtendedKeyStore) ExtendedKeyStore.getInstance("OpenPGP/KeyRing");
    ring.load(in, null);

    in.close();

    secretKeyBundle = ring.getKeyBundle(secretAliasId);
  }
Ejemplo n.º 5
0
  private void readPublicKeyRing() throws Exception {
    logger.debug(System.getProperties().get("user.dir"));
    InputStream in = IOUtils.getResourceAsStream(publicKeyRingFileName, getClass());

    ExtendedKeyStore ring = (ExtendedKeyStore) ExtendedKeyStore.getInstance("OpenPGP/KeyRing");
    ring.load(in, null);
    in.close();

    for (Enumeration e = ring.aliases(); e.hasMoreElements(); ) {
      String aliasId = (String) e.nextElement();

      KeyBundle bundle = ring.getKeyBundle(aliasId);

      if (bundle != null) {
        for (Iterator users = bundle.getPrincipals(); users.hasNext(); ) {
          Principal princ = (Principal) users.next();

          principalsKeyBundleMap.put(princ.getName(), bundle);
        }
      }
    }
  }
Ejemplo n.º 6
0
 private void initKeyManagerFactory() throws InitialisationException {
   if (logger.isDebugEnabled()) {
     logger.debug("initialising key manager factory from keystore data");
   }
   KeyStore tempKeyStore;
   try {
     tempKeyStore = KeyStore.getInstance(keystoreType);
     InputStream is = IOUtils.getResourceAsStream(keyStoreName, getClass());
     if (null == is) {
       throw new FileNotFoundException(
           CoreMessages.cannotLoadFromClasspath("Keystore: " + keyStoreName).getMessage());
     }
     tempKeyStore.load(is, keyStorePassword.toCharArray());
   } catch (Exception e) {
     throw new InitialisationException(
         CoreMessages.failedToLoad("KeyStore: " + keyStoreName), e, this);
   }
   try {
     keyManagerFactory = KeyManagerFactory.getInstance(getKeyManagerAlgorithm());
     keyManagerFactory.init(tempKeyStore, keyPassword.toCharArray());
   } catch (Exception e) {
     throw new InitialisationException(CoreMessages.failedToLoad("Key Manager"), e, this);
   }
 }
Ejemplo n.º 7
0
 protected InputStream load(String name) throws IOException {
   InputStream stream = IOUtils.getResourceAsStream(name, getClass());
   assertNotNull("Cannot load " + name, stream);
   return stream;
 }
Ejemplo n.º 8
0
 public static InputStream toInputStream(String resource) throws IOException {
   return IOUtils.getResourceAsStream(resource, XMLTestUtils.class);
 }
Ejemplo n.º 9
0
  public void doInitialise() throws InitialisationException {
    if (getProvider() == null) {
      throw new NullPointerException("The security provider cannot be null");
    }
    if (getKeyStore() != null) {
      if (getKeyPassword() == null) {
        throw new NullPointerException("The Key password cannot be null");
      }
      if (getStorePassword() == null) {
        throw new NullPointerException("The KeyStore password cannot be null");
      }
      if (getKeyManagerAlgorithm() == null) {
        throw new NullPointerException("The Key Manager Algorithm cannot be null");
      }
      if (getKeyStoreType() == null) {
        throw new NullPointerException("The KeyStore type cannot be null");
      }
    }

    if (getKeyStore() != null) {
      KeyStore keystore;
      try {
        Security.addProvider(getProvider());
        // Create keyStore
        keystore = KeyStore.getInstance(keyStoreType);
        InputStream is = IOUtils.getResourceAsStream(getKeyStore(), getClass());
        if (is == null) {
          throw new FileNotFoundException(
              "Failed to load keystore from classpath or local file: " + getKeyStore());
        }
        keystore.load(is, getKeyPassword().toCharArray());
      } catch (Exception e) {
        throw new InitialisationException(
            new Message(Messages.FAILED_LOAD_X, "KeyStore: " + getKeyStore()), e, this);
      }
      try {
        // Get key manager
        keyManagerFactory = KeyManagerFactory.getInstance(getKeyManagerAlgorithm());
        // Initialize the KeyManagerFactory to work with our keyStore
        keyManagerFactory.init(keystore, getStorePassword().toCharArray());
      } catch (Exception e) {
        throw new InitialisationException(
            new Message(Messages.FAILED_LOAD_X, "Key Manager (" + getKeyManagerAlgorithm() + ")"),
            e,
            this);
      }
    }

    if (getTrustStore() != null) {
      KeyStore truststore;
      try {
        truststore = KeyStore.getInstance(trustStoreType);
        InputStream is = IOUtils.getResourceAsStream(getTrustStore(), getClass());
        if (is == null) {
          throw new FileNotFoundException(
              "Failed to load truststore from classpath or local file: " + getTrustStore());
        }
        truststore.load(is, getTrustStorePassword().toCharArray());
      } catch (Exception e) {
        throw new InitialisationException(
            new Message(Messages.FAILED_LOAD_X, "TrustStore: " + getTrustStore()), e, this);
      }

      try {
        trustManagerFactory = TrustManagerFactory.getInstance(getTrustManagerAlgorithm());
        trustManagerFactory.init(truststore);
      } catch (Exception e) {
        throw new InitialisationException(
            new Message(
                Messages.FAILED_LOAD_X, "Trust Manager (" + getTrustManagerAlgorithm() + ")"),
            e,
            this);
      }
    }

    super.doInitialise();

    if (protocolHandler != null) {
      System.setProperty("java.protocol.handler.pkgs", protocolHandler);
    }
    if (clientKeyStore != null) {
      try {
        String clientPath = FileUtils.getResourcePath(clientKeyStore, getClass());
        System.setProperty("javax.net.ssl.keyStore", clientPath);
        System.setProperty("javax.net.ssl.keyStorePassword", clientKeyStorePassword);

        logger.info("Set Client Key store: javax.net.ssl.keyStore=" + clientPath);
      } catch (IOException e) {
        throw new InitialisationException(
            new Message(Messages.FAILED_LOAD_X, "Client KeyStore: " + clientKeyStore), e, this);
      }
    }

    if (trustStore != null) {
      System.setProperty("javax.net.ssl.trustStore", getTrustStore());
      System.setProperty("javax.net.ssl.trustStorePassword", getTrustStorePassword());
      logger.debug("Set Trust store: javax.net.ssl.trustStore=" + getTrustStore());
    } else if (!isExplicitTrustStoreOnly()) {
      logger.info("Defaulting trust store to client Key Store");
      trustStore = getClientKeyStore();
      trustStorePassword = getClientKeyStorePassword();
      System.setProperty("javax.net.ssl.trustStore", getTrustStore());
      System.setProperty("javax.net.ssl.trustStorePassword", getTrustStorePassword());
      logger.debug("Set Trust store: javax.net.ssl.trustStore=" + getTrustStore());
    }
  }