BUG-2544: Enabled TLS1.1 & 1.2 to fix jira connectivity and do not use the JIRA session support as this was deprecated.

This commit is contained in:
Krom, Robertus 2020-02-11 16:04:09 +01:00
commit 41baf27d84
4 changed files with 31 additions and 41 deletions

View file

@ -20,6 +20,7 @@
*/ */
using System; using System;
using System.Globalization; using System.Globalization;
using System.Net;
using System.Reflection; using System.Reflection;
// Remove AppendPrivatePath warning: // Remove AppendPrivatePath warning:
@ -47,7 +48,11 @@ namespace Greenshot {
} }
[STAThread] [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.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.InvariantCulture; CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.InvariantCulture;
MainForm.Start(args); MainForm.Start(args);

View file

@ -1,4 +1,3 @@
/* /*
* Greenshot - a free and open source screenshot tool * Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2020 Thomas Braun, Jens Klingen, Robin Krom * Copyright (C) 2007-2020 Thomas Braun, Jens Klingen, Robin Krom
@ -45,9 +44,6 @@ namespace GreenshotJiraPlugin {
private static readonly CoreConfiguration CoreConfig = IniConfig.GetIniSection<CoreConfiguration>(); private static readonly CoreConfiguration CoreConfig = IniConfig.GetIniSection<CoreConfiguration>();
// Used to remove the wsdl information from the old SOAP Uri // Used to remove the wsdl information from the old SOAP Uri
public const string DefaultPostfix = "/rpc/soap/jirasoapservice-v2?wsdl"; 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 IJiraClient _jiraClient;
private IssueTypeBitmapCache _issueTypeBitmapCache; private IssueTypeBitmapCache _issueTypeBitmapCache;
@ -72,7 +68,7 @@ namespace GreenshotJiraPlugin {
public void Dispose() { public void Dispose() {
if (_jiraClient != null) if (_jiraClient != null)
{ {
Task.Run(async () => await LogoutAsync()).Wait(); Logout();
} }
FavIcon?.Dispose(); FavIcon?.Dispose();
} }
@ -83,7 +79,6 @@ namespace GreenshotJiraPlugin {
public JiraConnector() public JiraConnector()
{ {
JiraConfig.Url = JiraConfig.Url.Replace(DefaultPostfix, ""); JiraConfig.Url = JiraConfig.Url.Replace(DefaultPostfix, "");
_timeout = JiraConfig.Timeout;
} }
/// <summary> /// <summary>
@ -96,7 +91,7 @@ namespace GreenshotJiraPlugin {
/// <summary> /// <summary>
/// Internal login which catches the exceptions /// Internal login which catches the exceptions
/// </summary> /// </summary>
/// <returns>true if login was done sucessfully</returns> /// <returns>true if login was done successfully</returns>
private async Task<bool> DoLoginAsync(string user, string password, CancellationToken cancellationToken = default) private async Task<bool> DoLoginAsync(string user, string password, CancellationToken cancellationToken = default)
{ {
if (string.IsNullOrEmpty(user) || string.IsNullOrEmpty(password)) if (string.IsNullOrEmpty(user) || string.IsNullOrEmpty(password))
@ -105,11 +100,11 @@ namespace GreenshotJiraPlugin {
} }
_jiraClient = JiraClient.Create(new Uri(JiraConfig.Url)); _jiraClient = JiraClient.Create(new Uri(JiraConfig.Url));
_jiraClient.Behaviour.SetConfig(new SvgConfiguration { Width = CoreConfig.IconSize.Width, Height = CoreConfig.IconSize.Height }); _jiraClient.Behaviour.SetConfig(new SvgConfiguration { Width = CoreConfig.IconSize.Width, Height = CoreConfig.IconSize.Height });
_jiraClient.SetBasicAuthentication(user, password);
_issueTypeBitmapCache = new IssueTypeBitmapCache(_jiraClient); _issueTypeBitmapCache = new IssueTypeBitmapCache(_jiraClient);
try try
{ {
await _jiraClient.Session.StartAsync(user, password, cancellationToken);
Monitor = new JiraMonitor(); Monitor = new JiraMonitor();
await Monitor.AddJiraInstanceAsync(_jiraClient, cancellationToken); await Monitor.AddJiraInstanceAsync(_jiraClient, cancellationToken);
@ -124,8 +119,10 @@ namespace GreenshotJiraPlugin {
Log.Warn("Exception details: ", ex); 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 false;
} }
return true; return true;
@ -137,7 +134,7 @@ namespace GreenshotJiraPlugin {
/// </summary> /// </summary>
/// <returns>Task</returns> /// <returns>Task</returns>
public async Task LoginAsync(CancellationToken cancellationToken = default) { public async Task LoginAsync(CancellationToken cancellationToken = default) {
await LogoutAsync(cancellationToken); Logout();
try { try {
// Get the system name, so the user knows where to login to // Get the system name, so the user knows where to login to
var credentialsDialog = new CredentialsDialog(JiraConfig.Url) var credentialsDialog = new CredentialsDialog(JiraConfig.Url)
@ -149,8 +146,7 @@ namespace GreenshotJiraPlugin {
if (credentialsDialog.SaveChecked) { if (credentialsDialog.SaveChecked) {
credentialsDialog.Confirm(true); credentialsDialog.Confirm(true);
} }
_loggedIn = true; IsLoggedIn = true;
_loggedInTime = DateTime.Now;
return; return;
} }
// Login failed, confirm this // Login failed, confirm this
@ -175,14 +171,11 @@ namespace GreenshotJiraPlugin {
/// <summary> /// <summary>
/// End the session, if there was one /// End the session, if there was one
/// </summary> /// </summary>
public async Task LogoutAsync(CancellationToken cancellationToken = default) { public void Logout() {
if (_jiraClient != null && _loggedIn) if (_jiraClient == null || !IsLoggedIn) return;
{ Monitor.Dispose();
Monitor.Dispose(); IsLoggedIn = false;
await _jiraClient.Session.EndAsync(cancellationToken); }
_loggedIn = false;
}
}
/// <summary> /// <summary>
/// check the login credentials, to prevent timeouts of the session, or makes a login /// check the login credentials, to prevent timeouts of the session, or makes a login
@ -190,18 +183,13 @@ namespace GreenshotJiraPlugin {
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
private async Task CheckCredentialsAsync(CancellationToken cancellationToken = default) { private async Task CheckCredentialsAsync(CancellationToken cancellationToken = default) {
if (_loggedIn) { if (!IsLoggedIn) {
if (_loggedInTime.AddMinutes(_timeout-1).CompareTo(DateTime.Now) < 0) {
await LogoutAsync(cancellationToken);
await LoginAsync(cancellationToken);
}
} else {
await LoginAsync(cancellationToken); await LoginAsync(cancellationToken);
} }
} }
/// <summary> /// <summary>
/// Get the favourite filters /// Get the favorite filters
/// </summary> /// </summary>
/// <returns>List with filters</returns> /// <returns>List with filters</returns>
public async Task<IList<Filter>> GetFavoriteFiltersAsync(CancellationToken cancellationToken = default) public async Task<IList<Filter>> GetFavoriteFiltersAsync(CancellationToken cancellationToken = default)
@ -287,9 +275,9 @@ namespace GreenshotJiraPlugin {
/// </summary> /// </summary>
public Uri JiraBaseUri => _jiraClient.JiraBaseUri; public Uri JiraBaseUri => _jiraClient.JiraBaseUri;
/// <summary> /// <summary>
/// Is the user "logged in? /// Is the user "logged in?
/// </summary> /// </summary>
public bool IsLoggedIn => _loggedIn; public bool IsLoggedIn { get; private set; }
} }
} }

View file

@ -111,8 +111,8 @@ namespace GreenshotJiraPlugin
/// <summary> /// <summary>
/// Add an instance of a JIRA system /// Add an instance of a JIRA system
/// </summary> /// </summary>
/// <param name="jiraInstance"></param> /// <param name="jiraInstance">IJiraClient</param>
/// <param name="token"></param> /// <param name="token">CancellationToken</param>
public async Task AddJiraInstanceAsync(IJiraClient jiraInstance, CancellationToken token = default) public async Task AddJiraInstanceAsync(IJiraClient jiraInstance, CancellationToken token = default)
{ {
_jiraInstances.Add(jiraInstance); _jiraInstances.Add(jiraInstance);

View file

@ -142,11 +142,8 @@ namespace GreenshotJiraPlugin {
public void Shutdown() { public void Shutdown() {
Log.Debug("Jira Plugin shutdown."); Log.Debug("Jira Plugin shutdown.");
if (JiraConnector != null) JiraConnector?.Logout();
{ }
Task.Run(async () => await JiraConnector.LogoutAsync());
}
}
/// <summary> /// <summary>
/// Implementation of the IPlugin.Configure /// Implementation of the IPlugin.Configure
@ -157,9 +154,9 @@ namespace GreenshotJiraPlugin {
// check for re-login // check for re-login
if (JiraConnector != null && JiraConnector.IsLoggedIn && !string.IsNullOrEmpty(url)) { if (JiraConnector != null && JiraConnector.IsLoggedIn && !string.IsNullOrEmpty(url)) {
if (!url.Equals(_config.Url)) { if (!url.Equals(_config.Url)) {
JiraConnector.Logout();
Task.Run(async () => Task.Run(async () =>
{ {
await JiraConnector.LogoutAsync();
await JiraConnector.LoginAsync(); await JiraConnector.LoginAsync();
}); });
} }