/[pdpsoft]/branches/nl.nikhef.jgridstart-flyingsaucer/nl.nikhef.jgridstart/src/nl/nikhef/jgridstart/install/certinstall_moz.html
ViewVC logotype

Contents of /branches/nl.nikhef.jgridstart-flyingsaucer/nl.nikhef.jgridstart/src/nl/nikhef/jgridstart/install/certinstall_moz.html

Parent Directory Parent Directory | Revision Log Revision Log


Revision 435 - (show annotations) (download)
Wed Jun 17 12:48:32 2009 UTC (12 years, 5 months ago) by wvengen
File MIME type: text/plain
File size: 3335 byte(s)
(mega-commit) introduce new Browsers API for opening an external web browser and installing certificates into it; current implementation is for Linux and Mac OS X and needs to be finished
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2 <html>
3 <head>
4 <script type="text/javascript"><!--
5 /*
6 * Certificate installation page for Mozilla-based browsers
7 *
8 * This HTML page contains Javascript that installs a PKCS#12 file into
9 * the browser's certificate store. This requires the user to
10 * 1) Grant access to this scripting functionality
11 * 2) Enter the password which protects the PKCS#12 file
12 * A password is required on the PKCS#12 file when it contains a
13 * private key.
14 *
15 * Useful links for development:
16 * - https://developer.mozilla.org/En/XPCOM_API_Reference
17 * - http://kb.mozillazine.org/Development_resources#XPCOM_.2F_XPConnect
18 * - https://developer.mozilla.org/En/Code_snippets/Miscellaneous
19 * - http://mb.eschew.org/16
20 * - http://www.mozilla.org/projects/security/components/signed-scripts.html
21 *
22 * @author wvengen
23 */
24
25 // which PKCS#12 file to import; path relative to this html file
26 var pkcsfile = "import.p12";
27 // whether to close the window when the operation is finished, or no
28 var closeWhenFinished = true;
29
30 function error(msg) {
31 alert("Error while importing certificate:\n"+msg);
32 if (closeWhenFinished) window.close();
33 }
34 function errorhandler(msg, url, line) {
35 error(msg);
36 }
37
38 // returns a File for the absolute filename
39 function getAbsoluteFile(name) {
40 var file = Components.classes["@mozilla.org/file/local;1"].getService(Components.interfaces.nsILocalFile);
41 file.initWithPath(name);
42 return file;
43 }
44
45 // returns a File for the relative filename
46 function getRelativeFile(name) {
47 var ios = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
48 var fh = ios.getProtocolHandler("file").QueryInterface(Components.interfaces.nsIFileProtocolHandler);
49 var file = fh.getFileFromURLSpec(window.location);
50 file = file.parent;
51 file.append(name);
52 return file;
53 }
54
55 function importcerts() {
56 // request required privileges
57 netscape.security.PrivilegeManager.enablePrivilege('UniversalFileRead UniversalXPConnect');
58
59 // it can be quite hard to find the operations of certdb nowadays. Pointer:
60 // http://www.oxymoronical.com/experiments/apidocs/interface/nsIX509CertDB
61 var certdb = Components.classes["@mozilla.org/security/x509certdb;1"].getService(Components.interfaces.nsIX509CertDB);
62
63 // file to import
64 var file = getRelativeFile(pkcsfile);
65
66 // import pkcs12 file, using name from the file
67 certdb.importPKCS12File(null, file);
68
69 /*
70 Some crawling of the mozilla source on mxr.mozilla.org shows that the
71 following functions are called to import a pkcs12 file. This may be
72 useful to know in the future to avoid a password prompt during import.
73
74 importPKCS12File
75 sec_pkcs12_add_key
76 PK11_ImportPrivateKeyInfo (/ PK11_ImportEncryptedPrivateKeyInfo)
77 PK11_ImportPrivateKeyInfoAndReturnKey
78 sec_pkcs12_add_cert
79 PK11_ImportCertForKeyToSlot
80 (or PK11_ImportDERCert for CA cert without key)
81 */
82
83 if (closeWhenFinished) window.close();
84 }
85
86 window.onerror = errorhandler;
87 window.onload = importcerts;
88
89 //-->
90 </script>
91 </head>
92 <body>
93 <h3>Certificate installation page</h3>
94 <p>This page will close automatically when finished.</p>
95 <noscript>
96 <h4>Whoops</h4>
97 <p>you need to enable Javascript to be able to install the certificate.</p>
98 </noscript>
99 </body>
100 </html>

Properties

Name Value
svn:mime-type text/plain

grid.support@nikhef.nl
ViewVC Help
Powered by ViewVC 1.1.28