Package com.intel.mtwilson.crypto

Examples of com.intel.mtwilson.crypto.SimpleKeystore


        httpClient = new ApacheHttpClient(baseURL, keystore, config);
    }
   
    private void setKeystore(Configuration config) throws KeyManagementException {
        if( config != null && config.containsKey("mtwilson.api.keystore") && config.containsKey("mtwilson.api.keystore.password") ) {
            keystore = new SimpleKeystore(new File(config.getString("mtwilson.api.keystore")), config.getString("mtwilson.api.keystore.password"));
        }
        else if( config != null && config.containsKey("javax.net.ssl.keyStore") && config.containsKey("javax.net.ssl.keyStorePassword") ) {
            keystore = new SimpleKeystore(new File(config.getString("javax.net.ssl.keyStore")), config.getString("javax.net.ssl.keyStorePassword"));           
        }
    }
View Full Code Here


            InternetAddress hostAddress = new InternetAddress(host.getName());
            String connectionString = getConnectionString(host);
            String tlsPolicyName = host.getTlsPolicyName() == null ? "TRUST_FIRST_CERTIFICATE" : host.getTlsPolicyName(); // txtHost.getTlsPolicy();  // XXX TODO TxtHost doesn't have this field yet
//            ByteArrayResource resource = new ByteArrayResource(host.getTlsKeystore() == null ? new byte[0] : host.getTlsKeystore()); // XXX TODO it's the responsibility of the caller to save the TblHosts record after calling this method if the policy is trust first certificate ; we need to get tie the keystore to the database, especially for TRUST_FIRST_CERTIFICATE, so if it's the first connection we can save the certificate back to the database after connecting
            String password = "password"; // XXX TODO uh oh... opening a keystore requires a password, so we can verify its signed contents, which is important. putting the password in the txthost record won't be secure.  password needs to  come from attestation service configuration - or from the user.  this isn't an issue for the factory because the factory is supposed to get the keystore AFTER it has been opened with the password.  but when this code moves to the JPA/DAO/Repository layer, we'll need to have a password from somewhere.        
            SimpleKeystore tlsKeystore = new SimpleKeystore(host.getTlsKeystoreResource(), password); // XXX TODO see above commment about password;  the per-host trusted certificates keystore has to either be protected by a password known to all mt wilson instances (stored in database or sync'd across each server's configuration files) or it has to be protected by a group secret known to all authorized clients (and then we need a mechanism for the api client to send us the secret in the request, and a way get secrets in and out of api client's keystore so it can be sync'd across the authorized group of clients) or we can just not store it encrypted and use a pem-format keystore instead of a java KeyStore
            TlsPolicy tlsPolicy = getTlsPolicy(tlsPolicyName, tlsKeystore); // XXX TODO not sure that this belongs in the http-authorization package, because policy names are an application-level thing (allowed configurations), and creating the right repository is an application-level thing too (mutable vs immutable, and underlying implementation - keystore, array, cms of pem-list.
            HostAgent hostAgent = getHostAgent(hostAddress, connectionString, tlsPolicy);
            HashMap<String, ? extends IManifest> manifest = hostAgent.getManifest();
//            host.setTlsKeystore(resource.toByteArray()); // if the tls policy is TRUST_FIRST_CERTIFICATE then it's possible a new cert has been saved in it and we have to make sure it gets saved to the host record;  for all other tls policies there would be no change so this is a no-op -  the byte array will be the same as the one we started with
            return manifest;
View Full Code Here

        return tlsPolicy;
    }

    public TlsPolicy getTlsPolicy(String tlsPolicyName, Resource resource) throws KeyManagementException {
        String password = "password"; // XXX TODO uh oh... opening a keystore requires a password, so we can verify its signed contents, which is important. putting the password in the txthost record won't be secure.  password needs to  come from attestation service configuration - or from the user.  this isn't an issue for the factory because the factory is supposed to get the keystore AFTER it has been opened with the password.  but when this code moves to the JPA/DAO/Repository layer, we'll need to have a password from somewhere.        
        SimpleKeystore tlsKeystore = new SimpleKeystore(resource, password); // XXX TODO only because txthost doesn't have the field yet... we should get the keystore from the txthost object
        TlsPolicy tlsPolicy = getTlsPolicy(tlsPolicyName, tlsKeystore); // XXX TODO not sure that this belongs in the http-authorization package, because policy names are an application-level thing (allowed configurations), and creating the right repository is an application-level thing too (mutable vs immutable, and underlying implementation - keystore, array, cms of pem-list.
        return tlsPolicy;
    }
View Full Code Here

   
    //Creating ModelAndView Object with Login page to return to user if Login is not successful.
    ModelAndView view = new ModelAndView("Login");
    //RsaCredential credential = null;
                File keystoreFile = null;
                SimpleKeystore keystore = null;
   
    String username = "admin";

    URL baseURL = new URL(WLMPConfig.getConfiguration().getString("mtwilson.api.baseurl"))
               
    final String keystoreFilename = WLMPConfig.getConfiguration().getString("mtwilson.wlmp.keystore.dir") + File.separator +  "portal.jks";
                final String keystorePassword = WLMPConfig.getConfiguration().getString("mtwilson.wlmp.keystore.password");
               
    try{
                    //this line will throw exception if file with username is not present in specific dir.
                    keystoreFile = new File(keystoreFilename);
                }catch(Exception e){
                    logger.severe("File Not found on server >> "+keystoreFilename);
                    view.addObject("message", "Key store is not configured/saved correctly in " + keystoreFilename + ".");
                    return view;
                }
               
                  
    try {
                    keystore = new SimpleKeystore(keystoreFile, keystorePassword);
                    //credential = keystore.getRsaCredentialX509(username, keystorePassword);
    } catch (Exception e) {
                        view.addObject("result", false);
      view.addObject("message", "Username or Password does not match. Please try again.");
      return view;
View Full Code Here

   
    //Creating ModelAndView Object with Login page to return to user if Login is not successful.
    ModelAndView view = new ModelAndView("Login");
    //RsaCredential credential = null;
    File keystoreFile = null;
                SimpleKeystore keystore = null;
   
    String username = "admin";
       
                URL baseURL = new URL(TDPConfig.getConfiguration().getString("mtwilson.api.baseurl"));

               
                final String keystoreFilename = TDPConfig.getConfiguration().getString("mtwilson.tdbp.keystore.dir") + File.separator +  "portal.jks";
                final String keystorePassword = TDPConfig.getConfiguration().getString("mtwilson.tdbp.keystore.password");
               
    try{
      keystoreFile = new File(keystoreFilename);
                }catch(Exception e){
                        logger.severe("File Not found on server >> "+keystoreFilename);
                        e.printStackTrace();
                        view.addObject("message", "Private key file is missing on server.");
                        return view;
                }
   
               
    try {
                        keystore = new SimpleKeystore(keystoreFile, keystorePassword);
                        //credential = keystore.getRsaCredentialX509(username, keystorePassword);
    } catch (Exception e) {
                    view.addObject("message", "The username or password you entered is incorrect.");
                    return view;
    }
View Full Code Here

                System.exit(1);
            }
            String subject = username; //String.format("CN=%s", username);
           
            File keystoreFile = new File(directory.getAbsoluteFile() + File.separator + Filename.encode(username) + ".jks");
            SimpleKeystore keystore = new SimpleKeystore(keystoreFile, password);
            KeyPair keypair = RsaUtil.generateRsaKeyPair(RsaUtil.MINIMUM_RSA_KEY_SIZE);
            X509Certificate certificate = RsaUtil.generateX509Certificate(subject, keypair, RsaUtil.DEFAULT_RSA_KEY_EXPIRES_DAYS);
            keystore.addKeyPairX509(keypair.getPrivate(), certificate, username, password);
            keystore.save();
            System.out.println("Created keystore: "+keystoreFile.getName());
    }
View Full Code Here

        else if( password.startsWith("env:") && password.length() > 4 ) {
            String varName = password.substring(4);
            password = System.getenv(varName);
        }

        SimpleKeystore keystore = new SimpleKeystore(keystoreFile, password);
        KeyPair keypair = RsaUtil.generateRsaKeyPair(RsaUtil.MINIMUM_RSA_KEY_SIZE);
        X509Certificate certificate = RsaUtil.generateX509Certificate(subject, alternateName, keypair, RsaUtil.DEFAULT_RSA_KEY_EXPIRES_DAYS);
        keystore.addKeyPairX509(keypair.getPrivate(), certificate, alias, password);
        keystore.save();
    }
View Full Code Here

TOP

Related Classes of com.intel.mtwilson.crypto.SimpleKeystore

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.