mirror of
https://github.com/OPCFoundation/UA-.NETStandard.git
synced 2026-10-23 10:23:13 +08:00
Merge pull request #860 from AlinMoldovean/master
Nonce validation fix in Client Session
This commit is contained in:
@@ -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.");
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user