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;
115 /* TODO: Ask for confirmation */
116 /* TODO: Check if display name already exists */
126 using MoonshotRpcInterface;
128 /* This class must be a singleton, because we use a global RPC
129 * binding handle. I cannot picture a situation where more than
130 * one instance of the same interface would be needed so this
131 * shouldn't be a problem.
133 * Shutdown is automatically done by the RPC runtime when the
136 public class MoonshotServer : Object {
137 private static MainWindow main_window;
139 private static MoonshotServer instance = null;
141 public static void start (Gtk.Window window)
143 main_window = (MainWindow) window;
144 Rpc.server_start (MoonshotRpcInterface.spec, "/org/janet/Moonshot", Rpc.Flags.PER_USER);
147 public static MoonshotServer get_instance ()
149 if (instance == null)
150 instance = new MoonshotServer ();
154 [CCode (cname = "moonshot_get_identity_rpc")]
155 public static void get_identity (Rpc.AsyncCall call,
160 ref string password_out,
161 ref string server_certificate_hash,
162 ref string ca_certificate,
163 ref string subject_name_constraint,
164 ref string subject_alt_name_constraint)
168 var request = new IdentityRequest (main_window,
173 // Pass execution to the main loop and block the RPC thread
174 request.mutex = new Mutex ();
175 request.cond = new Cond ();
176 request.set_callback (return_identity_cb);
178 request.mutex.lock ();
179 Idle.add (request.execute);
181 while (request.complete == false)
182 request.cond.wait (request.mutex);
186 server_certificate_hash = "";
188 subject_name_constraint = "";
189 subject_alt_name_constraint = "";
191 var id_card = request.id_card;
193 if (id_card == null) {
194 // The strings are freed by the RPC runtime
195 nai_out = id_card.nai;
196 password_out = id_card.password;
197 server_certificate_hash = "certificate";
199 return_if_fail (nai_out != null);
200 return_if_fail (password_out != null);
201 return_if_fail (server_certificate_hash != null);
202 return_if_fail (ca_certificate != null);
203 return_if_fail (subject_name_constraint != null);
204 return_if_fail (subject_alt_name_constraint != null);
209 // The outputs must be set before this function is called. For this
210 // reason they are 'ref' not 'out' parameters - Vala assigns to the
211 // 'out' parameters only at the end of the function, which is too
213 call.return (&result);
215 request.cond.signal ();
216 request.mutex.unlock ();
219 [CCode (cname = "moonshot_get_default_identity_rpc")]
220 public static void get_default_identity (Rpc.AsyncCall call,
222 ref string password_out,
223 ref string server_certificate_hash,
224 ref string ca_certificate,
225 ref string subject_name_constraint,
226 ref string subject_alt_name_constraint)
230 var request = new IdentityRequest.default (main_window);
231 request.mutex = new Mutex ();
232 request.cond = new Cond ();
233 request.set_callback (return_identity_cb);
235 request.mutex.lock ();
236 Idle.add (request.execute);
238 while (request.complete == false)
239 request.cond.wait (request.mutex);
243 server_certificate_hash = "";
245 subject_name_constraint = "";
246 subject_alt_name_constraint = "";
248 if (request.id_card != null)
250 nai_out = request.id_card.nai;
251 password_out = request.id_card.password;
252 server_certificate_hash = "certificate";
254 return_if_fail (nai_out != null);
255 return_if_fail (password_out != null);
256 return_if_fail (server_certificate_hash != null);
257 return_if_fail (ca_certificate != null);
258 return_if_fail (subject_name_constraint != null);
259 return_if_fail (subject_alt_name_constraint != null);
268 call.return (&result);
270 request.cond.signal ();
271 request.mutex.unlock ();
274 // Called from the main loop thread when an identity has
276 static void return_identity_cb (IdentityRequest request) {
277 // Notify the RPC thread that the request is complete
278 request.mutex.lock ();
279 request.cond.signal ();
281 // Block the main loop until the RPC call has returned
282 // to avoid any races
283 request.cond.wait (request.mutex);
284 request.mutex.unlock ();