コード例 #1
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();
        }
コード例 #2
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);
        }
コード例 #3
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;
        }
コード例 #4
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));
        }
コード例 #5
0
        private void Parse(byte[] bytes)
        {
            CBORObject cborObject;
            try
            {
                cborObject = CBORObject.DecodeFromBytes(bytes);
            }
            catch
            {
                throw new ArgumentException("Could not parse IssuerSignedTicketBundle. Byte array could not be decoded to CBOR Object");
            }

            if (cborObject.Type == CBORType.Array)
            {
                var byteStringList = cborObject.ConvertToList();
                if (byteStringList.Count != 3)
                    throw new ArgumentException($"Could not parse IssuerSignedTicketBundle. Unexpected length of array: {byteStringList.Count}, expected 3.");

                Header = new IssuerSignatureHeader(byteStringList.ElementAt(0).GetByteString());
                TicketBundle = new TicketBundle(byteStringList.ElementAt(1).GetByteString());
                Signature = byteStringList.ElementAt(2).GetByteString();
            }
        }
コード例 #6
0
 public IssuerSignedTicketBundle(TicketBundle ticketBundle)
 {
     TicketBundle = ticketBundle;
 }