Пример #1
0
        private async Task <DeviceConnectionStatus> DeveloperCheckDeviceConnectionState(HttpClient client, string sshPublicKey)
        {
            HttpResponseMessage response = null;


            DeveloperCheckDeviceConnectionArgs args = new DeveloperCheckDeviceConnectionArgs();

            args.DeveloperSshPublicKey = sshPublicKey;
            args.DeviceName            = Configuration.Instance.TargetDevice;

            response = await client.PostAsJsonAsync(apiBaseAddress + "DeveloperCheckDeviceConnection", args);

            if (response.IsSuccessStatusCode)
            {
                bool authenticated = hmacAuthenticator.IsResponseAuthenticated(response);
                if (authenticated)
                {
                    string responseString = await response.Content.ReadAsStringAsync();

                    DeviceConnectionStatus currentStatus = Newtonsoft.Json.JsonConvert.DeserializeObject <DeviceConnectionStatus>(responseString);
                    logger.Debug(responseString);

                    return(currentStatus);
                }
            }
            else
            {
                await PrintFailMessage(response);
            }

            return(null);
        }
Пример #2
0
        public IActionResult DeveloperCheckDeviceConnection([FromBody] DeveloperCheckDeviceConnectionArgs args)
        {
            string developerIdentity = (string)HttpContext.Items["ClientName"];

            Console.WriteLine("Developer identity is: " + developerIdentity);

            // Check developer device connection authorization
            bool isDeveloperAuthorized =
                developerAuthorizationsRepository.IsDeveloperConnectionToDeviceAuthorized(developerIdentity, args.DeviceName);

            if (isDeveloperAuthorized)
            {
                // Checking device connection status
                var deviceConnection = this.clientConnectionsRepository.CheckDeviceConnection(args.DeviceName);

                Core.Entities.DeviceConnectionStatus currentDeviceConnectionStatus = ClientConnectionMapper.Mapper.Map <Core.Entities.DeviceConnectionStatus>(deviceConnection);

                if (currentDeviceConnectionStatus.State == EnumClientConnectionState.Ready || currentDeviceConnectionStatus.State == EnumClientConnectionState.Connected)
                {
                    this.ssh.SaveClientKeys(currentDeviceConnectionStatus.SshForwarding, "developer_" + developerIdentity, args.DeveloperSshPublicKey);
                }

                return(Ok(currentDeviceConnectionStatus));
            }
            else if (!isDeveloperAuthorized)
            {
                return(StatusCode(403, "Develeper is not authorized to connect to this device"));
            }
            else
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, "Database error"));
            }
        }
Пример #3
0
        private static async Task <HttpResponseMessage> DeveloperConnectionRequest_DONE(HttpClient client)
        {
            Console.WriteLine("Test di inserimento di una richiesta di connessione da parte dello sviluppatore, VALIDA");
            DeveloperCheckDeviceConnectionArgs args = new DeveloperCheckDeviceConnectionArgs();

            args.DeveloperSshPublicKey = "abcde";
            args.DeviceName            = "50148590-1b48-4cf5-a76d-8a7f9474a3de";
            return(await client.PostAsJsonAsync(apiBaseAddress + "DeveloperDeviceConnectionRequest", args));
        }
Пример #4
0
        private static async Task <HttpResponseMessage> DeveloperConnectionRequest_FAIL(HttpClient client)
        {
            Console.WriteLine("Test di una richiesta di connessione da parte dello sviluppatore, NON VALIDA (device name inesistente)");
            DeveloperCheckDeviceConnectionArgs args = new DeveloperCheckDeviceConnectionArgs();

            args.DeveloperSshPublicKey = "abcde";
            args.DeviceName            = "blabla";

            return(await client.PostAsJsonAsync(apiBaseAddress + "DeveloperDeviceConnectionRequest", args));
        }