private XService cmsvc;
public XregistryServer(GlobalContext globalContext) throws XregistryException {
try {
int port = globalContext.getPort();
PureTLSContext ctx = null;
String trustedCertsFile = globalContext.getTrustedCertsFile();
String certKeyFile = globalContext.getHostcertsKeyFile();
//try to load host certificate
if(globalContext.isSecurityEnabled()){
if(certKeyFile != null){
ctx = new PureTLSContext();
if(globalContext.getTrustedCertificates() != null){
ctx.setTrustedCertificates(globalContext.getTrustedCertificates());
}else if(trustedCertsFile != null && new File(trustedCertsFile).isFile()){
ctx.loadRootCertificates(trustedCertsFile);
}else if(trustedCertsFile != null && new File(trustedCertsFile).isDirectory()){
TrustedCertificates certificates = TrustedCertificates.load(trustedCertsFile);
TrustedCertificates.setDefaultTrustedCertificates(certificates);
ctx.setTrustedCertificates(certificates.getCertificates());
}
else{
TrustedCertificates tc = TrustedCertificates.getDefaultTrustedCertificates();
ctx.setTrustedCertificates(tc.getCertificates());
}
ctx.loadEAYKeyFile(certKeyFile, "");
SSLPolicyInt policy = new SSLPolicyInt();
policy.requireClientAuth(true);
policy.setAcceptNoClientCert(true);
ctx.setPolicy(policy);
}else{
//Use Globous crednatials if it is there
try {
ctx = new PureTLSContext();
GSSCredential gssCredntial = globalContext.getCredential();
if(gssCredntial instanceof GlobusGSSCredentialImpl){
GlobusCredential globusCred = ((GlobusGSSCredentialImpl)gssCredntial).getGlobusCredential();
TrustedCertificates tc = TrustedCertificates.getDefaultTrustedCertificates();
if (tc == null)
{
throw new XregistryException("Trusted certificates is null");
}
X509Certificate[] certs = tc.getCertificates();
ctx.setTrustedCertificates(certs);
ctx.setCredential(globusCred);
}else{
throw new XregistryException("Can not find the credantial to start a secure server");
}
} catch (RuntimeException e) {
throw new XregistryException("Secuirty is enabled, but no credentials found");