~gnomefreak/firefox-extensions/firegpg.ubuntu

« back to all changes in this revision

Viewing changes to content/.svn/text-base/api.js.svn-base

  • Committer: John Vivirito
  • Date: 2008-08-12 11:47:33 UTC
  • Revision ID: gnomefreak@ubuntu.com-20080812114733-hn73tjxi26ylibrf
* import of upstream source version 0.5.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ***** BEGIN LICENSE BLOCK *****
 
2
 *   Version: MPL 1.1/GPL 2.0/LGPL 2.1
 
3
 *
 
4
 * The contents of this file are subject to the Mozilla Public License Version
 
5
 * 1.1 (the "License"); you may not use this file except in compliance with
 
6
 * the License. You may obtain a copy of the License at
 
7
 * http://www.mozilla.org/MPL/
 
8
 *
 
9
 * Software distributed under the License is distributed on an "AS IS" basis,
 
10
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
11
 * for the specific language governing rights and limitations under the
 
12
 * License.
 
13
 *
 
14
 * The Original Code is FireGPG.
 
15
 *
 
16
 * The Initial Developer of the Original Code is
 
17
 * FireGPG Team.
 
18
 * Portions created by the Initial Developer are Copyright (C) 2007
 
19
 * the Initial Developer. All Rights Reserved.
 
20
 *
 
21
 * Contributor(s):
 
22
 *
 
23
 * Alternatively, the contents of this file may be used under the terms of
 
24
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 
25
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
26
 * in which case the provisions of the GPL or the LGPL are applicable instead
 
27
 * of those above. If you wish to allow use of your version of this file only
 
28
 * under the terms of either the GPL or the LGPL, and not to allow others to
 
29
 * use your version of this file under the terms of the MPL, indicate your
 
30
 * decision by deleting the provisions above and replace them with the notice
 
31
 * and other provisions required by the GPL or the LGPL. If you do not delete
 
32
 * the provisions above, a recipient may use your version of this file under
 
33
 * the terms of any one of the MPL, the GPL or the LGPL.
 
34
 *
 
35
 * ***** END LICENSE BLOCK ***** */
 
36
 
 
37
var gpgApi = {
 
38
        onLoad: function() {
 
39
                this.initialized = true;
 
40
                this.strings = document.getElementById( "firegpg-strings" );
 
41
 
 
42
                this.prefs = Components.classes["@mozilla.org/preferences-service;1"].
 
43
                                getService(Components.interfaces.nsIPrefService);
 
44
                this.prefs = this.prefs.getBranch("extensions.firegpg.");
 
45
 
 
46
                if ( this.prefs.prefHasUserValue( "enable_gpgapi" ) ) {
 
47
                        var gpgapi_enabled = this.prefs.getBoolPref( "enable_gpgapi" );
 
48
                } else {
 
49
                        var gpgapi_enabled = true;
 
50
                }
 
51
 
 
52
                if ( gpgapi_enabled ) {
 
53
                        window.addEventListener( "firegpg:hello", this.hello, false, true );
 
54
            window.addEventListener( "firegpg:auth", this.auth, false, true );
 
55
            window.addEventListener( "firegpg:register", this.register, false, true );
 
56
            window.addEventListener( "firegpg:listkey", this.listkey, false, true );
 
57
            window.addEventListener( "firegpg:listprivkey", this.listprivkey, false, true );
 
58
            window.addEventListener( "firegpg:check", this.check, false, true );
 
59
            window.addEventListener( "firegpg:sign", this.sign, false, true );
 
60
            window.addEventListener( "firegpg:decrypt", this.decrypt, false, true );
 
61
            window.addEventListener( "firegpg:encrypt", this.encrypt, false, true );
 
62
            window.addEventListener( "firegpg:signandencrypt", this.signandencrypt, false, true );
 
63
                        window.addEventListener( "unload", function() { gpgApi.listenerUnload() }, false );
 
64
                }
 
65
 
 
66
        },
 
67
 
 
68
        listenerUnload: function( event ) {
 
69
                window.removeEventListener( "firegpg:hello", this.hello, false, true );
 
70
        window.removeEventListener( "firegpg:auth", this.auth, false, true );
 
71
        window.removeEventListener( "firegpg:register", this.register, false, true );
 
72
        window.removeEventListener( "firegpg:listkey", this.listkey, false, true );
 
73
        window.removeEventListener( "firegpg:listprivkey", this.listprivkey, false, true );
 
74
        window.removeEventListener( "firegpg:check", this.check, false, true );
 
75
        window.removeEventListener( "firegpg:sign", this.sign, false, true );
 
76
        window.removeEventListener( "firegpg:decrypt", this.decrypt, false, true );
 
77
        window.removeEventListener( "firegpg:encrypt", this.encrypt, false, true );
 
78
        window.removeEventListener( "firegpg:signandencrypt", this.signandencrypt, false, true );
 
79
 
 
80
        },
 
81
 
 
82
 
 
83
    //Return 'firegpg-ok' in 'result' (useful to test firegpg's api presence)
 
84
    hello: function ( event ) {
 
85
 
 
86
        returnData = gpgApi.getReturnDataNode(event.target);
 
87
 
 
88
        returnData.setAttribute('result', 'firegpg-ok');
 
89
 
 
90
        return;
 
91
 
 
92
    },
 
93
 
 
94
    //Return 'auth-ok' in 'result' (or 'auth-fail' is the website have rights to use the api
 
95
    //Paramters : 'auth_key' --> the key for the website
 
96
    auth: function ( event ) {
 
97
 
 
98
 
 
99
        data = gpgApi.getDataNode(event.target);
 
100
 
 
101
        key_auth = data.getAttribute('auth_key');
 
102
 
 
103
        returnData = gpgApi.getReturnDataNode(event.target);
 
104
 
 
105
        if (key_auth == '' || key_auth == undefined || gpgApi.isAuth(key_auth, event.target.ownerDocument) == false )
 
106
        {
 
107
            returnData.setAttribute('result', 'auth-fail');
 
108
            return;
 
109
        }
 
110
 
 
111
        returnData.setAttribute('result', 'auth-ok');
 
112
 
 
113
    },
 
114
 
 
115
    //Try to register a webpage (ask the user). Put 'register-ok' in 'result' or 'register-fail'. It's all is ok, put the auth key in 'auth_key'
 
116
    register: function ( event ) {
 
117
 
 
118
        domain = gpgApi.getDomain(event.target.ownerDocument.location);
 
119
 
 
120
        var texte = document.getElementById("firegpg-strings").getString('api-accept');
 
121
 
 
122
        var reg=new RegExp("\!D\!", "g");
 
123
        texte = texte.replace(reg,domain);
 
124
        var reg=new RegExp("\!N\!", "g");
 
125
        texte = texte.replace(reg,"\n");
 
126
 
 
127
        if (confirm(texte) == false)
 
128
        {
 
129
            returnData.setAttribute('result', 'register-fail');
 
130
            return;
 
131
        }
 
132
 
 
133
        access = gpgApi.getAccessList();
 
134
 
 
135
 
 
136
        auth_key = genreate_api_key();
 
137
 
 
138
        while (access[auth_key] != null) {
 
139
            auth_key = genreate_api_key();
 
140
        }
 
141
 
 
142
        access[auth_key] = domain;
 
143
 
 
144
        gpgApi.setAccessList(access);
 
145
 
 
146
        returnData = gpgApi.getReturnDataNode(event.target);
 
147
 
 
148
        returnData.setAttribute('auth_key', auth_key);
 
149
        returnData.setAttribute('result', 'register-ok');
 
150
 
 
151
        return;
 
152
 
 
153
    },
 
154
 
 
155
    // Return the node with data attributes for return
 
156
    getDataNode: function(d) {
 
157
 
 
158
        liste = d.getElementsByTagName( "firegpg:data" );
 
159
 
 
160
        return liste[0]
 
161
 
 
162
    },
 
163
 
 
164
    //Return 'list-ok' in 'result' (or 'list-err' is there is a problem), and the list of public key in list
 
165
    //Paramters : 'auth_key' --> the key for the website
 
166
    listkey: function ( event ) {
 
167
 
 
168
 
 
169
        data = gpgApi.getDataNode(event.target);
 
170
 
 
171
        key_auth = data.getAttribute('auth_key');
 
172
 
 
173
        returnData = gpgApi.getReturnDataNode(event.target);
 
174
 
 
175
        if (key_auth == '' || key_auth == undefined || gpgApi.isAuth(key_auth, event.target.ownerDocument) == false )
 
176
        {
 
177
            return;
 
178
        }
 
179
 
 
180
        keylistcall = FireGPG.listKeys();
 
181
 
 
182
        if (keylistcall.result == RESULT_SUCCESS)
 
183
            keylist = keylistcall.keylist;
 
184
        else
 
185
            return;
 
186
 
 
187
        return_list = "";
 
188
 
 
189
        for (key in keylist) {
 
190
 
 
191
            return_list = return_list + gpgApi.removeDoublePoint(keylist[key].keyId) + ":" + gpgApi.removeDoublePoint(keylist[key].keyName) + ",";
 
192
        }
 
193
 
 
194
        returnData.setAttribute('list', return_list);
 
195
        returnData.setAttribute('result', 'list-ok');
 
196
 
 
197
    },
 
198
 
 
199
    //Return 'list-ok' in 'result' (or 'list-err' is there is a problem), and the list of private key in list
 
200
    //Paramters : 'auth_key' --> the key for the website
 
201
    listprivkey: function ( event ) {
 
202
 
 
203
 
 
204
        data = gpgApi.getDataNode(event.target);
 
205
 
 
206
        key_auth = data.getAttribute('auth_key');
 
207
 
 
208
        returnData = gpgApi.getReturnDataNode(event.target);
 
209
 
 
210
        if (key_auth == '' || key_auth == undefined || gpgApi.isAuth(key_auth, event.target.ownerDocument) == false )
 
211
        {
 
212
            return;
 
213
        }
 
214
 
 
215
        keylistcall = FireGPG.listKeys(true);
 
216
 
 
217
        if (keylistcall.result == RESULT_SUCCESS)
 
218
            keylist = keylistcall.keylist;
 
219
        else
 
220
            return;
 
221
 
 
222
        return_list = "";
 
223
 
 
224
        for (key in keylist) {
 
225
 
 
226
            return_list = return_list + gpgApi.removeDoublePoint(keylist[key].keyId) + ":" + gpgApi.removeDoublePoint(keylist[key].keyName) + ",";
 
227
        }
 
228
 
 
229
        returnData.setAttribute('list', return_list);
 
230
        returnData.setAttribute('result', 'list-ok');
 
231
 
 
232
    },
 
233
 
 
234
    // Return 'check-ok' in 'result' (or 'check-err' is there is a problem) if the sign is valid.
 
235
    // Return in 'ckeck-infos' info on sign
 
236
    // Paramters : 'auth_key' --> the key for the website, 'text' -> the text to check
 
237
    check: function ( event ) {
 
238
 
 
239
 
 
240
        data = gpgApi.getDataNode(event.target);
 
241
 
 
242
        key_auth = data.getAttribute('auth_key');
 
243
 
 
244
        returnData = gpgApi.getReturnDataNode(event.target);
 
245
 
 
246
        if (key_auth == '' || key_auth == undefined || gpgApi.isAuth(key_auth, event.target.ownerDocument) == false )
 
247
        {
 
248
            return;
 
249
        }
 
250
 
 
251
        text = data.getAttribute('text');
 
252
 
 
253
        if (text == "") {
 
254
                        returnData.setAttribute('result', 'check-err');
 
255
            returnData.setAttribute('error', 'no-data');
 
256
                        return;
 
257
                }
 
258
 
 
259
                var result = FireGPG.verify(true,text);
 
260
 
 
261
                // For I18N
 
262
                var i18n = document.getElementById("firegpg-strings");
 
263
    //TODO : multi signs ?
 
264
                if (result.result == RESULT_ERROR_NO_GPG_DATA) {
 
265
            returnData.setAttribute('result', 'check-err');
 
266
            returnData.setAttribute('error', 'no-gpg');
 
267
                        return;
 
268
        }
 
269
        else if (result.result != RESULT_SUCCESS)
 
270
        {
 
271
            returnData.setAttribute('result', 'check-err');
 
272
            returnData.setAttribute('error', 'unknow');
 
273
                        return;
 
274
        }
 
275
                else if (result.signresult== RESULT_ERROR_BAD_SIGN)
 
276
        {
 
277
            returnData.setAttribute('result', 'check-err');
 
278
            returnData.setAttribute('error', 'bad-sign');
 
279
                        return;
 
280
        }
 
281
        else if (result.signresult == RESULT_ERROR_NO_KEY)
 
282
        {
 
283
            returnData.setAttribute('result', 'check-err');
 
284
            returnData.setAttribute('error', 'no-key');
 
285
                        return;
 
286
        }
 
287
                else {
 
288
 
 
289
                        returnData.setAttribute('result', 'check-ok');
 
290
            returnData.setAttribute('check-infos', result.signresulttext);
 
291
 
 
292
            return;
 
293
 
 
294
        }
 
295
 
 
296
        returnData.setAttribute('result', 'check-err');
 
297
        returnData.setAttribute('error', 'unknow');
 
298
 
 
299
    },
 
300
 
 
301
    // Return 'sign-ok' in 'result' (or 'sign-err' is there is a problem) if makeing a sign was successfull
 
302
    // Return in 'text' a signed text
 
303
    // Paramters : 'auth_key' --> the key for the website, 'text' -> the text to check, 'force-key' --> optional, to force the gpg's key to use
 
304
    sign: function ( event ) {
 
305
 
 
306
        data = gpgApi.getDataNode(event.target);
 
307
 
 
308
        key_auth = data.getAttribute('auth_key');
 
309
 
 
310
        returnData = gpgApi.getReturnDataNode(event.target);
 
311
 
 
312
        if (key_auth == '' || key_auth == undefined || gpgApi.isAuth(key_auth, event.target.ownerDocument) == false )
 
313
        {
 
314
            return;
 
315
        }
 
316
 
 
317
        text = data.getAttribute('text');
 
318
        keyID = data.getAttribute('force-key');
 
319
 
 
320
        if (text == "") {
 
321
                        returnData.setAttribute('result', 'sign-err');
 
322
            returnData.setAttribute('error', 'no-data');
 
323
                        return;
 
324
                }
 
325
 
 
326
        // Needed for a sign
 
327
        if(keyID == null)
 
328
            keyID = getSelfKey();
 
329
                if(keyID == null)
 
330
                        return;
 
331
 
 
332
                var password = getPrivateKeyPassword(false,gpgApi.getDomain(event.target.ownerDocument.location));
 
333
                if(password == null)
 
334
                        return;
 
335
 
 
336
        var result = FireGPG.sign(true,text,keyID,password);
 
337
 
 
338
                // For I18N
 
339
                var i18n = document.getElementById("firegpg-strings");
 
340
 
 
341
                if (result.result  == RESULT_SUCCESS)
 
342
        {
 
343
            returnData.setAttribute('result', 'sign-ok');
 
344
            returnData.setAttribute('text', result.signed);
 
345
 
 
346
            return;
 
347
        }
 
348
                else if (result.result  == RESULT_ERROR_PASSWORD)
 
349
        {
 
350
            returnData.setAttribute('result', 'sign-err');
 
351
            returnData.setAttribute('error', 'bad-pass');
 
352
                        return;
 
353
        }
 
354
                else {
 
355
 
 
356
                        returnData.setAttribute('result', 'sign-err');
 
357
            returnData.setAttribute('error', 'unknow');
 
358
                        return;
 
359
 
 
360
        }
 
361
 
 
362
        returnData.setAttribute('result', 'sign-err');
 
363
        returnData.setAttribute('error', 'unknow');
 
364
 
 
365
    },
 
366
 
 
367
    // Return 'signandencrypt-ok' in 'result' (or 'signandencrypt-err' is there is a problem) if makeing a signed and encrypted text was successfull
 
368
    // Return in 'text' the encrypted  text
 
369
    // Paramters : 'auth_key' --> the key for the website, 'text' -> the text to check, 'keys' --> the keys list, 'force-key' --> optional, to force the gpg's key to use
 
370
    signandencrypt: function ( event ) {
 
371
 
 
372
 
 
373
        data = gpgApi.getDataNode(event.target);
 
374
 
 
375
        key_auth = data.getAttribute('auth_key');
 
376
 
 
377
        returnData = gpgApi.getReturnDataNode(event.target);
 
378
 
 
379
        if (key_auth == '' || key_auth == undefined || gpgApi.isAuth(key_auth, event.target.ownerDocument) == false )
 
380
        {
 
381
            return;
 
382
        }
 
383
 
 
384
        text = data.getAttribute('text');
 
385
        keys = data.getAttribute('keys');
 
386
 
 
387
        if (text == "") {
 
388
                        returnData.setAttribute('result', 'signandencrypt-err');
 
389
            returnData.setAttribute('error', 'no-data');
 
390
                        return;
 
391
                }
 
392
 
 
393
        keyID = data.getAttribute('force-key');
 
394
 
 
395
        // Needed for a sign
 
396
        if(keyID == null)
 
397
            keyID = getSelfKey();
 
398
                if(keyID == null)
 
399
                        return;
 
400
 
 
401
         keyIdList = keys.split(/;/g);
 
402
 
 
403
 
 
404
        var password = getPrivateKeyPassword(false,gpgApi.getDomain(event.target.ownerDocument.location));
 
405
                if(password == null)
 
406
                        return
 
407
 
 
408
        // We get the result
 
409
                var result = FireGPG.cryptAndSign(true,text,keyIdList,false,password,keyID);
 
410
 
 
411
                if (result.result  == RESULT_SUCCESS)
 
412
        {
 
413
            returnData.setAttribute('result', 'signandencrypt-ok');
 
414
            returnData.setAttribute('text', result.encrypted);
 
415
 
 
416
            return;
 
417
        }
 
418
                else if (result.result  == RESULT_ERROR_PASSWORD)
 
419
        {
 
420
            returnData.setAttribute('result', 'signandencrypt-err');
 
421
            returnData.setAttribute('error', 'bad-pass');
 
422
                        return;
 
423
        }
 
424
                else {
 
425
 
 
426
                        returnData.setAttribute('result', 'signandencrypt-err');
 
427
            returnData.setAttribute('error', 'unknow');
 
428
                        return;
 
429
 
 
430
        }
 
431
 
 
432
        returnData.setAttribute('result', 'signandencrypt-err');
 
433
        returnData.setAttribute('error', 'unknow');
 
434
 
 
435
    },
 
436
 
 
437
 
 
438
    // Return 'encrypt-ok' in 'result' (or 'encrypt-err' is there is a problem) if makeing a ecnrypted text was successfull
 
439
    // Return in 'text' the encrypted  text
 
440
    // Paramters : 'auth_key' --> the key for the website, 'text' -> the text to check, 'keys' --> the keys list
 
441
    encrypt: function ( event ) {
 
442
 
 
443
 
 
444
        data = gpgApi.getDataNode(event.target);
 
445
 
 
446
        key_auth = data.getAttribute('auth_key');
 
447
 
 
448
        returnData = gpgApi.getReturnDataNode(event.target);
 
449
 
 
450
        if (key_auth == '' || key_auth == undefined || gpgApi.isAuth(key_auth, event.target.ownerDocument) == false )
 
451
        {
 
452
            return;
 
453
        }
 
454
 
 
455
        text = data.getAttribute('text');
 
456
        keys = data.getAttribute('keys');
 
457
 
 
458
        if (text == "") {
 
459
                        returnData.setAttribute('result', 'encrypt-err');
 
460
            returnData.setAttribute('error', 'no-data');
 
461
                        return;
 
462
                }
 
463
 
 
464
        keyIdList = keys.split(/;/g);
 
465
 
 
466
        // We get the result
 
467
                var result = FireGPG.crypt(true, text, keyIdList);
 
468
 
 
469
                if (result.result  == RESULT_SUCCESS)
 
470
        {
 
471
            returnData.setAttribute('result', 'encrypt-ok');
 
472
            returnData.setAttribute('text', result.encrypted);
 
473
 
 
474
            return;
 
475
        }
 
476
                else {
 
477
 
 
478
                        returnData.setAttribute('result', 'encrypt-err');
 
479
            returnData.setAttribute('error', 'unknow');
 
480
                        return;
 
481
 
 
482
        }
 
483
 
 
484
        returnData.setAttribute('result', 'encrypt-err');
 
485
        returnData.setAttribute('error', 'unknow');
 
486
 
 
487
    },
 
488
 
 
489
    // Return 'decrypt-ok' in 'result' (or 'decrypt-err' is there is a problem) if trying to decrypt a text was successfull
 
490
    // Return in 'text' the decrypted text
 
491
    // Paramters : 'auth_key' --> the key for the website, 'text' -> the text to decrypt
 
492
    decrypt: function ( event ) {
 
493
 
 
494
 
 
495
        data = gpgApi.getDataNode(event.target);
 
496
 
 
497
        key_auth = data.getAttribute('auth_key');
 
498
 
 
499
        returnData = gpgApi.getReturnDataNode(event.target);
 
500
 
 
501
        if (key_auth == '' || key_auth == undefined || gpgApi.isAuth(key_auth, event.target.ownerDocument) == false )
 
502
        {
 
503
            return;
 
504
        }
 
505
 
 
506
        text = data.getAttribute('text');
 
507
 
 
508
        if (text == "") {
 
509
                        returnData.setAttribute('result', 'decrypt-err');
 
510
            returnData.setAttribute('error', 'no-data');
 
511
                        return;
 
512
                }
 
513
 
 
514
        // Needed for decrypt
 
515
 
 
516
                var password = getPrivateKeyPassword(false,gpgApi.getDomain(event.target.ownerDocument.location));
 
517
                if(password == null)
 
518
                        return;
 
519
 
 
520
        // We get the result
 
521
                var result = FireGPG.decrypt(true, text,password);
 
522
 
 
523
 
 
524
                // For I18N
 
525
                var i18n = document.getElementById("firegpg-strings");
 
526
 
 
527
                if (result.result  == RESULT_SUCCESS)
 
528
        {
 
529
            //If there was a sign with the crypted text
 
530
                        if (result.signresult == RESULT_SUCCESS)
 
531
                        {
 
532
                returnData.setAttribute('sign-info', result.signresulttext);
 
533
                        }
 
534
 
 
535
 
 
536
                        returnData.setAttribute('result', 'decrypt-ok');
 
537
            returnData.setAttribute('text', result.decrypted);
 
538
 
 
539
            return;
 
540
        }
 
541
                else if (result.result  == RESULT_ERROR_PASSWORD)
 
542
        {
 
543
            returnData.setAttribute('result', 'decrypt-err');
 
544
            returnData.setAttribute('error', 'bad-pass');
 
545
                        return;
 
546
        }
 
547
                else {
 
548
 
 
549
            returnData.setAttribute('result', 'decrypt-err');
 
550
            returnData.setAttribute('error', 'unknow');
 
551
                        return;
 
552
 
 
553
        }
 
554
 
 
555
        returnData.setAttribute('result', 'decrypt-err');
 
556
        returnData.setAttribute('error', 'unknow');
 
557
 
 
558
    },
 
559
 
 
560
 
 
561
 
 
562
 
 
563
    // Change # to #1, : to #2 and , to #3 in a string
 
564
    removeDoublePoint: function(s) {
 
565
 
 
566
        s = s.toString();
 
567
 
 
568
        s = s.replace(/#/g,"#1");
 
569
        s = s.replace(/:/g,"#2");
 
570
        s = s.replace(/,/g,"#2");
 
571
 
 
572
        return s;
 
573
    },
 
574
 
 
575
 
 
576
    // Return the node with data attributes for return
 
577
    getReturnDataNode: function(d) {
 
578
 
 
579
        liste = d.getElementsByTagName( "firegpg:returndata" );
 
580
 
 
581
        return liste[0]
 
582
 
 
583
    },
 
584
 
 
585
    // Return true if the user have sign to use FireGPG's api
 
586
    isAuth: function(key, document) {
 
587
 
 
588
        try {
 
589
 
 
590
            access = this.getAccessList();
 
591
 
 
592
            if (access[key.toString()] == gpgApi.getDomain(document.location))
 
593
                return true;
 
594
 
 
595
        } catch (e) { }
 
596
 
 
597
        return false;
 
598
 
 
599
    },
 
600
 
 
601
    //Get the current domain for the page, or the webpage if we're in local (file://)
 
602
    getDomain: function(url) {
 
603
 
 
604
 
 
605
        var first_split = url.toString().split("//");
 
606
 
 
607
        if (first_split[0] == "file:")
 
608
        {
 
609
            url = url.toString().replace(",","GPG1");
 
610
            url = url.toString().replace(";","GPG2");
 
611
            return url;
 
612
        }
 
613
 
 
614
        var without_resource = first_split[1];
 
615
 
 
616
        var second_split = without_resource.split("/");
 
617
 
 
618
        var domain = second_split[0];
 
619
 
 
620
        return domain;
 
621
 
 
622
    },
 
623
 
 
624
    //Return the list of access
 
625
    getAccessList: function() {
 
626
 
 
627
        var array_return = new Array();
 
628
 
 
629
        var prefs = Components.classes["@mozilla.org/preferences-service;1"].
 
630
                                       getService(Components.interfaces.nsIPrefService);
 
631
                prefs = prefs.getBranch("extensions.firegpg.");
 
632
        var auths_chain  = ";,;";
 
633
        try {
 
634
            auths_chain = prefs.getCharPref("api_list_auth");
 
635
        } catch (e) { auths_chain = ";,;";  }
 
636
 
 
637
        if (auths_chain == ";,;" || auths_chain == "" || auths_chain ==  null)
 
638
            return array_return;
 
639
 
 
640
        var reg=new RegExp(";", "g");
 
641
 
 
642
        splitage = auths_chain.split(reg);
 
643
 
 
644
        for (var i=0; i< splitage.length; i++) {
 
645
 
 
646
            domain_and_key = splitage[i];
 
647
 
 
648
            var reg2 = new RegExp(",", "g");
 
649
 
 
650
            domain_and_key = domain_and_key.split(reg2);
 
651
 
 
652
            if (domain_and_key[1] != undefined && domain_and_key[1] != "" && domain_and_key[1] != 0) {
 
653
 
 
654
                array_return[domain_and_key[1]] = domain_and_key[0];
 
655
 
 
656
            }
 
657
        }
 
658
 
 
659
        return array_return;
 
660
 
 
661
    },
 
662
 
 
663
    //Set a new list of access
 
664
    setAccessList: function(arrayy) {
 
665
 
 
666
        var final_data = ';';
 
667
 
 
668
        for (var key in arrayy) {
 
669
 
 
670
            final_data = final_data + arrayy[key] + ',' + key + ';';
 
671
 
 
672
        }
 
673
 
 
674
        var prefs = Components.classes["@mozilla.org/preferences-service;1"].
 
675
                                       getService(Components.interfaces.nsIPrefService);
 
676
                prefs = prefs.getBranch("extensions.firegpg.");
 
677
 
 
678
        prefs.setCharPref("api_list_auth",final_data);
 
679
 
 
680
 
 
681
    },
 
682
 
 
683
 
 
684
};
 
685
 
 
686
window.addEventListener("load", function(e) { gpgApi.onLoad(e); }, false);