Add command to display an existing GSS name; avoid truncating the output_token from...
authorMark Donnelly <mark@painless-security.com>
Wed, 5 Nov 2014 20:05:01 +0000 (15:05 -0500)
committerMark Donnelly <mark@painless-security.com>
Wed, 5 Nov 2014 20:05:01 +0000 (15:05 -0500)
chrome/app/navigator.gss.js
chrome/test/test.html
json_gssapi/CMakeLists.txt
json_gssapi/src/GSSRequest.cpp
json_gssapi/src/commands/GSSDisplayName.cpp [new file with mode: 0644]
json_gssapi/src/commands/GSSDisplayName.h [new file with mode: 0644]
json_gssapi/src/commands/GSSInitSecContext.cpp

index e6e8f71..4a2e09c 100644 (file)
@@ -42,7 +42,7 @@ var GSSEap = (function ()
     {
         // Public attributes
         this.version = "0.0.1";
-        this.implemented_methods = ["gss_import_name", "gss_init_sec_context", "gss_acquire_cred"];
+        this.implemented_methods = ["gss_import_name", "gss_display_name", "gss_init_sec_context", "gss_acquire_cred"];
        // MRW -- combine success/error callback hashes?
         this.callbacks = {};
         this.errors = {};
@@ -179,6 +179,50 @@ var GSSEap = (function ()
         
     };
 
+    GSSEap.prototype.display_name = function(params)
+    {
+        /* Variables */
+        // required parameters
+        var input_name = params.input_name;
+        var callback = params.success;
+
+        if ( "undefined" == typeof(name) ||
+             "undefined" == typeof(callback) )
+        {
+          error(-1, -1, 
+            "import_name called missing either name or success callback"
+          );
+          return;
+        }
+
+        var error = params.error || this.default_error; 
+        var app_tag = params.app_tag || this.appTag;
+        
+        /* 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_display_name",
+            "arguments":
+            {
+                "input_name": input_name,
+            },
+            "cookies":
+            {
+                "navigator_gss_tag": nonce,
+                "app_tag": app_tag
+            }
+        }, "*");
+        
+    }
+
     GSSEap.prototype.import_name = function (params) 
     {
         /* variables */
index c33c395..c99aba6 100644 (file)
       </div> 
    </div>
 
+   <div class="row">
+      <div class="col-xs-4">
+        <!-- middle column -->
+        <h2>GSS Display Name</h2>
+        <div class="form-group">
+          <label for="display_name_name">Name:</label>
+          <select name="display_name_name" id="display_name_name" class="gss_name">
+          </select>
+        </div>
+
+        <button id="display_name">gss_display_name</button>
+        <div id="display_name_response" style="overflow: auto;"></div>
+
+      </div>
+   </div>
+
     <div class="row">
       <div class="col-xs-12">
         <div class="form-group">
         });
       } // doImportName
 
+      function doDisplayName() {
+        gss = gss || new navigator.gss_eap({
+          appTag: "TestApp"
+        });
+        gss.error = function(major, minor, errMsg, appTag) 
+        {
+          report("Error", '#display_response');
+          report("Major: " + major + "; Minor: " + minor, '#display_response');
+          report("<blockquote>" + errMsg + "</blockquote>", '#display_response');
+          report("appTag: " + appTag, '#display_response');
+        };
+        gss.display_name({
+          input_name:      document.getElementById('display_name_name').value,
+          success:   function(data, appTag) {
+                       report("GSS displayed name: " + data.gss_name, '#display_response');
+                       report("appTag: " + appTag, '#display_response');
+                       newOption = $('<option></option>');
+                       newOption.attr('value', data.gss_name);
+                       newOption.append(document.getElementById('display_name_name').value);
+                       $('.gss_name').append(newOption);
+                     },
+          error: function(major, minor, errMsg, appTag) 
+        {
+          report("Error", '#display_response');
+          report("Major: " + major + "; Minor: " + minor, '#display_response');
+          report("<blockquote>" + errMsg + "</blockquote>", '#display_response');
+          report("appTag: " + appTag, '#display_response');
+        }
+        });
+      } // doDisplayName
+
+
       function doAcquireCred() {
         gss = gss || new navigator.gss_eap({
           appTag: "TestApp"
           'click', doImportName
         );
 
+        <!-- Listen for the import name button click -->
+        document.getElementById('display_name').addEventListener(
+          'click', doDisplayName
+        );
+
         <!-- Listen for the acquire cred button click -->
         document.getElementById('acquire_cred').addEventListener(
           'click', doAcquireCred
index 170b231..9e8e1ef 100644 (file)
@@ -18,6 +18,7 @@ add_library(jsongssapi SHARED
                        src/commands/GSSCommand.cpp 
                        src/commands/GSSImportName.cpp
                        src/commands/GSSAcquireCred.cpp 
+                       src/commands/GSSDisplayName.cpp
                        src/commands/GSSPseudoRandom.cpp
                        src/commands/GSSWrap.cpp  
                        src/commands/GSSUnwrap.cpp
index d2925f4..5d8b0b5 100644 (file)
@@ -11,6 +11,7 @@
 #include "commands/GSSAcquireCred.h"
 #include "commands/GSSInitSecContext.h"
 #include "commands/GSSImportName.h"
+#include "commands/GSSDisplayName.h"
 #include "GSSRequest.h"
 
 using std::bad_alloc;
@@ -93,6 +94,10 @@ void GSSRequest::getCommand()
   {
     cmd = new GSSAcquireCred ( &arguments );
   } 
+  else if ( "gss_display_name" == method )
+  {
+    cmd = new GSSDisplayName ( &arguments );
+  }
   else 
   {
     string error_message = string("Unrecognized command: ") + method;
diff --git a/json_gssapi/src/commands/GSSDisplayName.cpp b/json_gssapi/src/commands/GSSDisplayName.cpp
new file mode 100644 (file)
index 0000000..abb79dd
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * 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.
+ *
+ */
+
+#include "GSSDisplayName.h"
+#include "cache/GSSNameCache.h"
+
+
+using std::string;
+
+GSSDisplayName::GSSDisplayName()
+{
+
+}
+
+GSSDisplayName::~GSSDisplayName()
+{
+
+}
+
+JSONObject* GSSDisplayName::toJSON()
+{
+  JSONObject *values = new JSONObject;
+  values->set("major_status", (json_int_t)0);
+  values->set("minor_status", (json_int_t)0);
+  values->set("output_name", inputName.toString().c_str());
+  
+  return(values);
+}
+
+void GSSDisplayName::execute()
+{
+  // Execution is a side effect of the toJSON calls
+}
+
+bool GSSDisplayName::loadParameters ( const JSONObject* params )
+{
+  /* Variables */
+  string key;
+  
+  /* Error checking */
+  if ( params->isNull() )
+    return true;
+  
+  /* Setup */
+  
+  /* Main processing */
+  // MRW -- finish parsing all of the variables
+  // claimant_cred_handle
+
+  // input_name
+  if (!(params->get("input_name").isNull() ||
+       (params->get("input_name").isString() &&
+        string("") == params->get("input_name").string())))
+  {
+    if (params->get("input_name").isString())
+    {
+      key = params->get("input_name").string();
+      this->inputName = GSSNameCache::instance()->retrieve( key.c_str() );
+    }
+  }
+  return(true);  
+}
+
+
+GSSDisplayName::GSSDisplayName ( JSONObject *params )
+{
+  loadParameters(params);
+}
diff --git a/json_gssapi/src/commands/GSSDisplayName.h b/json_gssapi/src/commands/GSSDisplayName.h
new file mode 100644 (file)
index 0000000..df944ac
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * 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.
+ *
+ */
+
+#ifndef GSSDISPLAYNAME_H
+#define GSSDISPLAYNAME_H
+
+#include <commands/GSSCommand.h>
+#include <datamodel/GSSName.h>
+
+class GSSDisplayName : public GSSCommand
+{
+public:
+    GSSDisplayName();
+    GSSDisplayName ( JSONObject *params );
+    ~GSSDisplayName();
+    virtual JSONObject* toJSON();
+    virtual void execute();
+    
+private:
+  GSSName inputName;
+  bool loadParameters( const JSONObject *params );
+};
+
+#endif // GSSDISPLAYNAME_H
index 3cab428..55df3c1 100644 (file)
@@ -282,7 +282,7 @@ JSONObject *GSSInitSecContext::toJSON()
 {
   /* Variables */
   // MRW -- values should be scoped to the class, so execute can set error values?
-  std::string output_str;
+  std::string output_str((char *)output_token.value, output_token.length);
   JSONObject *values = new JSONObject();
   
   /* Error checking */
@@ -295,7 +295,7 @@ JSONObject *GSSInitSecContext::toJSON()
   values->set("context_handle", this->contextKey.c_str());
   values->set("actual_mech_type", this->getActualMechType().toString().c_str());
   // MRW -- is output_token.value guaranteed to be null-terminated?
-  output_str = (char *)output_token.value;
+  //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);