3
3
import java .util .Set ;
4
4
import java .util .HashSet ;
5
5
import java .util .Properties ;
6
+ import javax .crypto .KeyGenerator ;
7
+ import javax .crypto .SecretKey ;
6
8
import javax .xml .namespace .QName ;
7
9
import javax .xml .transform .*;
8
10
import javax .xml .transform .dom .DOMResult ;
12
14
import jakarta .xml .ws .handler .soap .SOAPMessageContext ;
13
15
import jakarta .xml .soap .*;
14
16
import javax .xml .parsers .DocumentBuilderFactory ;
15
- import org .apache .ws .security .components .crypto .Crypto ;
16
- import org .apache .ws .security .components .crypto .CryptoFactory ;
17
- import org .apache .ws .security .message .WSSecEncrypt ;
18
- import org .apache .ws .security .message .WSSecHeader ;
19
- import org .apache .ws .security .message .WSSecSignature ;
20
- import org .apache .ws .security .message .WSSecTimestamp ;
17
+
18
+ import org .apache .wss4j .common .crypto .Crypto ;
19
+ import org .apache .wss4j .common .crypto .CryptoFactory ;
20
+ import org .apache .wss4j .dom .message .WSSecEncrypt ;
21
+ import org .apache .wss4j .dom .message .WSSecHeader ;
22
+ import org .apache .wss4j .dom .message .WSSecSignature ;
23
+ import org .apache .wss4j .dom .message .WSSecTimestamp ;
24
+
21
25
import org .w3c .dom .*;
22
26
import java .io .InputStream ;
23
27
import java .io .ByteArrayInputStream ;
26
30
import com .genexus .diagnostics .core .LogManager ;
27
31
import com .genexus .common .interfaces .*;
28
32
33
+ import static org .apache .wss4j .common .util .KeyUtils .getKeyGenerator ;
34
+
29
35
public class GXHandlerConsumerChain implements SOAPHandler <SOAPMessageContext >
30
36
{
31
37
public static final ILogger logger = LogManager .getLogger (GXHandlerConsumerChain .class );
@@ -156,8 +162,8 @@ public boolean handleMessage(SOAPMessageContext messageContext)
156
162
Document doc = messageToDocument (messageContext .getMessage ());
157
163
158
164
//Security header
159
- WSSecHeader secHeader = new WSSecHeader ();
160
- secHeader .insertSecurityHeader (doc );
165
+ WSSecHeader secHeader = new WSSecHeader (doc );
166
+ secHeader .insertSecurityHeader ();
161
167
Document signedDoc = null ;
162
168
163
169
//Signature
@@ -168,7 +174,7 @@ public boolean handleMessage(SOAPMessageContext messageContext)
168
174
signatureProperties .put ("org.apache.ws.security.crypto.merlin.keystore.password" , wsSignature .getKeystore ().getPassword ());
169
175
signatureProperties .put ("org.apache.ws.security.crypto.merlin.file" , wsSignature .getKeystore ().getSource ());
170
176
Crypto signatureCrypto = CryptoFactory .getInstance (signatureProperties );
171
- WSSecSignature sign = new WSSecSignature ();
177
+ WSSecSignature sign = new WSSecSignature (doc );
172
178
sign .setKeyIdentifierType (wsSignature .getKeyIdentifierType ());
173
179
sign .setUserInfo (wsSignature .getAlias (), wsSignature .getKeystore ().getPassword ());
174
180
if (wsSignature .getCanonicalizationalgorithm () != null )
@@ -177,13 +183,13 @@ public boolean handleMessage(SOAPMessageContext messageContext)
177
183
sign .setDigestAlgo (wsSignature .getDigest ());
178
184
if (wsSignature .getSignaturealgorithm () != null )
179
185
sign .setSignatureAlgorithm (wsSignature .getSignaturealgorithm ());
180
- signedDoc = sign .build (doc , signatureCrypto , secHeader );
186
+ signedDoc = sign .build ( signatureCrypto );
181
187
182
188
if (expirationTimeout > 0 )
183
189
{
184
- WSSecTimestamp timestamp = new WSSecTimestamp ();
190
+ WSSecTimestamp timestamp = new WSSecTimestamp (secHeader );
185
191
timestamp .setTimeToLive (expirationTimeout );
186
- signedDoc = timestamp .build (signedDoc , secHeader );
192
+ signedDoc = timestamp .build ();
187
193
}
188
194
}
189
195
@@ -195,14 +201,19 @@ public boolean handleMessage(SOAPMessageContext messageContext)
195
201
encryptionProperties .put ("org.apache.ws.security.crypto.merlin.keystore.password" , wsEncryption .getKeystore ().getPassword ());
196
202
encryptionProperties .put ("org.apache.ws.security.crypto.merlin.file" , wsEncryption .getKeystore ().getSource ());
197
203
Crypto encryptionCrypto = CryptoFactory .getInstance (encryptionProperties );
198
- WSSecEncrypt builder = new WSSecEncrypt ();
199
- builder .setUserInfo (wsEncryption .getAlias (), wsEncryption .getKeystore ().getPassword ());
200
- builder .setKeyIdentifierType (wsEncryption .getKeyIdentifierType ());
201
204
if (signedDoc == null )
202
205
{
203
206
signedDoc = doc ;
204
207
}
205
- builder .build (signedDoc , encryptionCrypto , secHeader );
208
+ WSSecEncrypt builder = new WSSecEncrypt (signedDoc );
209
+ builder .setUserInfo (wsEncryption .getAlias (), wsEncryption .getKeystore ().getPassword ());
210
+ builder .setKeyIdentifierType (wsEncryption .getKeyIdentifierType ());
211
+ //using wss4j default encryption algorithm AES128-CBC
212
+ KeyGenerator keyGenerator = KeyGenerator .getInstance ("AES" );
213
+ keyGenerator .init (128 );
214
+ SecretKey key = keyGenerator .generateKey ();
215
+
216
+ builder .build (encryptionCrypto , key );
206
217
}
207
218
208
219
Document securityDoc = doc ;
0 commit comments