The messages passed in to the C++ code will now have the following elements copied in to the response:
cookies
method
The c++ code was refactored to have a common point for top-level JSON parsing, and the GSSCommand subclasses now only pull out their specific arguments.
GSSCreateSecContextCommand was renamed to GSSInitSecContext.
There was an error in util_json in how a JSONObject implemented operator= that made it at best a no-op. (At worst it caused crashes.)
console.log("Loading content script #6...");
-var elt = document.createElement("script");
-elt.setAttribute("src",
- chrome.extension.getURL('navigator.gss.js')
- );
-document.head.appendChild(elt);
+function addScript(url) {
+ var elt = document.createElement("script");
+ elt.setAttribute("src",
+ url );
+ document.head.appendChild(elt);
+}
+
+addScript( chrome.extension.getURL('gssweb_utils.js') );
+addScript( chrome.extension.getURL('navigator.gss.js') );
var port = chrome.runtime.connect({name: "com.painlesssecurity.gssweb"});
*/
port.onMessage.addListener(
function(gssReplyJSON) {
- console.log("Extension port listener received message: [" +
+ var appTag = gssReplyJSON.cookies.app_tag;
+
+ console.log("[" + appTag + "] Extension port listener received message: [" +
JSON.stringify(gssReplyJSON) + "]"
);
window.postMessage(gssReplyJSON, "*");
// We only accept messages from ourselves
if (event.source != window)
return;
-
- console.log("Window message listener received message: [" +
+
+ if ( typeof(event.data.cookies) == 'undefined' )
+ {
+ event.data.cookies = {};
+ }
+ var appTag = event.data.cookies.app_tag;
+
+ console.log("[" + appTag + "] Window message listener received message: [" +
JSON.stringify(event.data) + "]"
);
port.postMessage(event.data);
}, false);
-
+
-
var gssNativePort = null;
-var applicationPort = null;
+var applicationPorts = {};
/* What to do with the output of the GSS command line */
function onGSSResponse(msg) {
- console.info('Response from GSS command line: [' +
+ var nonce;
+ var appPort;
+ var appTag;
+
+ // Read the cookies out of the response
+ if ( typeof(msg.cookies) == 'undefined' ||
+ typeof(msg.cookies.gssweb_bg_tag) == 'undefined' )
+ {
+ console.error(
+ "gssweb_background.js received a response from the command-line NativeHost with no gssweb_bg_tag cookie."
+ );
+ return;
+ }
+ appTag = msg.cookies.app_tag;
+ nonce = msg.cookies.gssweb_bg_tag;
+ msg.cookies.gssweb_bg_tag = undefined;
+
+ // Informationally log
+ console.info('[' + appTag + '] Response from GSS command line: [' +
JSON.stringify(msg) + ']'
);
-
+
+ // Find the content script's port that should receive this message
+ appPort = applicationPorts[nonce]
+ applicationPorts[nonce] = undefined;
+ if ( typeof(appPort) == "undefined")
+ {
+ console.error(
+ "[" + appTag + "] gssweb_background.js received a response from the command-line NativeHost with no associated application port."
+ );
+ return;
+ }
+ // appPort is now guaranteed to exist.
+
+
// Send the message on to the content script
- applicationPort.postMessage(msg);
- console.info('Response sent to the content script.');
+ appPort.postMessage(msg);
+
+ console.info('[' + appTag + '] Response sent to the content script.');
}
function connectToNativeHost() {
// When we receive a connection from a page through the content script...
chrome.runtime.onConnect.addListener(
- function(thePort)
+ function(appPort)
{
// ... 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;
+ console.assert(appPort.name == "com.painlesssecurity.gssweb");
- applicationPort.onMessage.addListener(
+ appPort.onMessage.addListener(
// Now, when we receive a message
function(msg)
{
+ var nonce;
+ var appTag;
+
+ // Deal with the cookies in the message
+ if ( typeof(msg.cookies) == 'undefined')
+ {
+ msg.cookies = {};
+ }
+ appTag = msg.cookies.app_tag;
+
+ // Save out the port
+ nonce = navigator.generateNonce();
+ applicationPorts[nonce] = appPort;
+ msg.cookies.gssweb_bg_tag = nonce;
+
+ // Send the message to the NativePort / command line
console.info(
- 'About to send message to Native Port: [' +
+ '[' + appTag + '] About to send message to Native Port: [' +
JSON.stringify(msg) + ']'
);
gssNativePort.postMessage(msg);
- console.info('... message sent to Native Port.')
+ console.info('[' + appTag + '] ... message sent to Native Port.')
}
);
--- /dev/null
+console.log('Loading gssweb_utils.js - #1');
+
+navigator.generateNonce = function() {
+ // TODO: Make sure that we don't have a collision!
+ // Random integer in the range [0..(2^32-1)]
+ return Math.floor(Math.random() * ( 4294967295 )) ;
+}
+
+
}
},
"background": {
- "scripts": ["gssweb_background.js"]
+ "scripts": [
+ "gssweb_utils.js",
+ "gssweb_background.js"
+ ]
},
"content_scripts": [
{
"permissions": [ "nativeMessaging" ],
"version": "1.0",
"web_accessible_resources": [
- "navigator.gss.js"
+ "navigator.gss.js",
+ "gssweb_utils.js"
]
}
/* 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);
+navigator.gss_callbacks = {};
+
+/*
+navigator.generateNonce = function() {
+ // TODO: Make sure that we don't have a collision!
+ // Random integer in the range [0..(2^32-1)]
+ return Math.floor(Math.random() * ( 4294967295 )) ;
+}
+*/
+
+navigator.gss_import_name = function(name, mech, callbackFn, appTag){
+ var nonce = navigator.generateNonce();
+ navigator.gss_callbacks[nonce] = callbackFn;
/* Listen for a message back from the content script */
window.addEventListener(
"message",
function(event)
{
- var nonce;
+ var app_tag;
var name;
+ var callback;
+ var nonce;
- if (event.data.command != "gss_import_name" ||
+ if (event.data.method != "gss_import_name" ||
(typeof(event.data.return_values) == "undefined") )
{
return;
}
+ var nonce = event.data.cookies.navigator_gss_tag;
+ event.data.cookies.navigator_gss_tag = undefined;
+ callback = navigator.gss_callbacks[nonce];
+ navigator.gss_callbacks[nonce] = undefined;
+
// Extract the data from the returned JSON
name = event.data.return_values.gss_name;
- nonce = event.data.nonce;
+ app_tag = event.data.cookies.app_tag;
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);
+ callback(name, major, minor, app_tag);
}
);
"input_name": name,
"input_name_type": mech
},
- "nonce": nonce
+ "cookies":
+ {
+ "navigator_gss_tag": nonce,
+ "app_tag": appTag
+ }
}, "*");
};
src/datamodel/GSSBuffer.cpp
src/datamodel/GSSCredential.cpp
src/GSSException.cpp
+ src/GSSRequest.cpp
src/commands/GSSGetMic.cpp
- src/commands/GSSCreateSecContextCommand.cpp
+ src/commands/GSSInitSecContext.cpp
src/commands/GSSCommand.cpp
src/commands/GSSImportName.cpp
src/commands/GSSAcquireCred.cpp
#include <commands/GSSImportName.h>
-#include <commands/GSSCreateSecContextCommand.h>
+#include <commands/GSSInitSecContext.h>
#include <commands/GSSAcquireCred.h>
#include <datamodel/GSSBuffer.h>
#include <exception>
#include <string>
#include <unistd.h>
#include <util_json.h>
+#include <GSSRequest.h>
using std::cin;
int main(int argc, char **argv) {
/* Variables */
- string method, output;
- const char* c_str;
+ string output;
char *input;
- JSONObject json;
- JSONObject *result;
- json_error_t jsonErr;
- GSSCommand *cmd;
int len;
ssize_t readTotal, readThisRound, readRemaining;
/* Main processing */
do
{
- try
+ // Read 32 bit length
+ len = 0;
+ readThisRound = readTotal = 0;
+ while(4 != readTotal)
{
- // Read 32 bit length
- len = 0;
- readThisRound = readTotal = 0;
- while(4 != readTotal)
- {
- readThisRound = read(0, ((&len) + readTotal), 4 - readTotal);
- readTotal += readThisRound;
- }
-
- // Reads the number of bytes indicated by the above read
- input = new char[len + 1];
- readTotal = readThisRound = 0;
- while (readTotal < len)
- {
- readRemaining = len - readTotal;
- readThisRound = read( 0, &(input[readTotal]), readRemaining);
- if (-1 == readThisRound)
- break;
- else
- readTotal += readThisRound;
- }
- // ... and null-terminate it
- input[len] = '\0';
-
-
- // Parse the JSON
- JSONObject json = JSONObject::load(input, 0, &jsonErr);
- delete[] input;
-
- if ( json.get("method").isNull() )
- {
- JSONObject response;
- response.set("method", "unknown");
- response.set("error_message", "Did not find a valid method to execute.");
- output = response.dump();
- len = output.length();
- cout.write((char *)&len, 4);
- cout << output << endl;
- continue;
- }
-
- // Oh, how I wish I could simply use: switch(json.get("method"))
- c_str = json.get("method").string();
- method = c_str;
- if ("gss_import_name" == method)
- {
- cmd = new GSSImportName(&json);
- }
- else if ("gss_create_sec_context" == method)
- {
- cmd = new GSSCreateSecContextCommand(&json);
- }
- else if ("gss_acquire_cred" == method)
- {
- cmd = new GSSAcquireCred(&json);
- }
- else
- {
- JSONObject response;
- response.set("method", "unknown");
- response.set("error_message", "Did not find a valid method to execute.");
- output = response.dump();
- len = output.length();
- cout.write((char *)&len, 4);
- cout << output << endl;
-
- continue;
- }
-
- cmd->execute();
- result = cmd->toJSON();
- delete cmd;
-
- output = result->dump();
- len = output.length();
-
- cout.write((char *)&len, 4);
- cout << output;
- cout.flush();
-
+ readThisRound = read(0, ((&len) + readTotal), 4 - readTotal);
+ readTotal += readThisRound;
}
- catch ( std::bad_alloc& e )
+
+ // Reads the number of bytes indicated by the above read
+ input = new char[len + 1];
+ readTotal = readThisRound = 0;
+ while (readTotal < len)
{
- JSONObject response;
- JSONObject error;
- response.set("method", "unknown");
- response.set("error_message", "Could not parse the input JSON");
- response.set("original message", input);
- error.set("text", jsonErr.text);
- error.set("source", jsonErr.source);
- error.set("line", jsonErr.line);
- error.set("column", jsonErr.column);
- error.set("position", jsonErr.position);
- response.set("error", error);
- output = response.dump();
- len = output.length();
- cout.write((char *)&len, 4);
- cout << output << endl;
+ readRemaining = len - readTotal;
+ readThisRound = read( 0, &(input[readTotal]), readRemaining);
+ if (-1 == readThisRound)
+ break;
+ else
+ readTotal += readThisRound;
}
+ // ... and null-terminate it
+ input[len] = '\0';
+
+
+ GSSRequest *req = new GSSRequest(string(input));
+ req->execute();
+ output = req->getResponse();
+ len = output.length();
+
+ cout.write((char *)&len, 4);
+ cout << output;
+ cout.flush();
+
} while(1);
return 0;
--- /dev/null
+/*
+ * Copyright (c) 2014 <copyright holder> <email>
+ *
+ * For license details, see the LICENSE file in the root of this project.
+ *
+ */
+
+#include <cstddef>
+#include <stdexcept>
+
+#include "commands/GSSAcquireCred.h"
+#include "commands/GSSInitSecContext.h"
+#include "commands/GSSImportName.h"
+#include "GSSRequest.h"
+
+using std::bad_alloc;
+
+GSSRequest::GSSRequest ( string jsonString )
+{
+ /* Local variables */
+ /* Error checking */
+ /* Setup */
+ /* Main processing */
+ response = JSONObject();
+ cmd = NULL;
+ requestString = jsonString;
+
+ /* Cleanup */
+ /* Return */
+}
+
+void GSSRequest::execute()
+{
+ /* variables */
+ /* Error checking */
+ /* Setup */
+ parseJSON();
+ getCommand();
+
+ /* Main processing */
+ if (NULL != cmd)
+ cmd->execute();
+
+ /* Cleanup */
+ /* Return */
+}
+
+
+
+void GSSRequest::parseJSON()
+{
+ /* variables */
+ json_error_t jsonErr;
+
+ try {
+ JSONObject cookies;
+ request = JSONObject::load(requestString.c_str(), 0, &jsonErr);
+ cookies = request.get("cookies");
+ response.set("cookies", cookies );
+ response.set("method", request.get("method").string());
+ }
+ /* bad_alloc is thrown when JSONObject can't parse the input string as JSON */
+ catch ( bad_alloc& e )
+ {
+ // Top-level response
+ response.set("error_message", "Could not parse the input JSON.");
+ response.set("original_message", requestString.c_str());
+ }
+}
+
+
+void GSSRequest::getCommand()
+{
+ string method;
+ JSONObject arguments = request.get("arguments");
+
+ /* Error checking */
+ /* Setup */
+ if (request.get("method").isNull() )
+ method = "";
+ else
+ method = string( request.get("method").string() );
+
+ if ( "gss_import_name" == method )
+ {
+ cmd = new GSSImportName ( &arguments );
+ }
+ else if ( "gss_create_sec_context" == method )
+ {
+ cmd = new GSSInitSecContext ( &arguments );
+ }
+ else if ( "gss_acquire_cred" == method )
+ {
+ cmd = new GSSAcquireCred ( &arguments );
+ }
+ else
+ {
+ string error_message = string("Unrecognized command: ") + method;
+ response.set("error_message", error_message.c_str() );
+ response.set("original_message", requestString.c_str());
+ cmd = NULL;
+ }
+}
+
+string GSSRequest::getResponse()
+{
+ /* Variables */
+ JSONObject *return_values;
+ string gssResponse;
+
+ /* Main processing */
+ // Put the return values into the response, assuming that the command
+ // was actually executed.
+ if (NULL != cmd)
+ {
+ return_values = cmd->toJSON();
+ response.set("return_values", *return_values);
+ }
+
+ // Convert the response into a string to return.
+ gssResponse = string( response.dump() );
+
+ /* Return */
+ return(gssResponse);
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 <copyright holder> <email>
+ *
+ * For license details, see the LICENSE file in the root of this project.
+ *
+ */
+
+#ifndef GSSREQUEST_H
+#define GSSREQUEST_H
+
+#include <string>
+
+#include "commands/GSSCommand.h"
+#include "util_json.h"
+
+using std::string;
+
+class GSSRequest
+{
+public:
+ GSSRequest(string jsonString);
+ ~GSSRequest();
+
+ void execute();
+ string getResponse();
+
+private:
+ string requestString;
+ JSONObject request;
+ JSONObject response;
+ GSSCommand *cmd;
+
+ void getCommand();
+ void parseJSON();
+};
+
+#endif // GSSREQUEST_H
/**************
* cred_usage *
**************/
- if ( ! params->get("arguments").get("cred_usage").isNull() )
+ if ( ! params->get("cred_usage").isNull() )
{
- if (params->get("arguments").get("cred_usage").isString())
+ if (params->get("cred_usage").isString())
{
- sCredUsage = params->get("arguments").get("cred_usage").string();
+ sCredUsage = params->get("cred_usage").string();
if (sCredUsage == "GSS_C_BOTH")
this->cred_usage = GSS_C_BOTH;
else if (sCredUsage == "GSS_C_INITIATE")
this->cred_usage = GSS_C_ACCEPT;
else
throw std::invalid_argument( std::string("Invalid cred_usage type given: ") + sCredUsage );
- } else if (params->get("arguments").get("cred_usage").isInteger())
- this->cred_usage = (gss_cred_usage_t)( params->get("arguments").get("cred_usage").integer() );
+ } else if (params->get("cred_usage").isInteger())
+ this->cred_usage = (gss_cred_usage_t)( params->get("cred_usage").integer() );
else
throw std::invalid_argument( "Unrecognized argument type for cred_usage." );
}
/*****************
* desired_mechs *
*****************/
- if ( ! params->get("arguments").get("desired_mechs").isNull() )
+ if ( ! params->get("desired_mechs").isNull() )
{
- if ( params->get("arguments").get("desired_mechs").isArray() )
+ if ( params->get("desired_mechs").isArray() )
{
for (nDesiredMechs = 0;
- nDesiredMechs < params->get("arguments").get("desired_mechs").size();
+ nDesiredMechs < params->get("desired_mechs").size();
nDesiredMechs++)
{
- std::string mechStr = params->get("arguments").get("desired_mechs")[nDesiredMechs].string();
+ std::string mechStr = params->get("desired_mechs")[nDesiredMechs].string();
desiredMechs.addOID( GSSOID(mechStr).toGss() );
}
} else
/****************
* desired_name *
****************/
- if ( ! params->get("arguments").get("desired_name").isNull() )
+ if ( ! params->get("desired_name").isNull() )
{
- std::string key = params->get("arguments").get("desired_name").string();
+ std::string key = params->get("desired_name").string();
this->desired_name = GSSNameCache::instance()->retrieve(key);
}
/* Desired JSON output:
*
* {
- * "command": "gss_acquire_cred",
- * "return_values": {
* "major_status": 0,
* "minor_status": 0,
* "cred_handle": "###########",
* "{ 5 6 7 8 }"
* ],
* "time_rec": 0
- * }
* }
*/
JSONObject *GSSAcquireCred::toJSON()
{
/* Variables */
- JSONObject *ret = new JSONObject();
JSONObject *values = new JSONObject();
-// JSONObject mechs = JSONObject::array();
JSONObject *temp;
/* Error checking */
temp = this->actualMechs.toJSONValue();
values->set("actual_mechs", *temp);
- // Put it all together.
- ret->set("command", "gss_acquire_cred");
- ret->set("return_values", *values);
-
/* Cleanup */
/* Return */
- return(ret);
+ return(values);
}
}
/*
- * {"method": "gss_get_mic",
- * "arguments":
* {
* "context_handle": "#######",
* "qop_req": "GSS_C_QOP_DEFAULT",
* "input_message": "mary had a little lamb"
* }
- * }
*
*/
bool GSSGetMic::loadParameters ( JSONObject* params )
/***********
* QOP_REQ *
***********/
- if ( ! params->get("arguments").get("qop_req").isNull() )
+ if ( ! params->get("qop_req").isNull() )
{
- if (params->get("arguments").get("qop_req").isString())
+ if (params->get("qop_req").isString())
{
- sQopReq = params->get("arguments").get("qop_req").string();
+ sQopReq = params->get("qop_req").string();
if (sQopReq == "GSS_C_QOP_DEFAULT")
this->qop_req = GSS_C_QOP_DEFAULT;
else
throw std::invalid_argument( std::string("Invalid QOP type given: ") + sQopReq );
- } else if (params->get("arguments").get("qop_req").isInteger())
- this->qop_req = (gss_cred_usage_t)( params->get("arguments").get("qop_req").integer() );
+ } else if (params->get("qop_req").isInteger())
+ this->qop_req = (gss_cred_usage_t)( params->get("qop_req").integer() );
else
throw std::invalid_argument( "Unrecognized argument type for qop_req." );
}
/*****************
* input_message *
*****************/
- if ( ! params->get("arguments").get("input_message").isNull() )
+ if ( ! params->get("input_message").isNull() )
{
- sInputMessage = params->get("arguments").get("input_message").string();
+ sInputMessage = params->get("input_message").string();
this->inputMessage.setValue(sInputMessage);
}
/******************
* context_handle *
******************/
- if ( ! params->get("arguments").get("context_handle").isNull() )
+ if ( ! params->get("context_handle").isNull() )
{
- sInputMessage = params->get("arguments").get("context_handle").string();
+ sInputMessage = params->get("context_handle").string();
GSSContext ctx = GSSContextCache::instance()->retrieve(sInputMessage);
this->context = ctx.getContext();
}
JSONObject* GSSGetMic::toJSON()
{
/* Variables */
- JSONObject *ret = new JSONObject();
JSONObject *values = new JSONObject();
/* Error checking */
this->outputToken.toString().c_str()
);
- // Put it all together.
- ret->set("command", "gss_get_mic");
- ret->set("return_values", *values);
-
/* Cleanup */
/* Return */
- return(ret);
+ return(values);
}
/* Example output:
*
- * {
- * "command": "gss_import_name",
- * "return_values":
* {
* "major_status": 0,
* "minor_status": 0,
* "gss_name": "base64_encoded_string"
* }
- * }
*
*/
JSONObject *GSSImportName::toJSON()
{
/* Variables */
- JSONObject *ret = new JSONObject();
JSONObject *values = new JSONObject();
/* Error checking */
values->set("major_status", this->retVal);
values->set("minor_status", this->minor_status);
values->set("gss_name", this->outputName.getKey().c_str() );
- ret->set("command", "gss_import_name");
- ret->set("return_values", *values);
/* Cleanup */
/* Return */
- return(ret);
+ return(values);
}
GSSImportName::GSSImportName ( gss_imp_name_type fn )
/* Main processing */
// Easy stuff(*params)
- if ( params->get("arguments").isNull() )
+ if ( params->isNull() )
return true;
- if ( !params->get("arguments").get("input_name").isNull() )
+ if ( !params->get("input_name").isNull() )
{
- if ( params->get("arguments").get("input_name").isString() )
+ if ( params->get("input_name").isString() )
{
- std::string input_name = params->get("arguments").get("input_name").string();
+ std::string input_name = params->get("input_name").string();
this->inputName.setValue( input_name );
}
}
- if ( !params->get("arguments").get("input_name_type").isNull() )
+ if ( !params->get("input_name_type").isNull() )
{
- if ( params->get("arguments").get("input_name_type").isString() )
+ if ( params->get("input_name_type").isString() )
{
- std::string input_name_type = params->get("arguments").get("input_name_type").string();
+ std::string input_name_type = params->get("input_name_type").string();
this->inputNameType.setValue( input_name_type );
}
}
}
-// /***********
-// * QOP_REQ *
-// ***********/
-// if ( ! params->get("arguments").get("qop_req").isNull() )
-// {
-// if (params->get("arguments").get("qop_req").isString())
-// {
-// sQopReq = params->get("arguments").get("qop_req").string();
-// if (sQopReq == "GSS_C_QOP_DEFAULT")
-// this->qop_req = GSS_C_QOP_DEFAULT;
-// else
-// throw std::invalid_argument( std::string("Invalid QOP type given: ") + sQopReq );
-// } else if (params->get("arguments").get("qop_req").isInteger())
-// this->qop_req = (gss_cred_usage_t)( params->get("arguments").get("qop_req").integer() );
-// else
-// throw std::invalid_argument( "Unrecognized argument type for qop_req." );
-// }
-//
-// /*****************
-// * input_message *
-// *****************/
-// if ( ! params->get("arguments").get("input_message").isNull() )
-// {
-// sInputMessage = params->get("arguments").get("input_message").string();
-// this->inputMessage.setValue(sInputMessage);
-// }
/* Variables */
*
*/
-#include "GSSCreateSecContextCommand.h"
+#include "GSSInitSecContext.h"
#include "GSSException.h"
#include <cache/GSSContextCache.h>
#include <cache/GSSNameCache.h>
);
void
-GSSCreateSecContextCommand::execute()
+GSSInitSecContext::execute()
{
/* Variables */
init_sec_context fn = (init_sec_context)function;
/* Return */
}
-const char* GSSCreateSecContextCommand::getTargetDisplayName()
+const char* GSSInitSecContext::getTargetDisplayName()
{
/* Variables */
gss_buffer_desc output_name;
return( ret );
}
-bool GSSCreateSecContextCommand::loadParameters(JSONObject *params)
+bool GSSInitSecContext::loadParameters(JSONObject *params)
{
/* Variables */
std::string key;
/* Error checking */
- if ( params->get("arguments").isNull() )
+ if ( params->isNull() )
return true;
/* Setup */
/* Main processing */
// Easy stuff(*params)
- if ( !params->get("arguments").get("time_req").isNull() )
- this->time_req = params->get("arguments").get("time_req").integer();
+ if ( !params->get("time_req").isNull() )
+ this->time_req = params->get("time_req").integer();
- if ( !params->get("arguments").get("req_flags").isNull() )
- this->req_flags = params->get("arguments").get("req_flags").integer();
+ if ( !params->get("req_flags").isNull() )
+ this->req_flags = params->get("req_flags").integer();
// context_handle
- if ( ! params->get("arguments").get("context_handle").isNull() )
+ if ( ! params->get("context_handle").isNull() )
{
this->context_handle = GSS_C_NO_CONTEXT;
- if (params->get("arguments").get("context_handle").isString())
+ if (params->get("context_handle").isString())
{
- key = params->get("arguments").get("context_handle").string();
+ key = params->get("context_handle").string();
context = GSSContextCache::instance()->retrieve( key.c_str() );
this->context_handle = context.getContext();
}
}
// target_name
- if ( ! params->get("arguments").get("target_name").isNull() )
+ if ( ! params->get("target_name").isNull() )
{
this->target_name = GSS_C_NO_NAME;
- if (params->get("arguments").get("target_name").isString())
+ if (params->get("target_name").isString())
{
- key = params->get("arguments").get("target_name").string();
+ key = params->get("target_name").string();
targetName = GSSNameCache::instance()->retrieve(key);
}
// mech_type
- if ( ! params->get("arguments").get("mech_type").isNull() )
+ if ( ! params->get("mech_type").isNull() )
{
key.clear();
- if (params->get("arguments").get("mech_type").isString())
+ if (params->get("mech_type").isString())
{
- key = params->get("arguments").get("mech_type").string();
+ key = params->get("mech_type").string();
mechType.setValue(key);
}
if (GSS_C_NO_OID == this->mechType.toGss() )
}
// input_token
- if ( ! params->get("arguments").get("input_token").isNull() )
+ if ( ! params->get("input_token").isNull() )
{
- key = params->get("arguments").get("input_token").string();
+ key = params->get("input_token").string();
this->input_token.value = (void *)key.c_str();
this->input_token.length = key.length();
}
return true;
}
-bool GSSCreateSecContextCommand::zeroOut(bool initialized)
+bool GSSInitSecContext::zeroOut(bool initialized)
{
/* Error checking */
/* Variables */
return(true);
}
-JSONObject *GSSCreateSecContextCommand::toJSON()
+JSONObject *GSSInitSecContext::toJSON()
{
/* Variables */
- JSONObject *ret = new JSONObject();
JSONObject *values = new JSONObject();
/* Error checking */
values->set("output_token", (const char *)this->output_token.value);
values->set("ret_flags", this->ret_flags);
values->set("time_rec", this->time_rec);
- ret->set("command", "gss_init_sec_context");
- ret->set("return_values", *values);
/* Cleanup */
/* Return */
- return(ret);
+ return(values);
}
-GSSCreateSecContextCommand::GSSCreateSecContextCommand(
+GSSInitSecContext::GSSInitSecContext(
JSONObject *params,
void *fn) : GSSCommand(params)
{
function = fn;
}
-GSSCreateSecContextCommand::GSSCreateSecContextCommand(void *fn)
+GSSInitSecContext::GSSInitSecContext(void *fn)
{
zeroOut(false);
function = fn;
*
*/
-#ifndef GSSCREATESECCONTEXTCOMMAND_H
-#define GSSCREATESECCONTEXTCOMMAND_H
+#ifndef GSSINITSECCONTEXT_H
+#define GSSINITSECCONTEXT_H
#include "GSSCommand.h"
#include <datamodel/GSSContext.h>
#include <datamodel/GSSOID.h>
#include <gssapi.h>
-class GSSCreateSecContextCommand : public GSSCommand
+class GSSInitSecContext : public GSSCommand
{
public:
void execute();
JSONObject *toJSON();
- GSSCreateSecContextCommand(void *fn = (void *)&gss_init_sec_context);
- GSSCreateSecContextCommand(JSONObject *params, void *fn = (void *)&gss_init_sec_context);
+ GSSInitSecContext(void *fn = (void *)&gss_init_sec_context);
+ GSSInitSecContext(JSONObject *params, void *fn = (void *)&gss_init_sec_context);
bool loadParameters(JSONObject *params);
bool zeroOut(bool initialized = true);
std::string contextKey;
};
-#endif // GSSCREATESECCONTEXTCOMMAND_H
+#endif // GSSINITSECCONTEXT_H
/* JSON input
*
- * {"method": "gss_pseudo_random",
- * "arguments":
* {
* "context_handle": "########",
* "prf_key": ###,
/***********
* prf_key *
***********/
- if ( ! params->get("arguments").get("prf_key").isNull() )
+ if ( ! params->get("prf_key").isNull() )
{
- if (params->get("arguments").get("prf_key").isInteger())
- this->key = params->get("arguments").get("prf_key").integer();
+ if (params->get("prf_key").isInteger())
+ this->key = params->get("prf_key").integer();
else
throw std::invalid_argument( "Unrecognized argument type for prf_key." );
}
/**********************
* desired_output_len *
**********************/
- if ( ! params->get("arguments").get("desired_output_len").isNull() )
+ if ( ! params->get("desired_output_len").isNull() )
{
- if (params->get("arguments").get("desired_output_len").isInteger())
- this->desiredOutputLength = params->get("arguments").get("desired_output_len").integer();
+ if (params->get("desired_output_len").isInteger())
+ this->desiredOutputLength = params->get("desired_output_len").integer();
else
throw std::invalid_argument( "Unrecognized argument type for desired_output_len." );
}
/**********
* prf_in *
**********/
- if ( ! params->get("arguments").get("prf_in").isNull() )
+ if ( ! params->get("prf_in").isNull() )
{
- if (params->get("arguments").get("prf_in").isString())
+ if (params->get("prf_in").isString())
{
- sInputMessage = params->get("arguments").get("prf_in").string();
+ sInputMessage = params->get("prf_in").string();
this->inputMessage.setValue(sInputMessage);
}
}
/******************
* context_handle *
******************/
- if ( ! params->get("arguments").get("context_handle").isNull() )
+ if ( ! params->get("context_handle").isNull() )
{
- if (params->get("arguments").get("context_handle").isString())
+ if (params->get("context_handle").isString())
{
- std::string contextKey = params->get("arguments").get("context_handle").string();
+ std::string contextKey = params->get("context_handle").string();
GSSContext ctx = GSSContextCache::instance()->retrieve(contextKey);
this->context = ctx.getContext();
}
JSONObject* GSSPseudoRandom::toJSON()
{
/* Variables */
- JSONObject *ret = new JSONObject();
JSONObject *values = new JSONObject();
/* Error checking */
this->outputMessage.toString().c_str()
);
- // Put it all together.
- ret->set("command", "gss_pseudo_random");
- ret->set("return_values", *values);
-
/* Cleanup */
/* Return */
- return(ret);
+ return(values);
}
/*****************
* input_message *
*****************/
- if ( ! params->get("arguments").get("input_message").isNull() )
+ if ( ! params->get("input_message").isNull() )
{
- sInputMessage = params->get("arguments").get("input_message").string();
+ sInputMessage = params->get("input_message").string();
this->inputMessage.setValue(sInputMessage);
}
/******************
* context_handle *
******************/
- if ( ! params->get("arguments").get("context_handle").isNull() )
+ if ( ! params->get("context_handle").isNull() )
{
- sInputMessage = params->get("arguments").get("context_handle").string();
+ sInputMessage = params->get("context_handle").string();
GSSContext ctx = GSSContextCache::instance()->retrieve(sInputMessage);
this->context = ctx.getContext();
}
{
/* Variables */
const char *conf_state;
- JSONObject *ret = new JSONObject();
JSONObject *values = new JSONObject();
/* Error checking */
this->outputMessage.toString().c_str()
);
- // Put it all together.
- ret->set("command", "gss_wrap");
- ret->set("return_values", *values);
-
/* Cleanup */
/* Return */
- return(ret);
+ return(values);
}
/************
* CONF_REQ *
************/
- if ( ! params->get("arguments").get("conf_req").isNull() )
+ if ( ! params->get("conf_req").isNull() )
{
- if (params->get("arguments").get("conf_req").isString())
+ if (params->get("conf_req").isString())
{
- sConfReq = params->get("arguments").get("conf_req").string();
+ sConfReq = params->get("conf_req").string();
if (sConfReq == "TRUE")
this->conf_req = 1;
else if (sConfReq == "FALSE")
this->conf_req = 0;
else
throw std::invalid_argument( std::string("Invalid QOP type given: ") + sConfReq );
- } else if (params->get("arguments").get("conf_req").isInteger())
- this->conf_req = (gss_cred_usage_t)( params->get("arguments").get("conf_req").integer() );
+ } else if (params->get("conf_req").isInteger())
+ this->conf_req = (gss_cred_usage_t)( params->get("conf_req").integer() );
else
throw std::invalid_argument( "Unrecognized argument type for conf_req." );
}
/***********
* QOP_REQ *
***********/
- if ( ! params->get("arguments").get("qop_req").isNull() )
+ if ( ! params->get("qop_req").isNull() )
{
- if (params->get("arguments").get("qop_req").isString())
+ if (params->get("qop_req").isString())
{
- sQopReq = params->get("arguments").get("qop_req").string();
+ sQopReq = params->get("qop_req").string();
if (sQopReq == "GSS_C_QOP_DEFAULT")
this->qop_req = GSS_C_QOP_DEFAULT;
else
throw std::invalid_argument( std::string("Invalid QOP type given: ") + sQopReq );
- } else if (params->get("arguments").get("qop_req").isInteger())
- this->qop_req = (gss_cred_usage_t)( params->get("arguments").get("qop_req").integer() );
+ } else if (params->get("qop_req").isInteger())
+ this->qop_req = (gss_cred_usage_t)( params->get("qop_req").integer() );
else
throw std::invalid_argument( "Unrecognized argument type for qop_req." );
}
/*****************
* input_message *
*****************/
- if ( ! params->get("arguments").get("input_message").isNull() )
+ if ( ! params->get("input_message").isNull() )
{
- sInputMessage = params->get("arguments").get("input_message").string();
+ sInputMessage = params->get("input_message").string();
this->inputMessage.setValue(sInputMessage);
}
/***********
* context *
***********/
- if ( ! params->get("arguments").get("context_handle").isNull() )
+ if ( ! params->get("context_handle").isNull() )
{
- std::string contextKey = params->get("arguments").get("context_handle").string();
+ std::string contextKey = params->get("context_handle").string();
GSSContext ctx = GSSContextCache::instance()->retrieve(contextKey);
this->context = ctx.getContext();
}
/* Desired JSON output:
*
- * {
- * "command": "gss_wrap",
- * "return_values":
* {
* "major_status": 0,
* "minor_status": 0,
* "conf_state": "TRUE",
* "output_message": "asdf"
* }
- * }
+ *
*/
JSONObject *GSSWrap::toJSON()
{
/* Variables */
const char *conf_state;
- JSONObject *ret = new JSONObject();
JSONObject *values = new JSONObject();
/* Error checking */
this->outputMessage.toString().c_str()
);
- // Put it all together.
- ret->set("command", "gss_wrap");
- ret->set("return_values", *values);
-
/* Cleanup */
/* Return */
- return(ret);
+ return(values);
}
void set(json_t *obj) {
if (m_obj != obj) {
json_decref(m_obj);
- m_obj = json_incref(m_obj);
+ m_obj = json_incref(obj);
}
}
GSSImportNameTest.cpp
command_mocks/MockImportName.cpp
test_run.cpp
- ../src/commands/GSSCreateSecContextCommand.cpp
+ ../src/commands/GSSInitSecContext.cpp
../src/util_json.cpp
../src/commands/GSSImportName.cpp
../src/GSSException.cpp
#include "GSSCreateSecContextTest.h"
-#include "GSSCreateSecContextCommand.h"
+#include "GSSInitSecContext.h"
#include "command_mocks/InitSecContextMock.h"
#include <iostream>
#include <string.h>
void
GSSCreateSecContextTest::testConstructor()
{
- GSSCreateSecContextCommand cmd = GSSCreateSecContextCommand();
+ GSSInitSecContext cmd = GSSInitSecContext();
void *cmdFn;
void *GSSFn;
const char *in = input.c_str();
JSONObject json = JSONObject::load(in, 0, &jsonErr);
- GSSCreateSecContextCommand cmd = GSSCreateSecContextCommand(
+ GSSInitSecContext cmd = GSSInitSecContext(
&json,
(void *)&mock_init_sec
);
{
gss_ctx_id_t expectedResult, expectedArgument;
- GSSCreateSecContextCommand cmd ((void *)&mock_init_sec);
+ GSSInitSecContext cmd ((void *)&mock_init_sec);
/* Set expectations on what the GSS function will be called with */
cmd.time_req = rand() % 1024;
void GSSCreateSecContextTest::testJSONMarshal()
{
/* Variables */
- GSSCreateSecContextCommand cmd ((void *)&mock_init_sec);
+ GSSInitSecContext cmd ((void *)&mock_init_sec);
JSONObject *result;
GSSContextCache *cache = GSSContextCache::instance();
GSSContext context;
#include <gssapi.h>
-#include "commands/GSSCreateSecContextCommand.h"
+#include "commands/GSSInitSecContext.h"
class GSSCreateSecContextTest : public CppUnit::TestFixture
{
void getCache();
private:
- GSSCreateSecContextCommand command;
+ GSSInitSecContext command;
};
#endif // GSSCREATESECCONTEXTTEST_H
#include <cppunit/extensions/HelperMacros.h>
#include <gssapi.h>
-#include "GSSCreateSecContextCommand.h"
+#include "GSSInitSecContext.h"
#include <stdlib.h>