diff options
Diffstat (limited to 'update/plugin/subversion/trunk/src/com')
-rw-r--r-- | update/plugin/subversion/trunk/src/com/fourisland/instadisc/update/svn/MD5.java | 68 | ||||
-rw-r--r-- | update/plugin/subversion/trunk/src/com/fourisland/instadisc/update/svn/Main.java | 210 |
2 files changed, 0 insertions, 278 deletions
diff --git a/update/plugin/subversion/trunk/src/com/fourisland/instadisc/update/svn/MD5.java b/update/plugin/subversion/trunk/src/com/fourisland/instadisc/update/svn/MD5.java deleted file mode 100644 index 0929022..0000000 --- a/update/plugin/subversion/trunk/src/com/fourisland/instadisc/update/svn/MD5.java +++ /dev/null | |||
@@ -1,68 +0,0 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | package com.fourisland.instadisc.update.svn; | ||
6 | |||
7 | import java.security.MessageDigest; | ||
8 | import java.util.logging.Level; | ||
9 | import java.util.logging.Logger; | ||
10 | |||
11 | /** | ||
12 | * | ||
13 | * @author hatkirby | ||
14 | */ | ||
15 | public class MD5 { | ||
16 | |||
17 | String ver; | ||
18 | |||
19 | public MD5(String ver) { | ||
20 | this.ver = ver; | ||
21 | } | ||
22 | |||
23 | public MD5(char[] password) { | ||
24 | int i=0; | ||
25 | ver=""; | ||
26 | for (i=0;i<password.length;i++) | ||
27 | { | ||
28 | ver += password[i]; | ||
29 | password[i] = 0; | ||
30 | } | ||
31 | } | ||
32 | |||
33 | public String hash() | ||
34 | { | ||
35 | StringBuilder verify = new StringBuilder(); | ||
36 | try { | ||
37 | MessageDigest md5 = MessageDigest.getInstance("MD5"); | ||
38 | int i = 0; | ||
39 | byte[] create = new byte[ver.length()]; | ||
40 | for (i = 0; i < ver.length(); i++) { | ||
41 | create[i] = (byte) ver.charAt(i); | ||
42 | } | ||
43 | byte buffer[] = md5.digest(create); | ||
44 | for (i = 0; i < buffer.length; i++) { | ||
45 | String hex = Integer.toHexString(buffer[i]); | ||
46 | verify.append(pad(hex.substring(max(hex.length() - 2, 0)),"0",2)); | ||
47 | } | ||
48 | } catch (Exception ex) { | ||
49 | Logger.getLogger(MD5.class.getName()).log(Level.SEVERE, null, ex); | ||
50 | } | ||
51 | ver = ""; | ||
52 | return verify.toString(); | ||
53 | } | ||
54 | |||
55 | private int max(int x, int y) | ||
56 | { | ||
57 | return (x > y ? x : y); | ||
58 | } | ||
59 | |||
60 | private String pad(String in, String pad, int len) | ||
61 | { | ||
62 | while (in.length() < len) | ||
63 | { | ||
64 | in = pad + in; | ||
65 | } | ||
66 | return in; | ||
67 | } | ||
68 | } | ||
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 deleted file mode 100644 index 5aaafe3..0000000 --- a/update/plugin/subversion/trunk/src/com/fourisland/instadisc/update/svn/Main.java +++ /dev/null | |||
@@ -1,210 +0,0 @@ | |||
1 | package com.fourisland.instadisc.update.svn; | ||
2 | |||
3 | import java.io.IOException; | ||
4 | import java.net.MalformedURLException; | ||
5 | import java.net.URL; | ||
6 | import java.security.InvalidAlgorithmParameterException; | ||
7 | import java.security.InvalidKeyException; | ||
8 | import java.security.NoSuchAlgorithmException; | ||
9 | import java.util.Random; | ||
10 | import java.util.logging.Level; | ||
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; | ||
18 | import org.apache.xmlrpc.XmlRpcException; | ||
19 | import org.apache.xmlrpc.client.XmlRpcClient; | ||
20 | import org.apache.xmlrpc.client.XmlRpcClientConfigImpl; | ||
21 | |||
22 | public class Main { | ||
23 | |||
24 | public static void main(String[] args) { | ||
25 | try | ||
26 | { | ||
27 | String pathScheme = getArg(1, args); | ||
28 | String author = getArg(2, args); | ||
29 | String seriesURL = getArg(3, args); | ||
30 | String subscriptionID = getArg(4, args); | ||
31 | String revision = getArg(5, args); | ||
32 | |||
33 | StringBuilder messBuilder = new StringBuilder(); | ||
34 | byte rs = 0; | ||
35 | |||
36 | while (rs != -1) | ||
37 | { | ||
38 | try | ||
39 | { | ||
40 | rs = (byte) System.in.read(); | ||
41 | if (rs != -1) | ||
42 | { | ||
43 | messBuilder.append(new String(new byte[]{rs})); | ||
44 | } | ||
45 | } catch (IOException ex) | ||
46 | { | ||
47 | Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); | ||
48 | } | ||
49 | } | ||
50 | |||
51 | String message = messBuilder.toString(); | ||
52 | message = message.substring(0, message.indexOf("\n")); | ||
53 | |||
54 | String path = pathScheme.replace("__REV__", revision); | ||
55 | |||
56 | Random r = new Random(); | ||
57 | int verID = r.nextInt(Integer.MAX_VALUE); | ||
58 | int encID = 0; | ||
59 | |||
60 | if (args.length > 7) | ||
61 | { | ||
62 | encID = r.nextInt(Integer.MAX_VALUE); | ||
63 | MD5 md5 = new MD5(padright(args[7], new Integer(encID).toString(), 16).substring(0, 16)); | ||
64 | String key = md5.hash().substring(0, 16); | ||
65 | String iv = reverse(key); | ||
66 | |||
67 | try | ||
68 | { | ||
69 | Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); | ||
70 | SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(), "AES"); | ||
71 | IvParameterSpec ivSpec = new IvParameterSpec(iv.getBytes()); | ||
72 | cipher.init(Cipher.ENCRYPT_MODE, keySpec, ivSpec); | ||
73 | |||
74 | message = new String(bytesToHex(cipher.doFinal(pad(message.getBytes())))).trim(); | ||
75 | author = new String(bytesToHex(cipher.doFinal(pad(author.getBytes())))).trim(); | ||
76 | path = new String(bytesToHex(cipher.doFinal(pad(path.getBytes())))).trim(); | ||
77 | } catch (IllegalBlockSizeException ex) | ||
78 | { | ||
79 | Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); | ||
80 | } catch (BadPaddingException ex) | ||
81 | { | ||
82 | Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); | ||
83 | } catch (InvalidKeyException ex) | ||
84 | { | ||
85 | Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); | ||
86 | } catch (InvalidAlgorithmParameterException ex) | ||
87 | { | ||
88 | Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); | ||
89 | } catch (NoSuchAlgorithmException ex) | ||
90 | { | ||
91 | Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); | ||
92 | } catch (NoSuchPaddingException ex) | ||
93 | { | ||
94 | Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); | ||
95 | } | ||
96 | } | ||
97 | |||
98 | XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl(); | ||
99 | config.setServerURL(new URL("http://central.fourisland.com/xmlrpc.php")); | ||
100 | XmlRpcClient client = new XmlRpcClient(); | ||
101 | client.setConfig(config); | ||
102 | Integer resp = (Integer) client.execute("InstaDisc.sendFromUpdate", new Object[]{seriesURL, | ||
103 | subscriptionID, | ||
104 | message, | ||
105 | author, | ||
106 | path, | ||
107 | "a:0:{}", | ||
108 | encID | ||
109 | }); | ||
110 | |||
111 | if (resp == 2) | ||
112 | { | ||
113 | main(args); | ||
114 | } | ||
115 | } catch (XmlRpcException ex) | ||
116 | { | ||
117 | Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); | ||
118 | } catch (MalformedURLException ex) | ||
119 | { | ||
120 | Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); | ||
121 | } | ||
122 | } | ||
123 | |||
124 | public static String getArg(int arg, String[] args) { | ||
125 | if (args.length < (arg + 1)) | ||
126 | { | ||
127 | System.out.println("Program requires 7 arguments and you only provided " + arg); | ||
128 | System.exit(1); | ||
129 | } | ||
130 | |||
131 | return args[arg]; | ||
132 | } | ||
133 | |||
134 | public static String reverse(String in) { | ||
135 | String out = ""; | ||
136 | int i = 0; | ||
137 | |||
138 | for (i = 0; i < in.length(); i++) | ||
139 | { | ||
140 | out = in.charAt(i) + out; | ||
141 | } | ||
142 | |||
143 | return out; | ||
144 | } | ||
145 | |||
146 | public static String padright(String in, String pad, int len) { | ||
147 | while (in.length() < len) | ||
148 | { | ||
149 | in += pad; | ||
150 | } | ||
151 | |||
152 | if (in.length() > len) | ||
153 | { | ||
154 | in = in.substring(0, len); | ||
155 | } | ||
156 | |||
157 | return in; | ||
158 | } | ||
159 | |||
160 | public static String bytesToHex(byte[] buffer) { | ||
161 | if (buffer == null) | ||
162 | { | ||
163 | return null; | ||
164 | } else | ||
165 | { | ||
166 | StringBuilder result = new StringBuilder(); | ||
167 | for (int i = 0; i < buffer.length; i++) | ||
168 | { | ||
169 | String hex = Integer.toHexString(Integer.decode(new Byte(buffer[i]).toString())); | ||
170 | result.append(padleft(hex.substring(max(hex.length() - 2, 0)), "0", 2)); | ||
171 | } | ||
172 | |||
173 | return result.toString(); | ||
174 | } | ||
175 | } | ||
176 | |||
177 | public static int max(int x, int y) { | ||
178 | return (x > y ? x : y); | ||
179 | } | ||
180 | |||
181 | public static String padleft(String in, String pad, int len) { | ||
182 | while (in.length() < len) | ||
183 | { | ||
184 | in = pad + in; | ||
185 | } | ||
186 | |||
187 | if (in.length() > len) | ||
188 | { | ||
189 | in = in.substring(0, len); | ||
190 | } | ||
191 | |||
192 | return in; | ||
193 | } | ||
194 | |||
195 | public static byte[] pad(byte[] buffer) | ||
196 | { | ||
197 | while (buffer.length % 16 != 0) | ||
198 | { | ||
199 | byte[] tmp = new byte[buffer.length+1]; | ||
200 | int i=0; | ||
201 | for (i=0;i<buffer.length;i++) | ||
202 | { | ||
203 | tmp[i] = buffer[i]; | ||
204 | } | ||
205 | tmp[buffer.length] = 0; | ||
206 | buffer = tmp; | ||
207 | } | ||
208 | return buffer; | ||
209 | } | ||
210 | } | ||