about summary refs log tree commit diff stats
path: root/client/trunk/src
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2008-08-13 03:56:10 +0000
committerKelly Rauchenberger <fefferburbia@gmail.com>2008-08-13 03:56:10 +0000
commitbb8b50baffc429aa711e8c1a756a01924007745f (patch)
tree5574477a084bb52d66621a688f8ffd833e25b2e8 /client/trunk/src
parent3e6d87739117bd9908549180408f8145f3868de4 (diff)
downloadinstadisc-bb8b50baffc429aa711e8c1a756a01924007745f.tar.gz
instadisc-bb8b50baffc429aa711e8c1a756a01924007745f.tar.bz2
instadisc-bb8b50baffc429aa711e8c1a756a01924007745f.zip
Client: Added password protection support
Closes #10
Diffstat (limited to 'client/trunk/src')
-rw-r--r--client/trunk/src/com/fourisland/instadisc/AskForPasswordForm.form123
-rw-r--r--client/trunk/src/com/fourisland/instadisc/AskForPasswordForm.java166
-rw-r--r--client/trunk/src/com/fourisland/instadisc/Database/Subscription.java11
-rw-r--r--client/trunk/src/com/fourisland/instadisc/Functions.java81
-rw-r--r--client/trunk/src/com/fourisland/instadisc/Item/MD5.java17
-rw-r--r--client/trunk/src/com/fourisland/instadisc/Item/SubscriptionFile.java48
-rw-r--r--client/trunk/src/com/fourisland/instadisc/Item/WellFormedItem.java89
-rw-r--r--client/trunk/src/com/fourisland/instadisc/resources/AskForPasswordForm.properties9
8 files changed, 521 insertions, 23 deletions
diff --git a/client/trunk/src/com/fourisland/instadisc/AskForPasswordForm.form b/client/trunk/src/com/fourisland/instadisc/AskForPasswordForm.form new file mode 100644 index 0000000..e16a917 --- /dev/null +++ b/client/trunk/src/com/fourisland/instadisc/AskForPasswordForm.form
@@ -0,0 +1,123 @@
1<?xml version="1.0" encoding="UTF-8" ?>
2
3<Form version="1.5" maxVersion="1.5" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
4 <Properties>
5 <Property name="defaultCloseOperation" type="int" value="2"/>
6 <Property name="name" type="java.lang.String" value="Form" noResource="true"/>
7 </Properties>
8 <SyntheticProperties>
9 <SyntheticProperty name="formSizePolicy" type="int" value="1"/>
10 </SyntheticProperties>
11 <AuxValues>
12 <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="2"/>
13 <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="true"/>
14 <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
15 <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
16 <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
17 <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
18 <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
19 <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
20 </AuxValues>
21
22 <Layout>
23 <DimensionLayout dim="0">
24 <Group type="103" groupAlignment="0" attributes="0">
25 <Group type="102" attributes="0">
26 <EmptySpace max="-2" attributes="0"/>
27 <Group type="103" groupAlignment="0" attributes="0">
28 <Group type="103" alignment="0" groupAlignment="0" attributes="0">
29 <Group type="102" alignment="0" attributes="0">
30 <Component id="jLabel1" min="-2" max="-2" attributes="0"/>
31 <EmptySpace min="-2" pref="136" max="-2" attributes="0"/>
32 </Group>
33 <Group type="102" alignment="0" attributes="0">
34 <EmptySpace min="12" pref="12" max="12" attributes="0"/>
35 <Group type="103" groupAlignment="0" attributes="0">
36 <Component id="jLabel2" alignment="0" min="-2" pref="354" max="-2" attributes="0"/>
37 <Group type="102" alignment="0" attributes="0">
38 <Component id="jLabel3" min="-2" max="-2" attributes="0"/>
39 <EmptySpace max="-2" attributes="0"/>
40 <Component id="jPasswordField1" pref="278" max="32767" attributes="0"/>
41 </Group>
42 </Group>
43 <EmptySpace max="-2" attributes="0"/>
44 </Group>
45 </Group>
46 <Group type="102" alignment="1" attributes="0">
47 <Component id="jButton2" min="-2" max="-2" attributes="0"/>
48 <EmptySpace max="-2" attributes="0"/>
49 <Component id="jButton1" min="-2" max="-2" attributes="0"/>
50 <EmptySpace max="-2" attributes="0"/>
51 </Group>
52 </Group>
53 </Group>
54 </Group>
55 </DimensionLayout>
56 <DimensionLayout dim="1">
57 <Group type="103" groupAlignment="0" attributes="0">
58 <Group type="102" alignment="0" attributes="0">
59 <EmptySpace min="-2" max="-2" attributes="0"/>
60 <Component id="jLabel1" min="-2" max="-2" attributes="0"/>
61 <EmptySpace max="-2" attributes="0"/>
62 <Component id="jLabel2" pref="68" max="32767" attributes="0"/>
63 <EmptySpace max="-2" attributes="0"/>
64 <Group type="103" groupAlignment="3" attributes="0">
65 <Component id="jLabel3" alignment="3" min="-2" max="-2" attributes="0"/>
66 <Component id="jPasswordField1" alignment="3" min="-2" max="-2" attributes="0"/>
67 </Group>
68 <EmptySpace min="-2" max="-2" attributes="0"/>
69 <Group type="103" groupAlignment="3" attributes="0">
70 <Component id="jButton1" alignment="3" min="-2" max="-2" attributes="0"/>
71 <Component id="jButton2" alignment="3" min="-2" max="-2" attributes="0"/>
72 </Group>
73 <EmptySpace min="-2" max="-2" attributes="0"/>
74 </Group>
75 </Group>
76 </DimensionLayout>
77 </Layout>
78 <SubComponents>
79 <Component class="javax.swing.JLabel" name="jLabel1">
80 <Properties>
81 <Property name="font" type="java.awt.Font" resourceKey="jLabel1.font"/>
82 <Property name="text" type="java.lang.String" resourceKey="jLabel1.text"/>
83 <Property name="name" type="java.lang.String" value="jLabel1" noResource="true"/>
84 </Properties>
85 </Component>
86 <Component class="javax.swing.JLabel" name="jLabel2">
87 <Properties>
88 <Property name="text" type="java.lang.String" resourceKey="jLabel2.text"/>
89 <Property name="name" type="java.lang.String" value="jLabel2" noResource="true"/>
90 </Properties>
91 </Component>
92 <Component class="javax.swing.JLabel" name="jLabel3">
93 <Properties>
94 <Property name="text" type="java.lang.String" resourceKey="jLabel3.text"/>
95 <Property name="name" type="java.lang.String" value="jLabel3" noResource="true"/>
96 </Properties>
97 </Component>
98 <Component class="javax.swing.JPasswordField" name="jPasswordField1">
99 <Properties>
100 <Property name="text" type="java.lang.String" resourceKey="jPasswordField1.text"/>
101 <Property name="name" type="java.lang.String" value="jPasswordField1" noResource="true"/>
102 </Properties>
103 </Component>
104 <Component class="javax.swing.JButton" name="jButton1">
105 <Properties>
106 <Property name="text" type="java.lang.String" resourceKey="jButton1.text"/>
107 <Property name="name" type="java.lang.String" value="jButton1" noResource="true"/>
108 </Properties>
109 <Events>
110 <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton1ActionPerformed"/>
111 </Events>
112 </Component>
113 <Component class="javax.swing.JButton" name="jButton2">
114 <Properties>
115 <Property name="text" type="java.lang.String" resourceKey="jButton2.text"/>
116 <Property name="name" type="java.lang.String" value="jButton2" noResource="true"/>
117 </Properties>
118 <Events>
119 <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton2ActionPerformed"/>
120 </Events>
121 </Component>
122 </SubComponents>
123</Form>
diff --git a/client/trunk/src/com/fourisland/instadisc/AskForPasswordForm.java b/client/trunk/src/com/fourisland/instadisc/AskForPasswordForm.java new file mode 100644 index 0000000..5b80edc --- /dev/null +++ b/client/trunk/src/com/fourisland/instadisc/AskForPasswordForm.java
@@ -0,0 +1,166 @@
1/*
2 * AskForPasswordForm.java
3 *
4 * Created on August 12, 2008, 4:24 PM
5 */
6
7package com.fourisland.instadisc;
8
9/**
10 *
11 * @author hatkirby
12 */
13public class AskForPasswordForm extends javax.swing.JDialog {
14
15 /** Creates new form AskForPasswordForm */
16 public AskForPasswordForm(java.awt.Frame parent, boolean modal) {
17 super(parent, modal);
18 initComponents();
19 }
20
21 /** This method is called from within the constructor to
22 * initialize the form.
23 * WARNING: Do NOT modify this code. The content of this method is
24 * always regenerated by the Form Editor.
25 */
26 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
27 private void initComponents() {
28
29 jLabel1 = new javax.swing.JLabel();
30 jLabel2 = new javax.swing.JLabel();
31 jLabel3 = new javax.swing.JLabel();
32 jPasswordField1 = new javax.swing.JPasswordField();
33 jButton1 = new javax.swing.JButton();
34 jButton2 = new javax.swing.JButton();
35
36 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
37 setName("Form"); // NOI18N
38
39 org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(com.fourisland.instadisc.InstaDiscApp.class).getContext().getResourceMap(AskForPasswordForm.class);
40 jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
41 jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
42 jLabel1.setName("jLabel1"); // NOI18N
43
44 jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
45 jLabel2.setName("jLabel2"); // NOI18N
46
47 jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
48 jLabel3.setName("jLabel3"); // NOI18N
49
50 jPasswordField1.setText(resourceMap.getString("jPasswordField1.text")); // NOI18N
51 jPasswordField1.setName("jPasswordField1"); // NOI18N
52
53 jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
54 jButton1.setName("jButton1"); // NOI18N
55 jButton1.addActionListener(new java.awt.event.ActionListener() {
56 public void actionPerformed(java.awt.event.ActionEvent evt) {
57 jButton1ActionPerformed(evt);
58 }
59 });
60
61 jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
62 jButton2.setName("jButton2"); // NOI18N
63 jButton2.addActionListener(new java.awt.event.ActionListener() {
64 public void actionPerformed(java.awt.event.ActionEvent evt) {
65 jButton2ActionPerformed(evt);
66 }
67 });
68
69 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
70 getContentPane().setLayout(layout);
71 layout.setHorizontalGroup(
72 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
73 .addGroup(layout.createSequentialGroup()
74 .addContainerGap()
75 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
76 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
77 .addGroup(layout.createSequentialGroup()
78 .addComponent(jLabel1)
79 .addGap(136, 136, 136))
80 .addGroup(layout.createSequentialGroup()
81 .addGap(12, 12, 12)
82 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
83 .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 354, javax.swing.GroupLayout.PREFERRED_SIZE)
84 .addGroup(layout.createSequentialGroup()
85 .addComponent(jLabel3)
86 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
87 .addComponent(jPasswordField1, javax.swing.GroupLayout.DEFAULT_SIZE, 278, Short.MAX_VALUE)))
88 .addContainerGap()))
89 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
90 .addComponent(jButton2)
91 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
92 .addComponent(jButton1)
93 .addContainerGap())))
94 );
95 layout.setVerticalGroup(
96 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
97 .addGroup(layout.createSequentialGroup()
98 .addContainerGap()
99 .addComponent(jLabel1)
100 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
101 .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 68, Short.MAX_VALUE)
102 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
103 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
104 .addComponent(jLabel3)
105 .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
106 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
107 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
108 .addComponent(jButton1)
109 .addComponent(jButton2))
110 .addContainerGap())
111 );
112
113 pack();
114 }// </editor-fold>//GEN-END:initComponents
115
116 private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
117 entered = true;
118 password = new String(jPasswordField1.getPassword());
119 setVisible(false);
120 }//GEN-LAST:event_jButton2ActionPerformed
121
122 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
123 entered = false;
124 password = "";
125 setVisible(false);
126 }//GEN-LAST:event_jButton1ActionPerformed
127
128 /**
129 * @param args the command line arguments
130 */
131 public static void main(String args[]) {
132 java.awt.EventQueue.invokeLater(new Runnable() {
133 public void run() {
134 AskForPasswordForm dialog = new AskForPasswordForm(new javax.swing.JFrame(), true);
135 dialog.addWindowListener(new java.awt.event.WindowAdapter() {
136 public void windowClosing(java.awt.event.WindowEvent e) {
137 System.exit(0);
138 }
139 });
140 dialog.setVisible(true);
141 }
142 });
143 }
144
145 // Variables declaration - do not modify//GEN-BEGIN:variables
146 private javax.swing.JButton jButton1;
147 private javax.swing.JButton jButton2;
148 private javax.swing.JLabel jLabel1;
149 private javax.swing.JLabel jLabel2;
150 private javax.swing.JLabel jLabel3;
151 private javax.swing.JPasswordField jPasswordField1;
152 // End of variables declaration//GEN-END:variables
153 private boolean entered;
154 private String password;
155
156 public boolean getEntered()
157 {
158 return entered;
159 }
160
161 public String getPassword()
162 {
163 return password;
164 }
165
166}
diff --git a/client/trunk/src/com/fourisland/instadisc/Database/Subscription.java b/client/trunk/src/com/fourisland/instadisc/Database/Subscription.java index 529d60a..a3ab6ed 100644 --- a/client/trunk/src/com/fourisland/instadisc/Database/Subscription.java +++ b/client/trunk/src/com/fourisland/instadisc/Database/Subscription.java
@@ -19,6 +19,7 @@ public class Subscription {
19 private String url; 19 private String url;
20 private String category; 20 private String category;
21 private String title; 21 private String title;
22 private String password;
22 23
23 public String getURL() 24 public String getURL()
24 { 25 {
@@ -35,6 +36,11 @@ public class Subscription {
35 return title; 36 return title;
36 } 37 }
37 38
39 public String getPassword()
40 {
41 return password;
42 }
43
38 public void setURL(String url) 44 public void setURL(String url)
39 { 45 {
40 this.url = url; 46 this.url = url;
@@ -49,4 +55,9 @@ public class Subscription {
49 { 55 {
50 this.title = title; 56 this.title = title;
51 } 57 }
58
59 public void setPassword(String password)
60 {
61 this.password = password;
62 }
52} 63}
diff --git a/client/trunk/src/com/fourisland/instadisc/Functions.java b/client/trunk/src/com/fourisland/instadisc/Functions.java new file mode 100644 index 0000000..78c6eec --- /dev/null +++ b/client/trunk/src/com/fourisland/instadisc/Functions.java
@@ -0,0 +1,81 @@
1package com.fourisland.instadisc;
2
3public class Functions {
4
5 public static boolean xor(boolean x, boolean y)
6 {
7 return (x == y);
8 }
9
10 public static int max(int x, int y)
11 {
12 return (x > y ? x : y);
13 }
14
15 public static String padleft(String in, String pad, int len)
16 {
17 while (in.length() < len)
18 {
19 in = pad + in;
20 }
21
22 if (in.length() > len)
23 {
24 in = in.substring(0,len);
25 }
26
27 return in;
28 }
29
30 public static String reverse(String in)
31 {
32 String out = "";
33 int i=0;
34
35 for (i=0;i<in.length();i++)
36 {
37 out = in.charAt(i) + out;
38 }
39
40 return out;
41 }
42
43 public static byte[] hexToBytes(String str)
44 {
45 if (str==null)
46 {
47 return null;
48 } else if (str.length() < 2)
49 {
50 return null;
51 } else if (str.length() < 2)
52 {
53 return null;
54 } else {
55 int len = str.length() / 2;
56 byte[] buffer = new byte[len];
57 for (int i=0; i<len; i++) {
58 buffer[i] = (byte) Integer.parseInt(str.substring(i*2,i*2+2),16);
59 }
60
61 return buffer;
62 }
63 }
64
65 public static String padright(String in, String pad, int len)
66 {
67 while (in.length() < len)
68 {
69 in += pad;
70 }
71
72 if (in.length() > len)
73 {
74 in = in.substring(0,len);
75 }
76
77 return in;
78 }
79
80}
81 \ No newline at end of file
diff --git a/client/trunk/src/com/fourisland/instadisc/Item/MD5.java b/client/trunk/src/com/fourisland/instadisc/Item/MD5.java index 7c2096c..31a7a5c 100644 --- a/client/trunk/src/com/fourisland/instadisc/Item/MD5.java +++ b/client/trunk/src/com/fourisland/instadisc/Item/MD5.java
@@ -4,6 +4,7 @@
4 */ 4 */
5package com.fourisland.instadisc.Item; 5package com.fourisland.instadisc.Item;
6 6
7import com.fourisland.instadisc.Functions;
7import java.security.MessageDigest; 8import java.security.MessageDigest;
8import java.util.logging.Level; 9import java.util.logging.Level;
9import java.util.logging.Logger; 10import java.util.logging.Logger;
@@ -43,7 +44,7 @@ public class MD5 {
43 byte buffer[] = md5.digest(create); 44 byte buffer[] = md5.digest(create);
44 for (i = 0; i < buffer.length; i++) { 45 for (i = 0; i < buffer.length; i++) {
45 String hex = Integer.toHexString(buffer[i]); 46 String hex = Integer.toHexString(buffer[i]);
46 verify.append(pad(hex.substring(max(hex.length() - 2, 0)),"0",2)); 47 verify.append(Functions.padleft(hex.substring(Functions.max(hex.length() - 2, 0)),"0",2));
47 } 48 }
48 } catch (Exception ex) { 49 } catch (Exception ex) {
49 Logger.getLogger(WellFormedItem.class.getName()).log(Level.SEVERE, null, ex); 50 Logger.getLogger(WellFormedItem.class.getName()).log(Level.SEVERE, null, ex);
@@ -51,18 +52,4 @@ public class MD5 {
51 ver = ""; 52 ver = "";
52 return verify.toString(); 53 return verify.toString();
53 } 54 }
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} 55}
diff --git a/client/trunk/src/com/fourisland/instadisc/Item/SubscriptionFile.java b/client/trunk/src/com/fourisland/instadisc/Item/SubscriptionFile.java index d9ed348..0236c11 100644 --- a/client/trunk/src/com/fourisland/instadisc/Item/SubscriptionFile.java +++ b/client/trunk/src/com/fourisland/instadisc/Item/SubscriptionFile.java
@@ -4,9 +4,11 @@
4 */ 4 */
5package com.fourisland.instadisc.Item; 5package com.fourisland.instadisc.Item;
6 6
7import com.fourisland.instadisc.AskForPasswordForm;
7import com.fourisland.instadisc.Database.Filter; 8import com.fourisland.instadisc.Database.Filter;
8import com.fourisland.instadisc.Database.Subscription; 9import com.fourisland.instadisc.Database.Subscription;
9import com.fourisland.instadisc.Database.Wrapper; 10import com.fourisland.instadisc.Database.Wrapper;
11import com.fourisland.instadisc.Functions;
10import com.fourisland.instadisc.XmlRpc; 12import com.fourisland.instadisc.XmlRpc;
11import java.io.FileNotFoundException; 13import java.io.FileNotFoundException;
12import java.io.IOException; 14import java.io.IOException;
@@ -16,6 +18,7 @@ import java.net.URL;
16import java.util.HashMap; 18import java.util.HashMap;
17import java.util.logging.Level; 19import java.util.logging.Level;
18import java.util.logging.Logger; 20import java.util.logging.Logger;
21import javax.swing.JFrame;
19import javax.swing.JLabel; 22import javax.swing.JLabel;
20 23
21/** 24/**
@@ -135,14 +138,43 @@ class SubscriptionFileThread implements Runnable {
135 s.setURL(headerMap.get("Subscription")); 138 s.setURL(headerMap.get("Subscription"));
136 s.setTitle(headerMap.get("Title")); 139 s.setTitle(headerMap.get("Title"));
137 s.setCategory(headerMap.get("Category")); 140 s.setCategory(headerMap.get("Category"));
138 Wrapper.addSubscription(s); 141
139 142 if (Functions.xor(headerMap.containsKey("Verification"),headerMap.containsKey("Verification-ID")))
140 XmlRpc xmlrpc = new XmlRpc("addSubscription"); 143 {
141 xmlrpc.addParam(headerMap.get("Subscription")); 144 if (headerMap.containsKey("Verification"))
142 xmlrpc.addParam(headerMap.get("Category")); 145 {
143 xmlrpc.execute(); 146 AskForPasswordForm afpf = new AskForPasswordForm(new JFrame(),true);
144 147 afpf.setVisible(true);
145 status.setText("You've sucessfully subscribed to that website"); 148
149 if (afpf.getEntered() || afpf.getPassword().equals(""))
150 {
151 MD5 md5 = new MD5(afpf.getPassword());
152 MD5 hash = new MD5(s.getTitle() + ":" + md5.hash() + ":" + headerMap.get("Verification-ID"));
153
154 if (hash.hash().equals(headerMap.get("Verification")))
155 {
156 s.setPassword(afpf.getPassword());
157 } else {
158 status.setText("Error: Incorrect password entered");
159 return;
160 }
161 } else {
162 status.setText("Error: No password entered");
163 return;
164 }
165 } else {
166 s.setPassword("");
167 }
168
169 Wrapper.addSubscription(s);
170
171 XmlRpc xmlrpc = new XmlRpc("addSubscription");
172 xmlrpc.addParam(headerMap.get("Subscription"));
173 xmlrpc.addParam(headerMap.get("Category"));
174 xmlrpc.execute();
175
176 status.setText("You've sucessfully subscribed to that website");
177 }
146 } else { 178 } else {
147 status.setText("Error: Subscription file is not well-formed"); 179 status.setText("Error: Subscription file is not well-formed");
148 } 180 }
diff --git a/client/trunk/src/com/fourisland/instadisc/Item/WellFormedItem.java b/client/trunk/src/com/fourisland/instadisc/Item/WellFormedItem.java index f0f5838..f04e2ad 100644 --- a/client/trunk/src/com/fourisland/instadisc/Item/WellFormedItem.java +++ b/client/trunk/src/com/fourisland/instadisc/Item/WellFormedItem.java
@@ -7,15 +7,28 @@ package com.fourisland.instadisc.Item;
7import com.fourisland.instadisc.Database.Filter; 7import com.fourisland.instadisc.Database.Filter;
8import com.fourisland.instadisc.Database.Subscription; 8import com.fourisland.instadisc.Database.Subscription;
9import com.fourisland.instadisc.Database.Wrapper; 9import com.fourisland.instadisc.Database.Wrapper;
10import com.fourisland.instadisc.Functions;
10import com.fourisland.instadisc.Item.Categories.Category; 11import com.fourisland.instadisc.Item.Categories.Category;
11import com.fourisland.instadisc.XmlRpc; 12import com.fourisland.instadisc.XmlRpc;
12import java.net.MalformedURLException; 13import java.net.MalformedURLException;
13import java.net.URI; 14import java.net.URI;
14import java.net.URISyntaxException; 15import java.net.URISyntaxException;
15import java.net.URL; 16import java.net.URL;
17import java.security.InvalidAlgorithmParameterException;
18import java.security.InvalidKeyException;
19import java.security.NoSuchAlgorithmException;
20import java.util.Collection;
16import java.util.HashMap; 21import java.util.HashMap;
22import java.util.Iterator;
23import java.util.Map.Entry;
17import java.util.logging.Level; 24import java.util.logging.Level;
18import java.util.logging.Logger; 25import java.util.logging.Logger;
26import javax.crypto.BadPaddingException;
27import javax.crypto.Cipher;
28import javax.crypto.IllegalBlockSizeException;
29import javax.crypto.NoSuchPaddingException;
30import javax.crypto.spec.IvParameterSpec;
31import javax.crypto.spec.SecretKeySpec;
19 32
20/** 33/**
21 * 34 *
@@ -33,6 +46,7 @@ public class WellFormedItem {
33 boolean good = true; 46 boolean good = true;
34 good = (good ? checkForRequiredHeaders() : false); 47 good = (good ? checkForRequiredHeaders() : false);
35 good = (good ? checkForSubscription() : false); 48 good = (good ? checkForSubscription() : false);
49 good = (good ? checkForEncryption() : false);
36 good = (good ? Category.checkForLegalCategory(aThis.headerMap) : false); 50 good = (good ? Category.checkForLegalCategory(aThis.headerMap) : false);
37 good = (good ? Category.checkForRequiredSemantics(aThis.headerMap) : false); 51 good = (good ? Category.checkForRequiredSemantics(aThis.headerMap) : false);
38 good = (good ? checkForProperVerification() : false); 52 good = (good ? checkForProperVerification() : false);
@@ -41,6 +55,74 @@ public class WellFormedItem {
41 return good; 55 return good;
42 } 56 }
43 57
58 private boolean checkForEncryption() {
59 if (!Wrapper.getSubscription(aThis.headerMap.get("Subscription")).getPassword().equals(""))
60 {
61 try
62 {
63 Subscription s = Wrapper.getSubscription(aThis.headerMap.get("Subscription"));
64 MD5 md5 = new MD5(Functions.padright(s.getPassword(), aThis.headerMap.get("Encryption-ID"), 16).substring(0, 16));
65 String key = md5.hash().substring(0, 16);
66 String iv = Functions.reverse(key);
67
68 Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
69 SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(), "AES");
70 IvParameterSpec ivSpec = new IvParameterSpec(iv.getBytes());
71 cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);
72
73 aThis.headerMap.put("Title", new String(cipher.doFinal(Functions.hexToBytes(aThis.headerMap.get("Title")))).trim());
74 aThis.headerMap.put("Author", new String(cipher.doFinal(Functions.hexToBytes(aThis.headerMap.get("Author")))).trim());
75 aThis.headerMap.put("URL", new String(cipher.doFinal(Functions.hexToBytes(aThis.headerMap.get("URL")))).trim());
76
77 HashMap<String, String> temp = new HashMap<String, String>(aThis.headerMap);
78 temp.remove("ID");
79 temp.remove("Verification");
80 temp.remove("Verification-ID");
81 temp.remove("Subscription");
82 temp.remove("Title");
83 temp.remove("Author");
84 temp.remove("URL");
85 temp.remove("Encryption-ID");
86
87 Collection<Entry<String,String>> vals = temp.entrySet();
88 Iterator<Entry<String,String>> i = vals.iterator();
89 while (i.hasNext())
90 {
91 Entry<String,String> e = (Entry<String,String>) i.next();
92 aThis.headerMap.put(e.getKey(), new String(cipher.doFinal(Functions.hexToBytes(e.getValue()))).trim());
93 }
94
95 return true;
96 } catch (IllegalBlockSizeException ex)
97 {
98 Logger.getLogger(WellFormedItem.class.getName()).log(Level.SEVERE, null, ex);
99 return false;
100 } catch (BadPaddingException ex)
101 {
102 Logger.getLogger(WellFormedItem.class.getName()).log(Level.SEVERE, null, ex);
103 return false;
104 } catch (InvalidKeyException ex)
105 {
106 Logger.getLogger(WellFormedItem.class.getName()).log(Level.SEVERE, null, ex);
107 return false;
108 } catch (InvalidAlgorithmParameterException ex)
109 {
110 Logger.getLogger(WellFormedItem.class.getName()).log(Level.SEVERE, null, ex);
111 return false;
112 } catch (NoSuchAlgorithmException ex)
113 {
114 Logger.getLogger(WellFormedItem.class.getName()).log(Level.SEVERE, null, ex);
115 return false;
116 } catch (NoSuchPaddingException ex)
117 {
118 Logger.getLogger(WellFormedItem.class.getName()).log(Level.SEVERE, null, ex);
119 return false;
120 }
121 } else {
122 return true;
123 }
124 }
125
44 private boolean checkForEqualFilters() { 126 private boolean checkForEqualFilters() {
45 boolean good = true; 127 boolean good = true;
46 128
@@ -117,6 +199,7 @@ public class WellFormedItem {
117 199
118 private boolean checkForRequiredHeaders() { 200 private boolean checkForRequiredHeaders() {
119 boolean good = true; 201 boolean good = true;
202
120 good = (good ? checkForRequiredHeader("ID") : false); 203 good = (good ? checkForRequiredHeader("ID") : false);
121 good = (good ? checkForRequiredHeader("Verification") : false); 204 good = (good ? checkForRequiredHeader("Verification") : false);
122 good = (good ? checkForRequiredHeader("Verification-ID") : false); 205 good = (good ? checkForRequiredHeader("Verification-ID") : false);
@@ -124,6 +207,12 @@ public class WellFormedItem {
124 good = (good ? checkForRequiredHeader("Title") : false); 207 good = (good ? checkForRequiredHeader("Title") : false);
125 good = (good ? checkForRequiredHeader("Author") : false); 208 good = (good ? checkForRequiredHeader("Author") : false);
126 good = (good ? checkForRequiredHeader("URL") : false); 209 good = (good ? checkForRequiredHeader("URL") : false);
210
211 if (!Wrapper.getSubscription(aThis.headerMap.get("Subscription")).getPassword().equals(""))
212 {
213 good = (good ? checkForRequiredHeader("Encryption-ID") : false);
214 }
215
127 return good; 216 return good;
128 } 217 }
129 218
diff --git a/client/trunk/src/com/fourisland/instadisc/resources/AskForPasswordForm.properties b/client/trunk/src/com/fourisland/instadisc/resources/AskForPasswordForm.properties new file mode 100644 index 0000000..a1d9d3e --- /dev/null +++ b/client/trunk/src/com/fourisland/instadisc/resources/AskForPasswordForm.properties
@@ -0,0 +1,9 @@
1
2jLabel1.text=Ask For Password
3#NOI18N
4jLabel1.font=DejaVu Sans-Plain-18
5jLabel2.text=<HTML>If you can see this form, that must mean you are attempting to subscribe to a password-protected subscription. If you don't have the password to this subscription, well then, you cannot subscribe to it.
6jLabel3.text=Password:
7jPasswordField1.text=
8jButton1.text=Cancel
9jButton2.text=OK