End-to-end working gss_import_name call
authorMark Donnelly <mark@painless-security.com>
Tue, 30 Sep 2014 13:35:11 +0000 (09:35 -0400)
committerMark Donnelly <mark@painless-security.com>
Tue, 30 Sep 2014 13:35:11 +0000 (09:35 -0400)
chrome/app/gssweb.contentscript.js [new file with mode: 0644]
chrome/app/gssweb_background.js [new file with mode: 0644]
chrome/app/manifest.json
chrome/app/navigator.gss.js [new file with mode: 0644]
chrome/test/test.html [new file with mode: 0644]
json_gssapi/json_protocol.txt

diff --git a/chrome/app/gssweb.contentscript.js b/chrome/app/gssweb.contentscript.js
new file mode 100644 (file)
index 0000000..abcea95
--- /dev/null
@@ -0,0 +1,34 @@
+console.log("Loading content script #6...");
+
+var elt = document.createElement("script");
+elt.setAttribute("src", 
+                 chrome.extension.getURL('navigator.gss.js')
+                );
+document.head.appendChild(elt);
+
+
+var port = chrome.runtime.connect({name: "com.painlesssecurity.gssweb"});
+
+/* When we get a message back from the extension 
+ * background script
+ */
+port.onMessage.addListener(
+  function(gssReplyJSON) {
+     console.log("Extension port listener received message: [" + 
+                  JSON.stringify(gssReplyJSON) + "]"
+               ); 
+     window.postMessage(gssReplyJSON, "*");
+  }
+);
+
+window.addEventListener("message", function(event) {
+    // We only accept messages from ourselves
+    if (event.source != window)
+       return;
+
+    console.log("Window message listener received message: [" +
+               JSON.stringify(event.data) + "]"
+               );
+    port.postMessage(event.data);
+}, false);
+    
diff --git a/chrome/app/gssweb_background.js b/chrome/app/gssweb_background.js
new file mode 100644 (file)
index 0000000..9233aa5
--- /dev/null
@@ -0,0 +1,56 @@
+console.log("gssweb_background.js loading: #4");
+
+
+
+
+var gssNativePort = null;
+var applicationPort = null;
+
+/* What to do with the output of the GSS command line */
+function onGSSResponse(msg) {
+  console.info('Response from GSS command line: [' + 
+              JSON.stringify(msg) + ']'
+             );
+  
+  // Send the message on to the content script
+  applicationPort.postMessage(msg);
+  console.info('Response sent to the content script.');
+}
+
+function connectToNativeHost() {
+  console.info('Connecting to json_gssapi command line.');
+  // var host = 'com.google.chrome.example.echo';
+  var host = 'com.painlesssecurity.jsongss';
+  gssNativePort = chrome.runtime.connectNative( host );
+  gssNativePort.onMessage.addListener( onGSSResponse );
+}
+
+
+connectToNativeHost();
+
+// When we receive a connection from a page through the content script...
+chrome.runtime.onConnect.addListener(
+  function(thePort) 
+  {
+    // ... First, make sure that we're talking to the right people
+    console.assert(thePort.name == "com.painlesssecurity.gssweb");
+
+    // ... Second, save out the port
+    applicationPort = thePort;
+    
+    applicationPort.onMessage.addListener(
+      // Now, when we receive a message
+      function(msg)
+      {
+        console.info(
+          'About to send message to Native Port: [' +
+          JSON.stringify(msg) + ']'
+        );
+       gssNativePort.postMessage(msg);
+        console.info('... message sent to Native Port.')
+       
+      }
+    );
+  }
+);
+
index d4cbb8c..a0a1355 100644 (file)
@@ -4,10 +4,22 @@
          "local_path": "gssweb.html"
       }
    },
+   "background": {
+       "scripts": ["gssweb_background.js"]
+   },
+   "content_scripts": [
+       {
+          "matches": ["*://*/*"],
+          "js": ["gssweb.contentscript.js"]
+       }
+   ],
    "description": "Chrome plugin to supply GSSAPI calls.",
    "key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyuV9oMZvryLveAqvoFrbQGGU/NOPSFqBymsGLuQKS4i6LfQ/z+pRUTri4r/YWgWvfGGZhjdBy935QWJ0lpfq+dX+XCYSZLzFSllrLB/NM8MI9OQQKeyrnf8ie1pTU92KJGNVAeN7KpgdZjI2G6SNzV6CGz1D7FWkcOyeyk1GWyiFeUc7yEVSTuDhREiD2zEelgc29i9bUh/JZs+yTbWkIkBxdvhBEaU0MJIVyNUhrUbTFANqBu3kigbji+LCb63c0u567jBGkQDtDVS4rstsBwTjuCbCfzppNsMvexrx3kA2FpUj4otHEO2I6W0xlSsv8wza6OFwbV+MISK7CiBmkwIDAQAB",
    "manifest_version": 2,
    "name": "GSS Web Plugin",
    "permissions": [ "nativeMessaging" ],
-   "version": "1.0"
+   "version": "1.0",
+   "web_accessible_resources": [
+      "navigator.gss.js"
+   ]
 }
diff --git a/chrome/app/navigator.gss.js b/chrome/app/navigator.gss.js
new file mode 100644 (file)
index 0000000..d65b810
--- /dev/null
@@ -0,0 +1,47 @@
+console.log('Loading navigator.gss.js - #5');
+
+/* This file gets injected into the web page verbatim */
+
+navigator.gss_import_name = function(name, mech, nonce, callbackFn){
+    console.log("Name: " + name);
+    console.log("Mech: " + mech);
+    
+    /* Listen for a message back from the content script */
+    window.addEventListener(
+      "message",
+      function(event)
+      {
+        var nonce;
+        var name;
+        
+        if (event.data.command != "gss_import_name" ||
+            (typeof(event.data.return_values) == "undefined") )
+        {
+          return;
+        }
+        
+        // Extract the data from the returned JSON
+        name = event.data.return_values.gss_name;
+        nonce = event.data.nonce;
+        major = event.data.return_values.major_status;
+        minor = event.data.return_values.minor_status;
+        
+        // Invoke the callback with the extracted data
+        callbackFn(name, nonce, major, minor);
+      }
+    );
+
+    /* Send a message off to the extension that we want to 
+     * call gss_import_name
+     */
+    window.postMessage({
+       "method":"gss_import_name",
+       "arguments":
+       {
+           "input_name": name,
+           "input_name_type": mech
+       },
+        "nonce": nonce
+    }, "*");
+
+};
diff --git a/chrome/test/test.html b/chrome/test/test.html
new file mode 100644 (file)
index 0000000..650a065
--- /dev/null
@@ -0,0 +1,46 @@
+<html>
+  <head>
+    <title>GSSApi Tester Application</title>
+    <script language="javascript">
+      function report(msg) {
+        var response = document.getElementById('response');
+        response.innerHTML = '<p>' + msg + '</p>' + response.innerHTML;
+      }
+
+      function doImportName() {
+        var ret = navigator.gss_import_name( 
+          document.getElementById('import_name_name').value,
+          document.getElementById('import_name_mech').value,
+          'nonce',
+          function(name, nonce, major, minor) {
+            report('GSS imported name: ' + name);
+            report('GSS imported nonce: ' + nonce);
+            report('GSS imported major status: ' + major);
+            report('GSS imported minor status: ' + minor);
+          }
+        );
+      }
+      
+      document.addEventListener('DOMContentLoaded', function () {
+        document.getElementById('import_name').addEventListener(
+          'click', doImportName);
+        console.log('DOMContentLoaded.');
+      });
+
+    </script>
+  </head>
+  <body>
+    <h2>GSS Import Name parameters:</h2>
+    <label for="import_name_name">Name:</label>
+    <input name="import_name_name" id="import_name_name" value="HTTP@localhost.localdomain" />
+    <br/>
+    <label for="import_name_mech">Mechanism:</label>
+    <input name="import_name_mech"
+           id="import_name_mech"
+           value="{1 2 840 113554 1 2 1 4 }" />
+    <br/>
+    <button id="import_name">gss_import_name</button>
+    <br/>
+    <div id='response'></div>
+  </body>
+</html>
index 9a6c30a..9305594 100644 (file)
Binary files a/json_gssapi/json_protocol.txt and b/json_gssapi/json_protocol.txt differ