3 [DBus (name = "org.janet.Moonshot")]
4 public interface MoonshotServer : Object
6 public async abstract bool get_identity (string nai,
10 out string password_out,
11 out string server_certificate_hash,
12 out string ca_certificate,
13 out string subject_name_constraint,
14 out string subject_alt_name_constraint)
17 public async abstract bool get_default_identity (out string nai_out,
18 out string password_out,
19 out string server_certificate_hash,
20 out string ca_certificate,
21 out string subject_name_constraint,
22 out string subject_alt_name_constraint)
25 public async abstract bool install_id_card (string display_name,
29 string[] rules_patterns,
30 string[] rules_always_confirm,
41 namespace WebProvisioning
47 check_stack (SList<string> stack, string[] reference)
49 if (stack.length () < reference.length)
52 for (int i = 0; i<reference.length; i++)
54 if (stack.nth_data(i) != reference[i])
62 always_confirm_handler (SList<string> stack)
64 string[] always_confirm_path = {"always-confirm", "rule", "selection-rules", "identity", "identities"};
66 return check_stack (stack, always_confirm_path);
70 pattern_handler (SList<string> stack)
72 string[] pattern_path = {"pattern", "rule", "selection-rules", "identity", "identities"};
74 return check_stack (stack, pattern_path);
78 server_cert_handler (SList<string> stack)
80 string[] server_cert_path = {"server-cert", "trust-anchor", "identity", "identities"};
82 return check_stack (stack, server_cert_path);
86 subject_alt_handler (SList<string> stack)
88 string[] subject_alt_path = {"subject-alt", "trust-anchor", "identity", "identities"};
90 return check_stack (stack, subject_alt_path);
94 subject_handler (SList<string> stack)
96 string[] subject_path = {"subject", "trust-anchor", "identity", "identities"};
98 return check_stack (stack, subject_path);
102 ca_cert_handler (SList<string> stack)
104 string[] ca_path = {"ca-cert", "trust-anchor", "identity", "identities"};
106 return check_stack (stack, ca_path);
110 realm_handler (SList<string> stack)
112 string[] realm_path = {"realm", "identity", "identities"};
114 return check_stack (stack, realm_path);
118 password_handler (SList<string> stack)
120 string[] password_path = {"password", "identity", "identities"};
122 return check_stack (stack, password_path);
126 user_handler (SList<string> stack)
128 string[] user_path = {"user", "identity", "identities"};
130 return check_stack (stack, user_path);
134 display_name_handler (SList<string> stack)
136 string[] display_name_path = {"display-name", "identity", "identities"};
138 return check_stack (stack, display_name_path);
142 start_element_func (MarkupParseContext context,
144 string[] attribute_names,
145 string[] attribute_values) throws MarkupError
147 if (element_name == "identity")
149 IdCard[] tmp_cards = cards;
151 cards = new IdCard[tmp_cards.length + 1];
152 for (int i=0; i<tmp_cards.length; i++)
154 cards[i] = tmp_cards[i];
157 cards[tmp_cards.length] = card;
159 else if (element_name == "rule")
161 Rule[] tmp_rules = card.rules;
162 card.rules = new Rule[tmp_rules.length + 1];
163 for (int i=0; i<tmp_rules.length; i++)
165 card.rules[i] = tmp_rules[i];
168 card.rules[tmp_rules.length] = Rule();
173 text_element_func (MarkupParseContext context,
175 size_t text_len) throws MarkupError
177 unowned SList<string> stack = context.get_element_stack ();
182 if (stack.nth_data(0) == "display-name" && display_name_handler (stack))
184 card.display_name = text;
186 else if (stack.nth_data(0) == "user" && user_handler (stack))
188 card.username = text;
190 else if (stack.nth_data(0) == "password" && password_handler (stack))
192 card.password = text;
194 else if (stack.nth_data(0) == "realm" && realm_handler (stack))
198 else if (stack.nth_data(0) == "service")
200 string[] services = card.services;
201 card.services = new string[services.length + 1];
202 for (int i = 0; i<services.length; i++)
204 card.services[i] = services[i];
206 card.services[services.length] = text;
209 else if (stack.nth_data(0) == "pattern" && pattern_handler (stack))
211 card.rules[card.rules.length - 1].pattern = text;
213 else if (stack.nth_data(0) == "always-confirm" && always_confirm_handler (stack))
215 if (text == "true" || text == "false")
216 card.rules[card.rules.length - 1].always_confirm = text;
219 else if (stack.nth_data(0) == "ca-cert" && ca_cert_handler (stack))
221 card.trust_anchor.ca_cert = text;
223 else if (stack.nth_data(0) == "subject" && subject_handler (stack))
225 card.trust_anchor.subject = text;
227 else if (stack.nth_data(0) == "subject-alt" && subject_alt_handler (stack))
229 card.trust_anchor.subject_alt = text;
231 else if (stack.nth_data(0) == "server-cert" && server_cert_handler (stack))
233 card.trust_anchor.server_cert = text;
239 private MarkupParser parser;
242 public Parser (string path)
247 var file = File.new_for_path (path);
251 var dis = new DataInputStream (file.read ());
253 while ((line = dis.read_line (null)) != null)
258 error ("Could not retreive file size");
261 parser = {start_element_func, null, text_element_func, null, null};
267 var ctx = new MarkupParseContext(parser, 0, null, null);
271 ctx.parse (text, text.length);
275 error ("Could not parse %s, invalid content", path);
280 public static int main (string[] args)
284 error ("Usage %s [-a] WEB_PROVISIONING_FILE", args[0]);
287 if (!FileUtils.test (args[1], FileTest.EXISTS | FileTest.IS_REGULAR))
289 error ("%s does not exist", args[1]);
292 var webp = new Parser (args[1]);
295 foreach (IdCard card in cards)
299 var conn = DBus.Bus.get (DBus.BusType.SESSION);
300 dynamic DBus.Object bus = conn.get_object ("org.janet.Moonshot",
301 "/org/janet/moonshot",
302 "org.janet.Moonshot");
304 string[] rules_patterns = {};
305 string[] rules_always_confirm = {};
307 if (card.rules.length > 0)
310 rules_patterns = new string[card.rules.length];
311 rules_always_confirm = new string[card.rules.length];
312 foreach (Rule r in card.rules)
314 rules_patterns[i] = r.pattern;
315 rules_always_confirm[i] = r.always_confirm;
320 bus.install_id_card (card.display_name,
325 rules_always_confirm,
327 card.trust_anchor.ca_cert,
328 card.trust_anchor.subject,
329 card.trust_anchor.subject_alt,
330 card.trust_anchor.server_cert);
335 stderr.printf ("Error: %s", e.message);