diff --git a/dotnet/IEC61850forCSharp/AcseAuthenticationParameter.cs b/dotnet/IEC61850forCSharp/AcseAuthenticationParameter.cs index 1e5496b6..a0502fbe 100644 --- a/dotnet/IEC61850forCSharp/AcseAuthenticationParameter.cs +++ b/dotnet/IEC61850forCSharp/AcseAuthenticationParameter.cs @@ -61,6 +61,12 @@ namespace IEC61850 [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] static extern int AcseAuthenticationParameter_getAuthMechanism(IntPtr self); + [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] + static extern IntPtr AcseAuthenticationParameter_getPassword(IntPtr self); + + [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] + static extern int AcseAuthenticationParameter_getPasswordLength(IntPtr self); + private IntPtr self = IntPtr.Zero; public AcseAuthenticationParameter() @@ -87,6 +93,21 @@ namespace IEC61850 { return (AcseAuthenticationMechanism)AcseAuthenticationParameter_getAuthMechanism(self); } + + public string GetPassword() + { + IntPtr password = AcseAuthenticationParameter_getPassword(self); + + if (password != IntPtr.Zero) + return Marshal.PtrToStringAnsi(password); + else + return null; + } + + public int GetPasswordLenght() + { + return AcseAuthenticationParameter_getPasswordLength(self); + } } public class IsoApplicationReference diff --git a/dotnet/server_example_access_control/Program.cs b/dotnet/server_example_access_control/Program.cs index ac67dbef..fd4919fc 100644 --- a/dotnet/server_example_access_control/Program.cs +++ b/dotnet/server_example_access_control/Program.cs @@ -347,18 +347,41 @@ namespace server_access_control bool clientAuthenticator (object parameter, AcseAuthenticationParameter authParameter, object securityToken, IsoApplicationReference isoApplicationReference) { + List passwords = parameter as List; Console.WriteLine("ACSE Authenticator:\n"); IEC61850.AcseAuthenticationMechanism acseAuthenticationMechanism = authParameter.GetAuthMechanism(); if (acseAuthenticationMechanism == IEC61850.AcseAuthenticationMechanism.ACSE_AUTH_PASSWORD) { - + int passwordLenght = authParameter.GetPasswordLenght(); + string password = authParameter.GetPassword(); + if (passwordLenght == passwords.First().Length) + { + if (password == passwords.First()) + { + securityToken = passwords.First(); + return true; + } + } + else if (passwordLenght == passwords[1].Length) + { + if (password == passwords[1]) + { + securityToken = passwords[1]; + return true; + } + } } + return false; } - iedServer.SetAuthenticator(clientAuthenticator, null); + List passwords = new List(); + passwords.Add("user1@testpw"); + passwords.Add("user2@testpw"); + + iedServer.SetAuthenticator(clientAuthenticator, passwords); iedServer.Start(102); diff --git a/src/mms/inc/iso_connection_parameters.h b/src/mms/inc/iso_connection_parameters.h index af5a3db0..32f5b854 100644 --- a/src/mms/inc/iso_connection_parameters.h +++ b/src/mms/inc/iso_connection_parameters.h @@ -97,6 +97,12 @@ AcseAuthenticationParameter_getAuthMechanism(AcseAuthenticationParameter self); LIB61850_API void AcseAuthenticationParameter_setPassword(AcseAuthenticationParameter self, char* password); +LIB61850_API const char* +AcseAuthenticationParameter_getPassword(AcseAuthenticationParameter self); + +LIB61850_API int +AcseAuthenticationParameter_getPasswordLength(AcseAuthenticationParameter self); + /** * \brief Callback function to authenticate a client diff --git a/src/mms/iso_common/iso_connection_parameters.c b/src/mms/iso_common/iso_connection_parameters.c index 2478db6e..04c8997d 100644 --- a/src/mms/iso_common/iso_connection_parameters.c +++ b/src/mms/iso_common/iso_connection_parameters.c @@ -57,6 +57,30 @@ AcseAuthenticationParameter_setPassword(AcseAuthenticationParameter self, char* self->value.password.passwordLength = strlen(password); } +const char* +AcseAuthenticationParameter_getPassword(AcseAuthenticationParameter self) +{ + if (self == NULL) + return NULL; + + if (self->mechanism != ACSE_AUTH_PASSWORD) + return NULL; + + return (char*)self->value.password.octetString; +} + +int +AcseAuthenticationParameter_getPasswordLength(AcseAuthenticationParameter self) +{ + if (self == NULL) + return 0; + + if (self->mechanism != ACSE_AUTH_PASSWORD) + return 0; + + return self->value.password.passwordLength; +} + void AcseAuthenticationParameter_setAuthMechanism(AcseAuthenticationParameter self, AcseAuthenticationMechanism mechanism) {