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

Method Communicate

examples/client.java:425–487  ·  view source on GitHub ↗
(Socket clientSocket,
            InputStream serverIn, OutputStream serverOut)

Source from the content-addressed store, hash-verified

423 } /* end Authenticate() */
424
425 public static int Communicate(Socket clientSocket,
426 InputStream serverIn, OutputStream serverOut)
427 {
428 long maj_status = 0;
429 long[] min_status = {0};
430 long[] qop_state = {0};
431 int[] state = {0};
432 int err = 0;
433 gss_buffer_desc in_buf = new gss_buffer_desc("Hello Server!");
434 gss_buffer_desc out_buf = new gss_buffer_desc();
435 byte[] sigBlockBuffer = null;
436
437 System.out.println("Beginning communication with server");
438
439 /* Sign and encrypt plain message */
440 maj_status = gsswrapper.gss_wrap(min_status, context, 1,
441 GSS_C_QOP_DEFAULT, in_buf,
442 state, out_buf);
443
444 if (maj_status != GSS_S_COMPLETE) {
445 Util.displayError("wrapping message, gss_wrap",
446 min_status, maj_status);
447 return -1;
448 } else if (state[0] == 0) {
449 System.out.println("Warning! Message not encrypted.");
450 }
451
452 /* Send wrapped message to server */
453 byte[] temp_token = new byte[(int)out_buf.getLength()];
454 temp_token = gsswrapper.getDescArray(out_buf);
455 err = Util.WriteToken(serverOut, temp_token);
456 if (err != 0) {
457 System.out.println("Error sending wrapped message to " +
458 "server, WriteToken");
459 return -1;
460 }
461
462 /* Read signature block from the server */
463 sigBlockBuffer = Util.ReadToken(serverIn);
464
465 if (sigBlockBuffer != null) {
466 gsswrapper.setDescArray(out_buf, sigBlockBuffer);
467 out_buf.setLength(sigBlockBuffer.length);
468 }
469
470 /* Verify signature block */
471 maj_status = gsswrapper.gss_verify_mic(min_status, context,
472 in_buf, out_buf, qop_state);
473
474 if (maj_status != GSS_S_COMPLETE) {
475 Util.displayError("verifying signature, gss_verify_mic",
476 min_status, maj_status);
477 return -1;
478 } else {
479 System.out.println("Signature Verified");
480 }
481
482 gsswrapper.gss_release_buffer(min_status, in_buf);

Callers 1

mainMethod · 0.95

Calls 5

displayErrorMethod · 0.95
WriteTokenMethod · 0.95
ReadTokenMethod · 0.95
getLengthMethod · 0.80
setLengthMethod · 0.80

Tested by

no test coverage detected