コード例 #1
0
ファイル: MtbContainer.cs プロジェクト: staryd/MobileTicket
        private void Parse(byte[] bytes)
        {
            CBORObject cborObject;
            try
            {
                cborObject = CBORObject.DecodeFromBytes(bytes);
            }
            catch
            {
                throw new ArgumentException("Could not parse MTB. Byte array could not be decoded to CBOR Object");
            }

            if (cborObject.Type == CBORType.Map)
            {
                var dict = cborObject.ConvertToDictionary();

                if (dict["v"] == null || !dict["v"].GetByteString().SequenceEqual(mtbVersion))
                    throw new ArgumentException("Could not parse MTB. Only container version 1 is supported.");

                var p = dict["p"].GetByteString();

                // TODO: Refactor
                var signedData = new SignedData(p);

                if (signedData.SignatureType == SignatureType.Issuer)
                    IssuerSignedTicketBundle = new IssuerSignedTicketBundle(p);
                else
                    IssuerSignedTicketBundle = new IssuerSignedTicketBundle(signedData.Payload);
            }
            else
            {
                throw new ArgumentException("Could not parse MtbContainer. Decoded bytes not of expected type CBOR Map");
            }
        }
コード例 #2
0
        public void GetBytes_Returns_SameSequence_As_Parsed_Data()
        {
            var bytes = Convert.FromBase64String(issuerSignedTicketBundleB64);
            var signedBundle = new IssuerSignedTicketBundle(bytes);

            var result = signedBundle.GetBytes();

            Assert.That(result.SequenceEqual(bytes), Is.True);
        }
コード例 #3
0
ファイル: MtbHandler.cs プロジェクト: staryd/MobileTicket
        /// <summary>
        /// Creates a signed MTB with one participant object.
        /// Participant object is expected to be serialized to JSON-array;
        /// [{participantTicketObject-1}, {participantTicketObject-2}, ... ]
        /// </summary>
        /// <param name="jsonString">Participant object serialized to JSON</param>
        /// <param name="participantId">Participant id (PID) for Ticket Bundle map</param>
        /// <returns>Signed MTB as byte[]</returns>
        public byte[] CreateSigned(string jsonString, string participantId)
        {
            var participantObject = new ParticipantObject(jsonString);
            var ticketBundle = new TicketBundle();
            ticketBundle.ParticipantObjects.Add(participantId, participantObject);
            var unSignedBundle = new IssuerSignedTicketBundle(ticketBundle);
            var mtbContainer = new MtbContainer(unSignedBundle);

            // Sign
            var signedMtb = _service.Sign(mtbContainer);

            return signedMtb.GetBytes();
        }
コード例 #4
0
        public void Sign_Creates_a_MTB_with_valid_signature()
        {
            var ticketBundle = new TicketBundle();
            var issuerTicketBundle = new IssuerSignedTicketBundle(ticketBundle);
            var mtb = new MtbContainer(issuerTicketBundle);

            var signed = service.Sign(mtb);
            var signedBundle = signed.IssuerSignedTicketBundle;
            var validationResult = service.Verify(mtb);

            Assert.That(signedBundle.Signature, Is.Not.Null);
            Assert.That(validationResult, Is.True);
        }
コード例 #5
0
        public void SetUp()
        {
            keyRepo = new TestKeyRepository();
            service = new SignatureService(keyRepo);

            // Create a bundle
            var signatureHeader = new IssuerSignatureHeader(header);
            var ticketBundle = new TicketBundle(payload);

            issuerSignedTicketBundle = new IssuerSignedTicketBundle(ticketBundle);
            issuerSignedTicketBundle.Header = signatureHeader;
            issuerSignedTicketBundle.Signature = signature;
        }
コード例 #6
0
        public void Sign_Creates_a_MTB_with_valid_header()
        {
            var ticketBundle = new TicketBundle();
            var issuerTicketBundle = new IssuerSignedTicketBundle(ticketBundle);
            var mtb = new MtbContainer(issuerTicketBundle);

            var signed = service.Sign(mtb);
            var signedBundle = signed.IssuerSignedTicketBundle;

            Assert.That(signedBundle.Header, Is.Not.Null);
            Assert.That(signedBundle.Header.alg, Is.EqualTo(SignatureAlgorithm.ES256));
            Assert.That(signedBundle.Header.iid, Is.EqualTo(keyRepo.SigningIssuerId));
            Assert.That(signedBundle.Header.kid, Is.EqualTo(keyRepo.SigningKeyId));
        }
コード例 #7
0
ファイル: MtbContainer.cs プロジェクト: staryd/MobileTicket
 public MtbContainer(IssuerSignedTicketBundle issuerSignedTicketBundle)
 {
     IssuerSignedTicketBundle = issuerSignedTicketBundle;
 }