Updated code for gss_init_sec_context. First round trip now works, but input token is
authorMargaret Wasserman <mrw@painless-security.com>
Thu, 30 Oct 2014 10:57:26 +0000 (06:57 -0400)
committerMargaret Wasserman <mrw@painless-security.com>
Thu, 30 Oct 2014 10:57:26 +0000 (06:57 -0400)
not passed in the JSON for second round trip.

chrome/app/navigator.gss.js
chrome/test/test.html
json_gssapi/src/GSSRequest.cpp
json_gssapi/src/cache/GSSContextCache.cpp
json_gssapi/src/cache/GSSNameCache.cpp
json_gssapi/src/commands/GSSInitSecContext.cpp

index 0c4ec32..e6e8f71 100644 (file)
@@ -1,18 +1,50 @@
-console.log('Loading navigator.gss.js - #8');
+/*
+ * Copyright (c) 2014, JANET(UK)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of JANET(UK) nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+console.log('Loading navigator.gss.js - #9');
 
 /* This file gets injected into the web page verbatim */
 
-
-
 var GSSEap = (function () 
   {
     function GSSEap(config)
     {
         // Public attributes
         this.version = "0.0.1";
-        this.implemented_methods = ["gss_import_name"];
+        this.implemented_methods = ["gss_import_name", "gss_init_sec_context", "gss_acquire_cred"];
+       // MRW -- combine success/error callback hashes?
         this.callbacks = {};
-        this.methods = {};
         this.errors = {};
         this.appTag = config.appTag || "";
         this.default_error = config.error || 
@@ -55,8 +87,7 @@ var GSSEap = (function ()
         nonce = event.data.cookies.navigator_gss_tag;
         event.data.cookies.navigator_gss_tag = undefined;
         callback = this.callbacks[nonce];
-        if ("undefined" == typeof (callback) || 
-            this.methods[nonce] != method) {
+        if ("undefined" == typeof (callback)) {
             return;
         }
 
@@ -82,6 +113,72 @@ var GSSEap = (function ()
         }
     };
 
+
+    GSSEap.prototype.init_sec_context = function (params) 
+    {
+        /* variables */
+        // internal variables
+        var nonce;
+        
+        // Required parameters
+        var target_name = params.target_name;
+        var callback = params.success || this.success;
+
+        // Optional & defaulted parameters (some are defaulted at lower layer)
+        var context_handle = params.context_handle;
+        var cred_handle = params.cred_handle; 
+       var mech_type = params.mech_type; 
+       var req_flags = params.req_flags;
+       var time_req = params.time_req;
+       var input_token = params.input_token;
+
+        var error = params.error || this.default_error; 
+        var app_tag = params.app_tag || this.appTag;
+
+        /* Error checking */
+        // Call an error if we don't have the required parameters.
+        // - name
+        // - success()
+        if ( "undefined" == typeof(target_name) ||
+             "undefined" == typeof(callback) )
+        {
+          error(-1, -1, 
+            "init_sec_context called missing either target_name or success callback"
+          );
+          return;
+        }
+        
+        /* Setup */
+        nonce = navigator.generateNonce();
+
+        /* Main processing */
+        // Save our callback, method name, and error function
+        this.callbacks[nonce] = callback;
+        this.errors[nonce] = error;
+        
+        // Now pass the request on to the C code
+        window.postMessage({
+            "method":"gss_init_sec_context",
+            "arguments":
+            {
+                "target_name": target_name,
+               "context_handle": context_handle,
+               "cred_handle": cred_handle,
+               "mech_type": mech_type,
+               "req_flags": req_flags,
+               "time_req": time_req,
+               "input_token": input_token
+               
+            },
+            "cookies":
+            {
+                "navigator_gss_tag": nonce,
+                "app_tag": app_tag
+            }
+        }, "*");
+        
+    };
+
     GSSEap.prototype.import_name = function (params) 
     {
         /* variables */
@@ -119,7 +216,6 @@ var GSSEap = (function ()
         /* Main processing */
         // Save our callback, method name, and error function
         this.callbacks[nonce] = callback;
-        this.methods[nonce] = "gss_import_name";
         this.errors[nonce] = error;
         
         // Now pass the request on to the C code
index 41b38fd..865db9f 100644 (file)
       function doInitSecContext() {
         gss = gss || new navigator.gss_eap({
           appTag: "TestApp",
-          success: function(data, appTag) {
-            $('#init_sec_context_context_handle').attr("value",
-                                                       data.context_handle);
-            report("Output token: " + data.output_token,
-                   '#init_sec_context_response');
-          }
         });
         gss.error = function(major, minor, errMsg, appTag) 
         {
         };        
 
         var params = {
-          target_name: document.getElementById('init_sec_context_target_name').value
+          target_name: document.getElementById('init_sec_context_target_name').value,
+          success: function(data, appTag) {
+            $('#init_sec_context_context_handle').attr("value",
+                                                       data.context_handle);
+            report("Output token: " + data.output_token,
+                   '#init_sec_context_response');
+          }
         };
         gss.init_sec_context(params);
       }
index aa3de6e..d2925f4 100644 (file)
@@ -85,7 +85,7 @@ void GSSRequest::getCommand()
   {
     cmd = new GSSImportName ( &arguments );
   } 
-  else if ( "gss_create_sec_context" == method ) 
+  else if ( "gss_init_sec_context" == method ) 
   {
     cmd = new GSSInitSecContext ( &arguments );
   } 
index c4a518d..d6f6ca3 100644 (file)
@@ -5,11 +5,12 @@
  *
  */
 
-#include <glib.h>
+// #include <glib.h>
 #include <stdexcept>
 #include <openssl/err.h>
 #include <openssl/rand.h>
 
+#include "utils/base64.h"
 #include "GSSContextCache.h"
 
 #define KEYLEN 128
@@ -92,7 +93,8 @@ bool GSSContextCache::generateKey(std::string &key)
   }
 
   // Encode the binary string
-  key = g_base64_encode(theKey, KEYLEN);
+  key = (char *)theKey;
+  key = base64_encode(key);
   
   /* Cleanup        */
   /* Return         */
index 7044edc..f0a6b0f 100644 (file)
@@ -5,13 +5,13 @@
  *
  */
 
-#include <glib.h>
+// #include <glib.h>
 #include <stdexcept>
 #include <openssl/err.h>
 #include <openssl/rand.h>
 
 #include "GSSNameCache.h"
-// #include "util/base64.h"
+#include "utils/base64.h"
 
 #define KEYLEN 128
 
@@ -98,7 +98,8 @@ bool GSSNameCache::generateKey(std::string &key)
   }
 
   // Encode the binary string
-  key = g_base64_encode(theKey, KEYLEN);
+  key = (char *)theKey;
+  key = base64_encode(key);
   
   /* Cleanup        */
   /* Return         */
index e79d440..7688c1e 100644 (file)
@@ -43,6 +43,8 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "utils/base64.h"
+
 typedef OM_uint32 (*init_sec_context)(
     OM_uint32 *,        /* minor_status */
     gss_cred_id_t,      /* claimant_cred_handle */
@@ -107,7 +109,6 @@ GSSInitSecContext::execute()
   /* Return */
 }
 
-#if 0
 const char* GSSInitSecContext::getTargetDisplayName()
 {
   /* Variables */
@@ -132,12 +133,13 @@ const char* GSSInitSecContext::getTargetDisplayName()
   /* return */
   return( ret );
 }
-#endif
 
 bool GSSInitSecContext::loadParameters(JSONObject *params)
 {
   /* Variables */
   std::string key;
+  std::string token;
+  size_t len;
   
   /* Error checking */
   if ( params->isNull() )
@@ -205,9 +207,10 @@ bool GSSInitSecContext::loadParameters(JSONObject *params)
   // input_token
   if ( ! params->get("input_token").isNull() )
   {
-    key = params->get("input_token").string();
-    this->input_token.value = (void *)key.c_str();
-    this->input_token.length = key.length();
+    token = params->get("input_token").string();
+    token = (char *)base64_decode(token, &len);
+    this->input_token.value = (void *)token.c_str();
+    this->input_token.length = token.length();
   }
 
   /* Cleanup */
@@ -267,6 +270,7 @@ JSONObject *GSSInitSecContext::toJSON()
 {
   /* Variables */
   // MRW -- values should be scoped to the class, so execute can set error values?
+  std::string output_str;
   JSONObject *values = new JSONObject();
   
   /* Error checking */
@@ -278,7 +282,9 @@ JSONObject *GSSInitSecContext::toJSON()
   values->set("minor_status", this->minor_status);
   values->set("context_handle", this->contextKey.c_str());
   values->set("actual_mech_type", this->getActualMechType().toString().c_str());
-  values->set("output_token", (const char *)this->output_token.value);
+  // MRW -- is output_token.value guaranteed to be null-terminated?
+  output_str = (char *)output_token.value;
+  values->set("output_token", base64_encode(output_str));
   values->set("ret_flags", this->ret_flags);
   values->set("time_rec", this->time_rec);
   // MRW -- modify for new error handling