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 console.log('Loading navigator.gss.js - #9');
37 /* This file gets injected into the web page verbatim */
39 var GSSEap = (function ()
41 function GSSEap(config)
44 this.version = "0.0.1";
45 this.implemented_methods = ["gss_import_name", "gss_init_sec_context", "gss_acquire_cred"];
46 // MRW -- combine success/error callback hashes?
49 this.appTag = config.appTag || "";
50 this.default_error = config.error ||
51 function (major, minor, error, appTag) {
54 window.addEventListener(
56 this.dispatch_responses.bind(this)
59 GSSEap.prototype.dispatch_responses = function (event)
67 /* This message is destined for us only if all the following apply:
68 * - The data.method_name is one of the methods implemented by this
70 * - data.return_values exists
71 * - data.cookies exists
72 * - One of my callbacks matches the nonce in
73 * data.cookies.navigator_gss_tag
74 * - One of my methods matches the nonce in
75 * data.cookies.navigator_gss_tag and that method matches
78 method = event.data.method;
80 ( -1 == this.implemented_methods.indexOf(method) ) ||
81 ("undefined" == typeof (event.data.return_values)) ||
82 ("undefined" == typeof (event.data.cookies)))
87 nonce = event.data.cookies.navigator_gss_tag;
88 event.data.cookies.navigator_gss_tag = undefined;
89 callback = this.callbacks[nonce];
90 if ("undefined" == typeof (callback)) {
94 // We now know that this message is for us!
95 this.callbacks[nonce] = undefined;
96 app_tag = event.data.cookies.app_tag;
97 error = this.errors[nonce] || this.default_error;
99 if (this.gss_error(event.data.return_values.major_status))
101 var errMsg = "Error during " + method + ": " +
102 "Major status message: " +
103 event.data.return_values.errors.major_status_message +
104 "; Minor status message: " +
105 event.data.return_values.errors.minor_status_message;
107 event.data.return_values.major_status,
108 event.data.return_values.minor_status,
112 callback(event.data.return_values, app_tag);
117 GSSEap.prototype.init_sec_context = function (params)
120 // internal variables
123 // Required parameters
124 var target_name = params.target_name;
125 var callback = params.success || this.success;
127 // Optional & defaulted parameters (some are defaulted at lower layer)
128 var context_handle = params.context_handle;
129 var cred_handle = params.cred_handle;
130 var mech_type = params.mech_type;
131 var req_flags = params.req_flags;
132 var time_req = params.time_req;
133 var input_token = params.input_token;
135 var error = params.error || this.default_error;
136 var app_tag = params.app_tag || this.appTag;
139 // Call an error if we don't have the required parameters.
142 if ( "undefined" == typeof(target_name) ||
143 "undefined" == typeof(callback) )
146 "init_sec_context called missing either target_name or success callback"
152 nonce = navigator.generateNonce();
154 /* Main processing */
155 // Save our callback, method name, and error function
156 this.callbacks[nonce] = callback;
157 this.errors[nonce] = error;
159 // Now pass the request on to the C code
161 "method":"gss_init_sec_context",
164 "target_name": target_name,
165 "context_handle": context_handle,
166 "cred_handle": cred_handle,
167 "mech_type": mech_type,
168 "req_flags": req_flags,
169 "time_req": time_req,
170 "input_token": input_token
175 "navigator_gss_tag": nonce,
182 GSSEap.prototype.import_name = function (params)
185 // internal variables
188 // Required parameters
189 var name = params.name;
190 var callback = params.success;
192 // Optional & defaulted parameters
193 var name_type = params.name_type || "{1 2 840 113554 1 2 1 4 }";
194 var error = params.error || this.default_error;
195 var app_tag = params.app_tag || this.appTag;
199 // Call an error if we don't have the required parameters.
202 if ( "undefined" == typeof(name) ||
203 "undefined" == typeof(callback) )
206 "import_name called missing either name or success callback"
213 nonce = navigator.generateNonce();
216 /* Main processing */
217 // Save our callback, method name, and error function
218 this.callbacks[nonce] = callback;
219 this.errors[nonce] = error;
221 // Now pass the request on to the C code
223 "method":"gss_import_name",
227 "input_name_type": name_type
231 "navigator_gss_tag": nonce,
238 GSSEap.prototype.gss_error = function (major)
244 callingMask = 255 << 24;
245 routineMask = 255 << 16;
246 mask = callingMask | routineMask;
248 return (0 != (major & mask));
253 navigator.gss_eap = GSSEap;