Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of Subject Names with specials Characters / and = using " as escaping character #2591

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions Stack/Opc.Ua.Core/Security/Certificates/X509Utils.cs
Expand Up @@ -437,8 +437,9 @@ public static List<string> ParseDistinguishedName(string name)
{
buffer.Append(value);
}

fields.Add(buffer.ToString());
//remove subject name escaping character " (used for escaping = and / ) from result as per spec Part 12 7.9.4
string filtered = buffer.Replace("\"/\"", "/").Replace("\"=\"", "=").ToString();
fields.Add(filtered);
buffer.Length = 0;
}

Expand Down
45 changes: 45 additions & 0 deletions Tests/Opc.Ua.Core.Tests/Security/Certificates/X509UtilsTest.cs
@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;

namespace Opc.Ua.Core.Tests.Security.Certificates
{
/// <summary>
/// Tests for the <see cref="X509Utils"/> class
/// </summary>
[TestFixture, Category("X509Utils")]
[Parallelizable]
[SetCulture("en-us")]
public class X509UtilsTest
{
[TestCase("CN=UA Yellow Green Server,DC=dogblueberry,O=OPC\"=\"Foundation")]
[TestCase("CN=UA Yellow Green Server,DC=dogblueberry,O=\"OPC=Foundation\"")]
public void ParseDistinguishedNameHandlesEscapingOfEqualsChar(string input)
{
List<string> result = X509Utils.ParseDistinguishedName(input);

Assert.True(result.Count == 3);
Assert.Contains("CN=UA Yellow Green Server", result);
Assert.Contains("DC=dogblueberry", result);
Assert.Contains("O=\"OPC=Foundation\"", result);
}



[TestCase("CN = UA Yellow Blue Server, DC = dogredberry, O =\"OPC/Foundation\"")]
[TestCase("CN = UA Yellow Blue Server, DC = dogredberry, O =OPC\"/\"Foundation")]
public void ParseDistinguishedNameHandlesEscapingOfSlashChar(string input)
{
List<string> result = X509Utils.ParseDistinguishedName(input);

Assert.True(result.Count == 3);
Assert.Contains("CN=UA Yellow Blue Server", result);
Assert.Contains("DC=dogredberry", result);
Assert.Contains("O=\"OPC/Foundation\"", result);
}
}
}