In this post I will write how to:
1) detach signature that is attached to the data
2) view the content of signature.
Bouncy Castle is a good library but it is hard to find something in its documentation.
Here is the class that detaches the signature and writes the content of data to the File:
This blog is a collection of minds around linux, java, javascript, etc. Looking for great opportunities.
Показаны сообщения с ярлыком CryptoPro. Показать все сообщения
Показаны сообщения с ярлыком CryptoPro. Показать все сообщения
вторник, 30 сентября 2014 г.
четверг, 27 декабря 2012 г.
Make friends: Apache CXF client + WSS4J + CryptoPro
Many of you who worked with government webservices know that the information passed to the service should be signed with GOST algorithm. This leads to the use of CryptoPro library. So here is the interesting part. What I have:
Then, configure the crypto.properties file for wss4j: org.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.Merlin
org.apache.ws.security.crypto.merlin.keystore.type=HDImageStore
org.apache.ws.security.crypto.merlin.keystore.password=1234567890
org.apache.ws.security.crypto.merlin.keystore.alias=tester
org.apache.ws.security.crypto.merlin.keystore.file=c:/cert.store
Then, configure your client:
Here is the example of client:
For this to work I had to patch WSS4j. Download the sources for WSS4j 1.6.6 and edit the file org.apache.ws.security.message.WSSecSignature.java. Find the init method and replace it with this code:
Compile the file and add the compiled class to the wss4j jar.
After this, I could successfully run the client.
- jdk 1.6.0.38 + JCP CryptoPro
- ready to use keystore
- wss4j 1.6.6
- apache cxf 2.6.1
- XMLDSigRI.jar
Then, configure the crypto.properties file for wss4j: org.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.Merlin
org.apache.ws.security.crypto.merlin.keystore.type=HDImageStore
org.apache.ws.security.crypto.merlin.keystore.password=1234567890
org.apache.ws.security.crypto.merlin.keystore.alias=tester
org.apache.ws.security.crypto.merlin.keystore.file=c:/cert.store
Then, configure your client:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> <!-- The SOAP client bean --> <jaxws:client id="client" serviceClass="ru.my.IService" address="http://test/IService/IdentificationService.svc"> <jaxws:inInterceptors> <bean class="org.apache.cxf.interceptor.LoggingInInterceptor"/> </jaxws:inInterceptors> <jaxws:outInterceptors> <bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"/> <ref bean="wss4jOutConfiguration" /> </jaxws:outInterceptors> </jaxws:client> <bean id="wss4jOutConfiguration" class="org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor"> <property name="properties"> <map> <entry key="action" value="Signature"/> <entry key="signaturePropFile" value="crypto.properties"/> <entry key="signatureKeyIdentifier" value="DirectReference"/> <entry key="user" value="tester"/> <entry key="signatureUser" value="tester"/> <entry key="passwordCallbackClass" value="ru.client.KeystorePasswordCallback"></entry> <entry key="signatureDigestAlgorithm" value="http://www.w3.org/2001/04/xmldsig-more#gostr3411"/> <entry key="signatureAlgorithm" value="http://www.w3.org/2001/04/xmldsig-more#gostr34102001-gostr3411"/> </map> </property> </bean> </beans>Everything seems good, but your client won't work.
Here is the example of client:
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"applicationContext.xml"});
ru.IService client = (ru.IService) context.getBean("client");
ru.CryptoPro.JCPxml.XmlInit.init();
if(!JCPXMLDSigInit.isInitialized()){
JCPXMLDSigInit.init();
}
Result res = client.callMethod(123);
For this to work I had to patch WSS4j. Download the sources for WSS4j 1.6.6 and edit the file org.apache.ws.security.message.WSSecSignature.java. Find the init method and replace it with this code:
private void init() {
Provider xmlDSigProvider = new ru.CryptoPro.JCPxml.dsig.internal.dom.XMLDSigRI();
signatureFactory = XMLSignatureFactory.getInstance("DOM", xmlDSigProvider);//XMLSignatureFactory.getInstance("DOM");
keyInfoFactory = KeyInfoFactory.getInstance("DOM", xmlDSigProvider);
}
Compile the file and add the compiled class to the wss4j jar.
After this, I could successfully run the client.
Подписаться на:
Комментарии (Atom)