aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/gnunet/voting/CertifyGroupCommand.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/gnunet/voting/CertifyGroupCommand.java')
-rw-r--r--src/main/java/org/gnunet/voting/CertifyGroupCommand.java129
1 files changed, 129 insertions, 0 deletions
diff --git a/src/main/java/org/gnunet/voting/CertifyGroupCommand.java b/src/main/java/org/gnunet/voting/CertifyGroupCommand.java
new file mode 100644
index 0000000..e76ba1f
--- /dev/null
+++ b/src/main/java/org/gnunet/voting/CertifyGroupCommand.java
@@ -0,0 +1,129 @@
1/*
2 This file is part of GNUnet.
3 (C) 2012, 2013 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19 */
20
21/*
22 This file is part of GNUnet.
23 (C) 2012, 2013 Christian Grothoff (and other contributing authors)
24
25 GNUnet is free software; you can redistribute it and/or modify
26 it under the terms of the GNU General Public License as published
27 by the Free Software Foundation; either version 3, or (at your
28 option) any later version.
29
30 GNUnet is distributed in the hope that it will be useful, but
31 WITHOUT ANY WARRANTY; without even the implied warranty of
32 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
33 General Public License for more details.
34
35 You should have received a copy of the GNU General Public License
36 along with GNUnet; see the file COPYING. If not, write to the
37 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
38 Boston, MA 02111-1307, USA.
39 */
40
41/*
42 This file is part of GNUnet.
43 (C) 2012, 2013 Christian Grothoff (and other contributing authors)
44
45 GNUnet is free software; you can redistribute it and/or modify
46 it under the terms of the GNU General Public License as published
47 by the Free Software Foundation; either version 3, or (at your
48 option) any later version.
49
50 GNUnet is distributed in the hope that it will be useful, but
51 WITHOUT ANY WARRANTY; without even the implied warranty of
52 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
53 General Public License for more details.
54
55 You should have received a copy of the GNU General Public License
56 along with GNUnet; see the file COPYING. If not, write to the
57 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
58 Boston, MA 02111-1307, USA.
59 */
60
61package org.gnunet.voting;
62
63
64import org.gnunet.mesh.Mesh;
65import org.gnunet.mesh.MeshRunabout;
66import org.gnunet.mesh.TunnelEndHandler;
67import org.gnunet.util.Configuration;
68import org.gnunet.util.CryptoECC;
69import org.gnunet.voting.messages.CertificateGrantMessage;
70import org.gnunet.voting.messages.CertificateRequestMessage;
71import org.gnunet.voting.messages.QueryFailureMessage;
72
73import java.io.File;
74import java.util.Random;
75
76public class CertifyGroupCommand extends MeshRunabout implements TunnelEndHandler {
77 private final String ballotFilename;
78 private final String pubKeyString;
79 private Ballot ballot;
80 private final Configuration cfg;
81 private Mesh mesh;
82 private Mesh.Tunnel<Void> tunnel;
83 private boolean submitted = false;
84
85 @Override
86 public void onTunnelEnd(Mesh.Tunnel tunnel) {
87 if (!submitted)
88 throw new AssertionError();
89 }
90
91 public void visit(CertificateGrantMessage m) {
92 submitted = true;
93 System.out.println("certificate granted");
94
95 tunnel.destroy();
96 mesh.destroy();
97 }
98
99
100 public void visit(QueryFailureMessage m) {
101 submitted = true;
102 System.out.println("failure to query result: authority refused");
103 tunnel.destroy();
104 mesh.destroy();
105 }
106
107 public CertifyGroupCommand(Configuration cfg, String ballotFilename, String pubKeyString) {
108 this.cfg = cfg;
109 this.ballotFilename = ballotFilename;
110 this.pubKeyString = pubKeyString;
111 }
112
113 public void run() {
114 File bf = new File(ballotFilename);
115 if (!bf.exists()) {
116 System.err.println("ballot file does not exist");
117 return;
118 }
119 ballot = new Ballot(ballotFilename);
120
121 Random r = new Random();
122 mesh = new Mesh(cfg, this, this);
123 tunnel = mesh.createTunnel(null /* FIXME */, CertificateAuthorityDaemon.MESH_PORT, true, true, null);
124 CertificateRequestMessage m = new CertificateRequestMessage();
125 m.group = ballot.group;
126 m.publicKey = CryptoECC.PublicSignKey.fromString(pubKeyString);
127 tunnel.send(m);
128 }
129}