public static void TriggerRequest(Context ctx, string pkgName, PluginDatabase pluginDatabase)
        {
            try
            {
                Intent triggerIntent = new Intent(Strings.ActionTriggerRequestAccess);
                triggerIntent.SetPackage(pkgName);
                triggerIntent.PutExtra(Strings.ExtraSender, ctx.PackageName);

                triggerIntent.PutExtra(Strings.ExtraRequestToken, pluginDatabase.GetRequestToken(pkgName));
                ctx.SendBroadcast(triggerIntent);
            }
            catch (Exception e)
            {
            }
        }
示例#2
0
 public static void TriggerRequest(Context ctx, string pkgName, PluginDatabase pluginDatabase)
 {
     try
     {
         Intent triggerIntent = new Intent(Strings.ActionTriggerRequestAccess);
         triggerIntent.SetPackage(pkgName);
         triggerIntent.PutExtra(Strings.ExtraSender, ctx.PackageName);
         string requestToken = pluginDatabase.GetRequestToken(pkgName);
         triggerIntent.PutExtra(Strings.ExtraRequestToken, requestToken);
         Android.Util.Log.Debug(_tag, "Request token: " + requestToken);
         ctx.SendBroadcast(triggerIntent);
     }
     catch (Exception e)
     {
     }
 }
示例#3
0
 public static void TriggerRequest(Context ctx, string pkgName, PluginDatabase pluginDatabase)
 {
     try
     {
         Intent triggerIntent = new Intent(Strings.ActionTriggerRequestAccess);
         triggerIntent.SetPackage(pkgName);
         triggerIntent.PutExtra(Strings.ExtraSender, ctx.PackageName);
         string requestToken = pluginDatabase.GetRequestToken(pkgName);
         triggerIntent.PutExtra(Strings.ExtraRequestToken, requestToken);
         Android.Util.Log.Debug(_tag, "Request token: " + requestToken);
         ctx.SendBroadcast(triggerIntent);
     }
     catch (Exception e)
     {
     }
 }
示例#4
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 });

            }
        }
示例#5
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
                    });
                }
            }
        }
示例#6
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!");
 }
示例#7
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!");
 }
示例#8
0
        public static void TriggerRequest(Context ctx, string pkgName, PluginDatabase pluginDatabase)
        {
            try
            {
                Intent triggerIntent = new Intent(Strings.ActionTriggerRequestAccess);
                triggerIntent.SetPackage(pkgName);
                triggerIntent.PutExtra(Strings.ExtraSender, ctx.PackageName);

                triggerIntent.PutExtra(Strings.ExtraRequestToken, pluginDatabase.GetRequestToken(pkgName));
                ctx.SendBroadcast(triggerIntent);
            }
            catch (Exception e)
            {
            }
        }