2 * Copyright (c) 2011-2014, 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
32 public class TrustAnchor : Object
34 public string ca_cert {get; set; default = "";}
35 public string subject {get; set; default = "";}
36 public string subject_alt {get; set; default = "";}
37 public string server_cert {get; set; default = "";}
38 public int Compare(TrustAnchor other)
40 if (this.ca_cert != other.ca_cert)
42 if (this.subject != other.subject)
44 if (this.subject_alt != other.subject_alt)
46 if (this.server_cert != other.server_cert)
54 public string pattern;
55 public string always_confirm;
56 public int Compare(Rule other) {
57 if (this.pattern != other.pattern)
59 if (this.always_confirm != other.always_confirm)
65 public class IdCard : Object
67 public const string NO_IDENTITY = "No Identity";
71 public string display_name { get; set; default = ""; }
73 public string username { get; set; default = ""; }
75 private unowned string _password;
76 public string password {
78 return (_password!=null) ? _password : "";
81 if (_password != null) {
82 GnomeKeyring.memory_free((void *)_password);
86 _password = GnomeKeyring.memory_strdup(value);
90 public string password { get; set; default = null; }
93 public string issuer { get; set; default = ""; }
95 public Rule[] rules {get; set; default = {};}
96 public string[] services { get; set; default = {}; }
97 public bool temporary {get; set; default = false; }
99 public TrustAnchor trust_anchor { get; set; default = new TrustAnchor (); }
101 public unowned string nai { get { _nai = username + "@" + issuer; return _nai;}}
103 public bool store_password { get; set; default = false; }
105 public bool IsNoIdentity()
107 return (display_name == NO_IDENTITY);
110 public enum DiffFlags {
120 public int Compare(IdCard other)
123 if (this.display_name != other.display_name)
124 diff |= 1 << DiffFlags.DISPLAY_NAME;
126 if (this.username != other.username)
127 diff |= 1 << DiffFlags.USERNAME;
129 if (this.password != other.password)
130 diff |= 1 << DiffFlags.PASSWORD;
132 if (this.issuer != other.issuer)
133 diff |= 1 << DiffFlags.ISSUER;
135 if (CompareRules(this.rules, other.rules)!=0)
136 diff |= 1 << DiffFlags.RULES;
138 if (CompareStringArray(this.services, other.services)!=0)
139 diff |= 1 << DiffFlags.SERVICES;
141 if (this.trust_anchor.Compare(other.trust_anchor)!=0)
142 diff |= 1 << DiffFlags.TRUST_ANCHOR;
144 stdout.printf("Diff Flags: %x\n", diff);
148 public static IdCard NewNoIdentity()
150 IdCard card = new IdCard();
151 card.display_name = NO_IDENTITY;
160 public int CompareRules(Rule[] a, Rule[] b)
162 if (a.length != b.length) {
166 for (int i = 0; i < a.length; i++) {
167 if (a[i].Compare(b[i]) != 0) {
174 public int CompareStringArray(string[] a, string [] b)
176 if (a.length != b.length) {
180 for (int i = 0; i < a.length; i++) {