mirror of
https://github.com/OPCFoundation/UA-.NETStandard.git
synced 2026-10-28 22:55:49 +08:00
Fix ip address parser, domain name check and reconnect (#333)
* bug fix in cert parser: return normalized ipaddress string instead of hex byte array string * connect with domain cert check, * fix ip address compares, * add dialog to connect anyway if cert domain check fails * fix reconnect case when cert domain check fails
This commit is contained in:
@@ -27,19 +27,14 @@
|
||||
* http://opcfoundation.org/License/MIT/1.00/
|
||||
* ======================================================================*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
|
||||
using Opc.Ua.Client;
|
||||
using Opc.Ua.Client.Controls;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Opc.Ua.Sample.Controls
|
||||
{
|
||||
@@ -58,6 +53,7 @@ namespace Opc.Ua.Sample.Controls
|
||||
private const string m_BrowseCertificates = "<Browse...>";
|
||||
private static long m_Counter = 0;
|
||||
private IList<string> m_preferredLocales;
|
||||
private bool m_checkDomain = true;
|
||||
#endregion
|
||||
|
||||
#region Public Interface
|
||||
@@ -163,7 +159,7 @@ namespace Opc.Ua.Sample.Controls
|
||||
|
||||
Cursor = Cursors.WaitCursor;
|
||||
|
||||
ThreadPool.QueueUserWorkItem(Open, new object[] { m_session, SessionNameTB.Text, identity, m_preferredLocales });
|
||||
ThreadPool.QueueUserWorkItem(Open, new object[] { m_session, SessionNameTB.Text, identity, m_preferredLocales, m_checkDomain });
|
||||
|
||||
CancelBTN.Enabled = false;
|
||||
OkBTN.Enabled = false;
|
||||
@@ -194,6 +190,35 @@ namespace Opc.Ua.Sample.Controls
|
||||
{
|
||||
Cursor = Cursors.Default;
|
||||
|
||||
ServiceResultException sre = e as ServiceResultException;
|
||||
if (sre != null)
|
||||
{
|
||||
if (m_checkDomain && sre.StatusCode == StatusCodes.BadCertificateHostNameInvalid)
|
||||
{
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
|
||||
buffer.AppendFormat(sre.Message);
|
||||
buffer.AppendFormat("\r\n\r\nRetry without certificate hostname validation?");
|
||||
|
||||
DialogResult result = MessageBox.Show(
|
||||
buffer.ToString(),
|
||||
"Exception: BadCertificateHostNameInvalid",
|
||||
MessageBoxButtons.YesNo,
|
||||
MessageBoxIcon.Warning);
|
||||
|
||||
if (result == DialogResult.Yes)
|
||||
{
|
||||
m_checkDomain = false;
|
||||
OkBTN.Enabled = true;
|
||||
OkBTN.PerformClick();
|
||||
return;
|
||||
}
|
||||
|
||||
DialogResult = DialogResult.OK;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (e != null)
|
||||
{
|
||||
GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), (Exception)e);
|
||||
@@ -228,9 +253,10 @@ namespace Opc.Ua.Sample.Controls
|
||||
string sessionName = ((object[])state)[1] as string;
|
||||
IUserIdentity identity = ((object[])state)[2] as IUserIdentity;
|
||||
IList<string> preferredLocales = ((object[])state)[3] as IList<string>;
|
||||
bool? checkDomain = ((object[])state)[4] as bool?;
|
||||
|
||||
// open the session.
|
||||
session.Open(sessionName, (uint)session.SessionTimeout, identity, preferredLocales);
|
||||
session.Open(sessionName, (uint)session.SessionTimeout, identity, preferredLocales, checkDomain ?? true);
|
||||
|
||||
OpenComplete(null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user