Ejemplo n.º 1
0
 byte[][] IGXDLMSBase.Invoke(object sender, int index, Object parameters)
 {
     //Check reply_to_HLS_authentication
     if (index == 8)
     {
         GXDLMSServerBase s = sender as GXDLMSServerBase;
         if (s == null)
         {
             throw new ArgumentException("sender");
         }
         GXDLMS b = s.m_Base;
         //Get server Challenge.
         List <byte> challenge = null;
         List <byte> CtoS      = null;
         //Find shared secret
         foreach (GXAuthentication it in s.Authentications)
         {
             if (it.Type == b.Authentication)
             {
                 CtoS      = new List <byte>(it.SharedSecret);
                 challenge = new List <byte>(it.SharedSecret);
                 challenge.AddRange(b.StoCChallenge);
                 break;
             }
         }
         byte[] serverChallenge = GXDLMS.Chipher(b.Authentication, challenge.ToArray(), null);
         byte[] clientChallenge = (byte[])parameters;
         int    pos             = 0;
         if (GXCommon.Compare(clientChallenge, ref pos, serverChallenge))
         {
             CtoS.AddRange(b.CtoSChallenge);
             return(s.Acknowledge(Command.WriteResponse, 0, GXDLMS.Chipher(b.Authentication, CtoS.ToArray(), null), DataType.OctetString));
         }
         else
         {
             //Return HW error.
             return(s.ServerReportError(Command.MethodRequest, 1));
         }
     }
     else
     {
         throw new ArgumentException("Invoke failed. Invalid attribute index.");
     }
 }