Merge pull request #860 from AlinMoldovean/master

Nonce validation fix in Client Session
This commit is contained in:
Alin Moldovean
2019-12-02 16:08:34 +02:00
committed by GitHub
2 changed files with 10 additions and 2 deletions
@@ -316,7 +316,7 @@ namespace Opc.Ua.Client
if (identity!= null && identity.TokenType != UserTokenType.Anonymous)
{
// the server nonce should be validated if the token includes a secret.
if (!Utils.Nonce.ValidateNonce(serverNonce, MessageSecurityMode.SignAndEncrypt, securityPolicyUri))
if (!Utils.Nonce.ValidateNonce(serverNonce, MessageSecurityMode.SignAndEncrypt, (uint)m_configuration.SecurityConfiguration.NonceLength))
{
throw ServiceResultException.Create(StatusCodes.BadNonceInvalid, "Server nonce is not the correct length or not random enough.");
}
+9 -1
View File
@@ -2664,6 +2664,14 @@ namespace Opc.Ua
/// Validates the nonce for a message security mode and security policy.
/// </summary>
public static bool ValidateNonce(byte[] nonce, MessageSecurityMode securityMode, string securityPolicyUri)
{
return ValidateNonce(nonce, securityMode, GetNonceLength(securityPolicyUri));
}
/// <summary>
/// Validates the nonce for a message security mode and a minimum length.
/// </summary>
public static bool ValidateNonce(byte[] nonce, MessageSecurityMode securityMode, uint minNonceLength)
{
// no nonce needed for no security.
if (securityMode == MessageSecurityMode.None)
@@ -2672,7 +2680,7 @@ namespace Opc.Ua
}
// check the length.
if (nonce == null || nonce.Length < GetNonceLength(securityPolicyUri))
if (nonce == null || nonce.Length < minNonceLength)
{
return false;
}