Skip to content

Commit

Permalink
Don't get cert twice
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit committed Oct 10, 2023
1 parent 814aa9d commit 01716c3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -163,23 +163,18 @@ public class Captive.MainWindow : Hdy.ApplicationWindow {

cert_button.sensitive = web_view.security != NONE && web_view.security != LOADING;

TlsCertificate cert;
TlsCertificateFlags cert_flags;

if (!web_view.get_tls_info (out cert, out cert_flags)) {
if (web_view.certificate == null) {
cert_button.active = false;
return;
}

var gcr_cert = new Gcr.SimpleCertificate (cert.certificate.data);

cert_expiry.label = _("Expires %s").printf (
gcr_cert.expiry_date.format (Granite.DateTime.get_default_date_format (false, true, true))
web_view.certificate.expiry_date.format (Granite.DateTime.get_default_date_format (false, true, true))
);

cert_issuer.label = _("Issued by “%s").printf (gcr_cert.issuer_name);
cert_issuer.label = _("Issued by “%s").printf (web_view.certificate.issuer_name);

cert_subject.label = gcr_cert.subject_name;
cert_subject.label = web_view.certificate.subject_name;
}

private bool is_privacy_mode_enabled () {
Expand Down
3 changes: 3 additions & 0 deletions src/TabbedWebView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
public class Captive.TabbedWebView : WebKit.WebView {
public bool load_cookies { get; construct; }
public Security security { get; private set; }
public Gcr.SimpleCertificate? certificate { get; private set; default = null; }

public enum Security {
NONE,
Expand Down Expand Up @@ -110,10 +111,12 @@ public class Captive.TabbedWebView : WebKit.WebView {
if (!get_tls_info (out cert, out cert_flags)) {
// The page is served over HTTP
is_secure = false;
certificate = null;
} else {
// The page is served over HTTPS, if cert_flags is set then there's
// some problem with the certificate provided by the website.
is_secure = (cert_flags == 0);
certificate = new Gcr.SimpleCertificate (cert.certificate.data);
}

if (is_secure) {
Expand Down

0 comments on commit 01716c3

Please sign in to comment.