runn signet Applet

Hi,

first sorry, but I kann not write well English:)

I have to create a Applet, who a Serial Port open and Kommands send. I'm using the IBM Comm API.

The Applet is finish and I've signet my JAR-FIle with the Klasses. I've create a Policy -File for the Applet, but I thing , there is the Problem, who I dont understand:(

I becamm a Error in my Applet when I start it: javax.comm.NoSuchPortException

I need a Sample for my Policy-File. I wand do Open all my Permissions to test my Applet.

My Applet and Files are in E:\jdk1.4\bin\Applet.jar

That is my Polici File

keystore"file:/E:/Dokumente und Einstellungen/borissov/.keystore";

grant signedBy"mykey", codeBase"file:/E:/*"{

permission java.security.AllPermission;

};

[924 byte] By [bobchoa] at [2007-10-1 17:11:23]
# 1

Does Allpermission to all code help (add that to THE java.policy in the "grant {" section)?

Because if that didn't help it's not the sandbox security that causes the exception.

Don't think you should add a keystore to THE java.policy (in the lib/security dir). Never

seen a SUN example do that.

Did you add the location of your policy ifle to your java.security?

Signing applets:

http://forum.java.sun.com/thread.jsp?forum=63&thread=524815

second post and last post for the java class file

http://forum.java.sun.com/thread.jsp?forum=63&thread=409341

4th post explaining how to set up your own policy with your own keystore

harmmeijera at 2007-7-11 1:51:58 > top of Java-index,Security,Signed Applets...
# 2

I dont understand, what I have to do! ?

lease kann you Write me the Code in my Policy-Dytei and what I have to do in my java.security?

My Path to the signet Applet is:

E:\welafiapplet2.jar

Path to the Policy File:

E:\Dokumente und Einstellungen\Bob\.java.policy

[CODE]

keystore "file:/C:/Dokumente und Einstellungen/borissov/.keystore";

grant signedBy "mykey" {

permission java.security.AllPermission;

};

[/CODE]

Path to my Serurity File: E:\Sun\AppServer\jdk\jre\lib\security\java.security

policy.url.3=file:/E:/Dokumente und Einstellungen/Bob/.java.policy

I kann send you my Applet to !

I have to finish that Problem in 1-2 Days, because I have to learn and work and I dont have much Time for that.

Thanks

Borislav

bobchooa at 2007-7-11 1:51:58 > top of Java-index,Security,Signed Applets...
# 3

The appserver is not running your applet, each client that opens the applet has to set up

a policy for it or (default installation of SUN jre) has to trust the signature.

Check your java.home/lib/security folder there is the java.policy, this contains a

grant {

section, this section applies to all code. If you add the following line under grant {

permission java.security.AllPermission;

Make sure you are using the java.home of the jre that is running your applet.

If the applet is running correctly with allpermission your problem is sandbox security, make sure that all jars are signed or put the non applet jars in lib/ext.

Make sure you have your policy settings correct on EVERY client that runs the applet:

http://forum.java.sun.com/thread.jsp?forum=63&thread=409341

4th post explaining how to set up your own policy with your own keystore

harmmeijera at 2007-7-11 1:51:58 > top of Java-index,Security,Signed Applets...
# 4

Hi,

kann you try to see my Problem - To sign My Programm.

I don't have any more Nerve to make that, and I don't understand well English.

Im Using the IBM COM API

http://public.planetmirror.com/pub/...bm/1.3.0/win32/

ibm-javacomm-win32-x86.zip

Thanks, if you can help me.

You cann send the Files (JAR, policy, security) at: boristdi@yahoo.com

import javax.swing.*;

import java.awt.Container;import java.awt.event.ActionEvent;

import javax.comm.NoSuchPortException;

import javax.comm.CommPortIdentifier;

import javax.comm.SerialPort;

import java.awt.Container;

import java.awt.Font;

import javax.swing.JButton;

import java.awt.Color;

import javax.comm.PortInUseException;

import java.io.InputStream;

import java.io.IOException;

import javax.swing.JTextField;

import java.awt.Panel;

import java.awt.Choice;

import java.util.Enumeration;

import java.io.OutputStream;

import java.awt.Label;

import javax.comm.UnsupportedCommOperationException;

import java.awt.event.ItemEvent;

import java.awt.event.ItemListener;

import javax.swing.JApplet;

import java.awt.Color;

import java.awt.event.*;

import java.io.*;

public class Myapplet extends JApplet implements ItemListener {

Choice aw1;

Choice aw2;

Choice aw3;

Choice aw4;

JButton vidStr=new JButton("Start videostream");

JButton on=new JButton("On");

JButton off=new JButton("Off");

JButton set2=new JButton("Set");

JButton mS=new JButton("Make Snapshot");

JTextField tf=new JTextField();

JTextField tf2=new JTextField();

String name;

String name2;

public void init() {

Container c = getContentPane();

Panel panel = new Panel();

panel.setLayout(null);

Label header = new Label("1. Videostream");

header.setFont(new Font("Serif", Font.BOLD, 25));

header.setBounds(20, 10, 180, 30);

panel.add(header);

Label header2 = new Label("resolution:");

header2.setFont(new Font("Serif", Font.PLAIN, 20));

header2.setBounds(50, 40, 100, 30);

panel.add(header2);

aw1 = new Choice();

aw1.setFont(new Font("Serif", Font.PLAIN, 15));

aw1.add("352x288 pixel");

aw1.add("176x144 pixel");

aw1.add("704x576 pixel");

aw1.setBounds(50, 75, 130, 40);

Label header3 = new Label("compression:");

header3.setFont(new Font("Serif", Font.PLAIN, 20));

header3.setBounds(50, 105, 150, 30);

panel.add(header3);

aw2 = new Choice();

aw2.setFont(new Font("Serif", Font.PLAIN, 15));

aw2.add("medium(50%)");

aw2.add("min(0%)");

aw2.add("low(30%)");

aw2.add("high(70%)");

aw2.add("very high(90%)");

aw2.setBounds(50, 140, 130, 40);

//Button Start videostream

vidStr.setBounds(50, 180, 137, 30);

Label header4 = new Label("2. Cam & Light");

header4.setFont(new Font("Serif", Font.BOLD, 25));

header4.setBounds(20, 220, 180, 30);

panel.add(header4);

Label header5 = new Label("(auto-off after 30 min)");

header5.setFont(new Font("Serif", Font.PLAIN, 18));

header5.setForeground(Color.red);

header5.setBounds(40, 245, 200, 30);

panel.add(header5);

//Button Cam On/Off

on.setBounds(30, 280, 80, 30);

off.setBounds(130, 280, 80, 30);

Label header6 = new Label("3. Motor voltage");

header6.setFont(new Font("Serif", Font.BOLD, 25));

header6.setBounds(20, 320, 180, 30);

panel.add(header6);

Label header7 = new Label("(Range:0;30-260 dV, integer)");

header7.setFont(new Font("Serif", Font.PLAIN, 18));

header7.setBounds(20, 350, 215, 30);

panel.add(header7);

//Textfeld + Button

tf.setBounds(40, 385, 80, 27);

panel.add(tf);

set2.setBounds(140, 385, 60, 27);

Label header8 = new Label("4. Stopwatch:");

header8.setFont(new Font("Serif", Font.BOLD, 25));

header8.setBounds(20, 420, 180, 30);

panel.add(header8);

tf2.setBounds(40, 455, 80, 27);

panel.add(tf2);

Label header8a = new Label("ms");

header8a.setFont(new Font("Serif", Font.BOLD, 15));

header8a.setBounds(125, 465, 25, 20);

panel.add(header8a);

Label header9 = new Label("5. Snapshot");

header9.setFont(new Font("Serif", Font.BOLD, 25));

header9.setBounds(20, 490, 180, 30);

panel.add(header9);

Label header10 = new Label("resolution:");

header10.setFont(new Font("Serif", Font.PLAIN, 20));

header10.setBounds(50, 515, 100, 30);

panel.add(header10);

aw3 = new Choice();

aw3.setFont(new Font("Serif", Font.PLAIN, 15));

aw3.add("352x288 pixel");

aw3.add("176x144 pixel");

aw3.add("704x576 pixel");

aw3.setBounds(50, 545, 130, 40);

Label header11 = new Label("compression:");

header11.setFont(new Font("Serif", Font.PLAIN, 20));

header11.setBounds(50, 570, 150, 30);

panel.add(header11);

aw4 = new Choice();

aw4.setFont(new Font("Serif", Font.PLAIN, 15));

aw4.add("low");

aw4.add("min");

aw4.add("medium");

aw4.add("high");

aw4.add("very high");

aw4.setBounds(50, 605, 130, 40);

// Button

mS.setBounds(50, 645, 140, 27);

panel.add(aw1);

panel.add(aw2);

panel.add(aw3);

panel.add(aw4);

panel.add(vidStr);

panel.add(on);

panel.add(off);

panel.add(set2);

panel.add(mS);

aw1.addItemListener(this);

c.add(panel);

on.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(ActionEvent e) {

Enumeration portList=null;

CommPortIdentifier portId=null;

SerialPort serialPort=null;

OutputStream outputStream=null;

InputStream inputStream=null;

String comando = "?; // Komando zum Starten senden

JPanel nachricht22 = new JPanel();

JOptionPane pane22 = new JOptionPane(nachricht22);

JDialog dialog22 = pane22.createDialog(null, "port versuchen ");

dialog22.show();

try{ // Port 鰂fnen

portId = CommPortIdentifier.getPortIdentifier("COM1");

} catch(NoSuchPortException nspe){tf.setText(nspe.toString());}

try { // Serial Port 鰂fnen

serialPort = (SerialPort) portId.open("Teste", 2000);

} catch (PortInUseException piue) {tf.setText(piue.toString());}

try { // Eingabe-/Ausgabestreams 鰂fnen

outputStream = serialPort.getOutputStream();

inputStream = serialPort.getInputStream();

} catch (IOException ioe) {tf.setText(ioe.toString());}

try { // Port Parameters

serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);

} catch (UnsupportedCommOperationException ucoe) {tf.setText(ucoe.toString());}

try { // Schicke das Befehl

//outputStream.write(comando.getBytes());

/*JPanel nachricht1 = new JPanel();

JOptionPane pane1 = new JOptionPane(nachricht1);

JDialog dialog1 = pane1.createDialog(null, "R點kgabe= "+inputStream.read());

dialog1.show();

*/

outputStream.close();

inputStream.close();

} catch (IOException ioex) {tf.setText(ioex.toString());}

}

});

off.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(ActionEvent e) {

String message = ""; // Komando zum Starten senden

JPanel nachricht = new JPanel();

JOptionPane pane = new JOptionPane(nachricht);

JDialog dialog = pane.createDialog(null, "HaalloooooOOoo");

dialog.show();

//SendenSerialPort mp=new SendenSerialPort(message);

}

});

}

public void itemStateChanged(ItemEvent ie) {

repaint();

}

}

bobchoooa at 2007-7-11 1:51:58 > top of Java-index,Security,Signed Applets...
# 5

Enschuldigung fur mein deutch, hab es shon lange nicht gesprochen.

hab die applet in c:\temp gemacht

put Myapplet in c:\temp

Unzipped der zipfile (mit path namen) und hab die bin sachen copiert zum:

Unziped the zipfile (keep path names) and copied the bin stuff to:

Copied the bin stuff to

C:\Program Files\Java\jdk1.5.0_03\jre\bin

C:\Program Files\Java\jdk1.5.0_03\bin

C:\Program Files\Java\jre1.5.0_03\bin

Die lib sachen im:

the lib stuff to

C:\Program Files\Java\jre1.5.0_03\lib

C:\Program Files\Java\jdk1.5.0_03\lib

C:\Program Files\Java\jdk1.5.0_03\jre\lib

(the ext stuff goes in the ext directory)

das hier

added this

grant codeBase "file://C:/*" {

permission java.security.AllPermission;

};

Im java.policy gezetzt im:

to the java.policy in

C:\Program Files\Java\jre1.5.0_03\lib\security

C:\Program Files\Java\jdk1.5.0_03\lib\security

C:\Program Files\Java\jdk1.5.0_03\jre\lib\security

Die html file geoffenet im c:\temp

Opened the html file in c:\temp:

<DIV id="lblOutputText">Output comes here</DIV>

<DIV id="dvObjectHolder">Applet comes here</DIV>

<script>

if(window.navigator.appName.toLowerCase().indexOf("netscape")!=-1){ // set object for Netscape:

document.getElementById('dvObjectHolder').innerHTML = "<object ID='appletTest1' classid=\"java:Myapplet.java\"" +

"height='700' width='700' onError=\"changeObject();\"" +

">" +//"<param name=\"archive\" value=\"sTest.jar\">" +

"<param name=\"mayscript\" value=\"Y\">" +

"</object>";

}else if(window.navigator.appName.toLowerCase().indexOf('internet explorer')!=-1){ //set object for IE

document.getElementById('dvObjectHolder').innerHTML ="<object ID='appletTest1'

classid=\"clsid:8AD9C840-044E-11D1-B3E9-00805F499D93\"" +

" height='700' width='700' >" +

"<param name=\"code\" value=\"Myapplet.java\" />" +// "<param name=\"archive\" value=\"sTest.jar\">" +

" </object>"

}

</script>

keen problemen, bitte printStacktrace mit jeder try sachen:

No problems, please printStacktract on all try stuff

harmmeijera at 2007-7-11 1:51:58 > top of Java-index,Security,Signed Applets...
# 6

Correction

grant codeBase "file://C:/*" {

permission java.security.AllPermission;

};

is

grant codeBase "file:/C:/-" {

permission java.security.AllPermission;

};

harmmeijera at 2007-7-11 1:51:59 > top of Java-index,Security,Signed Applets...
# 7

Hi,

so I have done all you say.

But it come the same Error : javax.comm.NoSuchPortException

I've Port "COM1" on my PC.

With JBuilder work my Applet. But with Browser don't work :)

I dont find a Permission for open a serial Port !? I think that is the Problem ?

Have you Tested my programm, to open a serial Port?

I dont know what I have to do:(

Deutsch:

Ich hab alles gemacht, was du mir geschrieben hast, aber es hat wieder dasselbe Fahler gegeben: javax.comm.NoSuchPortException

Ich hab mein Applet mit JBuilder getestet un es funktioniert, aber es funktioniert nicht wenn ich es mit einem Browser 鰂fne.

Ich finde keine Permission zum 謋fnen eines seriellen Ports! Ich glaube daran liegt das Problem.

Hast du mein Programm getestet, ob die ein Port 鰂fnet

I weis nicht woran mein Problem liegt:(

Gruss

Borislav

bobbchoa at 2007-7-11 1:51:59 > top of Java-index,Security,Signed Applets...
# 8

what does this do for you, run as application and applet

c:\temp\test.htm

<DIV id="lblOutputText">Output comes here</DIV>

<DIV id="dvObjectHolder">Applet comes here</DIV>

<script>

if(window.navigator.appName.toLowerCase().indexOf("netscape")!=-1){ // set object for Netscape:

document.getElementById('dvObjectHolder').innerHTML = "<object ID='appletTest1' classid=\"java:test.class\"" +

"height='700' width='700' onError=\"changeObject();\"" +

">" +//"<param name=\"archive\" value=\"sTest.jar\">" +

"<param name=\"mayscript\" value=\"Y\">" +

"</object>";

}else if(window.navigator.appName.toLowerCase().indexOf('internet explorer')!=-1){ //set object for IE

document.getElementById('dvObjectHolder').innerHTML ="<object ID='appletTest1' classid=\"clsid:8AD9C840-044E-11D1-B3E9-00805F499D93\"" +

" height='700' width='700' >" +

"<param name=\"code\" value=\"test.class\" />" +// "<param name=\"archive\" value=\"sTest.jar\">" +

" </object>"

}

</script>

c:\temp\test.java

/*

* Created on May 31, 2005

*

* TODO To change the template for this generated file go to

* Window - Preferences - Java - Code Style - Code Templates

*/

/**

* @author 209117

*

* TODO To change the template for this generated type comment go to Window -

* Preferences - Java - Code Style - Code Templates

*/

import javax.comm.*;

import java.io.*;

import java.util.Enumeration;

import java.applet.*;

public class test extends Applet implements Runnable {

public static void main(String[] args) {

new test();

}

public test() {

new Thread(this).start();

}

public void init(){

System.out.println("this is init");

}

public void run() {

try{

System.out.println("this is run");

Enumeration ports = CommPortIdentifier.getPortIdentifiers();

CommPortIdentifier portId = null;

while (ports.hasMoreElements()) {

CommPortIdentifier port = (CommPortIdentifier) ports.nextElement();

String type;

switch (port.getPortType()) {

case CommPortIdentifier.PORT_PARALLEL:

type = "Parallel";

break;

case CommPortIdentifier.PORT_SERIAL:

type = "Serial";

break;

default: /// Shouldn't happen

type = "Unknown";

break;

}

System.out.println(port.getName() + ": " + type);

if(port.getName().toLowerCase().indexOf("com1")!=-1){

portId = port;

}

}

CommPort port = portId.open("Application Name", 3000);

OutputStream os = port.getOutputStream();

os.write("okidoki".getBytes("UTF-8"));

System.out.println("done, no problems");

}catch(Exception e){

e.printStackTrace();

}

}

}

commands

c:

cd \temp\test

javac test.java

java test

open c:\test\test.htm in a browser and check console output.

harmmeijera at 2007-7-11 1:51:59 > top of Java-index,Security,Signed Applets...