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_display_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 or data.error_mssage 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.error_message) ) ) ||
83 ("undefined" == typeof (event.data.cookies)))
88 nonce = event.data.cookies.navigator_gss_tag;
89 event.data.cookies.navigator_gss_tag = undefined;
90 callback = this.callbacks[nonce];
91 if ("undefined" == typeof (callback)) {
95 // We now know that this message is for us!
96 this.callbacks[nonce] = undefined;
97 app_tag = event.data.cookies.app_tag;
98 error = this.errors[nonce] || this.default_error;
100 if ("undefined" != typeof(event.data.error_message) )
102 error(-1, -1, "Error parsing message: " + event.data.error_message, app_tag);
104 else if (this.gss_error(event.data.return_values.major_status))
106 var errMsg = "Error during " + method + ": " +
107 "Major status message: " +
108 event.data.return_values.errors.major_status_message +
109 "; Minor status message: " +
110 event.data.return_values.errors.minor_status_message;
112 event.data.return_values.major_status,
113 event.data.return_values.minor_status,
117 callback(event.data.return_values, app_tag);
122 GSSEap.prototype.init_sec_context = function (params)
125 // internal variables
128 // Required parameters
129 var target_name = params.target_name;
130 var callback = params.success || this.success;
132 // Optional & defaulted parameters (some are defaulted at lower layer)
133 var context_handle = params.context_handle;
134 var cred_handle = params.cred_handle;
135 var mech_type = params.mech_type;
136 var req_flags = params.req_flags;
137 var time_req = params.time_req;
138 var input_token = params.input_token;
140 var error = params.error || this.default_error;
141 var app_tag = params.app_tag || this.appTag;
144 // Call an error if we don't have the required parameters.
147 if ( "undefined" == typeof(target_name) ||
148 "undefined" == typeof(callback) )
151 "init_sec_context called missing either target_name or success callback"
157 nonce = navigator.generateNonce();
159 /* Main processing */
160 // Save our callback, method name, and error function
161 this.callbacks[nonce] = callback;
162 this.errors[nonce] = error;
164 // Now pass the request on to the C code
166 "method":"gss_init_sec_context",
169 "target_name": target_name,
170 "context_handle": context_handle,
171 "cred_handle": cred_handle,
172 "mech_type": mech_type,
173 "req_flags": req_flags,
174 "time_req": time_req,
175 "input_token": input_token
180 "navigator_gss_tag": nonce,
187 GSSEap.prototype.display_name = function(params)
190 // required parameters
191 var input_name = params.input_name;
192 var callback = params.success;
194 if ( "undefined" == typeof(name) ||
195 "undefined" == typeof(callback) )
198 "import_name called missing either name or success callback"
203 var error = params.error || this.default_error;
204 var app_tag = params.app_tag || this.appTag;
207 nonce = navigator.generateNonce();
210 /* Main processing */
211 // Save our callback, method name, and error function
212 this.callbacks[nonce] = callback;
213 this.errors[nonce] = error;
215 // Now pass the request on to the C code
217 "method":"gss_display_name",
220 "input_name": input_name,
224 "navigator_gss_tag": nonce,
231 GSSEap.prototype.import_name = function (params)
234 // internal variables
237 // Required parameters
238 var name = params.name;
239 var callback = params.success;
241 // Optional & defaulted parameters
242 var name_type = params.name_type || "{1 2 840 113554 1 2 1 4 }";
243 var error = params.error || this.default_error;
244 var app_tag = params.app_tag || this.appTag;
248 // Call an error if we don't have the required parameters.
251 if ( "undefined" == typeof(name) ||
252 "undefined" == typeof(callback) )
255 "import_name called missing either name or success callback"
262 nonce = navigator.generateNonce();
265 /* Main processing */
266 // Save our callback, method name, and error function
267 this.callbacks[nonce] = callback;
268 this.errors[nonce] = error;
270 // Now pass the request on to the C code
272 "method":"gss_import_name",
276 "input_name_type": name_type
280 "navigator_gss_tag": nonce,
287 GSSEap.prototype.gss_error = function (major)
293 callingMask = 255 << 24;
294 routineMask = 255 << 16;
295 mask = callingMask | routineMask;
297 return (0 != (major & mask));
302 navigator.gss_eap = GSSEap;