Exemple #1
0
        internal async Task <e_error> connect(string password)
        {
            y_register_c y      = new();
            var          dv_key = p_crypto.create_symmetrical_keys();

            y.a_key_data = m_key.create(dv_key);
            y.a_key_data = p_crypto.Encrypt(y.a_key_data, public_key.data);
            var login_m = new m_register_c()
            {
                a_device_name = Environment.MachineName,
                a_skeletid    = "wpf_skeleton",
                a_password    = password
            };

            y.a_register_data = p_crypto.convert(login_m);
            y.a_register_data = p_crypto.Encrypt(y.a_register_data, dv_key);
            var o = await y.run(a.run_null);

            if (o.z_error == e_error.non)
            {
                dv_key.id = o.deviceid;
                var db = a.api3.c_db.general <m_data>();
                await db.upsert(new m_data()
                {
                    id   = "key",
                    data = p_crypto.convert(dv_key)
                });

                a.api3.c_key = dv_key;
            }
            return(o.z_error);
        }
Exemple #2
0
        protected override async void implement()
        {
            a_key_data = p_crypto.Decrypt(a_key_data, private_key.data);
            m_key key = m_key.create(a_key_data);

            a_register_data = p_crypto.Decrypt(a_register_data, key);
            m_register_c login = p_crypto.convert <m_register_c>(a_register_data);

            if (!await check_login(login))
            {
                reply(new o()
                {
                    z_error = e_error.invalid_device_info
                });
                return;
            }
            var db = z_db.general_x <m.device>();

            m.device device = new()
            {
                creation_time = DateTime.Now,
                id            = "d_" + ObjectId.GenerateNewId(),
                iv16          = key.iv16,
                key32         = key.key32,
                name          = login.a_device_name
            };
            await db.upsert(device);

            reply(new o()
            {
                a_deviceid = device.id
            });
        }

        async Task <bool> check_login(m_register_c val)
        {
            await Task.CompletedTask;

            return(val.a_skeletid == "wpf_skeleton" && val.a_password == "1234");
        }
    }