private void UpdateView()
        {
            var scopesContainer = FindViewById <LinearLayout>(Resource.Id.scopes_list);
            //scopesContainer.RemoveAllViews();

            var pluginDb = new PluginDatabase(this);

            _checkbox.Checked = pluginDb.IsEnabled(_pluginPackageName);
            foreach (string scope in pluginDb.GetPluginScopes(_pluginPackageName))
            {
                string scopeId = scope.Substring("keepass2android.".Length);

                TextWithHelp help = new TextWithHelp(this,
                                                     GetString(Resources.GetIdentifier(scopeId + "_title", "string", PackageName)),
                                                     GetString(Resources.GetIdentifier(scopeId + "_explanation", "string", PackageName)));
                LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FillParent,
                                                                                       ViewGroup.LayoutParams.WrapContent);
                help.LayoutParameters = layoutParams;
                scopesContainer.AddView(help);
            }
        }
Exemplo n.º 2
0
        public override void OnReceive(Context context, Intent intent)
        {
            PluginDatabase pluginDb = new PluginDatabase(context);
            if (intent.Action == Strings.ActionRequestAccess)
            {
                var senderPackage = intent.GetStringExtra(Strings.ExtraSender);
                var requestToken = intent.GetStringExtra(Strings.ExtraRequestToken);

                var requestedScopes = intent.GetStringArrayListExtra(Strings.ExtraScopes);

                if (!AreScopesValid(requestedScopes))
                {
                    return;
                }

                if (pluginDb.GetRequestToken(senderPackage) != requestToken)
                {
                    Log.Warn(_tag, "Invalid requestToken!");
                    return;
                }
                string currentAccessToken = pluginDb.GetAccessToken(senderPackage);
                if ((currentAccessToken != null)
                    && (AccessManager.IsSubset(requestedScopes,
                                           pluginDb.GetPluginScopes(senderPackage))))
                {
                    //permission already there.
                    var i = new Intent(Strings.ActionReceiveAccess);
                    i.PutExtra(Strings.ExtraSender, context.PackageName);
                    i.PutExtra(Strings.ExtraAccessToken, currentAccessToken);
                    //TODO: Plugin should verify requestToken to make sure it doesn't receive accessTokens from malicious apps
                    i.PutExtra(Strings.ExtraRequestToken, requestToken);
                    i.SetPackage(senderPackage);
                    context.SendBroadcast(i);

                    Log.Debug(_tag, "Plugin " + senderPackage + " enabled.");
                }
                else
                {
                    //store that scope was requested but not yet approved (=> accessToken = null)
                    pluginDb.StorePlugin(senderPackage, null, requestedScopes);

                    Log.Debug(_tag, "Plugin " + senderPackage + " not enabled.");

                    //see if the plugin has an access token
                    string accessToken = intent.GetStringExtra(Strings.ExtraAccessToken);
                    if (accessToken != null)
                    {
                        //notify plugin that access token is no longer valid or sufficient
                        Intent i = new Intent(Strings.ActionRevokeAccess);
                        i.PutExtra(Strings.ExtraSender, context.PackageName);
                        i.PutExtra(Strings.ExtraAccessToken, accessToken);
                        i.SetPackage(senderPackage);
                        context.SendBroadcast(i);
                        Log.Warn(_tag, "Access token of plugin " + senderPackage + " not (or no more) valid.");
                    }

                }
                if (OnReceivedRequest != null)
                    OnReceivedRequest(this, new PluginHostEventArgs() { Package = senderPackage });

            }
        }
Exemplo n.º 3
0
        public override void OnReceive(Context context, Intent intent)
        {
            PluginDatabase pluginDb = new PluginDatabase(context);

            if (intent.Action == Strings.ActionRequestAccess)
            {
                string senderPackage = intent.GetStringExtra(Strings.ExtraSender);
                string requestToken  = intent.GetStringExtra(Strings.ExtraRequestToken);

                IList <string> requestedScopes = intent.GetStringArrayListExtra(Strings.ExtraScopes);

                if (!AreScopesValid(requestedScopes))
                {
                    Log.Debug(_tag, "requested scopes not valid");
                    return;
                }

                if (pluginDb.GetRequestToken(senderPackage) != requestToken)
                {
                    Log.Warn(_tag, "Invalid requestToken!");
                    return;
                }
                string currentAccessToken = pluginDb.GetAccessToken(senderPackage);
                if ((currentAccessToken != null) &&
                    (AccessManager.IsSubset(requestedScopes,
                                            pluginDb.GetPluginScopes(senderPackage))))
                {
                    //permission already there.
                    var i = new Intent(Strings.ActionReceiveAccess);
                    i.PutExtra(Strings.ExtraSender, context.PackageName);
                    i.PutExtra(Strings.ExtraAccessToken, currentAccessToken);
                    //TODO: Plugin should verify requestToken to make sure it doesn't receive accessTokens from malicious apps
                    i.PutExtra(Strings.ExtraRequestToken, requestToken);
                    i.SetPackage(senderPackage);
                    context.SendBroadcast(i);

                    Log.Debug(_tag, "Plugin " + senderPackage + " enabled.");
                }
                else
                {
                    //store that scope was requested but not yet approved (=> accessToken = null)
                    pluginDb.StorePlugin(senderPackage, null, requestedScopes);

                    Log.Debug(_tag, "Plugin " + senderPackage + " not enabled.");

                    //see if the plugin has an access token
                    string accessToken = intent.GetStringExtra(Strings.ExtraAccessToken);
                    if (accessToken != null)
                    {
                        //notify plugin that access token is no longer valid or sufficient
                        Intent i = new Intent(Strings.ActionRevokeAccess);
                        i.PutExtra(Strings.ExtraSender, context.PackageName);
                        i.PutExtra(Strings.ExtraAccessToken, accessToken);
                        i.SetPackage(senderPackage);
                        context.SendBroadcast(i);
                        Log.Warn(_tag, "Access token of plugin " + senderPackage + " not (or no more) valid.");
                    }
                }
                if (OnReceivedRequest != null)
                {
                    OnReceivedRequest(this, new PluginHostEventArgs()
                    {
                        Package = senderPackage
                    });
                }
            }
        }
Exemplo n.º 4
0
 private void EnsurePackageHasUnacceptedScope(PluginDatabase db, string plugin, string scope)
 {
     if (String.IsNullOrEmpty(db.GetRequestToken(plugin)))
         throw new Exception("invalid request token");
     if (db.GetAccessToken(plugin) != null)
         throw new Exception("invalid access token!");
     if (db.GetPluginScopes(plugin).Count != 1)
         throw new Exception("Unexpected scopes!");
     if (db.GetPluginScopes(plugin).First() != scope)
         throw new Exception("Unexpected scope in db!");
 }
Exemplo n.º 5
0
 private static void EnsurePackageDataIsEmpty(PluginDatabase db, string testPackageA)
 {
     if (String.IsNullOrEmpty(db.GetRequestToken(testPackageA)))
         throw new Exception("invalid request token");
     if (db.GetAccessToken(testPackageA) != null)
         throw new Exception("invalid access token!");
     if (db.GetPluginScopes(testPackageA).Count > 0)
         throw new Exception("Unexpected scopes!");
 }
Exemplo n.º 6
0
        private void UpdateView()
        {
            var scopesContainer = FindViewById<LinearLayout>(Resource.Id.scopes_list);
            //scopesContainer.RemoveAllViews();

            var pluginDb = new PluginDatabase(this);
            _checkbox.Checked = pluginDb.IsEnabled(_pluginPackageName);
            foreach (string scope in pluginDb.GetPluginScopes(_pluginPackageName))
            {
                string scopeId = scope.Substring("keepass2android.".Length);

                TextWithHelp help = new TextWithHelp(this,
                                                     GetString(Resources.GetIdentifier(scopeId + "_title", "string", PackageName)),
                                                     GetString(Resources.GetIdentifier(scopeId + "_explanation", "string", PackageName)));
                LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FillParent,
                                                                                       ViewGroup.LayoutParams.WrapContent);
                help.LayoutParameters = layoutParams;
                scopesContainer.AddView(help);
            }
        }