(LIB61850-513)

->Extend AcseAuthenticationParameter to get password
v1.6
Maxson Ramon dos Anjos Medeiros 4 weeks ago
parent b2631f1b25
commit 779c038d5c

@ -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

@ -347,18 +347,41 @@ namespace server_access_control
bool clientAuthenticator (object parameter, AcseAuthenticationParameter authParameter, object securityToken, IsoApplicationReference isoApplicationReference)
{
List<string> passwords = parameter as List<string>;
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<string> passwords = new List<string>();
passwords.Add("user1@testpw");
passwords.Add("user2@testpw");
iedServer.SetAuthenticator(clientAuthenticator, passwords);
iedServer.Start(102);

@ -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

@ -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)
{

Loading…
Cancel
Save