Explorar el Código

Support for irc cookies

master
Chris Smith hace 15 años
padre
commit
1fe1660415

+ 9
- 3
nbproject/build-impl.xml Ver fichero

70
         </condition>
70
         </condition>
71
         <condition property="have.sources">
71
         <condition property="have.sources">
72
             <or>
72
             <or>
73
+                <available file="${src.src4.dir}"/>
73
                 <available file="${src.src3.dir}"/>
74
                 <available file="${src.src3.dir}"/>
74
                 <available file="${src.src2.dir}"/>
75
                 <available file="${src.src2.dir}"/>
75
                 <available file="${src.src.dir}"/>
76
                 <available file="${src.src.dir}"/>
127
         <!-- You can override this target in the ../build.xml file. -->
128
         <!-- You can override this target in the ../build.xml file. -->
128
     </target>
129
     </target>
129
     <target depends="-pre-init,-init-private,-init-user,-init-project,-do-init" name="-init-check">
130
     <target depends="-pre-init,-init-private,-init-user,-init-project,-do-init" name="-init-check">
131
+        <fail unless="src.src4.dir">Must set src.src4.dir</fail>
130
         <fail unless="src.src3.dir">Must set src.src3.dir</fail>
132
         <fail unless="src.src3.dir">Must set src.src3.dir</fail>
131
         <fail unless="src.src2.dir">Must set src.src2.dir</fail>
133
         <fail unless="src.src2.dir">Must set src.src2.dir</fail>
132
         <fail unless="src.src.dir">Must set src.src.dir</fail>
134
         <fail unless="src.src.dir">Must set src.src.dir</fail>
152
     </target>
154
     </target>
153
     <target name="-init-macrodef-javac">
155
     <target name="-init-macrodef-javac">
154
         <macrodef name="javac" uri="http://www.netbeans.org/ns/j2se-project/3">
156
         <macrodef name="javac" uri="http://www.netbeans.org/ns/j2se-project/3">
155
-            <attribute default="${src.src3.dir}:${src.src2.dir}:${src.src.dir}:${src.dir}" name="srcdir"/>
157
+            <attribute default="${src.src4.dir}:${src.src3.dir}:${src.src2.dir}:${src.src.dir}:${src.dir}" name="srcdir"/>
156
             <attribute default="${build.classes.dir}" name="destdir"/>
158
             <attribute default="${build.classes.dir}" name="destdir"/>
157
             <attribute default="${javac.classpath}" name="classpath"/>
159
             <attribute default="${javac.classpath}" name="classpath"/>
158
             <attribute default="${includes}" name="includes"/>
160
             <attribute default="${includes}" name="includes"/>
171
             </sequential>
173
             </sequential>
172
         </macrodef>
174
         </macrodef>
173
         <macrodef name="depend" uri="http://www.netbeans.org/ns/j2se-project/3">
175
         <macrodef name="depend" uri="http://www.netbeans.org/ns/j2se-project/3">
174
-            <attribute default="${src.src3.dir}:${src.src2.dir}:${src.src.dir}:${src.dir}" name="srcdir"/>
176
+            <attribute default="${src.src4.dir}:${src.src3.dir}:${src.src2.dir}:${src.src.dir}:${src.dir}" name="srcdir"/>
175
             <attribute default="${build.classes.dir}" name="destdir"/>
177
             <attribute default="${build.classes.dir}" name="destdir"/>
176
             <attribute default="${javac.classpath}" name="classpath"/>
178
             <attribute default="${javac.classpath}" name="classpath"/>
177
             <sequential>
179
             <sequential>
343
     <target depends="init,deps-jar,-pre-pre-compile,-pre-compile,-compile-depend" if="have.sources" name="-do-compile">
345
     <target depends="init,deps-jar,-pre-pre-compile,-pre-compile,-compile-depend" if="have.sources" name="-do-compile">
344
         <j2seproject3:javac/>
346
         <j2seproject3:javac/>
345
         <copy todir="${build.classes.dir}">
347
         <copy todir="${build.classes.dir}">
348
+            <fileset dir="${src.src4.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
346
             <fileset dir="${src.src3.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
349
             <fileset dir="${src.src3.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
347
             <fileset dir="${src.src2.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
350
             <fileset dir="${src.src2.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
348
             <fileset dir="${src.src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
351
             <fileset dir="${src.src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
361
     <target depends="init,deps-jar,-pre-pre-compile" name="-do-compile-single">
364
     <target depends="init,deps-jar,-pre-pre-compile" name="-do-compile-single">
362
         <fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
365
         <fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
363
         <j2seproject3:force-recompile/>
366
         <j2seproject3:force-recompile/>
364
-        <j2seproject3:javac excludes="" includes="${javac.includes}" sourcepath="${src.src3.dir}:${src.src2.dir}:${src.src.dir}:${src.dir}"/>
367
+        <j2seproject3:javac excludes="" includes="${javac.includes}" sourcepath="${src.src4.dir}:${src.src3.dir}:${src.src2.dir}:${src.src.dir}:${src.dir}"/>
365
     </target>
368
     </target>
366
     <target name="-post-compile-single">
369
     <target name="-post-compile-single">
367
         <!-- Empty placeholder for easier customization. -->
370
         <!-- Empty placeholder for easier customization. -->
495
             <classpath>
498
             <classpath>
496
                 <path path="${javac.classpath}"/>
499
                 <path path="${javac.classpath}"/>
497
             </classpath>
500
             </classpath>
501
+            <fileset dir="${src.src4.dir}" excludes="${excludes}" includes="${includes}">
502
+                <filename name="**/*.java"/>
503
+            </fileset>
498
             <fileset dir="${src.src3.dir}" excludes="${excludes}" includes="${includes}">
504
             <fileset dir="${src.src3.dir}" excludes="${excludes}" includes="${includes}">
499
                 <filename name="**/*.java"/>
505
                 <filename name="**/*.java"/>
500
             </fileset>
506
             </fileset>

+ 3
- 3
nbproject/genfiles.properties Ver fichero

1
-build.xml.data.CRC32=0e8d4183
1
+build.xml.data.CRC32=aaeff047
2
 build.xml.script.CRC32=d4296ee3
2
 build.xml.script.CRC32=d4296ee3
3
 build.xml.stylesheet.CRC32=958a1d3e
3
 build.xml.stylesheet.CRC32=958a1d3e
4
 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
4
 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
5
 # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
5
 # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
6
-nbproject/build-impl.xml.data.CRC32=0e8d4183
7
-nbproject/build-impl.xml.script.CRC32=3c4579ea
6
+nbproject/build-impl.xml.data.CRC32=aaeff047
7
+nbproject/build-impl.xml.script.CRC32=9c9a087f
8
 nbproject/build-impl.xml.stylesheet.CRC32=65b8de21
8
 nbproject/build-impl.xml.stylesheet.CRC32=65b8de21

+ 1
- 0
nbproject/project.properties Ver fichero

77
 src.src.dir=externals/dmdirc/src
77
 src.src.dir=externals/dmdirc/src
78
 src.src2.dir=externals/evetool/src
78
 src.src2.dir=externals/evetool/src
79
 src.src3.dir=externals/dmdirc-plugins/calc/src
79
 src.src3.dir=externals/dmdirc-plugins/calc/src
80
+src.src4.dir=externals/util/src
80
 test.src.dir=test
81
 test.src.dir=test

+ 1
- 0
nbproject/project.xml Ver fichero

6
             <name>charliebravo</name>
6
             <name>charliebravo</name>
7
             <minimum-ant-version>1.6.5</minimum-ant-version>
7
             <minimum-ant-version>1.6.5</minimum-ant-version>
8
             <source-roots>
8
             <source-roots>
9
+                <root id="src.src4.dir"/>
9
                 <root id="src.src3.dir"/>
10
                 <root id="src.src3.dir"/>
10
                 <root id="src.src2.dir"/>
11
                 <root id="src.src2.dir"/>
11
                 <root id="src.src.dir"/>
12
                 <root id="src.src.dir"/>

+ 68
- 7
src/com/md87/charliebravo/InputHandler.java Ver fichero

10
 import com.dmdirc.parser.irc.ClientInfo;
10
 import com.dmdirc.parser.irc.ClientInfo;
11
 import com.dmdirc.parser.irc.IRCParser;
11
 import com.dmdirc.parser.irc.IRCParser;
12
 import com.dmdirc.parser.irc.callbacks.interfaces.IChannelMessage;
12
 import com.dmdirc.parser.irc.callbacks.interfaces.IChannelMessage;
13
+import com.dmdirc.parser.irc.callbacks.interfaces.IPrivateCTCP;
13
 import com.dmdirc.parser.irc.callbacks.interfaces.IPrivateMessage;
14
 import com.dmdirc.parser.irc.callbacks.interfaces.IPrivateMessage;
15
+import com.dmdirc.util.RollingList;
14
 import com.md87.charliebravo.commands.AuthenticateCommand;
16
 import com.md87.charliebravo.commands.AuthenticateCommand;
15
 import com.md87.charliebravo.commands.CalcCommand;
17
 import com.md87.charliebravo.commands.CalcCommand;
18
+import com.md87.charliebravo.commands.DefineCommand;
16
 import com.md87.charliebravo.commands.FollowupsCommand;
19
 import com.md87.charliebravo.commands.FollowupsCommand;
17
 import com.md87.charliebravo.commands.GitCommand;
20
 import com.md87.charliebravo.commands.GitCommand;
18
 import com.md87.charliebravo.commands.GoogleCommand;
21
 import com.md87.charliebravo.commands.GoogleCommand;
23
 import com.md87.charliebravo.commands.ReloadCommand;
26
 import com.md87.charliebravo.commands.ReloadCommand;
24
 import com.md87.charliebravo.commands.SetCommand;
27
 import com.md87.charliebravo.commands.SetCommand;
25
 import com.md87.charliebravo.commands.SkillCommand;
28
 import com.md87.charliebravo.commands.SkillCommand;
29
+import com.md87.charliebravo.commands.SnippetsCommand;
26
 import com.md87.charliebravo.commands.TranslateCommand;
30
 import com.md87.charliebravo.commands.TranslateCommand;
27
 import com.md87.charliebravo.commands.WhoisCommand;
31
 import com.md87.charliebravo.commands.WhoisCommand;
32
+import com.md87.util.crypto.ArcFourEncrypter;
28
 import java.util.ArrayList;
33
 import java.util.ArrayList;
29
 import java.util.HashMap;
34
 import java.util.HashMap;
30
 import java.util.List;
35
 import java.util.List;
31
 import java.util.Map;
36
 import java.util.Map;
37
+import java.util.Random;
32
 import java.util.regex.Matcher;
38
 import java.util.regex.Matcher;
39
+import net.miginfocom.Base64;
33
 
40
 
34
 /**
41
 /**
35
  *
42
  *
36
  * @author chris
43
  * @author chris
37
  */
44
  */
38
-public class InputHandler implements IChannelMessage, IPrivateMessage {
45
+public class InputHandler implements IChannelMessage, IPrivateMessage, IPrivateCTCP {
39
 
46
 
40
     protected IRCParser parser;
47
     protected IRCParser parser;
41
 
48
 
43
 
50
 
44
     protected final List<Command> commands = new ArrayList<Command>();
51
     protected final List<Command> commands = new ArrayList<Command>();
45
     protected final Map<String, Response> responses = new HashMap<String, Response>();
52
     protected final Map<String, Response> responses = new HashMap<String, Response>();
46
-    protected final Map<String, String> snippets = new HashMap<String, String>();
53
+    protected final Map<String, RollingList<String>> snippets = new HashMap<String, RollingList<String>>();
47
 
54
 
48
     public InputHandler(final Config config) {
55
     public InputHandler(final Config config) {
49
         this.config = config;
56
         this.config = config;
60
         commands.add(new GitCommand());
67
         commands.add(new GitCommand());
61
         commands.add(new SetCommand());
68
         commands.add(new SetCommand());
62
         commands.add(new SkillCommand());
69
         commands.add(new SkillCommand());
70
+        commands.add(new SnippetsCommand());
63
         commands.add(new NewzbinCommand());
71
         commands.add(new NewzbinCommand());
64
         commands.add(new ReloadCommand());
72
         commands.add(new ReloadCommand());
73
+        commands.add(new DefineCommand());
65
     }
74
     }
66
 
75
 
67
     public Config getConfig() {
76
     public Config getConfig() {
76
         return responses.get(target);
85
         return responses.get(target);
77
     }
86
     }
78
 
87
 
88
+    public RollingList<String> getSnippets(final String channel) {
89
+        return snippets.get(channel);
90
+    }
91
+
79
     public IRCParser getParser() {
92
     public IRCParser getParser() {
80
         return parser;
93
         return parser;
81
     }
94
     }
85
         
98
         
86
         parser.getCallbackManager().addCallback("OnChannelMessage", this);
99
         parser.getCallbackManager().addCallback("OnChannelMessage", this);
87
         parser.getCallbackManager().addCallback("OnPrivateMessage", this);
100
         parser.getCallbackManager().addCallback("OnPrivateMessage", this);
101
+        parser.getCallbackManager().addCallback("OnPrivateCTCP", this);
88
     }
102
     }
89
 
103
 
90
     public void onChannelMessage(final IRCParser tParser, final ChannelInfo cChannel,
104
     public void onChannelMessage(final IRCParser tParser, final ChannelInfo cChannel,
96
                 break;
110
                 break;
97
             } else if (sMessage.matches("^(?i)" + Matcher.quoteReplacement(nick) + "\\?")
111
             } else if (sMessage.matches("^(?i)" + Matcher.quoteReplacement(nick) + "\\?")
98
                     && snippets.containsKey(cChannel.getName())) {
112
                     && snippets.containsKey(cChannel.getName())) {
99
-                handleInput(ClientInfo.parseHost(sHost), cChannel.getName(),
100
-                        snippets.get(cChannel.getName()));
113
+                final RollingList<String> snips = snippets.get(cChannel.getName());
114
+                final String snippet = snips.get(snips.getList().size() - 1);
115
+                handleInput(ClientInfo.parseHost(sHost), cChannel.getName(), snippet);
116
+                snips.remove(snippet);
101
                 break;
117
                 break;
102
             }
118
             }
103
         }
119
         }
106
                 .getKeyDomain("snippets").entrySet()) {
122
                 .getKeyDomain("snippets").entrySet()) {
107
             System.out.println("Snippet test: " + snippet.getKey());
123
             System.out.println("Snippet test: " + snippet.getKey());
108
             if (sMessage.matches(snippet.getKey())) {
124
             if (sMessage.matches(snippet.getKey())) {
109
-                snippets.put(cChannel.getName(), sMessage.replaceFirst(snippet.getKey(),
125
+                if (!snippets.containsKey(cChannel.getName())) {
126
+                    snippets.put(cChannel.getName(), new RollingList<String>(10));
127
+                }
128
+
129
+                snippets.get(cChannel.getName()).add(sMessage.replaceFirst(snippet.getKey(),
130
+                        snippet.getValue()));
131
+                System.out.println("Snippet: " + sMessage.replaceFirst(snippet.getKey(),
110
                         snippet.getValue()));
132
                         snippet.getValue()));
111
-                System.out.println("Snippet: " + snippets.get(cChannel.getName()));
112
-                break;
113
             }
133
             }
114
         }
134
         }
115
     }
135
     }
127
         handleInput(ClientInfo.parseHost(sHost), ClientInfo.parseHost(sHost), sMessage);
147
         handleInput(ClientInfo.parseHost(sHost), ClientInfo.parseHost(sHost), sMessage);
128
     }
148
     }
129
 
149
 
150
+    @SuppressWarnings("unchecked")
151
+    public void onPrivateCTCP(IRCParser tParser, String sType, String sMessage, String sHost) {
152
+        final ClientInfo client = tParser.getClientInfoOrFake(sHost);
153
+        if ("COOKIE".equals(sType)) {
154
+            final String status = (String) client.getMap().get("Cookie");
155
+            final String key1 = (String) client.getMap().get("Key1");
156
+            final String key2 = (String) client.getMap().get("Key2");
157
+            final String idp = (String) client.getMap().get("OpenID-p");
158
+            
159
+            if ("GETKEY".equals(sMessage) && "SET".equals(status)) {
160
+                parser.sendCTCP(ClientInfo.parseHost(sHost), "COOKIE", "SETKEY " + key1);
161
+                client.getMap().put("Cookie", "GETKEY");
162
+            } else if (sMessage.startsWith("OFFER")) {
163
+                final String what = sMessage.substring(6);
164
+
165
+                if (config.getConfigfile().getKeyDomain("cookies").containsKey(what)) {
166
+                    client.getMap().put("Key1", config.getConfigfile()
167
+                            .getKeyDomain("cookies").get(what));
168
+                    client.getMap().put("OpenID-p", config.getConfigfile()
169
+                            .getKeyDomain("cookie-ids").get(what));
170
+                }
171
+
172
+                final byte[] bytes = new byte[50];
173
+                new Random().nextBytes(bytes);
174
+                final String newkey2 = Base64.encodeToString(bytes, false);
175
+
176
+                client.getMap().put("Cookie", "OFFER");
177
+                client.getMap().put("Key2", newkey2);
178
+                parser.sendCTCP(ClientInfo.parseHost(sHost), "COOKIE", "GET " + newkey2);
179
+            } else if (sMessage.startsWith("SHOW") && "OFFER".equals(status)) {
180
+                final String payload = sMessage.substring(5);
181
+                final String info = new String(new ArcFourEncrypter(key1 + key2)
182
+                        .encrypt(Base64.decode(payload)));
183
+
184
+                if (idp.equals(info)) {
185
+                    client.getMap().put("OpenID", idp);
186
+                }
187
+            }
188
+        }
189
+    }
190
+
130
     protected void handleInput(final String source, final String target, final String text) {
191
     protected void handleInput(final String source, final String target, final String text) {
131
         new Thread(new Runnable() {
192
         new Thread(new Runnable() {
132
             public void run() {
193
             public void run() {

+ 21
- 0
src/com/md87/charliebravo/commands/AuthenticateCommand.java Ver fichero

9
 import com.md87.charliebravo.Command;
9
 import com.md87.charliebravo.Command;
10
 import com.md87.charliebravo.InputHandler;
10
 import com.md87.charliebravo.InputHandler;
11
 import com.md87.charliebravo.Response;
11
 import com.md87.charliebravo.Response;
12
+import com.md87.util.crypto.ArcFourEncrypter;
12
 import java.util.List;
13
 import java.util.List;
14
+import java.util.Random;
15
+import net.miginfocom.Base64;
13
 
16
 
14
 /**
17
 /**
15
  *
18
  *
29
             if (result.isEmpty() || !result.get(0).trim().equalsIgnoreCase("Success")) {
32
             if (result.isEmpty() || !result.get(0).trim().equalsIgnoreCase("Success")) {
30
                 response.sendMessage("I could not authenticate that token", true);
33
                 response.sendMessage("I could not authenticate that token", true);
31
             } else {
34
             } else {
35
+                final byte[] bytes = new byte[50];
36
+                new Random().nextBytes(bytes);
37
+                final String key1 = Base64.encodeToString(bytes, false);
38
+                final int id = handler.getConfig().getConfigfile().getKeyDomain("cookies").size();
39
+                
32
                 final String openid = result.get(1).trim();
40
                 final String openid = result.get(1).trim();
33
                 handler.getParser().getClientInfoOrFake(response.getSource())
41
                 handler.getParser().getClientInfoOrFake(response.getSource())
34
                         .getMap().put("OpenID", openid);
42
                         .getMap().put("OpenID", openid);
43
+                handler.getParser().getClientInfoOrFake(response.getSource())
44
+                        .getMap().put("Key1", key1);
45
+                handler.getParser().getClientInfoOrFake(response.getSource())
46
+                        .getMap().put("Cookie", "SET");
35
                 handler.getConfig().setOption(openid, "internal.lastseen",
47
                 handler.getConfig().setOption(openid, "internal.lastseen",
36
                         System.currentTimeMillis());
48
                         System.currentTimeMillis());
37
                 handler.getConfig().setOption(openid, "internal.lastuser",
49
                 handler.getConfig().setOption(openid, "internal.lastuser",
38
                         handler.getParser().getClientInfoOrFake(response.getSource()).toString());
50
                         handler.getParser().getClientInfoOrFake(response.getSource()).toString());
39
                 response.sendMessage("You are now authenticated as " + openid, true);
51
                 response.sendMessage("You are now authenticated as " + openid, true);
52
+
53
+                handler.getConfig().getConfigfile().getKeyDomain("cookies")
54
+                        .put(String.valueOf(id), key1);
55
+                handler.getConfig().getConfigfile().getKeyDomain("cookie-ids")
56
+                        .put(String.valueOf(id), openid);
57
+
58
+                handler.getParser().sendCTCP(response.getSource(), "COOKIE",
59
+                        "SET " + id + " "+ Base64.encodeToString(
60
+                        new ArcFourEncrypter(key1).encrypt(openid.getBytes()), false));
40
             }
61
             }
41
         }
62
         }
42
 
63
 

Loading…
Cancelar
Guardar