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,
96 string[] rules_patterns,
97 string[] rules_always_confirm,
104 IdCard idcard = new IdCard ();
106 idcard.display_name = display_name;
107 idcard.username = user_name;
108 idcard.password = password;
109 idcard.issuer = realm;
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 if (rules_patterns.length == rules_always_confirm.length)
118 idcard.rules = new Rule[rules_patterns.length];
120 for (int i=0; i<idcard.rules.length; i++)
122 idcard.rules[i].pattern = rules_patterns[i];
123 idcard.rules[i].always_confirm = rules_always_confirm[i];
127 /* TODO: Check if display name already exists */
129 idcard.pixbuf = find_icon ("avatar-default", 48);
131 var dialog = new Gtk.MessageDialog (main_window,
132 Gtk.DialogFlags.DESTROY_WITH_PARENT,
133 Gtk.MessageType.QUESTION,
134 Gtk.ButtonsType.YES_NO,
135 _("Would you like to add '%s' ID Card to the ID Card Organizer?"),
136 idcard.display_name);
139 var ret = dialog.run ();
142 if (ret == Gtk.ResponseType.YES)
144 main_window.insert_id_card (idcard);
156 using MoonshotRpcInterface;
158 /* This class must be a singleton, because we use a global RPC
159 * binding handle. I cannot picture a situation where more than
160 * one instance of the same interface would be needed so this
161 * shouldn't be a problem.
163 * Shutdown is automatically done by the RPC runtime when the
166 public class MoonshotServer : Object {
167 private static MainWindow main_window;
169 private static MoonshotServer instance = null;
171 public static void start (Gtk.Window window)
173 main_window = (MainWindow) window;
174 Rpc.server_start (MoonshotRpcInterface.spec, "/org/janet/Moonshot", Rpc.Flags.PER_USER);
177 public static MoonshotServer get_instance ()
179 if (instance == null)
180 instance = new MoonshotServer ();
184 [CCode (cname = "moonshot_get_identity_rpc")]
185 public static void get_identity (Rpc.AsyncCall call,
190 ref string password_out,
191 ref string server_certificate_hash,
192 ref string ca_certificate,
193 ref string subject_name_constraint,
194 ref string subject_alt_name_constraint)
198 var request = new IdentityRequest (main_window,
203 // Pass execution to the main loop and block the RPC thread
204 request.mutex = new Mutex ();
205 request.cond = new Cond ();
206 request.set_callback (return_identity_cb);
208 request.mutex.lock ();
209 Idle.add (request.execute);
211 while (request.complete == false)
212 request.cond.wait (request.mutex);
216 server_certificate_hash = "";
218 subject_name_constraint = "";
219 subject_alt_name_constraint = "";
221 var id_card = request.id_card;
223 if (id_card == null) {
224 // The strings are freed by the RPC runtime
225 nai_out = id_card.nai;
226 password_out = id_card.password;
227 server_certificate_hash = "certificate";
229 return_if_fail (nai_out != null);
230 return_if_fail (password_out != null);
231 return_if_fail (server_certificate_hash != null);
232 return_if_fail (ca_certificate != null);
233 return_if_fail (subject_name_constraint != null);
234 return_if_fail (subject_alt_name_constraint != null);
239 // The outputs must be set before this function is called. For this
240 // reason they are 'ref' not 'out' parameters - Vala assigns to the
241 // 'out' parameters only at the end of the function, which is too
243 call.return (&result);
245 request.cond.signal ();
246 request.mutex.unlock ();
249 [CCode (cname = "moonshot_get_default_identity_rpc")]
250 public static void get_default_identity (Rpc.AsyncCall call,
252 ref string password_out,
253 ref string server_certificate_hash,
254 ref string ca_certificate,
255 ref string subject_name_constraint,
256 ref string subject_alt_name_constraint)
260 var request = new IdentityRequest.default (main_window);
261 request.mutex = new Mutex ();
262 request.cond = new Cond ();
263 request.set_callback (return_identity_cb);
265 request.mutex.lock ();
266 Idle.add (request.execute);
268 while (request.complete == false)
269 request.cond.wait (request.mutex);
273 server_certificate_hash = "";
275 subject_name_constraint = "";
276 subject_alt_name_constraint = "";
278 if (request.id_card != null)
280 nai_out = request.id_card.nai;
281 password_out = request.id_card.password;
282 server_certificate_hash = "certificate";
284 return_if_fail (nai_out != null);
285 return_if_fail (password_out != null);
286 return_if_fail (server_certificate_hash != null);
287 return_if_fail (ca_certificate != null);
288 return_if_fail (subject_name_constraint != null);
289 return_if_fail (subject_alt_name_constraint != null);
298 call.return (&result);
300 request.cond.signal ();
301 request.mutex.unlock ();
304 // Called from the main loop thread when an identity has
306 static void return_identity_cb (IdentityRequest request) {
307 // Notify the RPC thread that the request is complete
308 request.mutex.lock ();
309 request.cond.signal ();
311 // Block the main loop until the RPC call has returned
312 // to avoid any races
313 request.cond.wait (request.mutex);
314 request.mutex.unlock ();