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
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.display_name = function(params)
185 // required parameters
186 var input_name = params.input_name;
187 var callback = params.success;
189 if ( "undefined" == typeof(name) ||
190 "undefined" == typeof(callback) )
193 "import_name called missing either name or success callback"
198 var error = params.error || this.default_error;
199 var app_tag = params.app_tag || this.appTag;
202 nonce = navigator.generateNonce();
205 /* Main processing */
206 // Save our callback, method name, and error function
207 this.callbacks[nonce] = callback;
208 this.errors[nonce] = error;
210 // Now pass the request on to the C code
212 "method":"gss_display_name",
215 "input_name": input_name,
219 "navigator_gss_tag": nonce,
226 GSSEap.prototype.import_name = function (params)
229 // internal variables
232 // Required parameters
233 var name = params.name;
234 var callback = params.success;
236 // Optional & defaulted parameters
237 var name_type = params.name_type || "{1 2 840 113554 1 2 1 4 }";
238 var error = params.error || this.default_error;
239 var app_tag = params.app_tag || this.appTag;
243 // Call an error if we don't have the required parameters.
246 if ( "undefined" == typeof(name) ||
247 "undefined" == typeof(callback) )
250 "import_name called missing either name or success callback"
257 nonce = navigator.generateNonce();
260 /* Main processing */
261 // Save our callback, method name, and error function
262 this.callbacks[nonce] = callback;
263 this.errors[nonce] = error;
265 // Now pass the request on to the C code
267 "method":"gss_import_name",
271 "input_name_type": name_type
275 "navigator_gss_tag": nonce,
282 GSSEap.prototype.gss_error = function (major)
288 callingMask = 255 << 24;
289 routineMask = 255 << 16;
290 mask = callingMask | routineMask;
292 return (0 != (major & mask));
297 navigator.gss_eap = GSSEap;