MCPcopy Create free account
hub / github.com/cconlon/kerberos-java-gssapi / establishContext

Method establishContext

examples/gssClient.java:151–216  ·  view source on GitHub ↗

Establish a GSS-API context with example server, calling initSecContext() until context.isEstablished() is true. This method also tests exporting and re-importing the security context.

(InputStream serverIn,
            OutputStream serverOut)

Source from the content-addressed store, hash-verified

149 * context.
150 **/
151 public static void establishContext(InputStream serverIn,
152 OutputStream serverOut) {
153
154 byte[] inToken = new byte[0];
155 byte[] outToken = null;
156 int err = 0;
157
158 try {
159 GSSName peer = mgr.createName(serviceName,
160 GSSName.NT_HOSTBASED_SERVICE);
161
162 context = mgr.createContext(peer, mech, clientCred,
163 GSSContext.INDEFINITE_LIFETIME);
164
165 context.requestConf(true);
166 context.requestReplayDet(true);
167 context.requestMutualAuth(true);
168
169 while (!context.isEstablished()) {
170
171 System.out.println("Calling initSecContext");
172 outToken = context.initSecContext(inToken, 0, inToken.length);
173
174 if (outToken != null && outToken.length > 0) {
175 err = GssUtil.WriteToken(serverOut, outToken);
176 if (err == 0) {
177 System.out.println("Sent token to server...");
178 } else {
179 System.out.println("Error sending token to server...");
180 }
181 }
182
183 if (!context.isEstablished()) {
184 inToken = GssUtil.ReadToken(serverIn);
185 System.out.println("Received token from server... ");
186 }
187 }
188
189 GSSName peerName = context.getTargName();
190 GSSName srcName = context.getSrcName();
191 System.out.println("Security context established with " + peer);
192 GssUtil.printSubString("Source Name", srcName.toString());
193 GssUtil.printSubString("Mechanism", context.getMech().toString());
194 GssUtil.printSubString("AnonymityState", context.getAnonymityState());
195 GssUtil.printSubString("ConfState", context.getConfState());
196 GssUtil.printSubString("CredDelegState", context.getCredDelegState());
197 GssUtil.printSubString("IntegState", context.getIntegState());
198 GssUtil.printSubString("Lifetime", context.getLifetime());
199 GssUtil.printSubString("MutualAuthState", context.getMutualAuthState());
200 GssUtil.printSubString("ReplayDetState", context.getReplayDetState());
201 GssUtil.printSubString("SequenceDetState", context.getSequenceDetState());
202 GssUtil.printSubString("Is initiator?", context.isInitiator());
203 GssUtil.printSubString("Is Prot Ready?", context.isProtReady());
204
205 /* Test exporting/importing established security context */
206 byte[] exportedContext = context.export();
207 context = mgr.createContext(exportedContext);
208 GSSName serverInfo2 = context.getTargName();

Callers 1

mainMethod · 0.95

Calls 15

WriteTokenMethod · 0.95
ReadTokenMethod · 0.95
printSubStringMethod · 0.95
toStringMethod · 0.95
getMessageMethod · 0.80
requestConfMethod · 0.65
requestReplayDetMethod · 0.65
requestMutualAuthMethod · 0.65
isEstablishedMethod · 0.65
initSecContextMethod · 0.65
getTargNameMethod · 0.65
getSrcNameMethod · 0.65

Tested by

no test coverage detected