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.
36 #include <cache/GSSContextCache.h>
40 * gss_wrap_type function;
44 GSSBuffer inputMessage;
45 GSSBuffer outputMessage;
49 OM_uint32 minor_status;
53 bool GSSWrap::loadParameters(JSONObject *params)
56 std::string sQopReq, sConfReq, sInputMessage;
67 if ( ! params->get("conf_req").isNull() )
69 if (params->get("conf_req").isString())
71 sConfReq = params->get("conf_req").string();
72 if (sConfReq == "TRUE")
74 else if (sConfReq == "FALSE")
77 throw std::invalid_argument( std::string("Invalid QOP type given: ") + sConfReq );
78 } else if (params->get("conf_req").isInteger())
79 this->conf_req = (gss_cred_usage_t)( params->get("conf_req").integer() );
81 throw std::invalid_argument( "Unrecognized argument type for conf_req." );
87 if ( ! params->get("qop_req").isNull() )
89 if (params->get("qop_req").isString())
91 sQopReq = params->get("qop_req").string();
92 if (sQopReq == "GSS_C_QOP_DEFAULT")
93 this->qop_req = GSS_C_QOP_DEFAULT;
95 throw std::invalid_argument( std::string("Invalid QOP type given: ") + sQopReq );
96 } else if (params->get("qop_req").isInteger())
97 this->qop_req = (gss_cred_usage_t)( params->get("qop_req").integer() );
99 throw std::invalid_argument( "Unrecognized argument type for qop_req." );
105 if ( ! params->get("input_message").isNull() )
107 sInputMessage = params->get("input_message").string();
108 this->inputMessage.setValue(sInputMessage);
114 if ( ! params->get("context_handle").isNull() )
116 std::string contextKey = params->get("context_handle").string();
117 GSSContext ctx = GSSContextCache::instance()->retrieve(contextKey);
118 this->context = ctx.getContext();
126 GSSWrap::GSSWrap ( JSONObject* params, gss_wrap_type fn )
129 loadParameters(params);
138 void GSSWrap::execute()
141 gss_buffer_desc output_buf;
144 &(this->minor_status),
148 this->inputMessage.toGss(),
153 this->outputMessage.setValue( (char *)output_buf.value, output_buf.length );
156 /* Desired JSON output:
161 * "conf_state": "TRUE",
162 * "output_message": "asdf"
166 JSONObject *GSSWrap::toJSON()
169 const char *conf_state;
170 JSONObject *values = new JSONObject();
179 values->set("major_status", this->retVal);
180 values->set("minor_status", this->minor_status);
182 conf_state = (this->conf_state) ? "TRUE" : "FALSE";
183 values->set("conf_state", conf_state);
187 this->outputMessage.toString().c_str()