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);
92 public async bool install_id_card (string display_name,
103 IdCard idcard = new IdCard ();
105 idcard.display_name = display_name;
106 idcard.username = user_name;
107 idcard.password = password;
108 idcard.issuer = realm;
109 idcard.rules = rules;
110 idcard.services = services;
111 idcard.trust_anchor.ca_cert = ca_cert;
112 idcard.trust_anchor.subject = subject;
113 idcard.trust_anchor.subject_alt = subject_alt;
114 idcard.trust_anchor.server_cert = server_cert;
116 /* TODO: Check if display name already exists */
118 idcard.pixbuf = find_icon ("avatar-default", 48);
120 /* TODO: Act on close */
121 var dialog = new WebProvisioning.ConfirmDialog (idcard);
123 var ret = dialog.run ();
126 if (ret == Gtk.ResponseType.ACCEPT)
128 main_window.insert_id_card (idcard);
140 using MoonshotRpcInterface;
142 /* This class must be a singleton, because we use a global RPC
143 * binding handle. I cannot picture a situation where more than
144 * one instance of the same interface would be needed so this
145 * shouldn't be a problem.
147 * Shutdown is automatically done by the RPC runtime when the
150 public class MoonshotServer : Object {
151 private static MainWindow main_window;
153 private static MoonshotServer instance = null;
155 public static void start (Gtk.Window window)
157 main_window = (MainWindow) window;
158 Rpc.server_start (MoonshotRpcInterface.spec, "/org/janet/Moonshot", Rpc.Flags.PER_USER);
161 public static MoonshotServer get_instance ()
163 if (instance == null)
164 instance = new MoonshotServer ();
168 [CCode (cname = "moonshot_get_identity_rpc")]
169 public static void get_identity (Rpc.AsyncCall call,
174 ref string password_out,
175 ref string server_certificate_hash,
176 ref string ca_certificate,
177 ref string subject_name_constraint,
178 ref string subject_alt_name_constraint)
182 var request = new IdentityRequest (main_window,
187 // Pass execution to the main loop and block the RPC thread
188 request.mutex = new Mutex ();
189 request.cond = new Cond ();
190 request.set_callback (return_identity_cb);
192 request.mutex.lock ();
193 Idle.add (request.execute);
195 while (request.complete == false)
196 request.cond.wait (request.mutex);
200 server_certificate_hash = "";
202 subject_name_constraint = "";
203 subject_alt_name_constraint = "";
205 var id_card = request.id_card;
207 if (id_card == null) {
208 // The strings are freed by the RPC runtime
209 nai_out = id_card.nai;
210 password_out = id_card.password;
211 server_certificate_hash = "certificate";
213 return_if_fail (nai_out != null);
214 return_if_fail (password_out != null);
215 return_if_fail (server_certificate_hash != null);
216 return_if_fail (ca_certificate != null);
217 return_if_fail (subject_name_constraint != null);
218 return_if_fail (subject_alt_name_constraint != null);
223 // The outputs must be set before this function is called. For this
224 // reason they are 'ref' not 'out' parameters - Vala assigns to the
225 // 'out' parameters only at the end of the function, which is too
227 call.return (&result);
229 request.cond.signal ();
230 request.mutex.unlock ();
233 [CCode (cname = "moonshot_get_default_identity_rpc")]
234 public static void get_default_identity (Rpc.AsyncCall call,
236 ref string password_out,
237 ref string server_certificate_hash,
238 ref string ca_certificate,
239 ref string subject_name_constraint,
240 ref string subject_alt_name_constraint)
244 var request = new IdentityRequest.default (main_window);
245 request.mutex = new Mutex ();
246 request.cond = new Cond ();
247 request.set_callback (return_identity_cb);
249 request.mutex.lock ();
250 Idle.add (request.execute);
252 while (request.complete == false)
253 request.cond.wait (request.mutex);
257 server_certificate_hash = "";
259 subject_name_constraint = "";
260 subject_alt_name_constraint = "";
262 if (request.id_card != null)
264 nai_out = request.id_card.nai;
265 password_out = request.id_card.password;
266 server_certificate_hash = "certificate";
268 return_if_fail (nai_out != null);
269 return_if_fail (password_out != null);
270 return_if_fail (server_certificate_hash != null);
271 return_if_fail (ca_certificate != null);
272 return_if_fail (subject_name_constraint != null);
273 return_if_fail (subject_alt_name_constraint != null);
282 call.return (&result);
284 request.cond.signal ();
285 request.mutex.unlock ();
288 // Called from the main loop thread when an identity has
290 static void return_identity_cb (IdentityRequest request) {
291 // Notify the RPC thread that the request is complete
292 request.mutex.lock ();
293 request.cond.signal ();
295 // Block the main loop until the RPC call has returned
296 // to avoid any races
297 request.cond.wait (request.mutex);
298 request.mutex.unlock ();