diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2008-08-22 20:39:21 +0000 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2008-08-22 20:39:21 +0000 |
commit | f7a0bb1a348f68314f4a3f9a0525fd26350b9615 (patch) | |
tree | 0ba06a12d09c2498379386711291dc156d1e3d61 /update/plugin | |
parent | 7cea445927794450b03fe952cf7d235e7c266e4c (diff) | |
download | instadisc-f7a0bb1a348f68314f4a3f9a0525fd26350b9615.tar.gz instadisc-f7a0bb1a348f68314f4a3f9a0525fd26350b9615.tar.bz2 instadisc-f7a0bb1a348f68314f4a3f9a0525fd26350b9615.zip |
Update: Added pasword protection to Subversion
Closes #40
Diffstat (limited to 'update/plugin')
-rw-r--r-- | update/plugin/subversion/trunk/src/com/fourisland/instadisc/update/svn/Main.java | 132 |
1 files changed, 129 insertions, 3 deletions
diff --git a/update/plugin/subversion/trunk/src/com/fourisland/instadisc/update/svn/Main.java b/update/plugin/subversion/trunk/src/com/fourisland/instadisc/update/svn/Main.java index 16e2dd1..45c7485 100644 --- a/update/plugin/subversion/trunk/src/com/fourisland/instadisc/update/svn/Main.java +++ b/update/plugin/subversion/trunk/src/com/fourisland/instadisc/update/svn/Main.java | |||
@@ -3,9 +3,18 @@ package com.fourisland.instadisc.update.svn; | |||
3 | import java.io.IOException; | 3 | import java.io.IOException; |
4 | import java.net.MalformedURLException; | 4 | import java.net.MalformedURLException; |
5 | import java.net.URL; | 5 | import java.net.URL; |
6 | import java.security.InvalidAlgorithmParameterException; | ||
7 | import java.security.InvalidKeyException; | ||
8 | import java.security.NoSuchAlgorithmException; | ||
6 | import java.util.Random; | 9 | import java.util.Random; |
7 | import java.util.logging.Level; | 10 | import java.util.logging.Level; |
8 | import java.util.logging.Logger; | 11 | import java.util.logging.Logger; |
12 | import javax.crypto.BadPaddingException; | ||
13 | import javax.crypto.Cipher; | ||
14 | import javax.crypto.IllegalBlockSizeException; | ||
15 | import javax.crypto.NoSuchPaddingException; | ||
16 | import javax.crypto.spec.IvParameterSpec; | ||
17 | import javax.crypto.spec.SecretKeySpec; | ||
9 | import org.apache.xmlrpc.XmlRpcException; | 18 | import org.apache.xmlrpc.XmlRpcException; |
10 | import org.apache.xmlrpc.client.XmlRpcClient; | 19 | import org.apache.xmlrpc.client.XmlRpcClient; |
11 | import org.apache.xmlrpc.client.XmlRpcClientConfigImpl; | 20 | import org.apache.xmlrpc.client.XmlRpcClientConfigImpl; |
@@ -39,15 +48,54 @@ public class Main { | |||
39 | { | 48 | { |
40 | Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); | 49 | Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); |
41 | } | 50 | } |
42 | } | 51 | } |
43 | 52 | ||
44 | String message = messBuilder.toString(); | 53 | String message = messBuilder.toString(); |
45 | message = message.substring(0, message.indexOf("\n")); | 54 | message = message.substring(0, message.indexOf("\n")); |
46 | 55 | ||
56 | String path = pathScheme.replace("__REV__", revision); | ||
57 | |||
47 | Random r = new Random(); | 58 | Random r = new Random(); |
48 | int verID = r.nextInt(Integer.MAX_VALUE); | 59 | int verID = r.nextInt(Integer.MAX_VALUE); |
60 | int encID = 0; | ||
49 | 61 | ||
50 | String path = pathScheme.replace("__REV__", revision); | 62 | if (args.length > 7) |
63 | { | ||
64 | encID = r.nextInt(Integer.MAX_VALUE); | ||
65 | MD5 md5 = new MD5(padright(args[7], new Integer(encID).toString(), 16).substring(0, 16)); | ||
66 | String key = md5.hash().substring(0, 16); | ||
67 | String iv = reverse(key); | ||
68 | |||
69 | try | ||
70 | { | ||
71 | Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); | ||
72 | SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(), "AES"); | ||
73 | IvParameterSpec ivSpec = new IvParameterSpec(iv.getBytes()); | ||
74 | cipher.init(Cipher.ENCRYPT_MODE, keySpec, ivSpec); | ||
75 | |||
76 | message = new String(bytesToHex(cipher.doFinal(pad(message.getBytes())))).trim(); | ||
77 | author = new String(bytesToHex(cipher.doFinal(pad(author.getBytes())))).trim(); | ||
78 | path = new String(bytesToHex(cipher.doFinal(pad(path.getBytes())))).trim(); | ||
79 | } catch (IllegalBlockSizeException ex) | ||
80 | { | ||
81 | Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); | ||
82 | } catch (BadPaddingException ex) | ||
83 | { | ||
84 | Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); | ||
85 | } catch (InvalidKeyException ex) | ||
86 | { | ||
87 | Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); | ||
88 | } catch (InvalidAlgorithmParameterException ex) | ||
89 | { | ||
90 | Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); | ||
91 | } catch (NoSuchAlgorithmException ex) | ||
92 | { | ||
93 | Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); | ||
94 | } catch (NoSuchPaddingException ex) | ||
95 | { | ||
96 | Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); | ||
97 | } | ||
98 | } | ||
51 | 99 | ||
52 | XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl(); | 100 | XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl(); |
53 | config.setServerURL(new URL(centralServer)); | 101 | config.setServerURL(new URL(centralServer)); |
@@ -60,7 +108,8 @@ public class Main { | |||
60 | message, | 108 | message, |
61 | author, | 109 | author, |
62 | path, | 110 | path, |
63 | "a:0:{}" | 111 | "a:0:{}", |
112 | encID | ||
64 | }); | 113 | }); |
65 | 114 | ||
66 | if (resp == 2) | 115 | if (resp == 2) |
@@ -85,4 +134,81 @@ public class Main { | |||
85 | 134 | ||
86 | return args[arg]; | 135 | return args[arg]; |
87 | } | 136 | } |
137 | |||
138 | public static String reverse(String in) { | ||
139 | String out = ""; | ||
140 | int i = 0; | ||
141 | |||
142 | for (i = 0; i < in.length(); i++) | ||
143 | { | ||
144 | out = in.charAt(i) + out; | ||
145 | } | ||
146 | |||
147 | return out; | ||
148 | } | ||
149 | |||
150 | public static String padright(String in, String pad, int len) { | ||
151 | while (in.length() < len) | ||
152 | { | ||
153 | in += pad; | ||
154 | } | ||
155 | |||
156 | if (in.length() > len) | ||
157 | { | ||
158 | in = in.substring(0, len); | ||
159 | } | ||
160 | |||
161 | return in; | ||
162 | } | ||
163 | |||
164 | public static String bytesToHex(byte[] buffer) { | ||
165 | if (buffer == null) | ||
166 | { | ||
167 | return null; | ||
168 | } else | ||
169 | { | ||
170 | StringBuilder result = new StringBuilder(); | ||
171 | for (int i = 0; i < buffer.length; i++) | ||
172 | { | ||
173 | String hex = Integer.toHexString(Integer.decode(new Byte(buffer[i]).toString())); | ||
174 | result.append(padleft(hex.substring(max(hex.length() - 2, 0)), "0", 2)); | ||
175 | } | ||
176 | |||
177 | return result.toString(); | ||
178 | } | ||
179 | } | ||
180 | |||
181 | public static int max(int x, int y) { | ||
182 | return (x > y ? x : y); | ||
183 | } | ||
184 | |||
185 | public static String padleft(String in, String pad, int len) { | ||
186 | while (in.length() < len) | ||
187 | { | ||
188 | in = pad + in; | ||
189 | } | ||
190 | |||
191 | if (in.length() > len) | ||
192 | { | ||
193 | in = in.substring(0, len); | ||
194 | } | ||
195 | |||
196 | return in; | ||
197 | } | ||
198 | |||
199 | public static byte[] pad(byte[] buffer) | ||
200 | { | ||
201 | while (buffer.length % 16 != 0) | ||
202 | { | ||
203 | byte[] tmp = new byte[buffer.length+1]; | ||
204 | int i=0; | ||
205 | for (i=0;i<buffer.length;i++) | ||
206 | { | ||
207 | tmp[i] = buffer[i]; | ||
208 | } | ||
209 | tmp[buffer.length] = 0; | ||
210 | buffer = tmp; | ||
211 | } | ||
212 | return buffer; | ||
213 | } | ||
88 | } | 214 | } |