cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Wermus Fernando <fernando.wer...@xlnet.net.ar>
Subject RE: Cocoon + IXSIL
Date Tue, 23 Sep 2003 14:45:49 GMT
José,
            Qué tal? Soy de Argentina y en este momento estoy en la misma
situación que vos. Viste que en jsp hay que declarar las clases con
useBean... en el caso de cocoon es con xsp:incluye, estas seguro?
 
Si llego a resolverlo o lo haces vos en tu caso me avisas.
 
Salduso1
 
-----Mensaje original-----
De: Josep Riudavets [mailto:jriudavetsa@uoc.edu] 
Enviado el: martes, 23 de septiembre de 2003 6:46
Para: users@cocoon.apache.org
Asunto: Cocoon + IXSIL
 
Hi ... My name is Josep, from Barcelona (Spain).

I'm trying to develop a XSP page, including an instance of my own class:
 
<?xml version="1.0" encoding="UTF-8"?>
<?cocoon-process type="xsp"?>
<?cocoon-process type="xslt"?>
<xsp:page language="java" xmlns:xsp="http://apache.org/xsp"
xmlns:xsp-request="http://apache.org/xsp/request/2.0"
xmlns:esql="http://apache.org/cocoon/SQL/v2">
<xsp:structure>
<xsp:include>edu.uoc.riudavets.CrearSignatura</xsp:include>
<xsp:include>java.io.*</xsp:include>
</xsp:structure>
<procesa>
<xsp:logic>
String a00 = "/usr/local/tomcat/webapps/cocoon/fitxers/usuaria.p12";
String a11 = "federicoa";
String a22 = "/usr/local/tomcat/webapps/cocoon/fitxers/exped.xml";
CrearSignatura cs = new CrearSignatura();
cs.Signar(a00,a11,a22);
</xsp:logic>
</esql:connection>
</procesa>
</xsp:page>
This class is placed into a package "edu.uoc.riudavets" under
WEB-INF/classes. 

My problem: when I execute this class out of Cocoon, with a java IDE, it
works perfectly. Buy when I catch the class and I put the package into
WEB-INF/classes in order to use with Cocoon, it does not work. Cocoon
recognize the package and the cass, with its constructor ... but Cocoon does
not execute it !!!

I'm using Cocoon2 under Tomcat 4.1 and J2SDK 1.4. The class I have created
uses IXSIL_1_1 libraries.

I have a doubt: if the class uses a lot of IXSIL libraries, have I to put
these these libraries under WEB-INF/lib directory? Does Cocoon see the
libraries that are included ("import") into the class that I have created?
And does Tomcat see them?

Sorry about my English ... I hope to learn more in next months!!!

Thanks a lot.
 
 
CrearSignatura.java

package edu.uoc.riudavets;

import java.io.*;
import java.security.PublicKey;

import java.security.interfaces.RSAPrivateKey;

import org.apache.xerces.parsers.*;
import org.w3c.dom.*;
import iaik.x509.*; 
import iaik.pkcs.pkcs12.*;
import iaik.ixsil.core.*;
import iaik.ixsil.algorithms.*;
import iaik.ixsil.init.*;
import iaik.ixsil.util.*;
import iaik.ixsil.keyinfo.x509.*;
import iaik.ixsil.keyinfo.*;

public class CrearSignatura{
public CrearSignatura(){
}
public void Signar(String args[]){
PKCS12 p12 = null;
KeyBag bossa = null;
X509Certificate X509cert=null;
X509Certificate[] certs = new X509Certificate[1];
RSAPrivateKey sk = null;
PublicKey pk = null;
iaik.security.provider.IAIK.addAsProvider(true);
BufferedReader entrada = new BufferedReader(new
InputStreamReader(System.in));
try{
IXSILInit.init(new URI("file", null,
"C://j2sdk//IAIK-XML//init//properties//init.properties", null, null));
}catch(Exception ex){
ex.printStackTrace();
System.exit(1); 
}
try{
FileInputStream p12_f = new FileInputStream(args[0]);
p12 = new PKCS12(p12_f);
}catch(Exception e){
e.printStackTrace();
System.exit(1);
}
try{
System.out.println("\nIntentado Decrypt...\n");
char[] password = args[1].toCharArray();
p12.decrypt(password);
System.out.println("Decrypt realizado!!!\n");
}catch(Exception ex){
ex.printStackTrace();
System.exit(1); 
}
try{
System.out.println("Intentado obtener KeyBag...\n");
bossa = p12.getKeyBag();
System.out.println("KeyBag obtenido!!!\n");
}catch(Exception ex){
ex.printStackTrace();
System.exit(1); 
}
try{
System.out.println("Extrayendo Clave Privada...\n");
sk = (RSAPrivateKey)bossa.getPrivateKey();
System.out.println("Clave Privada guardada!!!\n");
}catch(Exception ex){
ex.printStackTrace();
System.exit(1); 
}
try{
System.out.println("Extrayendo Clave Publica...\n");
CertificateBag[] cb = p12.getCertificateBags();
X509cert = new X509Certificate();
X509cert = cb[0].getCertificate();
FileOutputStream cert_fitxer=new FileOutputStream("certificat_uocTest.cer");
X509cert.writeTo(cert_fitxer); 
cert_fitxer.close();
pk=X509cert.getPublicKey(); 
System.out.println("Clave Publica guardada!!!\n");
}catch(Exception ex){
ex.printStackTrace();
System.exit(1); 
}

try{
/*System.out.println("Extraccio dades a signar...\n");
FileInputStream fitxer = new FileInputStream(args[2]); 
byte[] body = new byte[fitxer.available()];
System.out.println("Dades a signar capturades!!!\n");*/
URI baseURI = new URI("file", null,args[2], null, null);
DOMParser parser = new DOMParser();
parser.parse(args[2]);
Document document = parser.getDocument();
Signer signer = new Signer(document, baseURI, new Position("/cad", null,
0));
SignerSignature signature = signer.getSignature();
SignerSignedInfo signedInfo = signer.getSignature().getSignerSignedInfo();

KeyManagerImpl keyManager = new KeyManagerImpl(signer.toDocument());
keyManager.setId("KeyInfo");
KeyProviderImplX509Data x509KeyProvider = new
KeyProviderImplX509Data(signer.toDocument());
X509Data x509CertificateData = new X509Data();
x509CertificateData.insertHintAt(X509cert, 0);
x509KeyProvider.insertX509DataAt(x509CertificateData, 0);
keyManager.addKeyProvider(x509KeyProvider);
signature.setKeyManager(keyManager);
CanonicalizationAlgorithmImplCanonicalXML c14nAlg = new
CanonicalizationAlgorithmImplCanonicalXML();
signedInfo.setCanonicalizationAlgorithm(c14nAlg);
SignatureAlgorithmImplRSA signatureAlg = new SignatureAlgorithmImplRSA();
signatureAlg.setSignerKey(sk);
signedInfo.setSignatureAlgorithm(signatureAlg);
SignerReference reference = signedInfo.createReference();
reference.setURI(new URI(""));
TransformImplEnvelopedSignature env = new TransformImplEnvelopedSignature();
reference.insertTransformAt(env, 0);
DigestAlgorithmImplSHA1 digestAlg = new DigestAlgorithmImplSHA1();
signedInfo.setSignatureAlgorithm(signatureAlg);
reference.setDigestAlgorithm(digestAlg);
signedInfo.addReference(reference);
// Add key info.
SignerReference keyInfo = signedInfo.createReference();
// Set reference URI
keyInfo.setURI(new URI("#KeyInfo"));
// Create new instance of digest algorithm
DigestAlgorithmImplSHA1 digestAlg1 = new DigestAlgorithmImplSHA1();
// Set digest algorithm
keyInfo.setDigestAlgorithm(digestAlg1);
// Add reference to signature
signedInfo.addReference(keyInfo);
signer.getSignature().sign();
/*digestAlg.setInput(new FileInputStream(args[2]));
InputStream out_t = digestAlg.digest();
signatureAlg.setInput(out_t);
InputStream out_t2 = signatureAlg.sign();*/
Document d = signer.toDocument();
FileOutputStream outputXMLDoc = new FileOutputStream("out.xml");
DOMUtilsImpl domUtilitites = new DOMUtilsImpl();
domUtilitites.serializeDocument(d, outputXMLDoc);
}catch(Exception ex){
ex.printStackTrace();
System.exit(1); 
}
}

}

Mime
View raw message