Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2013-2014 Dell, Inc ==================================================================== Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ====================================================================
 
 
 package org.dasein.cloud.azure;
 
 
 import java.util.List;

X509 certficate management for integration with Azure's outmoded form of authentication.

Author(s):
George Reese (george.reese@imaginary.com)
Tim Freeman (timothy.freeman@enstratus.com)
Version:
2012.04.1
Since:
2012.04.1
 
 public class AzureX509 {
     static public final String ENTRY_ALIAS = "";
     static public final String PASSWORD    = "memory";
 
     static {
         Security.addProvider(new BouncyCastleProvider());
     }
     
     private KeyStore        keystore;
 
     public AzureX509(Azure providerthrows InternalException {
         ProviderContext ctx = provider.getContext();
         try {
             String apiShared = "";
             String apiSecret = "";
             try {
                 List<ContextRequirements.Fieldfields = provider.getContextRequirements().getConfigurableValues();
                 for(ContextRequirements.Field f : fields ) {
                     if(f.type.equals(..)){
                         byte[][] keyPair = (byte[][])ctx.getConfigurationValue(f);
                         apiShared = new String(keyPair[0], "utf-8");
                         apiSecret = new String(keyPair[1], "utf-8");
                     }
                 }
             }
             catch (UnsupportedEncodingException ignore) {}
           //  System.out.println(apiShared);
           //  System.out.println(apiSecret);
 
             X509Certificate certificate = certFromString(apiShared);
             PrivateKey privateKey = keyFromString(apiSecret);
 
              = createJavaKeystore(certificateprivateKey);
         }
         catchException e ) {
             throw new InternalException(e);
         }
     }
 
     private X509Certificate certFromString(String pemthrows IOException {
         return (X509Certificate)readPemObject(pem);
     }
 
         KeyStore store = KeyStore.getInstance("JKS""SUN");
         char[] pw = .toCharArray();
         
         store.load(nullpw);
         store.setKeyEntry(keypwnew Certificate[] {cert});
         return store;
     }
    public KeyStore getKeystore() {
        return ;
    }
    private PrivateKey keyFromString(String pemthrows IOException {
        KeyPair keypair = (KeyPair)readPemObject(pem);
        ifkeypair == null ) {
            throw new IOException("Could not parse key from string");
        }
        return keypair.getPrivate();
    }
    private Object readPemObject(String pemStringthrows IOException {
        StringReader strReader = new StringReader(pemString);
        PEMReader pemReader = new PEMReader(strReadernull.);
        
        try {
            return pemReader.readObject();
        }
        finally {
            strReader.close();
            pemReader.close();
        }
    }
New to GrepCode? Check out our FAQ X