Exemple #1
0
        public void GenerateAndPrintComponentTest()
        {
            ConfigHelpers.SetAuthorizedState(true);
            Extensions.RndMachine = new NotSoRandom();
            string rsp;
            string rspAfterIo;

            TestMessageWithIo("001U", new GenerateAndPrintComponent_A2(), out rsp, out rspAfterIo);
            Assert.AreEqual("00U37C214786596A294ED92DBA27208C13B", rsp);
            Assert.IsNotNullOrEmpty(rspAfterIo);

            TestMessageWithIo("001T", new GenerateAndPrintComponent_A2(), out rsp, out rspAfterIo);
            Assert.AreEqual("00T07481EB9B807DF6E4AAF814F18038290CE01C666B4B2F652", rsp);
            Assert.IsNotNullOrEmpty(rspAfterIo);

            TestMessageWithIo("002X", new GenerateAndPrintComponent_A2(), out rsp, out rspAfterIo);
            Assert.AreEqual("00X3A6F3B5520B820EC3A6F3B5520B820EC", rsp);
            Assert.IsNotNullOrEmpty(rspAfterIo);

            TestMessageWithIo("002Y", new GenerateAndPrintComponent_A2(), out rsp, out rspAfterIo);
            Assert.AreEqual("00Y3A6F3B5520B820EC3A6F3B5520B820EC3A6F3B5520B820EC", rsp);
            Assert.IsNotNullOrEmpty(rspAfterIo);

            Extensions.RndMachine = new RandomMachine();

            ConfigHelpers.SetAuthorizedState(false);
            Assert.IsTrue(CommandExplorer.GetCommand(CommandType.Host, "A2").RequiresAuthorizedState);
        }
Exemple #2
0
        public void FormZmkFromTwoToNineComponentsTest()
        {
            ConfigHelpers.SetAuthorizedState(true);
            ConfigHelpers.SetLegacyMode(false);

            Assert.AreEqual("00C0BC1DFFC449A402DAB71250CA5869CC8CE39643DA9A9B99",
                            TestMessage(
                                "32EC8A0412B5D0E86E3C1E5ABFA19B3F5FF43378ED5D85B1BC465BF000335FBF1A235EDF4C58A2CB0C84641D07319CF21",
                                new FormZMKFromTwoToNineComponents_GY()));
            Assert.AreEqual("00U369835189A058604EB7F84EAE10C7D048CE396",
                            TestMessage(
                                "32EC8A0412B5D0E86E3C1E5ABFA19B3F5FF43378ED5D85B1BC465BF000335FBF1A235EDF4C58A2CB0C84641D07319CF21;0U1",
                                new FormZMKFromTwoToNineComponents_GY()));
            Assert.AreEqual("00XC0BC1DFFC449A402DAB71250CA5869CC8CE39643DA9A9B99",
                            TestMessage(
                                "32EC8A0412B5D0E86E3C1E5ABFA19B3F5FF43378ED5D85B1BC465BF000335FBF1A235EDF4C58A2CB0C84641D07319CF21;0X0",
                                new FormZMKFromTwoToNineComponents_GY()));

            Assert.AreEqual("15",
                            TestMessage(
                                "3U2EC8A0412B5D0E86E3C1E5ABFA19B3F5FF43378ED5D85B1BC465BF000335FBF1A235EDF4C58A2CB0C84641D07319CF21;0X0",
                                new FormZMKFromTwoToNineComponents_GY()));
            ConfigHelpers.SetAuthorizedState(false);
            Assert.IsTrue(CommandExplorer.GetCommand(CommandType.Host, "GY").RequiresAuthorizedState);
        }
Exemple #3
0
 public void DecryptEncryptedPinTest()
 {
     ConfigHelpers.SetAuthorizedState(true);
     Assert.AreEqual("001234F", TestMessage("12345678901201234", new DecryptEncryptedPIN_NG()));
     ConfigHelpers.SetAuthorizedState(false);
     Assert.IsTrue(CommandExplorer.GetCommand(CommandType.Host, "NG").RequiresAuthorizedState);
 }
Exemple #4
0
        public void EncryptClearPinTest()
        {
            ConfigHelpers.SetAuthorizedState(true);
            Assert.AreEqual("0001234", TestMessage("1234F" + "012345678901", new EncryptClearPIN_BA()));
            Assert.AreEqual("0001234", TestMessage("01234" + "012345678901", new EncryptClearPIN_BA()));

            ConfigHelpers.SetAuthorizedState(false);
            Assert.IsTrue(CommandExplorer.GetCommand(CommandType.Host, "BA").RequiresAuthorizedState);
        }
Exemple #5
0
        public void FormZmkFromThreeComponentsTest()
        {
            ConfigHelpers.SetAuthorizedState(true);
            Assert.AreEqual("00XC0BC1DFFC449A402DAB71250CA5869CC8CE39643DA9A9B99",
                            TestMessage(
                                "A235EDF4C58A2CB0C84641D07319CF21FF43378ED5D85B1BC465BF000335FBF12EC8A0412B5D0E86E3C1E5ABFA19B3F5",
                                new FormZMKFromThreeComponents_GG()));

            ConfigHelpers.SetAuthorizedState(false);
            Assert.IsTrue(CommandExplorer.GetCommand(CommandType.Host, "GG").RequiresAuthorizedState);
        }
Exemple #6
0
 public void FormKeyFromEncryptedComponentsTest()
 {
     ConfigHelpers.SetAuthorizedState(true);
     Assert.AreEqual("00FE018240022A76DCA192FE",
                     TestMessage("3002Z3B723AF4CF00A7A6954111D254A90D17EAAF49979FA95742",
                                 new FormKeyFromEncryptedComponents_A4()));
     Assert.AreEqual("00XC0BC1DFFC449A402DAB71250CA5869CC8CE396",
                     TestMessage("3000XX2EC8A0412B5D0E86E3C1E5ABFA19B3F5XFF43378ED5D85B1BC465BF000335FBF1XA235EDF4C58A2CB0C84641D07319CF21",
                                 new FormKeyFromEncryptedComponents_A4()));
     ConfigHelpers.SetAuthorizedState(false);
     Assert.IsTrue(CommandExplorer.GetCommand(CommandType.Host, "A4").RequiresAuthorizedState);
 }
Exemple #7
0
        /// <summary>
        /// Process a message.
        /// </summary>
        /// <param name="message">Byte array with request message.</param>
        /// <param name="resp">Host command response.</param>
        /// <param name="respAfterIo">Host command response after doing printer I/O.</param>
        public void ProcessMessage(byte[] message, out StreamResponse resp, out StreamResponse respAfterIo)
        {
            DumpMessage(message, "Incoming message");

            var msg = new StreamMessage(message);

            resp        = null;
            respAfterIo = null;

            try
            {
                if (msg.CharsLeft < Properties.Settings.Default.HeaderLength + 2)
                {
                    _log.ErrorFormat("Too small message, must be at least {0} bytes long",
                                     Properties.Settings.Default.HeaderLength + 2);
                    return;
                }

                var msgHeader  = msg.Substring(Properties.Settings.Default.HeaderLength);
                var code       = msg.Substring(2);
                var msgTrailer = Properties.Settings.Default.ExpectTrailers ? msg.GetTrailer() : string.Empty;

                _log.DebugFormat("Header {0}, command code {1}", msgHeader, code);

                var command = (HostCommand)CommandExplorer.GetCommand(CommandType.Host, code);
                if (command == null)
                {
                    _log.ErrorFormat("No implementor for {0}.", code);
                    return;
                }

                if (Properties.Settings.Default.CheckLMKParity && !LmkStorage.CheckLmkStorage())
                {
                    _log.Error("LMK storage check failed");
                    resp = new StreamResponse();
                    resp.Append(ErrorCodes.ER_13_MASTER_KEY_PARITY_ERROR);
                    resp.AppendFront(command.ResponseCode);
                    resp.AppendFront(msgHeader);
                    resp.Append(msgTrailer);
                    return;
                }

                _log.Debug("Instantiating command...");
                var o = (AHostCommand)Activator.CreateInstance(command.DeclaringType);

                _log.Debug("Calling AcceptMessage()...");
                o.AcceptMessage(msg);

                _log.Debug(o.DumpFields());

                if (o.XmlParseResult != ErrorCodes.ER_00_NO_ERROR)
                {
                    _log.DebugFormat("Error code {0} return while parsing message", o.XmlParseResult);
                    resp = new StreamResponse();
                    resp.Append(o.XmlParseResult);
                }
                else
                {
                    _log.Debug("Calling ConstructResponse()...");
                    resp = o.ConstructResponse();

                    _log.Debug("Calling ConstructResponseAfterIo()...");
                    respAfterIo = o.ConstructResponseAfterIo();
                }

                resp.AppendFront(command.ResponseCode);
                resp.AppendFront(msgHeader);
                resp.Append(msgTrailer);

                DumpMessage(resp.GetBytes(), "Response message");

                if (respAfterIo != null && !string.IsNullOrEmpty(command.ResponseCodeAfterIo))
                {
                    respAfterIo.AppendFront(command.ResponseCodeAfterIo);
                    respAfterIo.AppendFront(msgHeader);
                    respAfterIo.Append(msgTrailer);
                    DumpMessage(respAfterIo.GetBytes(), "Response message after I/O");
                }

                if (!string.IsNullOrEmpty(o.PrinterData))
                {
                    _log.InfoFormat("Printer data\r\n{0}", o.PrinterData);
                }
            }
            catch (Exception ex)
            {
                _log.Debug("Exception while processing message", ex);
                resp        = null;
                respAfterIo = null;
            }
        }