Esempio n. 1
0
        public void ExtendRequestPduToStringWithErrorTest()
        {
            ExtendResponsePdu tag = new ExtendResponsePdu(new TlvTagBuilder(Constants.ExtendResponsePdu.TagType, false, false,
                                                                            new ITlvTag[]
            {
                new PduHeader(new TlvTagBuilder(Constants.PduHeader.TagType, false, false,
                                                new ITlvTag[]
                {
                    new StringTag(Constants.PduHeader.LoginIdTagType, false, false, "Test Login Id"),
                    new IntegerTag(Constants.PduHeader.InstanceIdTagType, false, false, 1),
                    new IntegerTag(Constants.PduHeader.MessageIdTagType, false, false, 2)
                }).BuildTag()),
                new ExtendErrorPayload(new TlvTagBuilder(Constants.ErrorPayload.TagType, false, false, new ITlvTag[]
                {
                    new IntegerTag(Constants.PduPayload.StatusTagType, false, false, 1),
                    new StringTag(Constants.PduPayload.ErrorMessageTagType, false, false, "Test Error message")
                }).BuildTag()),
                new ImprintTag(Constants.Pdu.MacTagType, false, false,
                               new DataHash(HashAlgorithm.Sha2256,
                                            new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32 })),
            }).BuildTag());

            ExtendResponsePdu tag2 = new ExtendResponsePdu(new RawTag(tag.Type, tag.NonCritical, tag.Forward, tag.EncodeValue()));

            Assert.AreEqual(tag.ToString(), tag2.ToString());
        }
Esempio n. 2
0
        private static ExtendResponsePayload GetExtendResponsePayload(string path)
        {
            byte[] bytes = File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, path));

            using (TlvReader reader = new TlvReader(new MemoryStream(bytes)))
            {
                ExtendResponsePdu pdu = new ExtendResponsePdu(reader.ReadTag());
                return(pdu.Payloads[0] as ExtendResponsePayload);
            }
        }
        private static List <KsiServiceResponsePayloadInfo> GetExtenderResponsePayloadInfos(RawTag pdu)
        {
            List <KsiServiceResponsePayloadInfo> list = new List <KsiServiceResponsePayloadInfo>();
            IEnumerable <RawTag> children             = GetChildren(pdu.Value);

            bool containsUnknownPayload = false;

            foreach (RawTag child in children)
            {
                switch (child.Type)
                {
                case Constants.ExtendResponsePayload.TagType:
                    RawTag requestIdTag = GetTagByType(child.Value, Constants.PduPayload.RequestIdTagType);
                    if (requestIdTag == null)
                    {
                        throw new KsiServiceProtocolException("Cannot find request id tag from extender response payload.");
                    }
                    list.Add(new KsiServiceResponsePayloadInfo(KsiServiceResponsePayloadType.Extending, new IntegerTag(requestIdTag).Value));
                    break;

                case Constants.ExtenderConfigResponsePayload.TagType:
                    list.Add(new KsiServiceResponsePayloadInfo(KsiServiceResponsePayloadType.ExtenderConfig));
                    break;

                case Constants.ErrorPayload.TagType:
                    list.Add(new KsiServiceResponsePayloadInfo(KsiServiceResponsePayloadType.Error));
                    break;

                case Constants.PduHeader.TagType:
                case Constants.Pdu.MacTagType:
                    break;

                default:
                    containsUnknownPayload = true;
                    break;
                }
            }

            if (containsUnknownPayload)
            {
                // try to parse PDU to check if critical unknown tags are included in which case a parsing exceptions is thrown by ExtendResponsePdu
                ExtendResponsePdu extendResponsePdu = new ExtendResponsePdu(pdu);
                Logger.Warn(string.Format("TCP response processor received unexpected response payloads!{0}PDU:{0}{1}", Environment.NewLine, extendResponsePdu));
            }

            return(list);
        }
Esempio n. 4
0
        public void ExtendRequestPduToStringWithResponseTest()
        {
            ExtendResponsePdu tag = new ExtendResponsePdu(new TlvTagBuilder(Constants.ExtendResponsePdu.TagType, false, false,
                                                                            new ITlvTag[]
            {
                new PduHeader(new TlvTagBuilder(Constants.PduHeader.TagType, false, false,
                                                new ITlvTag[]
                {
                    new StringTag(Constants.PduHeader.LoginIdTagType, false, false, "Test Login Id"),
                    new IntegerTag(Constants.PduHeader.InstanceIdTagType, false, false, 1),
                    new IntegerTag(Constants.PduHeader.MessageIdTagType, false, false, 2)
                }).BuildTag()),
                new ExtendResponsePayload(new TlvTagBuilder(Constants.ExtendResponsePayload.TagType, false, false, new ITlvTag[]
                {
                    new IntegerTag(Constants.PduPayload.RequestIdTagType, false, false, 2),
                    new IntegerTag(Constants.PduPayload.StatusTagType, false, false, 0),
                    new StringTag(Constants.PduPayload.ErrorMessageTagType, false, false, "Test error message."),
                    new IntegerTag(Constants.ExtendResponsePayload.CalendarLastTimeTagType, false, false, 1),
                    new CalendarHashChain(new TlvTagBuilder(Constants.CalendarHashChain.TagType, false, false,
                                                            new ITlvTag[]
                    {
                        new IntegerTag(Constants.CalendarHashChain.PublicationTimeTagType, false, false, 1),
                        new IntegerTag(Constants.CalendarHashChain.AggregationTimeTagType, false, false, 0),
                        new ImprintTag(Constants.CalendarHashChain.InputHashTagType, false, false,
                                       new DataHash(HashAlgorithm.Sha2256,
                                                    new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32 })),
                        // add links
                        new ImprintTag((uint)LinkDirection.Left, false, false,
                                       new DataHash(HashAlgorithm.Sha2256,
                                                    new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32 }))
                    }).BuildTag())
                }).BuildTag()),
                new ImprintTag(Constants.Pdu.MacTagType, false, false,
                               new DataHash(HashAlgorithm.Sha2256,
                                            new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32 })),
            }).BuildTag());

            ExtendResponsePdu tag2 = new ExtendResponsePdu(new RawTag(tag.Type, tag.NonCritical, tag.Forward, tag.EncodeValue()));

            Assert.AreEqual(tag.ToString(), tag2.ToString());
        }
Esempio n. 5
0
        private static IKsiService GetService(List <PduPayload> payloads, ulong requestId = 1584727637)
        {
            List <ITlvTag> childTags = new List <ITlvTag> {
                new PduHeader(Settings.Default.HttpExtendingServiceUser)
            };

            childTags.AddRange(payloads);
            childTags.Add(new ImprintTag(Constants.Pdu.MacTagType, false, false, new DataHash(HashAlgorithm.Sha2256, new byte[32])));

            ExtendResponsePdu pdu = TestUtil.GetCompositeTag <ExtendResponsePdu>(Constants.ExtendResponsePdu.TagType, childTags.ToArray());

            MethodInfo m = pdu.GetType().GetMethod("SetMacValue", BindingFlags.Instance | BindingFlags.NonPublic);

            m.Invoke(pdu, new object[] { HashAlgorithm.Sha2256, Util.EncodeNullTerminatedUtf8String(TestConstants.ServicePass) });

            MemoryStream stream = new MemoryStream();

            using (TlvWriter writer = new TlvWriter(stream))
            {
                writer.WriteTag(pdu);
            }

            return(GetStaticKsiService(stream.ToArray(), requestId));
        }