Examples of KeyStore


Examples of java.security.KeyStore

        private void checkLocalTrust(X509Certificate[] chain,
                                    String authType,
                                    CertificateException certificateException)
            throws CertificateException
        {
            KeyStore kStore = getKeyStore();

            if(kStore == null)
                throw certificateException;

            try
            {
                for (int i = 0; i < chain.length; i++)
                {
                    X509Certificate c = chain[i];

                    // check for temporaly allowed certs
                    if(temporalyAllowed.contains(c))
                    {
                        return;
                    }

                    // now check for permanent allow of certs
                    String alias = kStore.getCertificateAlias(c);
                    if(alias != null)
                    {
                        return;
                    }
                }
View Full Code Here

Examples of java.security.KeyStore

    if (conn instanceof HttpsURLConnection) {
      // Setup the test keystore (truststore).
      URL keyStoreURL = Thread.currentThread().getContextClassLoader()
          .getResource("META-INF/tst.keystore");
      InputStream stream = keyStoreURL.openStream();
      KeyStore keyStore = KeyStore.getInstance("JKS");
      keyStore.load(stream, "unit-tests".toCharArray());
      // Setup the test TrustManagerFactory.
      TrustManagerFactory trustMgr = TrustManagerFactory
          .getInstance(TrustManagerFactory.getDefaultAlgorithm());
      trustMgr.init(keyStore);
      // Setup the test SSLSocketFactory.
View Full Code Here

Examples of java.security.KeyStore

         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

Examples of java.security.KeyStore

      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

Examples of java.security.KeyStore

  // 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

Examples of java.security.KeyStore

     * @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

Examples of java.security.KeyStore

    }

    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

Examples of java.security.KeyStore

     
        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

Examples of java.security.KeyStore

   
    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

Examples of java.security.KeyStore

     * @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
TOP
Copyright © 2018 www.massapi.com. 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.