Chapter 12. Remote Applications-P4
Figure 12-5. Downloading a certificate window
After the certificate is installed, it will appear in the Certificate Manager, as
shown in Figure 12-6
. The Certificate Manager can be accessed via the
global Mozilla preferences (Edit > Preferences > Privacy & Security >
Certificates). Mozilla is then ready to run signed remote Mozilla applications
bearing signatures from your certificate authority.
Figure 12-6. Certificate manager with a certs.mozdev.org CA certificate
12.6. Creating Signed Remote Applications
Security in Mozilla's web browser is designed to meet today's advanced
scripting needs in a secure manner. Mozilla is a much more secure browser
than past Netscape 4.x and Internet Explorer releases because it has a better
sense of what remote scripts can and cannot do.
Because of Mozilla's approach toward potentially insecure applications, if
you decide to serve up your own application remotely, remember that you
will not have automatic access to the chrome in the way you do when you
have a registered, locally installed Mozilla application. Unless you sign your
application or have the user turn on a special preference (see Section 12.3
),
services like XPConnect will not be available.
In Mozilla, you can bundle any number of files into a JAR archive (which,
you'll recall from Chapter 6
, is just a zip file with a JAR suffix) and
designate the archive as an object that can be signed. This designation makes
it very easy to produce an entire signed and secure remote Mozilla
application because it stores your application in a single file type that
Mozilla already treats as a separate package.
SignTool (part of the NSS tool sets) takes a directory of files, zips them up
into a JAR archive (refer to the section Section 12.6.3.1
later in this chapter
to see how to do this), and signs the archive using the certificate you specify.
SignTool comes with the latest release of NSS, Version 3.4.1. On
http://certs.mozdev.org, limited functionality versions of NSS contain
SignTool for Windows and Linux that you can use instead for the
processes in this book.
Use CertUtil to set up a database for SignTool. Next, run some commands to
set up the certificate environment:
C:\NSS\bin>certutil -N -d .
C:\NSS\bin>certutil -A -n
"certs.mozdev.org/signing" -t ",,C"
-i eric.cacert -d .
The first command creates an empty cert7.db file where certificates can
be stored. The second imports your Signing Certificate into the database.
SignTool can use only certificates that reside in a database, which is the
reason for this process.
12.6.3. Creating and Signing the Application
When someone obtains a private key (which is part of a Signing Certificate),
they can encrypt their scripts and produce a public key. The relationship of
the private key and the public key is called a private-public key pair. Using
this relationship, you can create a signed Mozilla application and make it
available to users in three steps:
1. Build the application itself, including the XUL, CSS, JavaScript, and
whatever else you use to create the Mozilla application.
For this section, let's assume that you already created the XUL and
JavaScript for the application and have all the files and directories
together.
-p"password_of_database" -Z"myapp.jar" myappfiles/
The -d option is where the certificate database resides and -k is the
certificate name.
12.6.3.2. Distributing the application
Once the file is created from the -Z option (e.g., myapp.jar from the
example above), you can put it online. On the application's web page, note
that the application is signed and put a link to
http://certs.mozdev.org/certs_mozdev.cacert so users can install the
necessary MozDev certificate if they do not have it.
To access the application online, you must use a special URL format. This
format looks like
jar:http://certs.mozdev.org/myapp.jar!/myapp.xul and
points into the JAR at the main application file. This URL is difficult to
type, so it may be wise to link it for user access or set up a redirected URL to
that address, as shown in Example 12-12
.
Example 12-12. Sample redirect into a signed application
<HTML>
<HEAD>
<META HTTP-EQUIV="REFRESH" CONTENT="0;
URL=
jar:http://certs.mozdev.org/sample.jar!/sample.xul"
>
</HEAD>
</HTML>
12.6.4. Receiving a Signed Application
As shown in Figure 12-8, when Mozilla receives a JAR, it must check it for
validity before displaying the contents. A public key in
certs_mozdev.cacert must be used along with the digital signature to
make sure that the contents are not tampered with and that the signature is
same origin check when reading from
any document.
UniversalBrowserWrite
Modifies sensitive browser data. This
modification allows the script to pass
the same origin check when writing
to any document.
UniversalXPConnect
Gives unrestricted access to browser
APIs using XPConnect.
UniversalPreferencesRead
Reads preferences using the
navigator.preference
method.
Privilege Purpose
UniversalPreferencesWrite
Allows you to set preferences using
the navigator.preference
method.
CapabilityPreferencesAccess
Allows you to read/set the
preferences that define security
policies, including which privileges
are granted and denied to scripts.
(You also need
UniversalPreferencesRead/Write.)
UniversalFileRead
Handles window.open of
file:// URLs. Makes the browser
upload files from the user's hard drive
Open
• Creates a window smaller than
100 x 100 pixels or larger than
the screen can accommodate
by using innerWidth,
Method / property Description
innerHeight,
outerWidth, and
outerHeight.
• Places a window offscreen by
using screenX and
screenY.
• Creates a window without a
titlebar by using
titlebar=no.
• Uses alwaysRaised,
alwaysLowered, or z-lock
for any setting.
resizeTo, resizeBy
Resizes a window smaller than 100 x
100 pixels or larger than the screen
can accommodate.
innerWidth, innerHeight
Sets the inner width of a window to a
size smaller than 100 x 100 or larger
than the screen can accommodate.
This snippet of code shows how to use the privilege manager in JavaScript:
netscape.security.PrivilegeManager.
enablePrivilege("UniversalBrowserWrite");
window.titlebar=no;