~tritone-team/tritone/eucalyptus

« back to all changes in this revision

Viewing changes to clc/modules/key-manager/src/main/java/com/eucalyptus/keys/KeyPairManager.java

  • Committer: Bazaar Package Importer
  • Author(s): Dustin Kirkland
  • Date: 2009-12-01 21:09:28 UTC
  • mto: This revision was merged to the branch mainline in revision 75.
  • Revision ID: james.westby@ubuntu.com-20091201210928-o2dvg0ubljhb0ft6
Tags: upstream-1.6.1~bzr1083
ImportĀ upstreamĀ versionĀ 1.6.1~bzr1083

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
        kp = SshKeyPair.NO_KEY;
36
36
      }
37
37
    }
38
 
    return new VmKeyInfo( kp.getDisplayName(), kp.getPublicKey(), kp.getFingerPrint() );
 
38
    if(kp != null)
 
39
        return new VmKeyInfo( kp.getDisplayName(), kp.getPublicKey(), kp.getFingerPrint() );
 
40
        return null;
39
41
  }
40
42
 
41
43
  public VmAllocationInfo verify( VmAllocationInfo vmAllocInfo ) throws EucalyptusCloudException {
75
77
 
76
78
  public CreateKeyPairResponseType CreateKeyPair( CreateKeyPairType request ) throws EucalyptusCloudException {
77
79
    CreateKeyPairResponseType reply = ( CreateKeyPairResponseType ) request.getReply( );
78
 
    PrivateKey pk = KeyPairUtil.createUserKeyPair( request.getUserId( ), request.getKeyName( ) );
79
 
    reply.setKeyFingerprint( Hashes.getFingerPrint( pk ) );
80
 
    ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
81
 
    PEMWriter privOut = new PEMWriter( new OutputStreamWriter( byteOut ) );
82
80
    try {
83
 
      privOut.writeObject( pk );
84
 
      privOut.close();
85
 
    } catch ( IOException e ) {
86
 
      LOG.error( e );
87
 
      throw new EucalyptusCloudException( e );
 
81
      KeyPairUtil.getUserKeyPair( request.getUserId( ), request.getKeyName( ) );
 
82
    } catch ( Exception e1 ) {
 
83
      PrivateKey pk = KeyPairUtil.createUserKeyPair( request.getUserId( ), request.getKeyName( ) );
 
84
      reply.setKeyFingerprint( Hashes.getFingerPrint( pk ) );
 
85
      ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
 
86
      PEMWriter privOut = new PEMWriter( new OutputStreamWriter( byteOut ) );
 
87
      try {
 
88
        privOut.writeObject( pk );
 
89
        privOut.close();
 
90
      } catch ( IOException e ) {
 
91
        LOG.error( e );
 
92
        throw new EucalyptusCloudException( e );
 
93
      }
 
94
      reply.setKeyName( request.getKeyName( ) );
 
95
      reply.setKeyMaterial( byteOut.toString( ) );
 
96
      return reply;
88
97
    }
89
 
    reply.setKeyName( request.getKeyName( ) );
90
 
    reply.setKeyMaterial( byteOut.toString( ) );
91
 
    return reply;
 
98
    throw new EucalyptusCloudException( "Creation failed.  Keypair already exists: " + request.getKeyName( ) );
92
99
  }
93
100
 
94
101
}