diff --git a/Greenshot/GreenshotMain.cs b/Greenshot/GreenshotMain.cs index c6fd9a714..b6f448c25 100644 --- a/Greenshot/GreenshotMain.cs +++ b/Greenshot/GreenshotMain.cs @@ -20,6 +20,7 @@ */ using System; using System.Globalization; +using System.Net; using System.Reflection; // Remove AppendPrivatePath warning: @@ -47,7 +48,11 @@ namespace Greenshot { } [STAThread] - public static void Main(string[] args) { + public static void Main(string[] args) + { + // Enable TLS 1.2 support + ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; + CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture; CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.InvariantCulture; MainForm.Start(args); diff --git a/GreenshotJiraPlugin/JiraConnector.cs b/GreenshotJiraPlugin/JiraConnector.cs index 4440be3e3..0d0925fa2 100644 --- a/GreenshotJiraPlugin/JiraConnector.cs +++ b/GreenshotJiraPlugin/JiraConnector.cs @@ -1,4 +1,3 @@ - /* * Greenshot - a free and open source screenshot tool * Copyright (C) 2007-2020 Thomas Braun, Jens Klingen, Robin Krom @@ -45,9 +44,6 @@ namespace GreenshotJiraPlugin { private static readonly CoreConfiguration CoreConfig = IniConfig.GetIniSection(); // Used to remove the wsdl information from the old SOAP Uri public const string DefaultPostfix = "/rpc/soap/jirasoapservice-v2?wsdl"; - private DateTimeOffset _loggedInTime = DateTimeOffset.MinValue; - private bool _loggedIn; - private readonly int _timeout; private IJiraClient _jiraClient; private IssueTypeBitmapCache _issueTypeBitmapCache; @@ -72,7 +68,7 @@ namespace GreenshotJiraPlugin { public void Dispose() { if (_jiraClient != null) { - Task.Run(async () => await LogoutAsync()).Wait(); + Logout(); } FavIcon?.Dispose(); } @@ -83,7 +79,6 @@ namespace GreenshotJiraPlugin { public JiraConnector() { JiraConfig.Url = JiraConfig.Url.Replace(DefaultPostfix, ""); - _timeout = JiraConfig.Timeout; } /// @@ -96,7 +91,7 @@ namespace GreenshotJiraPlugin { /// /// Internal login which catches the exceptions /// - /// true if login was done sucessfully + /// true if login was done successfully private async Task DoLoginAsync(string user, string password, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(user) || string.IsNullOrEmpty(password)) @@ -105,11 +100,11 @@ namespace GreenshotJiraPlugin { } _jiraClient = JiraClient.Create(new Uri(JiraConfig.Url)); _jiraClient.Behaviour.SetConfig(new SvgConfiguration { Width = CoreConfig.IconSize.Width, Height = CoreConfig.IconSize.Height }); + _jiraClient.SetBasicAuthentication(user, password); _issueTypeBitmapCache = new IssueTypeBitmapCache(_jiraClient); try { - await _jiraClient.Session.StartAsync(user, password, cancellationToken); Monitor = new JiraMonitor(); await Monitor.AddJiraInstanceAsync(_jiraClient, cancellationToken); @@ -124,8 +119,10 @@ namespace GreenshotJiraPlugin { Log.Warn("Exception details: ", ex); } } - catch (Exception) + catch (Exception ex2) { + Log.WarnFormat("Couldn't connect to JIRA {0}", JiraConfig.Url); + Log.Warn("Exception details: ", ex2); return false; } return true; @@ -137,7 +134,7 @@ namespace GreenshotJiraPlugin { /// /// Task public async Task LoginAsync(CancellationToken cancellationToken = default) { - await LogoutAsync(cancellationToken); + Logout(); try { // Get the system name, so the user knows where to login to var credentialsDialog = new CredentialsDialog(JiraConfig.Url) @@ -149,8 +146,7 @@ namespace GreenshotJiraPlugin { if (credentialsDialog.SaveChecked) { credentialsDialog.Confirm(true); } - _loggedIn = true; - _loggedInTime = DateTime.Now; + IsLoggedIn = true; return; } // Login failed, confirm this @@ -175,14 +171,11 @@ namespace GreenshotJiraPlugin { /// /// End the session, if there was one /// - public async Task LogoutAsync(CancellationToken cancellationToken = default) { - if (_jiraClient != null && _loggedIn) - { - Monitor.Dispose(); - await _jiraClient.Session.EndAsync(cancellationToken); - _loggedIn = false; - } - } + public void Logout() { + if (_jiraClient == null || !IsLoggedIn) return; + Monitor.Dispose(); + IsLoggedIn = false; + } /// /// check the login credentials, to prevent timeouts of the session, or makes a login @@ -190,18 +183,13 @@ namespace GreenshotJiraPlugin { /// /// private async Task CheckCredentialsAsync(CancellationToken cancellationToken = default) { - if (_loggedIn) { - if (_loggedInTime.AddMinutes(_timeout-1).CompareTo(DateTime.Now) < 0) { - await LogoutAsync(cancellationToken); - await LoginAsync(cancellationToken); - } - } else { + if (!IsLoggedIn) { await LoginAsync(cancellationToken); } } /// - /// Get the favourite filters + /// Get the favorite filters /// /// List with filters public async Task> GetFavoriteFiltersAsync(CancellationToken cancellationToken = default) @@ -287,9 +275,9 @@ namespace GreenshotJiraPlugin { /// public Uri JiraBaseUri => _jiraClient.JiraBaseUri; - /// - /// Is the user "logged in? - /// - public bool IsLoggedIn => _loggedIn; - } + /// + /// Is the user "logged in? + /// + public bool IsLoggedIn { get; private set; } + } } \ No newline at end of file diff --git a/GreenshotJiraPlugin/JiraMonitor.cs b/GreenshotJiraPlugin/JiraMonitor.cs index ebbd748e4..4fcb083a7 100644 --- a/GreenshotJiraPlugin/JiraMonitor.cs +++ b/GreenshotJiraPlugin/JiraMonitor.cs @@ -111,8 +111,8 @@ namespace GreenshotJiraPlugin /// /// Add an instance of a JIRA system /// - /// - /// + /// IJiraClient + /// CancellationToken public async Task AddJiraInstanceAsync(IJiraClient jiraInstance, CancellationToken token = default) { _jiraInstances.Add(jiraInstance); diff --git a/GreenshotJiraPlugin/JiraPlugin.cs b/GreenshotJiraPlugin/JiraPlugin.cs index 1f0ade69e..1b18c0ef4 100644 --- a/GreenshotJiraPlugin/JiraPlugin.cs +++ b/GreenshotJiraPlugin/JiraPlugin.cs @@ -142,11 +142,8 @@ namespace GreenshotJiraPlugin { public void Shutdown() { Log.Debug("Jira Plugin shutdown."); - if (JiraConnector != null) - { - Task.Run(async () => await JiraConnector.LogoutAsync()); - } - } + JiraConnector?.Logout(); + } /// /// Implementation of the IPlugin.Configure @@ -157,9 +154,9 @@ namespace GreenshotJiraPlugin { // check for re-login if (JiraConnector != null && JiraConnector.IsLoggedIn && !string.IsNullOrEmpty(url)) { if (!url.Equals(_config.Url)) { + JiraConnector.Logout(); Task.Run(async () => { - await JiraConnector.LogoutAsync(); await JiraConnector.LoginAsync(); }); }