1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
/* Authors:
* Petr Vobornik <pvoborni@redhat.com>
*
* Copyright (C) 2012 Red Hat
* see file 'COPYING' for use and warranty information
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
var EXPORTED_SYMBOLS = ["kerberosauth", "kerberosauth_listener"];
var Cc = Components.classes;
var Ci = Components.interfaces;
var kerberosauth = {
// Dictionary of configuration options this extension can configure.
// An alias (key) is set for each options. Using a set of aliases limits
// configuration pages from supplying potential malicious options.
config_options: {
referer: ['network.http.sendRefererHeader', 'int'],
native_gss_lib: ['network.negotiate-auth.using-native-gsslib', 'bool'],
trusted_uris: ['network.negotiate-auth.trusted-uris', 'str'],
allow_proxies: ['network.negotiate-auth.allow-proxies', 'bool']
},
// Some preconfigurations to make things easier. Can be good if UI is added
// (mostly for future usage).
predefined_configurations: {
ipa: {
referer: '2',
native_gss_lib: 'true',
trusted_uris: '',
allow_proxies: 'true',
append: ['trusted_uris']
}
},
page_listener: function(event, dom_window) {
var self = this;
var conf = {
event: event,
window: dom_window || window,
element: event.target
};
if (!conf.element.hasAttribute('method')) return;
var method = conf.element.getAttribute('method');
if (method === 'configure') self.configure(conf);
if (method === 'can_configure') self.send_response(conf.element, { answer: 'true' });
},
send_response: function(element, options) {
options = options || {};
var doc = element.ownerDocument;
for (var opt in options) {
element.setAttribute(opt, options[opt]);
}
var answer_event = doc.createEvent("HTMLEvents");
answer_event.initEvent("kerberos-auth-answer", true, false);
element.dispatchEvent(answer_event);
},
notify_installed: function(window) {
var doc = window.document;
var event = doc.createEvent("HTMLEvents");
event.initEvent("kerberos-auth-installed", true, false);
doc.dispatchEvent(event);
},
configure: function(conf) {
var self = this;
var options = {}; // options to be configured
var opt;
// use predefined configuration if supplied
if (conf.element.hasAttribute('predefined')) {
var predefined = conf.element.getAttribute('predefined');
var pconfig = self.predefined_configurations[predefined];
if (pconfig) {
for (opt in pconfig) {
options[opt] = pconfig[opt];
}
}
}
// overwrite predefined with supplied and only supported options
for (var i=0; i < conf.element.attributes.length; i++) {
var attr = conf.element.attributes[i].name;
if (attr in self.config_options) {
options[attr] = conf.element.getAttribute(attr);
}
}
if (self.prompt(conf, options)) {
self.configure_core(conf, options);
self.send_response(conf.element, { answer: 'configured' });
} else {
self.send_response(conf.element, { answer: 'aborted' });
}
},
configure_core: function(conf, options) {
var self = this;
var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
var append_opts = options.append || [];
for (var opt in options) {
if (!self.config_options[opt]) continue;
var name = self.config_options[opt][0];
var type = self.config_options[opt][1];
var value = options[opt];
if (type === 'str') {
if (value && append_opts.indexOf(opt) > -1) {
var current = prefs.getCharPref(name) || '';
if (this.str_contains(current, value)) {
continue;
} else if (current) {
value = current + ', ' + value;
}
}
prefs.setCharPref(name, value);
} else if (type ==='int') {
prefs.setIntPref(name, Number(value));
} else if (type === 'bool') {
prefs.setBoolPref(name, value === 'true');
}
}
},
str_contains: function(str, value) {
if (!str) return false;
var vals = str.split(',');
for (var i=0, l=vals.length; i<l; i++) {
if (vals[i].trim() === value) return true;
}
return false;
},
prompt: function(conf, options) {
var strs = Cc["@mozilla.org/intl/stringbundle;1"].
getService(Ci.nsIStringBundleService).
createBundle("chrome://kerberosauth/locale/kerberosauth.properties");
var prompts = Cc["@mozilla.org/embedcomp/prompt-service;1"].
getService(Ci.nsIPromptService);
var title = strs.GetStringFromName('prompt_title');
var text = strs.GetStringFromName('prompt_topic');
if (options.trusted_uris) {
text += strs.GetStringFromName('prompt_domain').replace('${domain}', options.trusted_uris);
}
text += strs.GetStringFromName('prompt_question');
var flags = prompts.STD_YES_NO_BUTTONS;
var confirmed = prompts.confirmEx(conf.window, title, text, flags, "","","",
null,{value: false}) === 0;
return confirmed;
}
};
var kerberosauth_listener = function(window) {
return function(event) {
kerberosauth.page_listener(event, window);
};
};
|