applet security and external URLs

G

Guest

I am developing an applet which loads data (an astronomical image) via
a DataInputStream/ BufferedInputStream/ FileInputStream from an URL

URL myurl = new URL ("http://host/file")

So far for testing I've been using a file residing on the same host
where I'm working (this host is also an apache web server). I'm invoking
the HTML page calling the applet either from appletviewer or firefox.

Now I wanted to use a file on a remote host (the production apache web
server). The remote host is where the actual files already reside.
Currently they are "protected" by .htaccess with a "SetEnvIf Referer",
so that the files can be accessed only if one gets to them from a
predefined set of pages (this is currently used for downloading from an
index page).

For preliminary testing I've disabled the .htaccess.


- QUESTION 1 : how to "relax" applet security ?

when I repointed the URL to the remote host I got an exception
"access denied java.net.SocketPermission remotehost... resolve"

I figured to go around it with the following procedure :

- I manually created a ~/.java.policy file (since policytools seems
not be working on my system... part of the input areas are in an
inaccessible part of the window !)

- In this I inserted two clauses.
The first one is honoured by the appletviewer
(invoked as appletviewer myApplet.html)

grant codebase "file:" {
permission java.net.SocketPermission "*", "accept,connect,resolve" ;
} ;


The second clause is preliminarily used by browsers

grant codebase "http://myhost/mypath/" {
permission java.net.SocketPermission "*", "accept,connect,resolve" ;
} ;

where /myhost/mypath is where myApplet.html resides

- I haven't found comprehensive documentation to the format of
the policy files. Pointers anybody ?

In particular what should go in place of "*" ? Could it be a
regexp for the URLs to be accessed ? (they will all be of the
form http://remotehost/somefixedpart/variablepart)


Also, if the applet has to be used by anybody else, I should
instruct my users to append to THEIR .java.policy the (final)
content of mine.

This seems a bit inconvenient. Why should each applet user need to
give permission to read something from a remote URL, instead
of being me as administrator of the central server to give
permission to read FROM me ?

Is there an (easy) way to embed grating the permission inside the
applet code ?

- QUESTION 2 : who is the referer of my URL ?

Assuming that the applet has permissions to read from my server
(at worst propagating my .java.policy above), I'd like to re-instate
the .htaccess to let external users access my data files only

- when coming from the download index page (as already setup)
- when coming from some form (as already setup)
- when coming from the applet (invoked by a browser)
- when coming from the applet (invoked by appletviewer)

The last is optional (used during development only)

So my question would be : what will be the Referer for the latter
two cases ?

I've been unable to figure it for the browser case
(myhost\.mydomain\/\.mypath\/myApplet.html seems not to work and
at least during testing I won't be using a stable path), and
I'm not sure the question makes sense for the appletviewer

Provisionally I solved it with

SetEnvIf Remote_Addr x.y.z.t okapplet
allow from env=okapplet

where x.y.z.t is the IP address of my host (the host where the
applet code resides ... but is that correct ? Assume that

- user is on machine a.b.c.d

- he calls an HTML page on x.y.z.t (which refers to a
class file also on x.y.z.t) to run the applet

- the applet opens the URL to the remote http server

- will the remote http server see as Remote_Addr x.y.z.t
or a.b.c.d ?

Obviously the first is good (always the same), the second not
(unpredictable a priori)
 
G

Guest

- QUESTION 2 : who is the referer of my URL ?
Provisionally I solved it with

SetEnvIf Remote_Addr x.y.z.t okapplet
allow from env=okapplet

This works for a browser (it may request me a user and password from the
same .htaccess, usually this should have been done previously in the
session to access the main web site). It does not work for the
appletviewer (fails with error 401, presumably because it has no way to
ask the password ; if the SetEnvIf and allow are not there both browser
and appletviewer give error 403)
 
A

Andrew Thompson

LC's No-Spam Newsreading account said:
I am developing an applet which loads data (an astronomical image) via
a DataInputStream/ BufferedInputStream/ FileInputStream from an URL
...

Long story short.

- A trusted applet can pull data from other hosts.
- To gain trust, the best strategy is to sign the applet.
- Messing with policy files is a path to madness.
- A sandboxed applet (or application) launched using web
start can access data from other hosts, but the Plug-In
will prompt the user to OK the cross-domain access. E.G.
<http://rabbitbrush.frazmtn.com/>
(Image Fader JApplet, using physci.org images)

--
Andrew Thompson
http://www.physci.org/

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-general/200801/1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top