using Gee;
-extern char* get_cert_valid_before(char* cert, int certlen, char* datebuf, int buflen);
+extern char* get_cert_valid_before(uchar* inbuf, int inlen, char* outbuf, int outlen);
+// A TrustAnchor object can be imported or installed via the API, but cannot
+// be modified by the user, other than being cleared. Hence the fields are read-only.
public class TrustAnchor : Object
{
private static const string CERT_HEADER = "-----BEGIN CERTIFICATE-----";
private string _subject = "";
private string _subject_alt = "";
private string _server_cert = "";
+ private string _datetime_added = "";
+ public bool user_verified = false;
+
+ private static string fixup (string s) {
+ return (s == null ? "" : s.strip());
+ }
+
+ public TrustAnchor(string ca_cert, string server_cert, string subject, string subject_alt, bool user_verified) {
+ _ca_cert = fixup(ca_cert);
+ _server_cert = fixup(server_cert);
+ _subject = fixup(subject);
+ _subject_alt = fixup(subject_alt);
+ this.user_verified = user_verified;
+
+ // If we're reading from store, this will be overridden (see set_datetime_added)
+ _datetime_added = "";
+ }
+
+ public TrustAnchor.empty() {
+ }
+
public string ca_cert {
get {
return _ca_cert;
}
- set {
- _ca_cert = (value ?? "");
- }
}
public string subject {
get {
return _subject;
}
- set {
- _subject = (value ?? "");
- }
}
public string subject_alt {
get {
return _subject_alt;
}
- set {
- _subject_alt = (value ?? "");
- }
}
get {
return _server_cert;
}
- set {
- _server_cert = (value ?? "");
+ }
+
+ public string datetime_added {
+ get {
+ return _datetime_added;
}
}
return server_cert == "" ? TrustAnchorType.CA_CERT : TrustAnchorType.SERVER_CERT;
}
+ internal void set_datetime_added(string datetime) {
+ _datetime_added = fixup(datetime);
+ }
+
+ internal static string format_datetime_now() {
+ DateTime now = new DateTime.now_utc();
+ string dt = now.format("%b %d %T %Y %Z");
+ return dt;
+ }
+
public int Compare(TrustAnchor other)
{
- if (this.ca_cert != other.ca_cert)
+ if (this.ca_cert != other.ca_cert) {
+ return 1;
+ }
+ if (this.subject != other.subject) {
return 1;
- if (this.subject != other.subject)
+ }
+ if (this.subject_alt != other.subject_alt) {
return 1;
- if (this.subject_alt != other.subject_alt)
+ }
+ if (this.server_cert != other.server_cert) {
return 1;
- if (this.server_cert != other.server_cert)
+ }
+ if (this.user_verified != other.user_verified) {
return 1;
+ }
+ // if (!is_empty() && this.datetime_added != other.datetime_added) {
+ // return 1;
+ // }
return 0;
}
string cert = this.ca_cert;
cert.chomp();
- if (cert.substring(0, CERT_HEADER.length) != CERT_HEADER) {
- cert = CERT_HEADER + "\n" + cert;
- }
- if (cert.substring(0, -CERT_FOOTER.length) != CERT_FOOTER) {
- cert += "\n" + CERT_FOOTER;
- }
- cert += "\n";
- IdCard.logger.trace(@"get_expiration_date: Sending " + cert);
+ uchar[] binary = Base64.decode(cert);
+ IdCard.logger.trace("get_expiration_date: encoded length=%d; decoded length=%d".printf(cert.length, binary.length));
char buf[64];
- string err = (string) get_cert_valid_before(cert, cert.length, buf, 64);
+ string err = (string) get_cert_valid_before(binary, binary.length, buf, 64);
if (err != "") {
IdCard.logger.error(@"get_expiration_date: get_cert_valid_before returned '$err'");
if (&err_out != null) {
public bool temporary {get; set; default = false; }
- public TrustAnchor trust_anchor { get; set; default = new TrustAnchor (); }
+ private TrustAnchor _trust_anchor = new TrustAnchor.empty();
+ public TrustAnchor trust_anchor {
+ get {
+ return _trust_anchor;
+ }
+ }
+
+ // For use by storage implementations.
+ internal void set_trust_anchor_from_store(TrustAnchor ta) {
+ _trust_anchor = ta;
+ }
+
+ internal void clear_trust_anchor() {
+ _trust_anchor = new TrustAnchor.empty();
+ }
public unowned string nai { get { _nai = username + "@" + issuer; return _nai;}}
diff |= 1 << DiffFlags.TRUST_ANCHOR;
// stdout.printf("Diff Flags: %x\n", diff);
+ if (this.display_name == other.display_name && diff != 0) {
+ logger.trace("Compare: Two IDs with display_name '%s', but diff_flags=%0x".printf(this.display_name, diff));
+ }
return diff;
}