コード例 #1
0
 public void Dispose()
 {
     try
     {
         if (_receiveDisruptor != null)
         {
             _receiveDisruptor.Dispose();
         }
         if (_publishDisruptor != null)
         {
             _publishDisruptor.Dispose();
         }
         if (_endpoint != null)
         {
             _endpoint.Dispose();
         }
     }
     catch (Exception ex)
     {
         LogTo.Error(ex.ToString());
     }
     finally
     {
         _receiveDisruptor = null;
         _publishDisruptor = null;
         _endpoint         = null;
     }
 }
コード例 #2
0
        static void Main(string[] args)
        {
            string bacstore = @"D:\AuthEP\svn\software\IDP\IDPWebsite\Bac\";
            string ppid     = "IHfP1FWxNwwvRTIBQ58xVVUnRAKZlWNPrJcHxzTF0k8=";
            string host     = "localhost";
            int    port     = 9303;

            if (args.Length > 0)
            {
                host = args[0];
            }
            if (args.Length > 1)
            {
                port = int.Parse(args[1]);
            }

            StreamReader reader       = File.OpenText(bacstore + ppid + ".bac");
            string       docNumber    = reader.ReadLine();
            string       dateOfBirth  = reader.ReadLine();
            string       dateOfExpiry = reader.ReadLine();

            reader.Close();

            NetworkClient client = new NetworkClient(host, port);

            client.SendBac(docNumber, dateOfBirth, dateOfExpiry);

            List <IDGFile> dgFiles = new List <IDGFile>();
            DG1File        dg1     = new DG1File(client.GetDG(IDGFile.EF_DG1_TAG));
            DG15File       dg15    = new DG15File(client.GetDG(IDGFile.EF_DG15_TAG));

            dgFiles.Add(dg1);
            dgFiles.Add(dg15);
            SODFile sod = new SODFile(client.GetDG(IDGFile.EF_SOD_TAG));

            Console.WriteLine("Hello " + dg1.MRZ.getPrimaryIdentifier());
            bool hashCheck = Verification.CheckHash(dgFiles, sod);

            Console.WriteLine("Hash check result - " + hashCheck);

            if (sod.CheckDocSignature())
            {
                Console.WriteLine("SOd signature Check - PASSED!");
                Console.WriteLine("Issuing state - {0}", dg1.MRZ.getIssuingState().getName());
            }
            else
            {
                Console.WriteLine("SOd signature Check - FAILED!");
            }

            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();
        }
コード例 #3
0
        public IEnumerator _StartClient()
        {
            using (NetworkServer server = new NetworkServer())
            {
                server.Start(localPort);
                Assert.IsTrue(server.IsRunning);

                NetworkClient client = new NetworkClient();

                client.Connect(localAddress, localPort);
                foreach (var o in Wait())
                {
                    yield return(null);
                }

                Assert.IsTrue(client.IsRunning);
                Assert.IsTrue(client.Connection.IsConnected);
                Assert.AreEqual(server.Connections.Count(), 1);
                Assert.AreEqual(server.Clients.Count(), 1);

                client.Dispose();
                foreach (var o in Wait())
                {
                    yield return(null);
                }
                Assert.IsFalse(client.IsRunning);
                server.Stop();
                Assert.IsFalse(server.IsRunning);
            }
        }
コード例 #4
0
        public async Task EncryptionTest()
        {
            Message.Initialize();
            NetworkServer.Start(5000);

            NetworkClient TestClient        = new NetworkClient("localhost", 5000);
            bool          EncryptionEnabled = await TestClient.InitializeEncryption();

            bool EncryptionClientEnabled = TestClient.HasEncryptedConnection;

            PingResponse Response = await TestClient.SendEncrypted <PingResponse>(new PingRequest()
            {
                Time = DateTime.FromBinary(12)
            });

            Response = await TestClient.SendEncrypted <PingResponse>(new PingRequest()
            {
                Time = DateTime.FromBinary(12)
            });

            Response = await TestClient.SendEncrypted <PingResponse>(new PingRequest()
            {
                Time = DateTime.FromBinary(12)
            });

            NetworkServer.Stop();
            TestClient.Dispose();

            Assert.AreEqual(true, EncryptionEnabled);
            Assert.AreEqual(true, EncryptionClientEnabled);
            Assert.AreEqual(true, TestClient.HasEncryptedConnection);
            Assert.AreEqual(12, Response?.Time.ToBinary());
        }
コード例 #5
0
        public async Task PingTest()
        {
            Message.Initialize();
            NetworkServer.Start(5000);

            NetworkClient TestClient = new NetworkClient("localhost", 5000);
            PingResponse  Response   = await TestClient.Send <PingResponse>(new PingRequest()
            {
                Time = DateTime.FromBinary(12)
            });

            PingResponse Response2 = await TestClient.Send <PingResponse>(new PingRequest()
            {
                Time = DateTime.FromBinary(13)
            });

            PingResponse Response3 = await TestClient.Send <PingResponse>(new PingRequest()
            {
                Time = DateTime.FromBinary(14)
            });

            TimeSpan Ping = await TestClient.GetPing();

            NetworkServer.Stop();
            TestClient.Dispose();

            Assert.AreEqual(12, Response?.Time.ToBinary());
            Assert.AreEqual(13, Response2?.Time.ToBinary());
            Assert.AreEqual(14, Response3?.Time.ToBinary());

            Console.WriteLine(Ping);
            Assert.AreNotEqual(TimeSpan.MaxValue, Ping);
        }
コード例 #6
0
        private async void btnLogin_Click(object sender, EventArgs e)
        {
            if (!IsValidCredentials())
            {
                return;
            }

            loader.Show();
            await Utility.SimulateWork(TimeSpan.FromSeconds(2));

            User user = new User(tbxUser.Text, tbxPassword.Text);

#if !LOCAL_TEST
            if (currentUser?.GetHashCode() != user.GetHashCode())
            {
                networkClient?.Dispose();
            }

            await AuthenticateUserValidation(user);

            if (!networkClient.IsAuthenticated)
            {
                loader.Hide();
                networkClient.Dispose();

                this.InvokeSafe(() =>
                                MessageBox.Show("Failed to login. Please try again.",
                                                "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information));

                return;
            }

            if (cbxRemember.Checked)
            {
                config.SetConfigurations(new ConfigurationData(cbxRemember.Checked, user));
            }
#endif
            currentUser = new User(user);
            this.InvokeSafe(() => new MainWindow(networkClient, user).Show(this));
            loader.Hide();
            this.Visible(false);
        }
コード例 #7
0
        public void ServerConnectionLoopbackV6Test()
        {
            NetworkServer.Start(5000);

            NetworkClient TestClient = new NetworkClient("::1", 5000);

            Thread.Sleep(20);

            int ClientCount = NetworkServer.Clients.Count;

            NetworkServer.Stop();
            TestClient.Dispose();

            Assert.AreEqual(1, ClientCount);
        }
コード例 #8
0
        private void Cleanup()
        {
            foreach (string group in _networkSecurityGroupsToCleanup)
            {
                try
                {
                    NetworkClient.NetworkSecurityGroups.Delete(group);
                }
                catch { }
            }

            DeleteNetworkConfiguration();

            NetworkClient.Dispose();
            ManagementClient.Dispose();
        }
コード例 #9
0
        public async Task AuthenticationTest()
        {
            Message.Initialize();
            NetworkServer.Start(5000, (Sender, Username, Password) => (Username == "User2" && Password == "P@ssw1rd!", ""));

            NetworkClient TestClient = new NetworkClient("localhost", 5000);

            (bool Accepted, string Reason)AuthenticationResult1 = await TestClient.Authenticate("User", "P@ssw0rd!");

            (bool Accepted, string Reason)AuthenticationResult2 = await TestClient.Authenticate("User2", "P@ssw0rd!");

            (bool Accepted, string Reason)AuthenticationResult3 = await TestClient.Authenticate("User", "P@ssw1rd!");

            (bool Accepted, string Reason)AuthenticationResult4 = await TestClient.Authenticate("User2", "P@ssw1rd!");

            bool EncryptionEnabled = await TestClient.InitializeEncryption();

            (bool Accepted, string Reason)AuthenticationResult5 = await TestClient.Authenticate("User", "P@ssw0rd!");

            (bool Accepted, string Reason)AuthenticationResult6 = await TestClient.Authenticate("User2", "P@ssw0rd!");

            (bool Accepted, string Reason)AuthenticationResult7 = await TestClient.Authenticate("User", "P@ssw1rd!");

            (bool Accepted, string Reason)AuthenticationResult8 = await TestClient.Authenticate("User2", "P@ssw1rd!");

            NetworkServer.Stop();
            TestClient.Dispose();

            Assert.IsFalse(AuthenticationResult1.Accepted);
            Assert.IsFalse(AuthenticationResult2.Accepted);
            Assert.IsFalse(AuthenticationResult3.Accepted);
            Assert.IsFalse(AuthenticationResult4.Accepted);

            Assert.IsFalse(AuthenticationResult5.Accepted);
            Assert.IsFalse(AuthenticationResult6.Accepted);
            Assert.IsFalse(AuthenticationResult7.Accepted);
            Assert.IsTrue(AuthenticationResult8.Accepted);

            Assert.IsTrue(TestClient.IsLocalClientAuthenticated);
        }
コード例 #10
0
 public override void OnScreenDispatch() => NetworkClient.Dispose();
コード例 #11
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);
            }
        }
コード例 #12
0
 private void OnDestroy()
 {
     Disconnect("Game stopped");
     _client?.Dispose();
 }
コード例 #13
0
 public void Dispose()
 {
     NetworkClient.ReceivedData -= OnNetworkClientReceivedData;
     NetworkClient.Dispose();
 }