You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wss4j-dev@ws.apache.org by he...@alice.it on 2006/06/12 13:36:54 UTC

[WSS4J 1.5] CryptoFactory: Cannot load properties: crypto.properties

hi all

i have a probelm when i created a soap message that i want to sign.

the code is:

public class signer {
	public static void main(String arg[]){
	
		try{
			
			Message signedSOAPMsg=null;
			
			//Crea message factory
			MessageFactory messageFactory = MessageFactory.newInstance();

		     // Creazione di un messaggio
		    
		    SOAPMessage message = messageFactory.createMessage();
			SOAPEnvelope env= new SOAPEnvelope();
		    
		    Message axisMessage = new Message(env,null);
			SOAPEnvelope unsignedEnvelope = axisMessage.getSOAPEnvelope();
			Document doc = unsignedEnvelope.getAsDocument();
		
			   // WSSignEnvelope signs a SOAP envelope according to the
			   // WS Specification (X509 profile) and adds the signature data
			   // to the envelope.
			   WSSecSignature signer = new WSSecSignature();
				  
			   String alias = "16c73ab6-b892-458f-abf5-2f875f74882e";
			   String password = "security";
			   signer.setUserInfo(alias, password);
				  
			   // create a vector of WSEncryptPart parts to sign, both the soap body
		       //and the attachments
			   SOAPConstants soapConstants =WSSecurityUtil.getSOAPConstants(unsignedEnvelope);
				    
			   Vector parts = new Vector();
			  
			   // add the body part
			   String localPart = soapConstants.getBodyQName().getLocalPart();
			   String envelopeURI = soapConstants.getEnvelopeURI();         
			   WSEncryptionPart body = new WSEncryptionPart(localPart, envelopeURI, "Content");
			  
			   parts.add(body);
				  
			   // how to add the attachment part?????         
			   signer.setParts(parts);
				  
			   // The "build" method, creates the signed SOAP envelope.
			   // It takes a SOAP Envelope as a W3C Document and adds
			   // a WSS Signature header to it. The signed elements
			   // depend on the signature parts that are specified by
			   // the WSBaseMessage.setParts(java.util.Vector parts)
			   // method. By default, SOAP Body is signed.
			   // The "crypto" parameter is the object that implements
			   // access to the keystore and handling of certificates.
			   // A default implementation is included:
			   //    org.apache.ws.security.components.crypto.Merlin
			 
			   Document signedDoc = signer.build(doc, CryptoFactory.getInstance(),null);
			  
			   // Convert the signed document into a SOAP message.
			   signedSOAPMsg =  (Message) toSOAPMessage(signedDoc);
			  System.out.println(signedSOAPMsg);
			   } catch (Exception e) {
			    e.printStackTrace();
			   }
			   
	}	   
	public static SOAPMessage toSOAPMessage(Document doc) throws Exception {
		Canonicalizer c14n =Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_WITH_COMMENTS);
		byte[] canonicalMessage = c14n.canonicalizeSubtree(doc);
		ByteArrayInputStream in = new ByteArrayInputStream(canonicalMessage);
		MessageFactory factory = MessageFactory.newInstance();
		return factory.createMessage(null, in);
	
}}

but when i compile there is this error:

java.lang.RuntimeException: CryptoFactory: Cannot load properties: crypto.properties
	at org.apache.ws.security.components.crypto.CryptoFactory.getProperties(CryptoFactory.java:185)
	at org.apache.ws.security.components.crypto.CryptoFactory.getProperties(CryptoFactory.java:168)
	at org.apache.ws.security.components.crypto.CryptoFactory.getInstance(CryptoFactory.java:96)
	at org.apache.ws.security.components.crypto.CryptoFactory.getInstance(CryptoFactory.java:54)
	at Perform.signer.main(signer.java:89)

How i can resolve this problem??

Thank you very much

Hermann

R: R: [WSS4J 1.5] CryptoFactory: Cannot load properties: crypto.properties

Posted by he...@alice.it.
> p.s. I'd really appreciate if you ask questions in the mailing list
> :-) This way a lot of others will learn from your experience as well

sorry for this when i reply i forgot to add Cc ;(

i do all your splendid info but the result is this:

java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at org.apache.ws.security.components.crypto.CryptoFactory.loadClass(CryptoFactory.java:142)
	at org.apache.ws.security.components.crypto.CryptoFactory.loadClass(CryptoFactory.java:119)
	at org.apache.ws.security.components.crypto.CryptoFactory.getInstance(CryptoFactory.java:101)
	at org.apache.ws.security.components.crypto.CryptoFactory.getInstance(CryptoFactory.java:54)
	at Perform.signer.main(signer.java:100)
Caused by: java.lang.NullPointerException: name
	at java.util.zip.ZipFile.getEntry(Unknown Source)
	at java.util.jar.JarFile.getEntry(Unknown Source)
	at java.util.jar.JarFile.getJarEntry(Unknown Source)
	at sun.misc.URLClassPath$JarLoader.getResource(Unknown Source)
	at sun.misc.URLClassPath.getResource(Unknown Source)
	at sun.misc.URLClassPath.getResource(Unknown Source)
	at java.lang.ClassLoader.getBootstrapResource(Unknown Source)
	at java.lang.ClassLoader.getResource(Unknown Source)
	at java.lang.ClassLoader.getResource(Unknown Source)
	at org.apache.commons.discovery.jdk.JDK12Hooks.getResources(JDK12Hooks.java:149)
	at org.apache.commons.discovery.resource.DiscoverResources$1.getNextResources(DiscoverResources.java:153)
	at org.apache.commons.discovery.resource.DiscoverResources$1.getNextResource(DiscoverResources.java:129)
	at org.apache.commons.discovery.resource.DiscoverResources$1.hasNext(DiscoverResources.java:116)
	at org.apache.ws.security.components.crypto.AbstractCrypto.<init>(AbstractCrypto.java:101)
	at org.apache.ws.security.components.crypto.Merlin.<init>(Merlin.java:62)
	... 9 more
java.lang.InstantiationException: org.apache.ws.security.components.crypto.Merlin
	at java.lang.Class.newInstance0(Unknown Source)
	at java.lang.Class.newInstance(Unknown Source)
	at org.apache.ws.security.components.crypto.CryptoFactory.loadClass(CryptoFactory.java:150)
	at org.apache.ws.security.components.crypto.CryptoFactory.loadClass(CryptoFactory.java:119)
	at org.apache.ws.security.components.crypto.CryptoFactory.getInstance(CryptoFactory.java:101)
	at org.apache.ws.security.components.crypto.CryptoFactory.getInstance(CryptoFactory.java:54)
	at Perform.signer.main(signer.java:100)
java.lang.RuntimeException: org.apache.ws.security.components.crypto.Merlin cannot create instance
	at org.apache.ws.security.components.crypto.CryptoFactory.loadClass(CryptoFactory.java:155)
	at org.apache.ws.security.components.crypto.CryptoFactory.loadClass(CryptoFactory.java:119)
	at org.apache.ws.security.components.crypto.CryptoFactory.getInstance(CryptoFactory.java:101)
	at org.apache.ws.security.components.crypto.CryptoFactory.getInstance(CryptoFactory.java:54)
	at Perform.signer.main(signer.java:100)
- Unable to instantiate (1): org.apache.ws.security.components.crypto.Merlin
java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at org.apache.ws.security.components.crypto.CryptoFactory.loadClass(CryptoFactory.java:142)
	at org.apache.ws.security.components.crypto.CryptoFactory.loadClass(CryptoFactory.java:119)
	at org.apache.ws.security.components.crypto.CryptoFactory.getInstance(CryptoFactory.java:101)
	at org.apache.ws.security.components.crypto.CryptoFactory.getInstance(CryptoFactory.java:54)
	at Perform.signer.main(signer.java:100)
Caused by: java.lang.NullPointerException: name
	at java.util.zip.ZipFile.getEntry(Unknown Source)
	at java.util.jar.JarFile.getEntry(Unknown Source)
	at java.util.jar.JarFile.getJarEntry(Unknown Source)
	at sun.misc.URLClassPath$JarLoader.getResource(Unknown Source)
	at sun.misc.URLClassPath.getResource(Unknown Source)
	at sun.misc.URLClassPath.getResource(Unknown Source)
	at java.lang.ClassLoader.getBootstrapResource(Unknown Source)
	at java.lang.ClassLoader.getResource(Unknown Source)
	at java.lang.ClassLoader.getResource(Unknown Source)
	at org.apache.commons.discovery.jdk.JDK12Hooks.getResources(JDK12Hooks.java:149)
	at org.apache.commons.discovery.resource.DiscoverResources$1.getNextResources(DiscoverResources.java:153)
	at org.apache.commons.discovery.resource.DiscoverResources$1.getNextResource(DiscoverResources.java:129)
	at org.apache.commons.discovery.resource.DiscoverResources$1.hasNext(DiscoverResources.java:116)
	at org.apache.ws.security.components.crypto.AbstractCrypto.<init>(AbstractCrypto.java:101)
	at org.apache.ws.security.components.crypto.Merlin.<init>(Merlin.java:62)
	... 9 more
- Unable to instantiate (2): org.apache.ws.security.components.crypto.Merlin
java.lang.InstantiationException: org.apache.ws.security.components.crypto.Merlin
	at java.lang.Class.newInstance0(Unknown Source)
	at java.lang.Class.newInstance(Unknown Source)
	at org.apache.ws.security.components.crypto.CryptoFactory.loadClass(CryptoFactory.java:150)
	at org.apache.ws.security.components.crypto.CryptoFactory.loadClass(CryptoFactory.java:119)
	at org.apache.ws.security.components.crypto.CryptoFactory.getInstance(CryptoFactory.java:101)
	at org.apache.ws.security.components.crypto.CryptoFactory.getInstance(CryptoFactory.java:54)
	at Perform.signer.main(signer.java:100)


How it's possible? Where i mistake

Thanks a lot for your answer




-----Messaggio originale-----
Da: Ruchith Fernando [mailto:ruchith.fernando@gmail.com]
Inviato: lun 12/06/2006 18.29
A: hescot@alice.it
Oggetto: Re: R: [WSS4J 1.5] CryptoFactory: Cannot load properties: crypto.properties
 
>   thank you for your help, sorry if i ask you stupid things but it's the
> first time i use this class and for my bad english.

No problem at all :-)

>  Iin effect i hava a pkcs12 keystore and i want to add its certificate to
> soap message and sign it with private key the problem is that for the moment
> i use eclipse and i don't know where set classpath
>  Can you help me to do this??


First you can create a dir (lets call it "temp") and create a dir by
the name "keys" in it and copy the PKCS12 keystore file into the
"keys" dir.

In eclipse you can
 - Right click on the project -> select properties
 - Select "Java Build Path" -> Libraries

This "Libraries" tab is is where you can add directories and jars to
your classpath. Use "Add class folder" button to add the "temp" dir we
created to  the classpath.

Now copy the crypto.properties file into the "src" dir of the eclipse
project. (into any of the dirs listed in Project->Properties->Java
Build Path ->Source)

Thanks,
Ruchith

p.s. I'd really appreciate if you ask questions in the mailing list
:-) This way a lot of others will learn from your experience as well


R: R: [WSS4J 1.5] CryptoFactory: Cannot load properties: crypto.properties

Posted by he...@alice.it.
> p.s. I'd really appreciate if you ask questions in the mailing list
> :-) This way a lot of others will learn from your experience as well

sorry for this when i reply i forgot to add Cc ;(

i do all your splendid info but the result is this:

java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at org.apache.ws.security.components.crypto.CryptoFactory.loadClass(CryptoFactory.java:142)
	at org.apache.ws.security.components.crypto.CryptoFactory.loadClass(CryptoFactory.java:119)
	at org.apache.ws.security.components.crypto.CryptoFactory.getInstance(CryptoFactory.java:101)
	at org.apache.ws.security.components.crypto.CryptoFactory.getInstance(CryptoFactory.java:54)
	at Perform.signer.main(signer.java:100)
Caused by: java.lang.NullPointerException: name
	at java.util.zip.ZipFile.getEntry(Unknown Source)
	at java.util.jar.JarFile.getEntry(Unknown Source)
	at java.util.jar.JarFile.getJarEntry(Unknown Source)
	at sun.misc.URLClassPath$JarLoader.getResource(Unknown Source)
	at sun.misc.URLClassPath.getResource(Unknown Source)
	at sun.misc.URLClassPath.getResource(Unknown Source)
	at java.lang.ClassLoader.getBootstrapResource(Unknown Source)
	at java.lang.ClassLoader.getResource(Unknown Source)
	at java.lang.ClassLoader.getResource(Unknown Source)
	at org.apache.commons.discovery.jdk.JDK12Hooks.getResources(JDK12Hooks.java:149)
	at org.apache.commons.discovery.resource.DiscoverResources$1.getNextResources(DiscoverResources.java:153)
	at org.apache.commons.discovery.resource.DiscoverResources$1.getNextResource(DiscoverResources.java:129)
	at org.apache.commons.discovery.resource.DiscoverResources$1.hasNext(DiscoverResources.java:116)
	at org.apache.ws.security.components.crypto.AbstractCrypto.<init>(AbstractCrypto.java:101)
	at org.apache.ws.security.components.crypto.Merlin.<init>(Merlin.java:62)
	... 9 more
java.lang.InstantiationException: org.apache.ws.security.components.crypto.Merlin
	at java.lang.Class.newInstance0(Unknown Source)
	at java.lang.Class.newInstance(Unknown Source)
	at org.apache.ws.security.components.crypto.CryptoFactory.loadClass(CryptoFactory.java:150)
	at org.apache.ws.security.components.crypto.CryptoFactory.loadClass(CryptoFactory.java:119)
	at org.apache.ws.security.components.crypto.CryptoFactory.getInstance(CryptoFactory.java:101)
	at org.apache.ws.security.components.crypto.CryptoFactory.getInstance(CryptoFactory.java:54)
	at Perform.signer.main(signer.java:100)
java.lang.RuntimeException: org.apache.ws.security.components.crypto.Merlin cannot create instance
	at org.apache.ws.security.components.crypto.CryptoFactory.loadClass(CryptoFactory.java:155)
	at org.apache.ws.security.components.crypto.CryptoFactory.loadClass(CryptoFactory.java:119)
	at org.apache.ws.security.components.crypto.CryptoFactory.getInstance(CryptoFactory.java:101)
	at org.apache.ws.security.components.crypto.CryptoFactory.getInstance(CryptoFactory.java:54)
	at Perform.signer.main(signer.java:100)
- Unable to instantiate (1): org.apache.ws.security.components.crypto.Merlin
java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at org.apache.ws.security.components.crypto.CryptoFactory.loadClass(CryptoFactory.java:142)
	at org.apache.ws.security.components.crypto.CryptoFactory.loadClass(CryptoFactory.java:119)
	at org.apache.ws.security.components.crypto.CryptoFactory.getInstance(CryptoFactory.java:101)
	at org.apache.ws.security.components.crypto.CryptoFactory.getInstance(CryptoFactory.java:54)
	at Perform.signer.main(signer.java:100)
Caused by: java.lang.NullPointerException: name
	at java.util.zip.ZipFile.getEntry(Unknown Source)
	at java.util.jar.JarFile.getEntry(Unknown Source)
	at java.util.jar.JarFile.getJarEntry(Unknown Source)
	at sun.misc.URLClassPath$JarLoader.getResource(Unknown Source)
	at sun.misc.URLClassPath.getResource(Unknown Source)
	at sun.misc.URLClassPath.getResource(Unknown Source)
	at java.lang.ClassLoader.getBootstrapResource(Unknown Source)
	at java.lang.ClassLoader.getResource(Unknown Source)
	at java.lang.ClassLoader.getResource(Unknown Source)
	at org.apache.commons.discovery.jdk.JDK12Hooks.getResources(JDK12Hooks.java:149)
	at org.apache.commons.discovery.resource.DiscoverResources$1.getNextResources(DiscoverResources.java:153)
	at org.apache.commons.discovery.resource.DiscoverResources$1.getNextResource(DiscoverResources.java:129)
	at org.apache.commons.discovery.resource.DiscoverResources$1.hasNext(DiscoverResources.java:116)
	at org.apache.ws.security.components.crypto.AbstractCrypto.<init>(AbstractCrypto.java:101)
	at org.apache.ws.security.components.crypto.Merlin.<init>(Merlin.java:62)
	... 9 more
- Unable to instantiate (2): org.apache.ws.security.components.crypto.Merlin
java.lang.InstantiationException: org.apache.ws.security.components.crypto.Merlin
	at java.lang.Class.newInstance0(Unknown Source)
	at java.lang.Class.newInstance(Unknown Source)
	at org.apache.ws.security.components.crypto.CryptoFactory.loadClass(CryptoFactory.java:150)
	at org.apache.ws.security.components.crypto.CryptoFactory.loadClass(CryptoFactory.java:119)
	at org.apache.ws.security.components.crypto.CryptoFactory.getInstance(CryptoFactory.java:101)
	at org.apache.ws.security.components.crypto.CryptoFactory.getInstance(CryptoFactory.java:54)
	at Perform.signer.main(signer.java:100)


How it's possible? Where i mistake

Thanks a lot for your answer




-----Messaggio originale-----
Da: Ruchith Fernando [mailto:ruchith.fernando@gmail.com]
Inviato: lun 12/06/2006 18.29
A: hescot@alice.it
Oggetto: Re: R: [WSS4J 1.5] CryptoFactory: Cannot load properties: crypto.properties
 
>   thank you for your help, sorry if i ask you stupid things but it's the
> first time i use this class and for my bad english.

No problem at all :-)

>  Iin effect i hava a pkcs12 keystore and i want to add its certificate to
> soap message and sign it with private key the problem is that for the moment
> i use eclipse and i don't know where set classpath
>  Can you help me to do this??


First you can create a dir (lets call it "temp") and create a dir by
the name "keys" in it and copy the PKCS12 keystore file into the
"keys" dir.

In eclipse you can
 - Right click on the project -> select properties
 - Select "Java Build Path" -> Libraries

This "Libraries" tab is is where you can add directories and jars to
your classpath. Use "Add class folder" button to add the "temp" dir we
created to  the classpath.

Now copy the crypto.properties file into the "src" dir of the eclipse
project. (into any of the dirs listed in Project->Properties->Java
Build Path ->Source)

Thanks,
Ruchith

p.s. I'd really appreciate if you ask questions in the mailing list
:-) This way a lot of others will learn from your experience as well


Re: [WSS4J 1.5] CryptoFactory: Cannot load properties: crypto.properties

Posted by Ruchith Fernando <ru...@gmail.com>.
Hi Hermann,

First you have to have the crypto.properties file in the classpath
when you rung this program.  Looking at the alias and password values
in your code seems like you are using this [1] PKCS12 keystore. You
can use this [2] crypto.properties file in you classpath if you make
the x509.PFX.MSFT
  file from [1] available in a "keys" dir in the classpath.

Also to get your code working you will have to pass a WSSecHeader
instance to the build() method of WSSecSignature. The modified main()
method is available here [3].

Thanks,
Ruchith

[1] https://svn.apache.org/repos/asf/webservices/wss4j/trunk/keys/x509.PFX.MSFT
[2] https://svn.apache.org/repos/asf/webservices/wss4j/trunk/src/crypto.properties
[3] http://rafb.net/paste/results/yoCbXV61.html

On 6/12/06, hescot@alice.it <he...@alice.it> wrote:
>
>
>
> hi all
>
>  i have a probelm when i created a soap message that i want to sign.
>
>  the code is:
>
>  public class signer {
>          public static void main(String arg[]){
>
>                  try{
>
>                          Message signedSOAPMsg=null;
>
>                          //Crea message factory
>                          MessageFactory messageFactory =
> MessageFactory.newInstance();
>
>                       // Creazione di un messaggio
>
>                      SOAPMessage message = messageFactory.createMessage();
>                          SOAPEnvelope env= new SOAPEnvelope();
>
>                      Message axisMessage = new Message(env,null);
>                          SOAPEnvelope unsignedEnvelope =
> axisMessage.getSOAPEnvelope();
>                          Document doc = unsignedEnvelope.getAsDocument();
>
>                             // WSSignEnvelope signs a SOAP envelope
> according to the
>                             // WS Specification (X509 profile) and adds the
> signature data
>                             // to the envelope.
>                             WSSecSignature signer = new WSSecSignature();
>
>                             String alias =
> "16c73ab6-b892-458f-abf5-2f875f74882e";
>                             String password = "security";
>                             signer.setUserInfo(alias, password);
>
>                             // create a vector of WSEncryptPart parts to
> sign, both the soap body
>                         //and the attachments
>                             SOAPConstants soapConstants
> =WSSecurityUtil.getSOAPConstants(unsignedEnvelope);
>
>                             Vector parts = new Vector();
>
>                             // add the body part
>                             String localPart =
> soapConstants.getBodyQName().getLocalPart();
>                             String envelopeURI =
> soapConstants.getEnvelopeURI();
>                             WSEncryptionPart body = new
> WSEncryptionPart(localPart, envelopeURI, "Content");
>
>                             parts.add(body);
>
>                             // how to add the attachment part?????
>                             signer.setParts(parts);
>
>                             // The "build" method, creates the signed SOAP
> envelope.
>                             // It takes a SOAP Envelope as a W3C Document
> and adds
>                             // a WSS Signature header to it. The signed
> elements
>                             // depend on the signature parts that are
> specified by
>                             // the WSBaseMessage.setParts(java.util.Vector
> parts)
>                             // method. By default, SOAP Body is signed.
>                             // The "crypto" parameter is the object that
> implements
>                             // access to the keystore and handling of
> certificates.
>                             // A default implementation is included:
>                             //
> org.apache.ws.security.components.crypto.Merlin
>
>                             Document signedDoc = signer.build(doc,
> CryptoFactory.getInstance(),null);
>
>                             // Convert the signed document into a SOAP
> message.
>                             signedSOAPMsg =  (Message)
> toSOAPMessage(signedDoc);
>                            System.out.println(signedSOAPMsg);
>                             } catch (Exception e) {
>                              e.printStackTrace();
>                             }
>
>          }
>          public static SOAPMessage toSOAPMessage(Document doc) throws
> Exception {
>                  Canonicalizer c14n
> =Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_WITH_COMMENTS);
>                  byte[] canonicalMessage = c14n.canonicalizeSubtree(doc);
>                  ByteArrayInputStream in = new
> ByteArrayInputStream(canonicalMessage);
>                  MessageFactory factory = MessageFactory.newInstance();
>                  return factory.createMessage(null, in);
>
>  }}
>
>  but when i compile there is this error:
>
>  java.lang.RuntimeException: CryptoFactory: Cannot load properties:
> crypto.properties
>          at
> org.apache.ws.security.components.crypto.CryptoFactory.getProperties(CryptoFactory.java:185)
>          at
> org.apache.ws.security.components.crypto.CryptoFactory.getProperties(CryptoFactory.java:168)
>          at
> org.apache.ws.security.components.crypto.CryptoFactory.getInstance(CryptoFactory.java:96)
>          at
> org.apache.ws.security.components.crypto.CryptoFactory.getInstance(CryptoFactory.java:54)
>          at Perform.signer.main(signer.java:89)
>
>  How i can resolve this problem??
>
>  Thank you very much
>
>  Hermann
>

---------------------------------------------------------------------
To unsubscribe, e-mail: wss4j-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: wss4j-dev-help@ws.apache.org


Re: [WSS4J 1.5] CryptoFactory: Cannot load properties: crypto.properties

Posted by Ruchith Fernando <ru...@gmail.com>.
Hi Hermann,

First you have to have the crypto.properties file in the classpath
when you rung this program.  Looking at the alias and password values
in your code seems like you are using this [1] PKCS12 keystore. You
can use this [2] crypto.properties file in you classpath if you make
the x509.PFX.MSFT
  file from [1] available in a "keys" dir in the classpath.

Also to get your code working you will have to pass a WSSecHeader
instance to the build() method of WSSecSignature. The modified main()
method is available here [3].

Thanks,
Ruchith

[1] https://svn.apache.org/repos/asf/webservices/wss4j/trunk/keys/x509.PFX.MSFT
[2] https://svn.apache.org/repos/asf/webservices/wss4j/trunk/src/crypto.properties
[3] http://rafb.net/paste/results/yoCbXV61.html

On 6/12/06, hescot@alice.it <he...@alice.it> wrote:
>
>
>
> hi all
>
>  i have a probelm when i created a soap message that i want to sign.
>
>  the code is:
>
>  public class signer {
>          public static void main(String arg[]){
>
>                  try{
>
>                          Message signedSOAPMsg=null;
>
>                          //Crea message factory
>                          MessageFactory messageFactory =
> MessageFactory.newInstance();
>
>                       // Creazione di un messaggio
>
>                      SOAPMessage message = messageFactory.createMessage();
>                          SOAPEnvelope env= new SOAPEnvelope();
>
>                      Message axisMessage = new Message(env,null);
>                          SOAPEnvelope unsignedEnvelope =
> axisMessage.getSOAPEnvelope();
>                          Document doc = unsignedEnvelope.getAsDocument();
>
>                             // WSSignEnvelope signs a SOAP envelope
> according to the
>                             // WS Specification (X509 profile) and adds the
> signature data
>                             // to the envelope.
>                             WSSecSignature signer = new WSSecSignature();
>
>                             String alias =
> "16c73ab6-b892-458f-abf5-2f875f74882e";
>                             String password = "security";
>                             signer.setUserInfo(alias, password);
>
>                             // create a vector of WSEncryptPart parts to
> sign, both the soap body
>                         //and the attachments
>                             SOAPConstants soapConstants
> =WSSecurityUtil.getSOAPConstants(unsignedEnvelope);
>
>                             Vector parts = new Vector();
>
>                             // add the body part
>                             String localPart =
> soapConstants.getBodyQName().getLocalPart();
>                             String envelopeURI =
> soapConstants.getEnvelopeURI();
>                             WSEncryptionPart body = new
> WSEncryptionPart(localPart, envelopeURI, "Content");
>
>                             parts.add(body);
>
>                             // how to add the attachment part?????
>                             signer.setParts(parts);
>
>                             // The "build" method, creates the signed SOAP
> envelope.
>                             // It takes a SOAP Envelope as a W3C Document
> and adds
>                             // a WSS Signature header to it. The signed
> elements
>                             // depend on the signature parts that are
> specified by
>                             // the WSBaseMessage.setParts(java.util.Vector
> parts)
>                             // method. By default, SOAP Body is signed.
>                             // The "crypto" parameter is the object that
> implements
>                             // access to the keystore and handling of
> certificates.
>                             // A default implementation is included:
>                             //
> org.apache.ws.security.components.crypto.Merlin
>
>                             Document signedDoc = signer.build(doc,
> CryptoFactory.getInstance(),null);
>
>                             // Convert the signed document into a SOAP
> message.
>                             signedSOAPMsg =  (Message)
> toSOAPMessage(signedDoc);
>                            System.out.println(signedSOAPMsg);
>                             } catch (Exception e) {
>                              e.printStackTrace();
>                             }
>
>          }
>          public static SOAPMessage toSOAPMessage(Document doc) throws
> Exception {
>                  Canonicalizer c14n
> =Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_WITH_COMMENTS);
>                  byte[] canonicalMessage = c14n.canonicalizeSubtree(doc);
>                  ByteArrayInputStream in = new
> ByteArrayInputStream(canonicalMessage);
>                  MessageFactory factory = MessageFactory.newInstance();
>                  return factory.createMessage(null, in);
>
>  }}
>
>  but when i compile there is this error:
>
>  java.lang.RuntimeException: CryptoFactory: Cannot load properties:
> crypto.properties
>          at
> org.apache.ws.security.components.crypto.CryptoFactory.getProperties(CryptoFactory.java:185)
>          at
> org.apache.ws.security.components.crypto.CryptoFactory.getProperties(CryptoFactory.java:168)
>          at
> org.apache.ws.security.components.crypto.CryptoFactory.getInstance(CryptoFactory.java:96)
>          at
> org.apache.ws.security.components.crypto.CryptoFactory.getInstance(CryptoFactory.java:54)
>          at Perform.signer.main(signer.java:89)
>
>  How i can resolve this problem??
>
>  Thank you very much
>
>  Hermann
>

---------------------------------------------------------------------
To unsubscribe, e-mail: wss4j-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: wss4j-dev-help@ws.apache.org