|
20 | 20 |
|
21 | 21 | package net.jradius.webservice; |
22 | 22 |
|
23 | | -import gnu.crypto.cipher.CipherFactory; |
24 | | -import gnu.crypto.cipher.IBlockCipher; |
25 | | -import gnu.crypto.util.Base64; |
26 | | - |
27 | 23 | import java.net.URLDecoder; |
28 | 24 | import java.security.InvalidKeyException; |
29 | 25 | import java.util.HashMap; |
30 | 26 | import java.util.Map; |
31 | 27 |
|
| 28 | +import javax.crypto.Cipher; |
| 29 | +import javax.crypto.spec.SecretKeySpec; |
| 30 | + |
32 | 31 | import net.jradius.handler.EventHandlerBase; |
33 | 32 | import net.jradius.log.RadiusLog; |
34 | 33 | import net.jradius.server.JRadiusEvent; |
35 | 34 | import net.jradius.session.JRadiusSession; |
36 | 35 | import net.jradius.session.JRadiusSessionManager; |
| 36 | +import net.jradius.util.Base64; |
37 | 37 |
|
38 | 38 |
|
39 | 39 | public class SSOProxyService extends EventHandlerBase |
@@ -64,29 +64,15 @@ public boolean handle(JRadiusEvent event) throws Exception |
64 | 64 |
|
65 | 65 | if (!"sso".equals(command)) throw new WebServiceException("invalid command"); |
66 | 66 | if (payload == null) throw new WebServiceException("invalid security"); |
| 67 | + |
| 68 | + byte[] KeyData = cipherKey.getBytes(); |
| 69 | + SecretKeySpec KS = new SecretKeySpec(KeyData, cipherType); |
| 70 | + Cipher cipher = Cipher.getInstance(cipherType); |
| 71 | + cipher.init(Cipher.DECRYPT_MODE, KS); |
67 | 72 |
|
68 | | - IBlockCipher cipher = CipherFactory.getInstance(cipherType); |
69 | | - Map attributes = new HashMap(); |
70 | | - attributes.put(IBlockCipher.KEY_MATERIAL, cipherKey.getBytes()); |
71 | | - |
72 | | - try |
73 | | - { |
74 | | - cipher.init(attributes); |
75 | | - } |
76 | | - catch(InvalidKeyException e) |
77 | | - { |
78 | | - RadiusLog.warn(e.getMessage(), e); |
79 | | - } |
80 | | - |
81 | | - int bs = cipher.currentBlockSize(); |
82 | 73 | byte[] data = Base64.decode(payload); |
83 | | - byte[] plaintext = new byte[(data.length / bs + 1) * bs]; |
| 74 | + byte[] plaintext = cipher.doFinal(data); |
84 | 75 |
|
85 | | - for (int i = 0; i + bs < data.length; i += bs) |
86 | | - { |
87 | | - cipher.decryptBlock(data, i, plaintext, i); |
88 | | - } |
89 | | - |
90 | 76 | String scommand = URLDecoder.decode(new String(plaintext).trim(), "US-ASCII"); |
91 | 77 | RadiusLog.debug("Secure command: " + scommand); |
92 | 78 | String session = scommand.substring("session=".length()); |
|
0 commit comments