#endif
+// For use when exporting certificates.
+static string export_directory = null;
+
class IdentityDialog : Dialog
{
private static Gdk.Color white = make_color(65535, 65535, 65535);
private Label selected_item = null;
+ // Whether to clear the card's TrustAnchor after the user selects OK
+ internal bool clear_trust_anchor = false;
+
public string display_name {
get { return displayname_entry.get_text(); }
}
add_as_vbox(content_area, realm_label, realm_entry);
add_as_vbox(content_area, password_label, password_entry);
- // var entries = new VBox(false, 6);
- // add_as_vbox(entries, displayname_label, displayname_entry);
- // add_as_vbox(entries, realm_label, realm_entry);
- // add_as_vbox(entries, username_label, username_entry);
- // add_as_vbox(entries, password_label, password_entry);
- // content_area.pack_start(entries, false, false, 0);
-
var remember_hbox = new HBox(false, 40);
remember_hbox.pack_start(new HBox(false, 0), false, false, 0);
remember_hbox.pack_start(remember_checkbutton, false, false, 0);
content_area.pack_start(remember_hbox, false, false, 2);
- // content_area.pack_start(remember_checkbutton, false, false, 2);
this.response.connect(on_response);
content_area.set_border_width(6);
if (!is_new_card)
{
+ Widget trust_anchor_box = make_trust_anchor_box(card);
+ content_area.pack_start(trust_anchor_box, false, false, 15);
+
var services_vbox = make_services_vbox();
content_area.pack_start(services_vbox);
+ var services_vbox_bottom_spacer = new Alignment(0, 0, 0, 0);
+ services_vbox_bottom_spacer.set_size_request(0, 12);
+ content_area.pack_start(services_vbox_bottom_spacer, false, false, 0);
}
if (card.is_no_identity())
this.show_all();
}
+ private Widget make_trust_anchor_box(IdCard id)
+ {
+
+ Label ta_label = new Label(_("Trust anchor: ")
+ + (id.trust_anchor.is_empty() ? _("None") : _("Enterprise provisioned")));
+ ta_label.set_alignment(0, 0.5f);
+
+ if (id.trust_anchor.is_empty()) {
+ return ta_label;
+ }
+
+
+ AttachOptions fill_and_expand = AttachOptions.EXPAND | AttachOptions.FILL;
+ AttachOptions fill = AttachOptions.FILL;
+
+ Table ta_table = new Table(6, 2, false);
+ int row = 0;
+
+ var ta_clear_button = new Button.with_label(_("Clear Trust Anchor"));
+ ta_clear_button.clicked.connect((w) => {
+ clear_trust_anchor = true;
+ ta_table.set_sensitive(false);
+ }
+ );
+
+ ta_table.attach(ta_label, 0, 1, row, row + 1, fill_and_expand, fill_and_expand, 0, 0);
+ ta_table.attach(ta_clear_button, 1, 2, row, row + 1, fill, fill, 0, 0);
+ row++;
+
+ Label added_label = new Label(_("Added : " + id.trust_anchor.datetime_added));
+ added_label.set_alignment(0, 0.5f);
+ ta_table.attach(added_label, 0, 1, row, row + 1, fill_and_expand, fill_and_expand, 20, 5);
+ row++;
+
+ if (id.trust_anchor.get_anchor_type() == TrustAnchor.TrustAnchorType.SERVER_CERT) {
+ Widget fingerprint = make_ta_fingerprint_widget(id.trust_anchor);
+ ta_table.attach(fingerprint, 0, 1, row, row + 2, fill_and_expand, fill_and_expand, 5, 5);
+
+ // To make the fingerprint box wider, try:
+ // ta_table.attach(fingerprint, 0, 2, row, row + 2, fill_and_expand, fill_and_expand, 20, 5);
+
+ }
+ else {
+ Label ca_cert_label = new Label(_("CA Certificate:"));
+ ca_cert_label.set_alignment(0, 0.5f);
+ var export_button = new Button.with_label(_("Export Certificate"));
+ //!!TODO!
+ export_button.clicked.connect((w) => {export_certificate(id);});
+
+ ta_table.attach(ca_cert_label, 0, 1, row, row + 1, fill_and_expand, fill_and_expand, 20, 0);
+ ta_table.attach(export_button, 1, 2, row, row + 1, fill, fill, 0, 0);
+ row++;
+
+ //!!TODO: When to show Subject, and when (if ever) show Subject-Altname here?
+ Label subject_label = new Label(_("Subject: ") + id.trust_anchor.subject);
+ subject_label.set_alignment(0, 0.5f);
+ ta_table.attach(subject_label, 0, 1, row, row + 1, fill_and_expand, fill_and_expand, 40, 5);
+ row++;
+
+ Label expiration_label = new Label(_("Expiration date: ") + id.trust_anchor.get_expiration_date());
+ expiration_label.set_alignment(0, 0.5f);
+ ta_table.attach(expiration_label, 0, 1, row, row + 1, fill_and_expand, fill_and_expand, 40, 5);
+ row++;
+
+ //!!TODO: What *is* this?
+ Label constraint_label = new Label(_("Constraint: "));
+ constraint_label.set_alignment(0, 0.5f);
+ ta_table.attach(constraint_label, 0, 1, row, row + 1, fill_and_expand, fill_and_expand, 20, 0);
+ row++;
+ }
+
+ return ta_table;
+
+ }
+
private static void add_as_vbox(Box content_area, Label label, Entry entry)
{
VBox vbox = new VBox(false, 2);
}
}
- private static void label_make_bold(Label label)
- {
- var font_desc = new Pango.FontDescription();
-
- font_desc.set_weight(Pango.Weight.BOLD);
-
- /* This will only affect the weight of the font. The rest is
- * from the current state of the widget, which comes from the
- * theme or user prefs, since the font desc only has the
- * weight flag turned on.
- */
- label.modify_font(font_desc);
- }
-
private VBox make_services_vbox()
{
logger.trace("make_services_vbox");
- var services_vbox_alignment = new Alignment(0, 0, 0, 1);
+ var services_vbox_alignment = new Alignment(0, 0, 1, 0);
var services_vscroll = new ScrolledWindow(null, null);
services_vscroll.set_policy(PolicyType.NEVER, PolicyType.AUTOMATIC);
services_vscroll.set_shadow_type(ShadowType.IN);
services_table.modify_bg(StateType.NORMAL, white);
var table_button_hbox = new HBox(false, 6);
- table_button_hbox.pack_start(services_vscroll, true, true, 6);
+ table_button_hbox.pack_start(services_vscroll, true, true, 4);
// Hack to prevent the button from growing vertically
VBox fixed_height = new VBox(false, 0);
fixed_height.pack_start(remove_button, false, false, 0);
- table_button_hbox.pack_start(fixed_height, false, false, 6);
+ table_button_hbox.pack_start(fixed_height, false, false, 0);
// A table doesn't have a background color, so put it in an EventBox, and
// set the EventBox's background color instead.
services_vbox_alignment.add(table_bg);
var services_vbox_title = new Label(_("Services:"));
- label_make_bold(services_vbox_title);
- services_vbox_title.set_alignment(0, (float) 0.5);
+ services_vbox_title.set_alignment(0, 0.5f);
var services_vbox = new VBox(false, 6);
- services_vbox.pack_start(services_vbox_title, false, false, 6);
- services_vbox.pack_start(table_button_hbox, true, true, 6);
+ services_vbox.pack_start(services_vbox_title, false, false, 0);
+ services_vbox.pack_start(table_button_hbox, true, true, 0);
int i = 0;
foreach (string service in card.services)
{
var label = new Label(service);
label.set_alignment((float) 0, (float) 0);
+ label.xpad = 3;
EventBox event_box = new EventBox();
event_box.modify_bg(StateType.NORMAL, white);
return false;
});
- AttachOptions opts = AttachOptions.EXPAND | AttachOptions.FILL;
- services_table.attach(event_box, 0, 1, i, i+1, opts, opts, 3, 0);
+ services_table.attach_defaults(event_box, 0, 1, i, i+1);
i++;
}
return services_vbox;
}
-
+ private void export_certificate(IdCard id)
+ {
+ var dialog = new FileChooserDialog("Save File",
+ this,
+ FileChooserAction.SAVE,
+ _("Cancel"),ResponseType.CANCEL,
+ _("Save"), ResponseType.ACCEPT,
+ null);
+ dialog.set_do_overwrite_confirmation(true);
+ if (export_directory != null) {
+ dialog.set_current_folder(export_directory);
+ }
+ // Remove slashes from the default filename.
+ string default_filename =
+ (id.display_name + ".pem").replace(Path.DIR_SEPARATOR_S, "_");
+ dialog.set_current_name(default_filename);
+ if (dialog.run() == ResponseType.ACCEPT)
+ {
+ // Export the certificate in PEM format.
+
+ const string CERT_HEADER = "-----BEGIN CERTIFICATE-----\n";
+ const string CERT_FOOTER = "\n-----END CERTIFICATE-----\n";
+
+ // Strip any embedded newlines in the certificate...
+ string cert = id.trust_anchor.ca_cert.replace("\n", "");
+
+ // Re-embed newlines every 64 chars.
+ string newcert = CERT_HEADER;
+ while (cert.length > 63) {
+ newcert += cert[0:64];
+ newcert += "\n";
+ cert = cert[64:cert.length];
+ }
+ if (cert.length > 0) {
+ newcert += cert;
+ }
+ newcert += CERT_FOOTER;
+
+ string filename = dialog.get_filename();
+ var file = File.new_for_path(filename);
+ var stream = file.replace(null, false, FileCreateFlags.PRIVATE);
+ stream.write(newcert.data);
+
+ // Save the parent directory to use as default for next save
+ export_directory = file.get_parent().get_path();
+ }
+ dialog.destroy();
+ }
}