Skip to content

Commit 1c22956

Browse files
committed
More risks and fix bad redirection
1 parent 1166d0f commit 1c22956

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

src/main/java/org/hdivsamples/controllers/DashboardController.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,22 @@
1010
import java.io.ObjectOutputStream;
1111
import java.io.OutputStream;
1212
import java.net.URL;
13+
import java.security.InvalidKeyException;
1314
import java.security.MessageDigest;
1415
import java.security.NoSuchAlgorithmException;
1516
import java.security.Principal;
17+
import java.security.spec.InvalidKeySpecException;
18+
import java.security.spec.KeySpec;
1619
import java.util.List;
1720

1821
import javax.crypto.BadPaddingException;
1922
import javax.crypto.Cipher;
2023
import javax.crypto.IllegalBlockSizeException;
2124
import javax.crypto.NoSuchPaddingException;
25+
import javax.crypto.SecretKey;
26+
import javax.crypto.SecretKeyFactory;
27+
import javax.crypto.spec.DESKeySpec;
28+
import javax.crypto.spec.SecretKeySpec;
2229
import javax.servlet.http.HttpServletResponse;
2330

2431
import org.apache.commons.io.IOUtils;
@@ -219,8 +226,28 @@ public void getMaliciousCertificate(final HttpServletResponse response, final Ac
219226

220227
}
221228

222-
private static byte [] getCipher(byte [] data) throws IllegalBlockSizeException, BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException {
229+
private static byte [] getCipher(byte [] data) throws IllegalBlockSizeException, BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidKeySpecException {
223230
Cipher cipher = Cipher.getInstance("DES");
231+
232+
byte[] keyBytes = {
233+
0x01, 0x23, 0x45, 0x67, (byte) 0x89, (byte) 0xAB, (byte) (Math.random()*0xCD), (byte) 0xEF
234+
};
235+
236+
// Create a DES key specification
237+
KeySpec keySpec = new DESKeySpec(keyBytes);
238+
239+
// Create a SecretKeyFactory for DES
240+
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
241+
242+
// Generate a SecretKey object
243+
SecretKey secretKey = keyFactory.generateSecret(keySpec);
244+
245+
// Create a SecretKeySpec object from the SecretKey
246+
SecretKeySpec secretKeySpec = new SecretKeySpec(secretKey.getEncoded(), "DES");
247+
248+
249+
250+
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec);
224251
return cipher.doFinal(data);
225252
}
226253

src/main/java/org/hdivsamples/controllers/TransferController.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,14 @@ public String transferCheck(final OperationConfirm operationConfirm, final Bindi
138138
return transferConfirmation(transfer, model, principal, accountType);
139139
}
140140
else {
141-
return "redirect:/transfer";
141+
return "redirect:/transfer/redirect/"+accountType;
142142
}
143143
}
144+
145+
@RequestMapping(value = "/redirect/{accountType}", method = RequestMethod.GET)
146+
public String transferRedirect() {
147+
return "redirect:/transfer";
148+
}
144149

145150
static class AccountType {
146151
public static final String PERSONAL = "Personal";

0 commit comments

Comments
 (0)