2 * Copyright (c) 2011-2016, JANET(UK)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of JANET(UK) nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 class TrustAnchorDialog : Dialog
36 private static Gdk.Color white = make_color(65535, 65535, 65535);
38 private Entry trust_anchor_entry;
40 public bool complete = false;
42 public TrustAnchorDialog(IdCard idcard, Window parent)
44 this.set_title(_("Trust Anchor"));
46 this.set_transient_for(parent);
47 this.modify_bg(StateType.NORMAL, white);
49 this.add_buttons(_("Connect"), ResponseType.OK,
50 _("Cancel"), ResponseType.CANCEL);
52 this.set_default_response(ResponseType.OK);
54 var content_area = this.get_content_area();
55 ((Box) content_area).set_spacing(12);
56 content_area.modify_bg(StateType.NORMAL, white);
58 Label dialog_label = new Label("");
59 dialog_label.set_alignment(0, 0);
61 string label_markup = _("<span font-weight='heavy'>You are using this identity for the first time with the following trust anchor:</span>");
63 dialog_label.set_markup(label_markup);
64 dialog_label.set_line_wrap(true);
65 dialog_label.set_width_chars(60);
67 var user_label = new Label(_("Username: ") + idcard.username);
68 user_label.set_alignment(0, 0.5f);
70 var realm_label = new Label(_("Realm: ") + idcard.issuer);
71 realm_label.set_alignment(0, 0.5f);
73 var fingerprint_label = new Label(_("SHA-256 fingerprint:"));
74 fingerprint_label.set_alignment(0, 0.5f);
76 var footprint = new TextView();
77 //footprint.activates_default = false;
78 // footprint.set_sensitive(false);
79 footprint.set_editable(false);
80 // footprint.set_text(idcard.trust_anchor.server_cert);
81 var buffer = footprint.get_buffer();
82 buffer.set_text(colonize(idcard.trust_anchor.server_cert), -1);
83 footprint.wrap_mode = WrapMode.WORD_CHAR;
85 set_atk_relation(fingerprint_label, footprint, Atk.RelationType.LABEL_FOR);
87 var footprint_width_constraint = new ScrolledWindow(null, null);
88 footprint_width_constraint.set_policy(PolicyType.NEVER, PolicyType.NEVER);
89 footprint_width_constraint.set_shadow_type(ShadowType.IN);
90 footprint_width_constraint.set_size_request(400, 60);
91 footprint_width_constraint.add_with_viewport(footprint);
93 Label confirm_label = new Label(_("Please confirm that this is the correct trust anchor."));
94 confirm_label.set_alignment(0, 0.5f);
96 var vbox = new VBox(false, 0);
97 vbox.set_border_width(6);
98 vbox.pack_start(dialog_label, true, true, 12);
99 vbox.pack_start(user_label, true, true, 2);
100 vbox.pack_start(realm_label, true, true, 2);
101 vbox.pack_start(fingerprint_label, true, true, 2);
102 vbox.pack_start(footprint_width_constraint, true, true, 2);
103 vbox.pack_start(confirm_label, true, true, 12);
105 ((Container) content_area).add(vbox);
107 this.set_border_width(6);
108 this.set_resizable(false);
110 this.response.connect(on_response);
115 private void on_response(Dialog source, int response_id)
117 switch (response_id) {
118 case ResponseType.OK:
121 case ResponseType.CANCEL:
127 // Yeah, it doesn't mean "colonize" the way you might think... :-)
128 private static string colonize(string input) {
129 return_if_fail(input.length % 2 == 0);
133 while (i < input.length) {
137 result += input[i : i + 2];