2 * Copyright (c) 2014, JANET(UK)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of JANET(UK) nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
31 * OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include "GSSGetMic.h"
36 #include <cache/GSSContextCache.h>
39 #include <gssapi/gssapi.h>
41 GSSGetMic::GSSGetMic ( JSONObject* params, gss_get_mic_type fn )
44 loadParameters(params);
49 * "context_handle": "#######",
50 * "qop_req": "GSS_C_QOP_DEFAULT",
51 * "input_message": "mary had a little lamb"
55 bool GSSGetMic::loadParameters ( JSONObject* params )
57 std::string sQopReq, sConfReq, sInputMessage;
68 if ( ! params->get("qop_req").isNull() )
70 if (params->get("qop_req").isString())
72 sQopReq = params->get("qop_req").string();
73 if (sQopReq == "GSS_C_QOP_DEFAULT")
74 this->qop_req = GSS_C_QOP_DEFAULT;
76 throw std::invalid_argument( std::string("Invalid QOP type given: ") + sQopReq );
77 } else if (params->get("qop_req").isInteger())
78 this->qop_req = (gss_cred_usage_t)( params->get("qop_req").integer() );
80 throw std::invalid_argument( "Unrecognized argument type for qop_req." );
86 if ( ! params->get("input_message").isNull() )
88 sInputMessage = params->get("input_message").string();
89 this->inputMessage.setValue(sInputMessage);
95 if ( ! params->get("context_handle").isNull() )
97 sInputMessage = params->get("context_handle").string();
98 GSSContext ctx = GSSContextCache::instance()->retrieve(sInputMessage);
99 this->context = ctx.getContext();
107 void GSSGetMic::execute()
109 gss_buffer_desc output;
111 this->retVal = this->function(
112 &(this->minor_status),
115 this->inputMessage.toGss(),
119 this->outputToken.setValue( (char *)(output.value), output.length );
122 JSONObject* GSSGetMic::toJSON()
125 JSONObject *values = new JSONObject();
134 values->set("major_status", this->retVal);
135 values->set("minor_status", this->minor_status);
139 this->outputToken.toString().c_str()