Exemple #1
0
        public Task <InitializationResponse> SyncProfilesAsync()
        {
            return(Task.Factory.StartNew(() =>
            {
                var initializationResponse = new InitializationResponse()
                {
                    MmeCode = _mmeCode
                };

                try
                {
                    if (Settings.Default.IsLocal)
                    {
                        initializationResponse.SyncMode = SyncMode.Local;
                    }
                    else
                    {
                        SyncProfiles();
                        SendUnSendedResult();
                        initializationResponse.SyncMode = SyncMode.Sync;
                    }
                }
                catch (Exception e)
                {
                    initializationResponse.SyncMode = SyncMode.NotSync;
                    _communication.PostDbSyncState(DeviceConnectionState.ConnectionFailed, e.Message);
                    MessageBox.Show(e.ToString(), "Error sync, передайте сообщение разработчику");
                }

                _communication.PostDbSyncState(DeviceConnectionState.ConnectionSuccess, string.Empty);

                return initializationResponse;
            }));
        }
Exemple #2
0
        public InitializationResponse Initialize(int n, int t)
        {
            if (Health.Initialized)
            {
                return(null);
            }

            using (var aes = Aes.Create())
                using (var tss = ThresholdSecretSharingAlgorithm.Create())
                    using (var sha = SHA512.Create())
                    {
                        aes.KeySize = 256;
                        aes.GenerateKey();
                        var rootKeyClear  = aes.Key;
                        var rootKeyCrypt  = tss.Split(rootKeyClear, n, t);
                        var rootKeyShares = tss.Shares.ToArray();
                        var rootToken     = Guid.NewGuid();

                        var resp = new InitializationResponse
                        {
                            Keys       = rootKeyShares.Select(x => BitConverter.ToString(x).Replace("-", "")).ToArray(),
                            KeysBase64 = rootKeyShares.Select(x => Convert.ToBase64String(x)).ToArray(),
                            RootToken  = rootToken.ToString(),
                        };

                        try
                        {
                            State.Durable = new DurableServerState();
                            State.Durable.SecretShares       = n;
                            State.Durable.SecretThreshold    = t;
                            State.Durable.RootKeyTerm        = 1;
                            State.Durable.RootKeyInstallTime = DateTime.UtcNow;
                            State.Durable.RootKeyEncrypted   = rootKeyCrypt;
                            State.Durable.RootKeyHash        = sha.ComputeHash(rootKeyClear);
                            State.Durable.RootTokenHash      = sha.ComputeHash(rootToken.ToByteArray());

                            State.Durable.ClusterName = Settings.ClusterName;
                            State.Durable.ClusterId   = Guid.NewGuid().ToString();

                            SaveState().Wait();
                            Health.Initialized = true;
                            return(resp);
                        }
                        catch
                        {
                            State.Durable = null;
                            throw;
                        }
                    }
        }
        public void Initialize()
        {
            stream          = new NetworkStream(client);
            public_endpoint = ((IPEndPoint)client.RemoteEndPoint).Convert();

            Log($"Session initialization started.");

            var initializationRequest = InitializationRequest.Parser.ParseDelimitedFrom(stream);

            private_endpoint = initializationRequest.PrivateEndpoint;
            id = initializationRequest.ClientId;

            var initializationResponse = new InitializationResponse();

            initializationResponse.SomeLobbyIds.AddRange(server.lobbies.Keys.Take(10));
            initializationResponse.WriteDelimitedTo(stream);

            Log($"Session established. Peer's private endpoint: {private_endpoint}");
        }
 public TransbankInitializationResponseException(string message, InitializationResponse response) : base(message)
 {
     RegisterInitializationResponse = response;
 }