/// <summary>
 /// Initiates the key negotiation to establish a secure channel.
 /// </summary>
 /// <param name="keys">When this method returns, contains the information about the keys.</param>
 /// <param name="cmd">The command to send.</param>
 public static void InitiateKeys(ref SSP_KEYS keys, ref SSP_COMMAND cmd)
 {
     lock (thisLock)
     {
         var result = libHandle.InitiateSSPHostKeys(keys, cmd);
         if (!result)
         {
             throw new LibraryException("Could not initiate keys", cmd);
         }
     }
 }
Exemple #2
0
 public static bool InitiateKeys(ref SSP_KEYS keys, ref SSP_COMMAND cmd)
 {
     try
     {
         lock (m_Lock)
         {
             return(m_LibHandle.InitiateSSPHostKeys(keys, cmd));
         }
     }
     catch (Exception ex)
     {
         m_LastEx = ex;
         return(false);
     }
 }
Exemple #3
0
 public bool NegotiateKeys(ref string log)
 {
     cmd.EncryptionStatus = false;
     if (log != null)
     {
         log += "Syncing... \r\n";
     }
     cmd.CommandData[0]    = 17;
     cmd.CommandDataLength = 1;
     if (!SendCommand(ref log))
     {
         return(false);
     }
     if (log != null)
     {
         log += "Success\r\n";
     }
     eSSP.InitiateSSPHostKeys(keys, cmd);
     cmd.CommandData[0]    = 74;
     cmd.CommandDataLength = 9;
     if (log != null)
     {
         log += "Setting generator... \r\n";
     }
     for (byte b = 0; b < 8; b = (byte)(b + 1))
     {
         cmd.CommandData[b + 1] = (byte)(keys.Generator >> 8 * b);
     }
     if (!SendCommand(ref log))
     {
         return(false);
     }
     if (log != null)
     {
         log += "Success\r\n";
     }
     cmd.CommandData[0]    = 75;
     cmd.CommandDataLength = 9;
     if (log != null)
     {
         log += "Sending modulus... \r\n";
     }
     for (byte b = 0; b < 8; b = (byte)(b + 1))
     {
         cmd.CommandData[b + 1] = (byte)(keys.Modulus >> 8 * b);
     }
     if (!SendCommand(ref log))
     {
         return(false);
     }
     if (log != null)
     {
         log += "Success\r\n";
     }
     cmd.CommandData[0]    = 76;
     cmd.CommandDataLength = 9;
     if (log != null)
     {
         log += "Exchanging keys... ";
     }
     for (byte b = 0; b < 8; b = (byte)(b + 1))
     {
         cmd.CommandData[b + 1] = (byte)(keys.HostInter >> 8 * b);
     }
     if (!SendCommand(ref log))
     {
         return(false);
     }
     if (log != null)
     {
         log += "Success\r\n";
     }
     keys.SlaveInterKey = 0uL;
     for (byte b = 0; b < 8; b = (byte)(b + 1))
     {
         keys.SlaveInterKey += (ulong)cmd.ResponseData[1 + b] << 8 * b;
     }
     eSSP.CreateSSPHostEncryptionKey(keys);
     cmd.Key.FixedKey    = 81985526925837671uL;
     cmd.Key.VariableKey = keys.KeyHost;
     if (log != null)
     {
         log += "Keys successfully negotiated\r\n";
     }
     return(true);
 }
        // This function performs a number of commands in order to setup the encryption between the host and the validator.
        public bool NegotiateKeys()
        {
            // make sure encryption is off
            m_cmd.EncryptionStatus = false;

            // send sync
            Log.WriteLog("Syncing...", "CashAcceptor");
            m_cmd.CommandData[0]    = CCommands.SSP_CMD_SYNC;
            m_cmd.CommandDataLength = 1;

            if (!SendCommand())
            {
                return(false);
            }
            Log.WriteLog("Success", "CashAcceptor");

            m_eSSP.InitiateSSPHostKeys(keys, m_cmd);

            // send generator
            m_cmd.CommandData[0]    = CCommands.SSP_CMD_SET_GENERATOR;
            m_cmd.CommandDataLength = 9;
            Log.WriteLog("Setting generator...", "CashAcceptor");

            // Convert generator to bytes and add to command data.
            BitConverter.GetBytes(keys.Generator).CopyTo(m_cmd.CommandData, 1);

            if (!SendCommand())
            {
                return(false);
            }
            Log.WriteLog("Success");

            // send modulus
            m_cmd.CommandData[0]    = CCommands.SSP_CMD_SET_MODULUS;
            m_cmd.CommandDataLength = 9;
            Log.WriteLog("Sending modulus...", "CashAcceptor");

            // Convert modulus to bytes and add to command data.
            BitConverter.GetBytes(keys.Modulus).CopyTo(m_cmd.CommandData, 1);

            if (!SendCommand())
            {
                return(false);
            }
            Log.WriteLog("Success ", "CashAcceptor");

            // send key exchange
            m_cmd.CommandData[0]    = CCommands.SSP_CMD_REQUEST_KEY_EXCHANGE;
            m_cmd.CommandDataLength = 9;
            Log.WriteLog("Exchanging keys...", "CashAcceptor");

            // Convert host intermediate key to bytes and add to command data.
            BitConverter.GetBytes(keys.HostInter).CopyTo(m_cmd.CommandData, 1);


            if (!SendCommand())
            {
                return(false);
            }
            Log.WriteLog("Success", "CashAcceptor");

            // Read slave intermediate key.
            keys.SlaveInterKey = BitConverter.ToUInt64(m_cmd.ResponseData, 1);

            m_eSSP.CreateSSPHostEncryptionKey(keys);

            // get full encryption key
            m_cmd.Key.FixedKey    = 0x0123456701234567;
            m_cmd.Key.VariableKey = keys.KeyHost;

            Log.WriteLog("Keys successfully negotiated", "CashAcceptor");

            return(true);
        }
Exemple #5
0
        // This function performs a number of commands in order to setup the encryption between the host and the validator.
        public bool NegotiateKeys(TextBox log = null)
        {
            byte i;

            // make sure encryption is off
            m_cmd.EncryptionStatus = false;

            // send sync
            if (log != null)
            {
                log.AppendText("Syncing... ");
            }
            if (!SendSync())
            {
                return(false);
            }
            if (log != null)
            {
                log.AppendText("Success\r\n");
            }

            m_eSSP.InitiateSSPHostKeys(m_keys, m_cmd);

            // send generator
            m_cmd.CommandData[0]    = CCommands.SSP_CMD_SET_GENERATOR;
            m_cmd.CommandDataLength = 9;
            if (log != null)
            {
                log.AppendText("Setting generator... ");
            }
            for (i = 0; i < 8; i++)
            {
                m_cmd.CommandData[i + 1] = (byte)(m_keys.Generator >> (8 * i));
            }

            if (!SendCommand(log))
            {
                return(false);
            }
            if (log != null)
            {
                log.AppendText("Success\r\n");
            }

            // send modulus
            m_cmd.CommandData[0]    = CCommands.SSP_CMD_SET_MODULUS;
            m_cmd.CommandDataLength = 9;
            if (log != null)
            {
                log.AppendText("Sending modulus... ");
            }
            for (i = 0; i < 8; i++)
            {
                m_cmd.CommandData[i + 1] = (byte)(m_keys.Modulus >> (8 * i));
            }

            if (!SendCommand(log))
            {
                return(false);
            }
            if (log != null)
            {
                log.AppendText("Success\r\n");
            }

            // send key exchange
            m_cmd.CommandData[0]    = CCommands.SSP_CMD_REQUEST_KEY_EXCHANGE;
            m_cmd.CommandDataLength = 9;
            if (log != null)
            {
                log.AppendText("Exchanging keys... ");
            }
            for (i = 0; i < 8; i++)
            {
                m_cmd.CommandData[i + 1] = (byte)(m_keys.HostInter >> (8 * i));
            }

            if (!SendCommand(log))
            {
                return(false);
            }
            if (log != null)
            {
                log.AppendText("Success\r\n");
            }

            m_keys.SlaveInterKey = 0;
            for (i = 0; i < 8; i++)
            {
                m_keys.SlaveInterKey += (UInt64)m_cmd.ResponseData[1 + i] << (8 * i);
            }

            m_eSSP.CreateSSPHostEncryptionKey(m_keys);

            // get full encryption key
            m_cmd.Key.FixedKey    = 0x0123456701234567;
            m_cmd.Key.VariableKey = m_keys.KeyHost;

            if (log != null)
            {
                log.AppendText("Keys successfully negotiated\r\n");
            }

            return(true);
        }
Exemple #6
0
        // This function performs a number of commands in order to setup the encryption between the host and the validator.
        public bool NegotiateKeys(TextBox log = null)
        {
            byte i;

            // send sync
            if (log != null)
            {
                log.AppendText("Syncing... ");
            }
            cmd.CommandData[0]    = CCommands.SSP_CMD_SYNC;
            cmd.CommandDataLength = 1;

            if (!SendCommand(log))
            {
                return(false);
            }
            if (log != null)
            {
                log.AppendText("Success\r\n");
            }

            eSSP.InitiateSSPHostKeys(keys, cmd);

            // send generator
            cmd.CommandData[0]    = CCommands.SSP_CMD_SET_GENERATOR;
            cmd.CommandDataLength = 9;
            if (log != null)
            {
                log.AppendText("Setting generator... ");
            }
            for (i = 0; i < 8; i++)
            {
                cmd.CommandData[i + 1] = (byte)(keys.Generator >> (8 * i));
            }

            if (!SendCommand(log))
            {
                return(false);
            }
            if (log != null)
            {
                log.AppendText("Success\r\n");
            }

            // send modulus
            cmd.CommandData[0]    = CCommands.SSP_CMD_SET_MODULUS;
            cmd.CommandDataLength = 9;
            if (log != null)
            {
                log.AppendText("Sending modulus... ");
            }
            for (i = 0; i < 8; i++)
            {
                cmd.CommandData[i + 1] = (byte)(keys.Modulus >> (8 * i));
            }

            if (!SendCommand(log))
            {
                return(false);
            }
            if (log != null)
            {
                log.AppendText("Success\r\n");
            }

            // send key exchange
            cmd.CommandData[0]    = CCommands.SSP_CMD_KEY_EXCHANGE;
            cmd.CommandDataLength = 9;
            if (log != null)
            {
                log.AppendText("Exchanging keys... ");
            }
            for (i = 0; i < 8; i++)
            {
                cmd.CommandData[i + 1] = (byte)(keys.HostInter >> (8 * i));
            }

            if (!SendCommand(log))
            {
                return(false);
            }
            if (log != null)
            {
                log.AppendText("Success\r\n");
            }

            keys.SlaveInterKey = 0;
            for (i = 0; i < 8; i++)
            {
                keys.SlaveInterKey += (UInt64)cmd.ResponseData[1 + i] << (8 * i);
            }

            eSSP.CreateSSPHostEncryptionKey(keys);

            // get full encryption key
            cmd.Key.FixedKey    = 0x0123456701234567;
            cmd.Key.VariableKey = keys.KeyHost;

            if (log != null)
            {
                log.AppendText("Keys successfully negotiated\r\n");
            }

            return(true);
        }
Exemple #7
0
        // This function performs a number of commands in order to setup the encryption between the host and the validator.
        public bool NegotiateKeys(TextBox log = null)
        {
            byte   i;
            string s = "";

            // make sure encryption is off
            cmd.EncryptionStatus = false;

            // open com port
            s += "Opening com port... ";
            if (eSSP.OpenSSPComPort(cmd) == false)
            {
                return(false);
            }
            s += "Success\r\n";

            // send sync
            s += "Syncing... ";
            cmd.CommandData[0]    = CCommands.SSP_CMD_SYNC;
            cmd.CommandDataLength = 1;

            if (!SendCommand(log))
            {
                return(false);
            }
            s += "Success\r\n";

            eSSP.InitiateSSPHostKeys(keys, cmd);

            // send generator
            cmd.CommandData[0]    = CCommands.SSP_CMD_SET_GENERATOR;
            cmd.CommandDataLength = 9;
            s += "Setting generator... ";
            for (i = 0; i < 8; i++)
            {
                cmd.CommandData[i + 1] = (byte)(keys.Generator >> (8 * i));
            }

            if (!SendCommand(log))
            {
                return(false);
            }
            s += "Success\r\n";

            // send modulus
            cmd.CommandData[0]    = CCommands.SSP_CMD_SET_MODULUS;
            cmd.CommandDataLength = 9;
            s += "Sending modulus... ";
            for (i = 0; i < 8; i++)
            {
                cmd.CommandData[i + 1] = (byte)(keys.Modulus >> (8 * i));
            }

            if (!SendCommand(log))
            {
                return(false);
            }
            s += "Success\r\n";

            // send key exchange
            cmd.CommandData[0]    = CCommands.SSP_CMD_KEY_EXCHANGE;
            cmd.CommandDataLength = 9;
            s += "Exchanging keys... ";
            for (i = 0; i < 8; i++)
            {
                cmd.CommandData[i + 1] = (byte)(keys.HostInter >> (8 * i));
            }

            if (!SendCommand(log))
            {
                return(false);
            }
            s += "Success\r\n";

            keys.SlaveInterKey = 0;
            for (i = 0; i < 8; i++)
            {
                keys.SlaveInterKey += (UInt64)cmd.ResponseData[1 + i] << (8 * i);
            }

            eSSP.CreateSSPHostEncryptionKey(keys);

            // get full encryption key
            cmd.Key.FixedKey    = 0x0123456701234567;
            cmd.Key.VariableKey = keys.KeyHost;

            s += "Keys successfully negotiated\r\n";

            if (log != null)
            {
                log.AppendText(s);
            }
            return(true);
        }
        public bool NegotiateKeys()
        {
            byte i;

            cmd.EncryptionStatus = false;

            // send sync
            cmd.CommandData[0]    = CCommands.SSP_CMD_SYNC;
            cmd.CommandDataLength = 1;
            if (!SendCommand())
            {
                return(false);
            }

            eSSP.InitiateSSPHostKeys(keys, cmd);

            // send generator
            cmd.CommandData[0]    = CCommands.SSP_CMD_SET_GENERATOR;
            cmd.CommandDataLength = 9;

            for (i = 0; i < 8; i++)
            {
                cmd.CommandData[i + 1] = (byte)(keys.Generator >> (8 * i));
            }
            if (!SendCommand())
            {
                return(false);
            }

            // send modulus
            cmd.CommandData[0]    = CCommands.SSP_CMD_SET_MODULUS;
            cmd.CommandDataLength = 9;

            for (i = 0; i < 8; i++)
            {
                cmd.CommandData[i + 1] = (byte)(keys.Modulus >> (8 * i));
            }
            if (!SendCommand())
            {
                return(false);
            }

            // send key exchange
            cmd.CommandData[0]    = CCommands.SSP_CMD_KEY_EXCHANGE;
            cmd.CommandDataLength = 9;

            for (i = 0; i < 8; i++)
            {
                cmd.CommandData[i + 1] = (byte)(keys.HostInter >> (8 * i));
            }
            if (!SendCommand())
            {
                return(false);
            }

            keys.SlaveInterKey = 0;
            for (i = 0; i < 8; i++)
            {
                keys.SlaveInterKey += (UInt64)cmd.ResponseData[1 + i] << (8 * i);
            }

            eSSP.CreateSSPHostEncryptionKey(keys);

            // get full encryption key
            cmd.Key.FixedKey    = 0x0123456701234567;
            cmd.Key.VariableKey = keys.KeyHost;

            return(true);
        }