Package java.security

Examples of java.security.KeyStore$Builder$BuilderImpl


         ClassLoader loader = getClass().getClassLoader();
         URL keyStoreURL = loader.getResource("tst.keystore");
         if( keyStoreURL == null )
            throw new IOException("Failed to find resource tst.keystore");
         log.debug("Opening KeyStore: "+keyStoreURL);
         KeyStore keyStore = KeyStore.getInstance("JKS");
         InputStream is = keyStoreURL.openStream();
         keyStore.load(is, KEYSTORE_PASSWORD.toCharArray());
         String algorithm = KeyManagerFactory.getDefaultAlgorithm();
         KeyManagerFactory keyMgr = KeyManagerFactory.getInstance(algorithm);
         keyMgr.init(keyStore, KEYSTORE_PASSWORD.toCharArray());
         algorithm = TrustManagerFactory.getDefaultAlgorithm();
         TrustManagerFactory trustMgr = TrustManagerFactory.getInstance(algorithm);
View Full Code Here


      if (keyPair == null) {
        String ksl = System.getProperty("ch.ethz.prose.keystore.location");
        String ksp = System.getProperty("ch.ethz.prose.keystore.password");
        String alias = "runes-system"; // FIX

        KeyStore ks = KeyStore.getInstance("JKS");
        ks.load(new FileInputStream(ksl), ksp.toCharArray());
        PrivateKey privateKey = (PrivateKey) ks.getKey(alias, alias.toCharArray()); // FIX, password
        PublicKey publicKey = ks.getCertificate(alias).getPublicKey();
        keyPair = new KeyPair(publicKey, privateKey);
      }

      return new SignedAspect(ext, keyPair);
View Full Code Here

  // is there a trusted certificate in our keystore?
  private boolean isTrusted(PublicKey key) throws KeyStoreException, NoSuchAlgorithmException, IOException, CertificateException {
    if (certTable == null) {
      certTable = new Hashtable();

      KeyStore ks = getKeyStore();

      Enumeration enumeration = ks.aliases();
      while (enumeration.hasMoreElements()) {
        String alias = (String) enumeration.nextElement();
        Certificate[] certs = ks.getCertificateChain(alias);

        if (certs != null) {
          for (int i=0; i<certs.length; i++) {
            certTable.put(certs[i].getPublicKey(), certs[i]);
          }
View Full Code Here

     * @param newAlias
     * @throws Exception on any error
     * @return the alias of the key imported
     */
    public String importPKCS12Key(File keyFile, String password, String alias, String newAlias) throws Exception {
        KeyStore kspkcs12 = KeyStore.getInstance("PKCS12");
        kspkcs12.load(new FileInputStream(keyFile), password == null ? null : password.toCharArray());
        boolean hasTemp = false;
        if(isKeyStoreEmpty()) {
            if(isKeyStoreExists()) {               
                deleteKeyStore();
            }
            createKeyStore();
          String dname = "cn=tmp, ou=tmp, o=tmp, l=tmp, st=tmp, c=GB";
          createKey("temporary-key", dname);
          hasTemp = true;
          reloadKeystore();
        }
        try {
       
            String firstAlias = (String) kspkcs12.aliases().nextElement();
           
          if(Util.isNullOrTrimmedBlank(alias)) {
            log.info("Alias not specified, importing first alias " + firstAlias);
            alias = firstAlias;
          }

            if(Util.isNullOrTrimmedBlank(newAlias)) {
                log.info("New alias not specified, using imported alias " + alias);
                newAlias = alias;
            }
         
          Certificate c[] = kspkcs12.getCertificateChain(alias);
          // Make sure we don't have a null chain
          if (c == null)
              c = new Certificate[] {};
          Key key = kspkcs12.getKey(alias, password == null ? null : password.toCharArray());
            if(key == null) {
                throw new Exception("No alias of '" + alias + "' in imported PKCS12 key file.");
            }
          this.keyStore.setKeyEntry(newAlias, key, getKeyStorePassword().toCharArray(), c);
        } finally {
View Full Code Here

    }

    private boolean validateKeyStore(String keyStoreType, String password, File keystoreFile) {
        InputStream inputStream = null;
        try {
            KeyStore keyStore = KeyStore.getInstance(keyStoreType);
            inputStream = new FileInputStream(keystoreFile);
            keyStore.load(inputStream, password.toCharArray());
            return true;
        } catch (Exception e) {
            log.error("Validation of key store failed", e);
            return false;
        } finally {
View Full Code Here

     
        try {
            KeyStoreManager km = KeyStoreManager.getInstance(KeyStoreManager.TRUSTED_SERVER_CERTIFICATES_KEY_STORE);

            if (!km.isKeyStoreEmpty()) {
                KeyStore trusted = km.getKeyStore();

                for (Enumeration e = trusted.aliases(); e.hasMoreElements();) {
                    String alias = (String) e.nextElement();
                    Certificate c = trusted.getCertificate(alias);

                    try {
                        chain[0].verify(c.getPublicKey());
                        return;
                    } catch (Exception ex) {

                    }
                }

                for (int i = 0; i < chain.length; i++) {
                    if (trusted.getCertificateAlias(chain[i]) != null) {
                        return;
                    }
                }
            }
View Full Code Here

   
    try {
      String filename = getTestKeyStoreFilename();
     
      char[] passphrase = PASSWORD.toCharArray();
      KeyStore ks = KeyStore.getInstance("JKS");
      ks.load(new FileInputStream(filename), passphrase);
 
      KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
      kmf.init(ks, passphrase);
     
      TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
View Full Code Here

     * @throws Exception
     */
    public ActionForward exportCertificate(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                    HttpServletResponse response) throws Exception {
        String sel = ((ShowKeyStoreForm) form).getSelectedItem();
        KeyStore systemClientStore = ((ShowKeyStoreForm) form).getSelectedKeyStore().getKeyStore();
        FileDownloadPageInterceptListener l = (FileDownloadPageInterceptListener) CoreUtil.getPageInterceptListenerById(request
                        .getSession(), "fileDownload");
        if (l == null) {
            l = new FileDownloadPageInterceptListener();
            CoreUtil.addPageInterceptListener(request.getSession(), l);
        }
        File clientCertFile = new File(CoreUtil.getTempDownloadDirectory(getSessionInfo(request)), sel + ".cer");
        FileOutputStream out = new FileOutputStream(clientCertFile);
        X509Certificate cert = (X509Certificate) systemClientStore.getCertificate(sel);
        out.write(cert.getEncoded());
        out.flush();
        out.close();
        l.addDownload(new CSRDownload(clientCertFile, clientCertFile.getName(), "application/octet-stream", mapping
                        .findForward("success"), "exportCertificate.message", "keystore", sel));
View Full Code Here

     */
    public ActionForward exportPrivate(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                        HttpServletResponse response) throws Exception {
        String sel = ((ShowKeyStoreForm) form).getSelectedItem();
       
        KeyStore systemClientStore = ((ShowKeyStoreForm) form).getSelectedKeyStore().getKeyStore();
        FileDownloadPageInterceptListener l = (FileDownloadPageInterceptListener) CoreUtil.getPageInterceptListenerById(request
                        .getSession(), "fileDownload");
        if (l == null) {
            l = new FileDownloadPageInterceptListener();
            CoreUtil.addPageInterceptListener(request.getSession(), l);
        }
        File clientCertFile = new File(CoreUtil.getTempDownloadDirectory(getSessionInfo(request)), sel + ".p12");
        FileOutputStream out = new FileOutputStream(clientCertFile);
        char[] password = ((ShowKeyStoreForm) form).getSelectedKeyStore().getKeyStorePassword().toCharArray();
        if (systemClientStore.isKeyEntry(sel)){
            PrivateKey keypair = ((ShowKeyStoreForm) form).getSelectedKeyStore().getPrivateKey(sel,
                            password);
          KeyStore userStore = KeyStore.getInstance("PKCS12", "BC");
          userStore.load(null, null);
          userStore.setKeyEntry(sel, keypair, ((ShowKeyStoreForm) form).getPassword().toCharArray(), ((ShowKeyStoreForm) form).getSelectedKeyStore().getCertificateChain(sel));
          userStore.store(out, ((ShowKeyStoreForm) form).getPassword().toCharArray());
          out.close();
        }
        l.addDownload(new CSRDownload(clientCertFile, clientCertFile.getName(), "application/octet-stream", mapping.findForward("success"),
                        "exportPrivateKey.message", "keystore", sel));
        return mapping.findForward("success");
View Full Code Here

    protected SSLServerSocketFactory createFactory() throws Exception {
        if(KeyStoreManager.getInstance(KeyStoreManager.DEFAULT_KEY_STORE).isKeyStoreEmpty()) {
            throw new Exception("The keystore does not contain any certificates. Please run the installation wizard (--install).");
        }
        KeyStore ks = KeyStoreManager.getInstance(KeyStoreManager.DEFAULT_KEY_STORE).getKeyStore();
        String pw = ContextHolder.getContext().getConfig().retrieveProperty(new ContextKey("webServer.keystore.sslCertificate.password"));
        KeyManager[] kma = new KeyManager[] { new CustomKeyManager(pw) };
        TrustManager[] tma = null;
        if(trustManager == null) {
            TrustManagerFactory tm = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
View Full Code Here

TOP

Related Classes of java.security.KeyStore$Builder$BuilderImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.