コード例 #1
0
 /// <summary>
 /// Initializes a new instance of the <b>RequestSecurityTokenResponse</b> using the specified
 /// security token request, ppid and MRZ information.
 /// </summary>
 /// <param name="rst"><b>RST</b> to which this instance is a response (RSTR)</param>
 /// <param name="ppid">Identifier of the person requesting the token</param>
 /// <param name="mrz">MRZ information used for constructing this RSTR</param>
 public RequestSecurityTokenResponse(RST rst, string ppid, MRZInfo mrz)
     : base(false)
 {
     this.context    = rst.Context;
     this.useKey     = rst.UseKey;
     this.keyType    = rst.KeyType;
     this.claimTypes = rst.ClaimTypes;
     this.ppid       = ppid;
     this.mrz        = mrz;
 }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the <b>RequestSecurityTokenResponse</b> using the specified
 /// security token request, ppid and MRZ information.
 /// </summary>
 /// <param name="rst"><b>RST</b> to which this instance is a response (RSTR)</param>
 /// <param name="ppid">Identifier of the person requesting the token</param>
 /// <param name="mrz">MRZ information used for constructing this RSTR</param>
 public RequestSecurityTokenResponse(RST rst, string ppid, MRZInfo mrz)
     : base(false)
 {
     this.context = rst.Context;
     this.useKey = rst.UseKey;
     this.keyType = rst.KeyType;
     this.claimTypes = rst.ClaimTypes;
     this.ppid = ppid;
     this.mrz = mrz;
 }
コード例 #3
0
        /// <summary>
        /// The WS-Trust Issue binding.
        /// </summary>
        /// <param name="request">A RequestSecurityToken (or RequestSecurityTokenResponse) message, with WS-Addressing Action http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue </param>
        /// <returns>A RequestSecurityTokenResponse message.</returns>
        public Message Issue(Message request)
        {
            try
            {
                OperationContext              context           = OperationContext.Current;
                MessageProperties             messageProperties = context.IncomingMessageProperties;
                RemoteEndpointMessageProperty endpointProperty  =
                    messageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
                Console.WriteLine("Request from {0}:{1}", endpointProperty.Address, endpointProperty.Port);

                if (request == null)
                {
                    throw new ArgumentNullException("request");
                }

                //Console.WriteLine("REQUEST: " + request.ToString());

                // Parse the incoming request, an RST
                RST rst = new RST(request.GetReaderAtBodyContents());

                //Console.WriteLine("new request (" + DateTime.Now.ToLongTimeString() + ") " + rst.KeyType);
                Console.WriteLine();
                // Try to find the PPID in the claimsets
                string ppid = "";
                AuthorizationContext ctx = OperationContext.Current.ServiceSecurityContext.AuthorizationContext;

                foreach (ClaimSet claimSet in ctx.ClaimSets)
                {
                    foreach (Claim c in claimSet)
                    {
                        if (c.ClaimType == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/privatepersonalidentifier")
                        {
                            ppid = c.Resource.ToString();
                        }
                        Console.WriteLine("incoming claim: " + c.ClaimType + " resource: " + c.Resource.ToString());
                    }
                }
                string ppidBase64 = BytesToHex(UTF8Encoding.UTF8.GetBytes(ppid));
                Console.WriteLine("ppid: " + ppid + " hex: " + ppidBase64);
                string bacPath = ConfigurationManager.AppSettings["bacstore"] + ppidBase64 + ".bac";
                Console.WriteLine("BacPath: " + bacPath);
                StreamReader reader       = File.OpenText(bacPath);
                string       docNumber    = reader.ReadLine();
                string       dateOfBirth  = reader.ReadLine();
                string       dateOfExpiry = reader.ReadLine();
                reader.Close();
                Console.WriteLine("BAC: " + docNumber + "<<<" + dateOfBirth + "<<<" + dateOfExpiry);

                //NetworkClient client = new NetworkClient(endpointProperty.Address, 9303);
                NetworkClient client = new NetworkClient(NetworkListener.IncomingClients[endpointProperty.Address]);
                Console.WriteLine("NetworkClient found: " + client.ToString());
                client.SendBac(docNumber, dateOfBirth, dateOfExpiry);
                Console.WriteLine("BAC Send");
                DG1File dg1 = new DG1File(client.GetDG(IDGFile.EF_DG1_TAG));
                Console.WriteLine("DG1 Received");
                DG15File dg15 = new DG15File(client.GetDG(IDGFile.EF_DG15_TAG));
                Console.WriteLine("DG15 Received");
                SODFile sod = new SODFile(client.GetDG(IDGFile.EF_SOD_TAG));
                Console.WriteLine("SOD Received");
                bool sodCheck = sod.CheckDocSignature();
                Console.WriteLine("SOD DOC SIGNATURE CHECK: " + sodCheck);
                bool hashCheck = Verification.CheckHash(dg1, sod);
                Console.WriteLine("HASH CHECK DG1: " + hashCheck);
                Random random  = new Random();
                byte[] message = new byte[8];
                random.NextBytes(message);
                byte[] signature = client.SendChallenge(message);
                bool   aaCheck   = Verification.CheckAA(dg15.PublicKey, message, signature);
                Console.WriteLine("AA CHECK: " + aaCheck);
                client.Dispose();

                RSTR rstr = null;
                // Process the request and generate an RSTR
                if (hashCheck && sodCheck && aaCheck)
                {
                    rstr = new RSTR(rst, ppid, dg1.MRZ);
                }
                else
                {
                    return(null);
                }

                // Generate a response message
                Message response = Message.CreateMessage(MessageVersion.Default, Constants.WSTrust.Actions.IssueResponse, rstr);

                // Set the RelatesTo
                if (request.Headers.MessageId != null)
                {
                    response.Headers.RelatesTo = request.Headers.MessageId;
                }
                else
                {
                    // not supported in this sample
                    throw new NotSupportedException("Caller must provide a Message Id");
                }

                // Send back to the caller
                return(response);
            }
            catch (Exception e)
            {
                throw WSTrustFaultException.FromException(e);
            }
        }
コード例 #4
0
        /// <summary>
        /// The WS-Trust Issue binding.
        /// </summary>
        /// <param name="request">A RequestSecurityToken (or RequestSecurityTokenResponse) message, with WS-Addressing Action http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue </param>
        /// <returns>A RequestSecurityTokenResponse message.</returns>
        public Message Issue(Message request)
        {
            try
            {
                OperationContext context = OperationContext.Current;
                MessageProperties messageProperties = context.IncomingMessageProperties;
                RemoteEndpointMessageProperty endpointProperty =
                    messageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
                Console.WriteLine("Request from {0}:{1}", endpointProperty.Address, endpointProperty.Port);

                if (request == null)
                {
                    throw new ArgumentNullException("request");
                }

                //Console.WriteLine("REQUEST: " + request.ToString());

                // Parse the incoming request, an RST
                RST rst = new RST(request.GetReaderAtBodyContents());

                //Console.WriteLine("new request (" + DateTime.Now.ToLongTimeString() + ") " + rst.KeyType);
                Console.WriteLine();
                // Try to find the PPID in the claimsets
                string ppid = "";
                AuthorizationContext ctx = OperationContext.Current.ServiceSecurityContext.AuthorizationContext;

                foreach (ClaimSet claimSet in ctx.ClaimSets)
                {
                    foreach (Claim c in claimSet)
                    {
                        if (c.ClaimType == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/privatepersonalidentifier")
                            ppid = c.Resource.ToString();
                        Console.WriteLine("incoming claim: " + c.ClaimType + " resource: " + c.Resource.ToString());
                    }
                }
                string ppidBase64 = BytesToHex(UTF8Encoding.UTF8.GetBytes(ppid));
                Console.WriteLine("ppid: " + ppid + " hex: "+ppidBase64);
                string bacPath = ConfigurationManager.AppSettings["bacstore"] + ppidBase64 + ".bac";
                Console.WriteLine("BacPath: " + bacPath);
                StreamReader reader = File.OpenText(bacPath);
                string docNumber = reader.ReadLine();
                string dateOfBirth = reader.ReadLine();
                string dateOfExpiry = reader.ReadLine();
                reader.Close();
                Console.WriteLine("BAC: " + docNumber + "<<<" + dateOfBirth + "<<<" + dateOfExpiry);

                //NetworkClient client = new NetworkClient(endpointProperty.Address, 9303);
                NetworkClient client = new NetworkClient(NetworkListener.IncomingClients[endpointProperty.Address]);
                Console.WriteLine("NetworkClient found: " + client.ToString());
                client.SendBac(docNumber, dateOfBirth, dateOfExpiry);
                Console.WriteLine("BAC Send");
                DG1File dg1 = new DG1File(client.GetDG(IDGFile.EF_DG1_TAG));
                Console.WriteLine("DG1 Received");
                DG15File dg15 = new DG15File(client.GetDG(IDGFile.EF_DG15_TAG));
                Console.WriteLine("DG15 Received");
                SODFile sod = new SODFile(client.GetDG(IDGFile.EF_SOD_TAG));
                Console.WriteLine("SOD Received");
                bool sodCheck = sod.CheckDocSignature();
                Console.WriteLine("SOD DOC SIGNATURE CHECK: " + sodCheck);
                bool hashCheck = Verification.CheckHash(dg1, sod);
                Console.WriteLine("HASH CHECK DG1: " + hashCheck);
                Random random = new Random();
                byte[] message = new byte[8];
                random.NextBytes(message);
                byte[] signature = client.SendChallenge(message);
                bool aaCheck = Verification.CheckAA(dg15.PublicKey, message, signature);
                Console.WriteLine("AA CHECK: " + aaCheck);
                client.Dispose();

                RSTR rstr =null;
                // Process the request and generate an RSTR
                if (hashCheck && sodCheck && aaCheck)
                    rstr = new RSTR(rst, ppid, dg1.MRZ);
                else
                    return null;

                // Generate a response message
                Message response = Message.CreateMessage(MessageVersion.Default, Constants.WSTrust.Actions.IssueResponse, rstr);

                // Set the RelatesTo
                if ( request.Headers.MessageId != null )
                {
                    response.Headers.RelatesTo = request.Headers.MessageId;
                }
                else
                {
                    // not supported in this sample
                    throw new NotSupportedException("Caller must provide a Message Id");
                }

                // Send back to the caller
                return response;
            }
            catch (Exception e)
            {
                throw WSTrustFaultException.FromException(e);
            }
        }