Accessing serial port through trusted applet

Hi,
We need to access data from serial port using applets. Obviously, applet has to be trusted. We have used signtool utility of netscape to generate certificate.
Our trusted applet works fine as far as reading and writing of a file is concerned.
We have written a small application in java (using javax.comm package) to access the serial port. It also works fine.
However, when I try to access serial port through applet, it does not work.
Anybody has any idea how to achieve this?
TikshyaAsked:
Who is Participating?
 
heyhey_Connect With a Mentor Commented:
more points won't solve the problem quicker :)

I got your e-mail, I decompiled the Comm package and it seems that you don't have permissions to load the library

class com.sun.comm.Win32Driver
    public void initialize()
    {
        try
        {
            System.loadLibrary("win32com");
        }
        catch(SecurityException securityexception)
        {
            System.err.println("Security Exception win32com: " + securityexception);
            return;
        }

this is your error message !
// System.err.println("Security Exception win32com: " + securityexception);

0
 
heyhey_Commented:
javax.comm package uses some native code (.dll's on Windows)
you have to download these files on the client and put them inside the system PATH.
0
 
TikshyaAuthor Commented:
Hi heyhey,

thanks for your response. I have written a java application to access the port and it works fine. So I guess all the required dll's should be in the PATH. (Please correct me if I am wrong.)

Gopal
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
heyhey_Commented:
you need these .dlls on the CLIENT computer (in the PATH).

app works fine because JavaComm instalation has installed everything on the local machine, but for remote machine you have to install the files yourself.


> However, when I try to access serial port through applet, it does not work.

this is just a guess :) please post the full exception stacktrace.
0
 
TikshyaAuthor Commented:
Hi,
Here is complete description of the problem. I think my earlier description was not enough.

****************************************
We need to read the data on the serial port of the client machine using applets.
The client machine runs on WINDOWS operating system and browser used is Netscape. We know that no other O.S and browser is used on the client side.
Since unsigned applets are not allowed to access client resources, we are using signed applets. The signing of the applets is done by using Netscape's "signtool".
We have generated a digital certificate using signtool. This certificate is imported on client's Netscape browser. We have created signed jar file
 which contains the applet to be executed. To access the client resources, we are using Netscape's PrivilegeManager class. In the code of the applet we enable the privileges by calling method "enablePrivilege" of PrivilegeManager class. When we try to access files on the client machine using this signed applet, it works fine. (The applet first asks the user to grant permission and once permission is obtained, it enables that
permission and accesses the files.)

To access serial port we are using javax.comm.* package. We have written a java application using this package to read serial port and this application works fine. Here is the piece of code written to access the port.
*************
              CommPortIdentifier com1 =
 CommPortIdentifier.getPortIdentifier("COM1");
           SerialPort ser1 = (SerialPort)com1.open("xxxx", 1000);
*************
Then data is read from the opened port.
This java application is tested and it works fine.

In the case of signed applet, we have written the same code in the applet.
Before this code, privileges are enabled. We are not sure what kind of privileges are required. So we have enabled many of them. They are given
below:
*************
                 PrivilegeManager.enablePrivilege("UniversalFileAccess");
PrivilegeManager.enablePrivilege("UniversalExecAccess");
PrivilegeManager.enablePrivilege("30Capabilities");
PrivilegeManager.enablePrivilege("TerminalEmulator");
PrivilegeManager.enablePrivilege("UniversalPropertyRead");
PrivilegeManager.enablePrivilege("UniversalPropertyWrite");
PrivilegeManager.enablePrivilege("AdministratorRegistryAccess");
PrivilegeManager.enablePrivilege("StandardRegistryAccess");
PrivilegeManager.enablePrivilege("UniversalPrintJobAccess");
PrivilegeManager.enablePrivilege("UniversalPreferencesRead");
PrivilegeManager.enablePrivilege("UniversalPreferencesWrite");
PrivilegeManager.enablePrivilege("UniversalConnectWithRedirect");
PrivilegeManager.enablePrivilege("SiteArchiveTarget");
*************
The javax.comm package is placed in the CLASSPATH of JVM of the client's browser.

When we run the applet through client's Netscape browser, first prompts for granting permissions is asked. When the client grants all the permissions, following exception occurs on the java console:
*************
Security Exception win32com: netscape.security.AppletSecurityException:
security.checklink: win32com javax.comm.NoSuchPortException   at
java.lang.Throwable.<init>(Compiled Code)   at
java.lang.Exception.<init>(Compiled Code)   at
javax.comm.NoSuchPortException.<init>(Compiled Code) * at
javax.comm.CommPortIdentifier.getPortIdentifier(Compiled Code)   at
ReadPortApplet$ButtonHandler.actionPerformed(Compiled Code)   at
java.awt.Button.processActionEvent(Compiled Code)   at
java.awt.Button.processEvent(Compiled Code)   at
java.awt.Component.dispatchEventImpl(Compiled Code)   at
java.awt.Component.dispatchEvent(Compiled Code)   at
java.awt.EventDispatchThread$EventPump.dispatchEvents(Compiled Code)   at
java.awt.EventDispatchThread.run(Compiled Code)   at
netscape.applet.DerivedAppletFrame$AppletEventDispatchThread.run(Compiled
Code)
*************
This exception occurs on the line
*************
          CommPortIdentifier com1 =
CommPortIdentifier.getPortIdentifier("COM1");
*************
We think that even after giving permissions on so many targets, we have missed some targets which are required to access ports. There is a target called "SuperUser" which grants all the permissions on the client's machine; but this target doesn't work. The applet throws exception
*************
netscape.security.ForbiddenTargetException: User didn't grant the
SuperUser privilege.   at java.lang.Throwable.<init>(Compiled Code)   at
java.lang.Exception.<init>(Compiled Code)   at
java.lang.RuntimeException.<init>(Compiled Code) at
netscape.security.ForbiddenTargetException.<initCompiled Code)   at
netscape.security.PrivilegeManager.enablePrincipalPrivilegeHelper(Compiled
Code)   at
netscape.security.PrivilegeManager.enablePrivilegePrivate(Compiled Code) *
at netscape.security.PrivilegeManager.enablePrivilege(Compiled Code)   at
ReadPortApplet$ButtonHandler.actionPerformed(Compiled Code)   at
java.awt.Button.processActionEvent(Compiled Code)   at
java.awt.Button.processEvent(Compiled Code)   at
java.awt.Component.dispatchEventImpl(Compiled Code)   at
java.awt.Component.dispatchEvent(Compiled Code)   at
java.awt.EventDispatchThread$EventPump.dispatchEvents(Compiled Code)   at
java.awt.EventDispatchThread.run(Compiled Code)   at
netscape.applet.DerivedAppletFrame$AppletEventDispatchThread.run(Compiled
Code)
*************
We don't know the reason for this exception.
Can somebody solve our problem? We think, sufficient information is given
to track the problem; but if more information is required, I can provide
mail that to you.
****************************************

Regards,
Gopal
0
 
TikshyaAuthor Commented:
Hi heyhey

You are correct in the sense that the applet could not load the dll. The name of the dll is "win32com.dll". It comes along with the javax.comm package. However, I could not figure out how it gets loaded in the application. It is not loaded using "PATH" or "CLASSPATH" variables.

In the case of the applet, I tried copying the dll in the CLASSPATH variable of the browser's JVM. But it didn't work.

Heyhey, I will be very glad if you help me out in this problem. If you give me your e-mail id, I can give you more details.
Thanks in advance,

Regards,
Tikshya
0
 
heyhey_Commented:
my e-mail is
heyhey_@iname.com

you have to put the .dll in the system PATH - that's the only way that Windows can load it ... (unless you can specify the full path ???)

I'll take a look at the JavaComm sources at home.
0
 
TikshyaAuthor Commented:
Hi heyhey,

The scenario has changed slightly from yesterday:

1. The applet picks up win32com.dll from the \program files\netscape\java\bin folder.

2. However, the applet gives a security exception while linking to the DLL.

PF the Netscape Navigator Error Text below:

Security Exception win32com: netscape.security.AppletSecurityException: security.checklink: win32com

Could you kindly provide some inputs on this.

Thanks / Best Regards,
Tikshya
( Gopal Parasnis)
0
 
TikshyaAuthor Commented:
Adjusted points to 500
0
 
heyhey_Commented:
the only thing I can think of is that you are trying to load the DLL (initialize the commDriver) before requesting loadLibrary permissions.

put this code inside your (signed) applet and post the output here

try
{
    System.loadLibrary("win32com");
}
catch(SecurityException securityexception)
{
    System.err.println("Security Exception win32com: " + securityexception);
    securityexception.printStackTrace();
    return;
}
catch(UnsatisfiedLinkError unsatisfiedlinkerror)
{
    System.err.println("Error loading win32com: " + unsatisfiedlinkerror);
    unsatisfiedlinkerror.printStackTrace();
    return;
}

0
 
TikshyaAuthor Commented:
We signed comm.jar with our certificate.
It worked !

Thanks everyone; especially heyhey, who held our hand all through this :)

0
 
TikshyaAuthor Commented:
HeyHey was great throughout - he provided invaluable insights and put in extra effort to try and help us work out a solution.

Since his comment did not provide the exact solution we haven't ranked it as excellent, but in all other aspects his assistance couldn't have been any better.

Best regards from the Tikshya team.
0
 
heyhey_Commented:
Thanks for the points
glad that you've solved your problem :)
0
All Courses

From novice to tech pro — start learning today.