# ClassNotFoundException

Shikha Gupta - NSB (shikhag@niitdel.niit.co.in)
Wed, 24 Feb 1999 17:29:00 +0000

- Messages sorted by: [ date ][ thread ][ subject ][ author ]
- Next message: Alvaro Fuentes: "HttpsURLConnection"
- Previous message: Ahmer Ali Khan: "SSL support"

    Date: Wed, 24 Feb 1999 17:29:00 +0000

    From: "Shikha Gupta - NSB" <shikhag@niitdel.niit.co.in>

    To: java-security@java.sun.com (security)

    Subject: ClassNotFoundException

This is the preamble of a multipart MIME formatted message.
If you are reading this text your mail system is most likely
not capable of properly decoding MIME messages. To extract
the contents of this message, save it to a file and then use
an external MIME decoding utility.

--mime-boundary-iaanaackpb-000FFFC0
Content-type: text/plain; charset="ISO-8859-1"
Content-disposition: inline
Content-Transfer-Encoding: 7bit

Hi,
I' m gettin the error ClassNotFoundException whem I'm running a applet
implementing the ObjectInputStream and ObjectOutputstreams.

The html file:doPost1.htm

Test

// html ends here

The code for the applet is :
NetworkClient.java
import java.net.* ;
import java.io.* ;
import java.security.* ;
import java.applet.Applet ;
import java.awt.* ;
import java.util.*;
interface PublicKey1 extends PublicKey {

}
class verifier {
private PublicKey1 key ;
private Signature sgn ;
private byte[] sig ;
String data ;
public verifier(PublicKey key, byte[] sig , String data) {

try {
this.key = key ;
this.sig = sig ;
this.data = data ;
sgn = Signature.getInstance(key.getAlgorithm()) ;
}
catch (NoSuchAlgorithmException e) {
System.out.println("No implementation of key") ;
System.exit(1) ;
}

}

public boolean verifySignature() {

boolean verify = false ;

try {
sgn.initVerify(key) ;
sgn.update(data.getBytes()) ;
verify = sgn.verify(sig) ;
} catch (Exception e) {
verify = false;
}
return verify ;
}

}

public class NetworkClient extends Applet{

protected URL url;
protected URLConnection connection;

private TextArea fileArea;

public void init() {

add(new Button("Button")) ;

fileArea = new TextArea() ;
fileArea.setFont(new Font("Courier" , Font.BOLD , 12));
add(fileArea) ;

}

public boolean action(Event e , Object o) {

try {
url = new URL("http","localhost",-1,"/scripts/cgi.exe");

} catch (MalformedURLException mue) {
System.out.println("Bad URL: " + mue) ;
System.exit(1);
} catch (IOException ioe) {
System.out.println("IOException " + ioe) ;
System.exit(1);
}

Connect() ;
return true ;
}

public void Connect() {
try {
connection =url.openConnection();
}catch (Exception e) {
System.out.println("Error");
System.exit(1);

}
handleConnection(connection);
}

public void handleConnection(URLConnection connection){

String response = null ;
String request = "CLIENT CERTIFICATE REQUEST";
byte[] signedData = null ;
verifier vrfr = null;
PublicKey key =null ;
connection.setDoOutput(true) ;
connection.setDoInput(true);

try {
PrintStream out = new PrintStream(connection.getOutputStream());

String str=
URLEncoder.encode("request")+"="+URLEncoder.encode(request);
String temp=null;
out.println(str) ;
out.close();

DataInputStream in = new DataInputStream(connection.getInputStream());
byte[] allData = new byte[100000] ;
int i = 0 ;
try {

while(true)
allData[i++] = in.readByte() ;
}
catch (EOFException e){} ;
showStatus("The no of bytes read"+i);

ByteArrayInputStream bin = new ByteArrayInputStream(allData, 2 , i);
ObjectInputStream oin = new ObjectInputStream(bin);

request = (String)oin.readObject() ;
System.out.println("The request :"+request);
fileArea.appendText("The request :"+request);
signedData = (byte[])oin.readObject();
// fileArea.appendText("The signed data"+signedData.toString());
key = (PublicKey)oin.readObject();

//fileArea.appendText("The key is"+key.toString());
} catch (IOException e){
System.out.println(e);
showStatus(e.toString());

}catch (ClassNotFoundException cnf) {
cnf.printStackTrace();
showStatus(cnf.toString());
System.out.println(cnf);
}

vrfr = new verifier(key,signedData,request);
if (vrfr.verifySignature())
fileArea.appendText("Generic Server verified signature") ;
else
fileArea.appendText("Generic Server signature failed") ;

}

}
// Applet ends here

Network Server.java
import java.net.* ;
import java.io.* ;
import java.security.* ;
import java.util.*;
import java.awt.*;
class exchange
{
private KeyPair pair ;
private Signature sgn ;
private byte[] sig ;

public exchange()
{
try
{
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA")

;
keyGen.initialize(1024, new SecureRandom());
pair = keyGen.generateKeyPair() ;
sgn = Signature.getInstance("SHA/DSA") ;
}
catch (NoSuchAlgorithmException e)
{
System.out.println("No implementation of keypair generator") ;
System.exit(1) ;
}
}

public byte[] getSignature(String data)
{
try
{
sgn.initSign(pair.getPrivate());
sgn.update(data.getBytes()) ;
sig = sgn.sign() ;
}
catch (Exception e)
{
System.out.println("No implementation of keypair") ;
System.exit(1) ;
}
return sig ;
}

public PublicKey getPublickey()
{
return pair.getPublic() ;
}

public boolean verifySignature(String data)
{
boolean verify = false ;
try
{
sgn.initVerify(pair.getPublic()) ;
sgn.update(data.getBytes()) ;
verify = sgn.verify(sig) ;
}
catch (Exception e)
{
verify = false;
}
return verify ;
}

public byte[] getSignedData(String data)
{
exchange sgn = new exchange() ;
return sgn.getSignature(data) ;
}

}

public class NetworkServer {
protected exchange sig = new exchange() ;
String request = null;

public NetworkServer(){
try {
request = URLDecoder.decode(System.getProperty("request"));

} catch (Exception e) {
System.out.println(e);
}
}

public void listen()
{
handleConnection();
}

protected void handleConnection() {

byte[] signedReq;
PublicKey1 key ;
String response = new String("");

try {
signedReq = sig.getSignature(request) ;
OutputStream out = System.out ;
ObjectOutputStream objout = new ObjectOutputStream(out);
objout.writeObject((String)request);
objout.writeObject(signedReq);
objout.writeObject(sig.getPublickey());

objout.close();
// objout.writeObject(sig.getPublickey());

} catch (Exception cnf){
System.out.println("Error " + cnf) ;

cnf.printStackTrace() ;
}

}

public static void main(String args[]) {

NetworkServer nwServer = new NetworkServer() ;
nwServer.listen() ;
}
}

The cgi program :
#include "cgi.h"
#include "CjavaFromCgi.h"

void main(int ac, char **av, char **envp)
{
char *programName;
char *path = av[0];
int iNoPairs;
CjavaFromCgi clCallJava;
path=".";
programName="NetworkServer";
clCallJava.makeCgiVars();

iNoPairs = clCallJava.returnPairCount();
clCallJava.buildArgv(envp, vars, programName, iNoPairs);

cout<<"\n"<<endl;
clCallJava.executeJavaCgi();// call the java program(Network server)
from c++ cgi

}
[[ cgi.zip : 2827 in cgi.zip ]]
The cgi.zip contains other header files and cpp files used for cgi
parsing
The platform used:Windows NT4.0
Web Server IIS4.0.
Browser:IE4.0

When I'm running the program through the Web Server ,it prints the
request and the signed data but does not give the public key and gives
the error ClassNotFoundException .

key = (PublicKey)oin.readObject(); at this line in NetworkClient.java

It runs fine in standalone or through the AppletViewer.
I 've also tried by making my own Public Key but it didn't help.
Please help me out.
Bye
Shikha

--mime-boundary-iaanaackpb-000FFFC0
Content-type: application/zip; name="cgi.zip"
Content-disposition: attachment; filename="cgi.zip"
Content-Transfer-Encoding: base64

UEsDBBQAAAAIADKHTSZafeba7QEAAGkEAAAQAAAAQ2phdmFGcm9tQ2dpLmNwcJ1TwW6bQBA9
Y4l/GFEl2gXS9NBTiCshV20VuVZU2qiSZUUbvOBtYUG7QKpW/ffusGBjJ8qhN2bm7Zt5M49X
QqZFu+XgLX6wjn1QVbnIxeud587c2TQFV1cwjQl1Z3/AnTnpjinH99N7Hau8gzkQzIDvUyhZ
UVQp0eI3r7IhTcGHz/H3+/jLx4RG7uwvNuoqsYXTbg+tKLbIORJy2dUhDEHHlB6DWlW5YuWK
lTwEIRsQq+qWCaVxxsOI7H/mM88NoyPNwzfREIhoT1pbCFKvZRBsDMxDHV50mr1IC6Z1zZrd
k9piGSfJbfz1kyXLKgVE9A0BZa7FBs7PQcL1frIIRBAYdQ7Kc0QGhNTmQc4bsyQyPKIUERZy
1K9kP7lZ7IgLoUaljmNu4fT3cC4vn8M3O6Ev3inetErisomgIYzJsup4XBRJzVKuj6B3rGgR
S/suVt3caBPX4532cp6f88W+Rx2eXmPijcPasbD6tlxa+MG6WH3Rk/wXT9uG35js+A8YAsx2
5Ca+i40jLdne2oPZTons3AaZNErIfGSy6ZHEcliGU4JxN7Yqe+vb7w6XMXE++A9tlnFl9En+
2IPWRDeq4JJYLAQwxMiD4VvqT38LSje4PF2bWZuMWL7QePr9mZ6faS8EO4Cliw5CLBJ1/ANQ
SwMEFAAAAAgANGpLJqFHh7HtAAAApAEAAAUAAABjZ2kuaFWPy2rDMBBF1xXoH4yzKyU/0AcI
efwAW3J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4Pj5eRwP1FRsZQoWym8Gx+it7KOBulSU7u7h3hgmlNaAOGNlgwpX3v2/d6hQMzsPG9K35g
itzwUhdMWHifGT62c5yxdk1RGoLPDBXtrDRbt3Cp/tp1NDxart3I0GFFrIw1Zz28KjFnx8/x
1lT21uTTC8PzVMs+wS3T8xm3sTPADVSbuSISIu8ZB71eoKDtBvjvh1Fm9wK5M806W9xwkf4p
jVXSdRSOnazA1O2JuNaO+am6yfUzXRCArLD+BVBLAQIUABQAAAAIADKHTSZafeba7QEAAGkE
AAAQAAAAAAAAAAEAIAC2gQAAAABDamF2YUZyb21DZ2kuY3BwUEsBAhQAFAAAAAgANGpLJqFH
h7HtAAAApAEAAAUAAAAAAAAAAQAgALaBGwIAAGNnaS5oUEsBAhQAFAAAAAgAbYpWJjJnpPgw
AQAAIwIAAA4AAAAAAAAAAQAgALaBKwMAAENqYXZhRnJvbUNnaS5oUEsBAhQAFAAAAAgA2IhN
JnMGWQxvAwAA/hAAAA8AAAAAAAAAAQAgALaBhwQAAENnZXRDZ2lWYXJzLmNwcFBLAQIUABQA
AAAIADZ7SyaR6sTQFgEAAEcCAAANAAAAAAAAAAEAIAC2gSMIAABDZ2V0Q2dpVmFycy5oUEsF
BgAAAAAFAAUAJQEAAGQJAAAAAA==

--mime-boundary-iaanaackpb-000FFFC0--

- Next message: Alvaro Fuentes: "HttpsURLConnection"
- Previous message: Ahmer Ali Khan: "SSL support"