1
/*___INFO__MARK_BEGIN__*/
2
/*************************************************************************
4
* The Contents of this file are made available subject to the terms of
5
* the Sun Industry Standards Source License Version 1.2
7
* Sun Microsystems Inc., March, 2001
10
* Sun Industry Standards Source License Version 1.2
11
* =================================================
12
* The contents of this file are subject to the Sun Industry Standards
13
* Source License Version 1.2 (the "License"); You may not use this file
14
* except in compliance with the License. You may obtain a copy of the
15
* License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
17
* Software provided under this License is provided on an "AS IS" basis,
18
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
19
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
20
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
21
* See the License for the specific provisions governing your rights and
22
* obligations concerning the Software.
24
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.GECAKeyManager.java
26
* Copyright: 2006 by Sun Microsystems, Inc
28
* All Rights Reserved.
30
************************************************************************/
31
/*___INFO__MARK_END__*/
32
package com.sun.grid.security.login;
35
import java.io.FileInputStream;
36
import java.io.IOException;
37
import java.net.Socket;
38
import java.security.KeyStore;
39
import java.security.Principal;
40
import java.security.PrivateKey;
41
import java.security.cert.X509Certificate;
42
import java.util.logging.Level;
43
import java.util.logging.Logger;
44
import javax.net.ssl.KeyManagerFactory;
45
import javax.net.ssl.X509KeyManager;
48
* The GECAKeyManager handles the specific KeyManager properties
49
* of a Grid Engine CSP system
51
public class GECAKeyManager implements X509KeyManager {
53
private final static Logger log = Logger.getLogger(GECAKeyManager.class.getName());
54
private X509KeyManager keyManager;
56
public GECAKeyManager() {
60
* Creates a new instance of GECAKeyManager.
62
* @param serverKeystore keystore file of the daemon
63
* @param pw keystore password
65
public GECAKeyManager(File serverKeystore, char[] pw) throws SecurityException {
66
setKeystore(serverKeystore, pw);
69
public synchronized void setKeystore(KeyStore serverKeystore, char[] pw) throws SecurityException {
71
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
72
kmf.init(serverKeystore, pw);
73
keyManager = (X509KeyManager)kmf.getKeyManagers()[0];
74
} catch (Exception ex) {
75
throw new SecurityException("Cannnot create keymanager", ex);
79
public synchronized void setKeystore(File serverKeystore, char[] pw) throws SecurityException {
80
FileInputStream fi = null;
82
log.log(Level.FINER, "loading keystore file {0}", serverKeystore);
83
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
84
fi = new FileInputStream(serverKeystore);
87
} catch (Exception ex) {
88
throw new SecurityException("Cannnot create keymanager", ex);
92
} catch (IOException ex) {
97
public synchronized void reset() {
102
public synchronized String[] getClientAliases(String arg0, Principal[] arg1) {
103
if(keyManager == null) {
104
return new String[0];
106
return keyManager.getClientAliases(arg0, arg1);
109
public synchronized String chooseClientAlias(String[] keyType, Principal[] arg1, Socket arg2) {
110
if(keyManager == null) {
113
return keyManager.chooseClientAlias(keyType, arg1, arg2);
116
public synchronized String[] getServerAliases(String arg0, Principal[] arg1) {
117
if(keyManager == null) {
118
return new String[0];
120
return keyManager.getServerAliases(arg0, arg1);
123
public synchronized String chooseServerAlias(String arg0, Principal[] arg1, Socket arg2) {
124
if(keyManager == null) {
127
return keyManager.chooseServerAlias(arg0, arg1, arg2);
130
public synchronized X509Certificate[] getCertificateChain(String arg0) {
131
if(keyManager == null) {
132
return new X509Certificate[0];
134
return keyManager.getCertificateChain(arg0);
137
public synchronized PrivateKey getPrivateKey(String arg0) {
138
if(keyManager == null) {
141
return keyManager.getPrivateKey(arg0);