3 [DBus (name = "org.janet.Moonshot")]
4 public class MoonshotServer : Object {
6 private MainWindow main_window;
8 public MoonshotServer (Gtk.Window window)
10 this.main_window = (MainWindow) window;
13 public async bool get_identity (string nai,
17 out string password_out,
18 out string server_certificate_hash,
19 out string ca_certificate,
20 out string subject_name_constraint,
21 out string subject_alt_name_constraint)
23 var request = new IdentityRequest (main_window,
27 request.set_callback ((IdentityRequest) => get_identity.callback());
33 server_certificate_hash = "";
35 subject_name_constraint = "";
36 subject_alt_name_constraint = "";
38 var id_card = request.id_card;
40 if (id_card != null) {
41 nai_out = id_card.nai;
42 password_out = id_card.password;
44 server_certificate_hash = "certificate";
46 // User should have been prompted if there was no p/w.
47 return_if_fail (nai_out != null);
48 return_if_fail (password_out != null);
56 public async bool get_default_identity (out string nai_out,
57 out string password_out,
58 out string server_certificate_hash,
59 out string ca_certificate,
60 out string subject_name_constraint,
61 out string subject_alt_name_constraint)
63 var request = new IdentityRequest.default (main_window);
64 request.set_callback ((IdentityRequest) => get_default_identity.callback());
70 server_certificate_hash = "";
72 subject_name_constraint = "";
73 subject_alt_name_constraint = "";
75 if (request.id_card != null)
77 nai_out = request.id_card.nai;
78 password_out = request.id_card.password;
80 server_certificate_hash = "certificate";
82 // User should have been prompted if there was no p/w.
83 return_val_if_fail (nai_out != null, false);
84 return_val_if_fail (password_out != null, false);
96 using MoonshotRpcInterface;
98 /* This class must be a singleton, because we use a global RPC
99 * binding handle. I cannot picture a situation where more than
100 * one instance of the same interface would be needed so this
101 * shouldn't be a problem.
103 * Shutdown is automatically done by the RPC runtime when the
106 public class MoonshotServer : Object {
107 private static MainWindow main_window;
109 private static MoonshotServer instance = null;
111 public static void start (Gtk.Window window)
113 main_window = (MainWindow) window;
114 Rpc.server_start (MoonshotRpcInterface.spec, "/org/janet/Moonshot", Rpc.Flags.PER_USER);
117 public static MoonshotServer get_instance ()
119 if (instance == null)
120 instance = new MoonshotServer ();
124 [CCode (cname = "moonshot_get_identity_rpc")]
125 public static void get_identity (Rpc.AsyncCall call,
130 ref string password_out,
131 ref string server_certificate_hash,
132 ref string ca_certificate,
133 ref string subject_name_constraint,
134 ref string subject_alt_name_constraint)
138 var request = new IdentityRequest (main_window,
143 // Pass execution to the main loop and block the RPC thread
144 request.mutex = new Mutex ();
145 request.cond = new Cond ();
146 request.set_callback (return_identity_cb);
148 request.mutex.lock ();
149 Idle.add (request.execute);
151 while (request.complete == false)
152 request.cond.wait (request.mutex);
156 server_certificate_hash = "";
158 subject_name_constraint = "";
159 subject_alt_name_constraint = "";
161 var id_card = request.id_card;
163 if (id_card == null) {
164 // The strings are freed by the RPC runtime
165 nai_out = id_card.nai;
166 password_out = id_card.password;
167 server_certificate_hash = "certificate";
169 return_if_fail (nai_out != null);
170 return_if_fail (password_out != null);
175 // The outputs must be set before this function is called. For this
176 // reason they are 'ref' not 'out' parameters - Vala assigns to the
177 // 'out' parameters only at the end of the function, which is too
179 call.return (&result);
181 request.cond.signal ();
182 request.mutex.unlock ();
185 [CCode (cname = "moonshot_get_default_identity_rpc")]
186 public static void get_default_identity (Rpc.AsyncCall call,
188 ref string password_out,
189 ref string server_certificate_hash,
190 ref string ca_certificate,
191 ref string subject_name_constraint,
192 ref string subject_alt_name_constraint)
196 var request = new IdentityRequest.default (main_window);
197 request.mutex = new Mutex ();
198 request.cond = new Cond ();
199 request.set_callback (return_identity_cb);
201 request.mutex.lock ();
202 Idle.add (request.execute);
204 while (request.complete == false)
205 request.cond.wait (request.mutex);
209 server_certificate_hash = "";
211 subject_name_constraint = "";
212 subject_alt_name_constraint = "";
214 if (request.id_card != null)
216 nai_out = request.id_card.nai;
217 password_out = request.id_card.password;
218 server_certificate_hash = "certificate";
220 return_if_fail (nai_out != null);
221 return_if_fail (password_out != null);
230 call.return (&result);
232 request.cond.signal ();
233 request.mutex.unlock ();
236 // Called from the main loop thread when an identity has
238 static void return_identity_cb (IdentityRequest request) {
239 // Notify the RPC thread that the request is complete
240 request.mutex.lock ();
241 request.cond.signal ();
243 // Block the main loop until the RPC call has returned
244 // to avoid any races
245 request.cond.wait (request.mutex);
246 request.mutex.unlock ();