1 2 29 30 package com.jcraft.jsch.jgss; 31 32 import com.jcraft.jsch.JSchException; 33 34 import java.net.InetAddress ; 35 import java.net.UnknownHostException ; 36 import org.ietf.jgss.GSSContext ; 37 import org.ietf.jgss.GSSCredential ; 38 import org.ietf.jgss.GSSException ; 39 import org.ietf.jgss.GSSManager ; 40 import org.ietf.jgss.GSSName ; 41 import org.ietf.jgss.MessageProp ; 42 import org.ietf.jgss.Oid ; 43 44 public class GSSContextKrb5 implements com.jcraft.jsch.GSSContext{ 45 private GSSContext context=null; 46 public void create(String user, String host) throws JSchException{ 47 try{ 48 Oid krb5=new Oid ("1.2.840.113554.1.2.2"); 50 Oid principalName=new Oid ("1.2.840.113554.1.2.2.1"); 52 53 GSSManager mgr=GSSManager.getInstance(); 54 55 GSSCredential crd=null; 56 67 68 String cname=host; 69 try{ 70 cname=InetAddress.getByName(cname).getCanonicalHostName(); 71 } 72 catch(UnknownHostException e){ 73 } 74 GSSName _host=mgr.createName("host/"+cname, principalName); 75 76 context=mgr.createContext(_host, 77 krb5, 78 crd, 79 GSSContext.DEFAULT_LIFETIME); 80 81 93 context.requestMutualAuth(true); 96 context.requestConf(true); 97 context.requestInteg(true); context.requestCredDeleg(true); 99 context.requestAnonymity(false); 100 101 return; 102 } 103 catch(GSSException ex){ 104 throw new JSchException(ex.toString()); 105 } 106 } 107 108 public boolean isEstablished(){ 109 return context.isEstablished(); 110 } 111 112 public byte[] init(byte[] token, int s, int l) throws JSchException { 113 try{ 114 return context.initSecContext(token, 0, l); 115 } 116 catch(GSSException ex){ 117 throw new JSchException(ex.toString()); 118 } 119 } 120 121 public byte[] getMIC(byte[] message, int s, int l){ 122 try{ 123 MessageProp prop = new MessageProp (0, true); 124 return context.getMIC(message, s, l, prop); 125 } 126 catch(GSSException ex){ 127 return null; 128 } 129 } 130 131 public void dispose(){ 132 try{ 133 context.dispose(); 134 } 135 catch(GSSException ex){ 136 } 137 } 138 } 139 | Popular Tags |