コード例 #1
0
        private static T GetState <T>(IFirebaseAppPlatform app, int state, Dictionary <int, Dictionary <string, T> > store)
        {
            if (app == null)
            {
                app = FirebaseHandler.AppUtils.GetDefaultInstance();
            }
            object sync = AppConfigExtensions.Sync;
            T      result;

            lock (sync)
            {
                string text = app.Name;
                if (string.IsNullOrEmpty(text))
                {
                    text = AppConfigExtensions.Default;
                }
                Dictionary <string, T> dictionary;
                if (!store.TryGetValue(state, out dictionary))
                {
                    dictionary   = new Dictionary <string, T>();
                    store[state] = dictionary;
                }
                T t;
                if (!dictionary.TryGetValue(text, out t))
                {
                    result = default(T);
                }
                else
                {
                    result = t;
                }
            }
            return(result);
        }
コード例 #2
0
        public void UpdateRootCertificates(IFirebaseAppPlatform app)
        {
            if (!InstallRootCerts.InstallationRequired)
            {
                return;
            }
            object sync = InstallRootCerts.Sync;

            lock (sync)
            {
                if (!InstallRootCerts._attemptedWebDownload)
                {
                    InstallRootCerts._attemptedWebDownload = true;
                    X509CertificateCollection x509CertificateCollection = null;
                    try
                    {
                        x509CertificateCollection = InstallRootCerts.DecodeWebRootCollection(app);
                    }
                    catch (Exception ex)
                    {
                        Services.Logging.LogMessage(PlatformLogLevel.Error, ex.ToString());
                    }
                    if (x509CertificateCollection != null && x509CertificateCollection.Count != 0)
                    {
                        X509Store x509Store = new X509Store(InstallRootCerts.TrustedRoot);
                        x509Store.Open(OpenFlags.ReadWrite);
                        X509CertificateCollection certificates = x509Store.Certificates;
                        X509CertificateCollection.X509CertificateEnumerator enumerator = x509CertificateCollection.GetEnumerator();
                        try
                        {
                            while (enumerator.MoveNext())
                            {
                                X509Certificate current = enumerator.Current;
                                if (!certificates.Contains(current))
                                {
                                    try
                                    {
                                        x509Store.Add((X509Certificate2)current);
                                    }
                                    catch (Exception ex2)
                                    {
                                        Services.Logging.LogMessage(PlatformLogLevel.Error, ex2.ToString());
                                    }
                                }
                            }
                        }
                        finally
                        {
                            IDisposable disposable;
                            if ((disposable = (enumerator as IDisposable)) != null)
                            {
                                disposable.Dispose();
                            }
                        }
                        x509Store.Close();
                        this.HackRefreshMonoRootStore();
                    }
                }
            }
        }
コード例 #3
0
        public virtual string GetEditorAuthUserId(IFirebaseAppPlatform app)
        {
            string text = Services.Auth.GetCurrentUserId(app);

            if (string.IsNullOrEmpty(text))
            {
                text = AppConfigExtensions.GetState <string>(app, 4, AppConfigExtensions.SStringState);
            }
            return(text);
        }
コード例 #4
0
        public Uri GetCertUpdateUrl(IFirebaseAppPlatform app)
        {
            string state = AppConfigExtensions.GetState <string>(app, 6, AppConfigExtensions.SStringState);

            if (string.IsNullOrEmpty(state))
            {
                return(AppConfigExtensions.DefaultUpdateUrl);
            }
            return(new Uri(state));
        }
コード例 #5
0
        public virtual string GetDatabaseUrl(IFirebaseAppPlatform app)
        {
            string text = AppConfigExtensions.GetState <string>(app, 0, AppConfigExtensions.SStringState);

            if (string.IsNullOrEmpty(text) && app != null)
            {
                Uri databaseUrl = app.DatabaseUrl;
                text = ((!(databaseUrl != null)) ? null : databaseUrl.ToString());
            }
            return(text);
        }
コード例 #6
0
        protected bool GetIsServiceAccountAuth(IFirebaseAppPlatform app)
        {
            if (app == null)
            {
                app = FirebaseHandler.AppUtils.GetDefaultInstance();
            }
            string editorP12FileName         = Services.AppConfig.GetEditorP12FileName(app);
            string editorServiceAccountEmail = Services.AppConfig.GetEditorServiceAccountEmail(app);

            return(!string.IsNullOrEmpty(editorP12FileName) && !string.IsNullOrEmpty(editorServiceAccountEmail) && File.Exists(editorP12FileName));
        }
コード例 #7
0
        public virtual Task <string> GetTokenAsync(IFirebaseAppPlatform app, bool forceRefresh)
        {
            if (app == null)
            {
                app = FirebaseHandler.AppUtils.GetDefaultInstance();
            }
            TaskCompletionSource <string> taskCompletionSource = new TaskCompletionSource <string>();

            if (this.GetIsServiceAccountAuth(app))
            {
                string editorP12FileName = Services.AppConfig.GetEditorP12FileName(app);
                string text = Services.AppConfig.GetEditorP12Password(app);
                string editorServiceAccountEmail = Services.AppConfig.GetEditorServiceAccountEmail(app);
                if (string.IsNullOrEmpty(text))
                {
                    text = "notasecret";
                }
                X509Certificate2         certificate = new X509Certificate2(editorP12FileName, text, X509KeyStorageFlags.Exportable);
                ServiceAccountCredential serviceAccountCredential = new ServiceAccountCredential(new ServiceAccountCredential.Initializer(editorServiceAccountEmail)
                {
                    Scopes = new List <string>(new string[]
                    {
                        "https://www.googleapis.com/auth/firebase.database",
                        "https://www.googleapis.com/auth/userinfo.email"
                    })
                }.FromCertificate(certificate));
                string accessTokenForRequest = serviceAccountCredential.GetAccessTokenForRequest();
                if (string.IsNullOrEmpty(accessTokenForRequest))
                {
                    Services.Logging.LogMessage(PlatformLogLevel.Debug, "FirebaseDatabase: Error obtaining service credential. Attempting unauthenticated access");
                    taskCompletionSource.SetResult(string.Empty);
                }
                else
                {
                    string editorAuthUserId = Services.AppConfig.GetEditorAuthUserId(app);
                    Dictionary <string, object> dictionary = null;
                    if (!string.IsNullOrEmpty(editorAuthUserId))
                    {
                        dictionary        = new Dictionary <string, object>();
                        dictionary["uid"] = editorAuthUserId;
                    }
                    GAuthToken gauthToken = new GAuthToken(accessTokenForRequest, dictionary);
                    taskCompletionSource.SetResult(gauthToken.SerializeToString());
                }
            }
            else
            {
                taskCompletionSource.SetResult(string.Empty);
            }
            return(taskCompletionSource.Task);
        }
コード例 #8
0
        private static X509CertificateCollection DecodeCollection(IFirebaseAppPlatform app)
        {
            string certPemFile = Services.AppConfig.GetCertPemFile(app);

            if (!string.IsNullOrEmpty(certPemFile))
            {
                TextAsset textAsset = Resources.Load(certPemFile) as TextAsset;
                if (textAsset != null)
                {
                    return(InstallRootCerts.DecodeCertificateCollectionFromString(textAsset.text));
                }
            }
            return(new X509CertificateCollection());
        }
コード例 #9
0
 public void GetTokenAsync(IFirebaseAppPlatform app, bool forceRefresh, IGetTokenCompletionListener listener)
 {
     this.GetTokenAsync(app, forceRefresh).ContinueWith(delegate(Task <string> task)
     {
         if (task.Exception != null)
         {
             Services.Logging.LogMessage(PlatformLogLevel.Error, task.Exception.ToString());
             listener.OnSuccess(string.Empty);
         }
         else
         {
             listener.OnSuccess(task.Result);
         }
     });
 }
コード例 #10
0
        public override void SetEditorP12FileName(IFirebaseAppPlatform app, string p12Filename)
        {
            string text = p12Filename;

            if (!string.IsNullOrEmpty(text) && !File.Exists(text))
            {
                text = string.Concat(new object[]
                {
                    Application.dataPath,
                    Path.DirectorySeparatorChar,
                    "Editor Default Resources",
                    Path.DirectorySeparatorChar,
                    text
                });
            }
            if (!string.IsNullOrEmpty(text) && !File.Exists(text))
            {
                FirebaseLogger.LogMessage(PlatformLogLevel.Warning, p12Filename + " was not found.  Also looked in " + text);
            }
            base.SetEditorP12FileName(app, text);
        }
コード例 #11
0
        private static X509CertificateCollection DecodeWebRootCollection(IFirebaseAppPlatform app)
        {
            Uri certUpdateUrl = Services.AppConfig.GetCertUpdateUrl(app);

            if (certUpdateUrl != null)
            {
                FirebaseHttpRequest firebaseHttpRequest = Services.HttpFactory.OpenConnection(certUpdateUrl);
                firebaseHttpRequest.SetRequestMethod("GET");
                if (firebaseHttpRequest.ResponseCode >= 200 && firebaseHttpRequest.ResponseCode < 300)
                {
                    Services.Logging.LogMessage(PlatformLogLevel.Debug, string.Format("updated certs from {0} completed with code {1}", certUpdateUrl, firebaseHttpRequest.ResponseCode.ToString()));
                    StreamReader streamReader = new StreamReader(firebaseHttpRequest.InputStream);
                    return(InstallRootCerts.DecodeCertificateCollectionFromString(streamReader.ReadToEnd()));
                }
                Services.Logging.LogMessage(PlatformLogLevel.Error, string.Format("error loading updated certs from {0} with code {1}", certUpdateUrl, firebaseHttpRequest.ResponseCode.ToString()));
            }
            else
            {
                Services.Logging.LogMessage(PlatformLogLevel.Warning, "No root cert url to download.");
            }
            return(new X509CertificateCollection());
        }
コード例 #12
0
        private static void SetState <T>(IFirebaseAppPlatform app, int state, T value, Dictionary <int, Dictionary <string, T> > store)
        {
            if (app == null)
            {
                app = FirebaseHandler.AppUtils.GetDefaultInstance();
            }
            object sync = AppConfigExtensions.Sync;

            lock (sync)
            {
                string text = app.Name;
                if (string.IsNullOrEmpty(text))
                {
                    text = AppConfigExtensions.Default;
                }
                Dictionary <string, T> dictionary;
                if (!store.TryGetValue(state, out dictionary))
                {
                    dictionary   = new Dictionary <string, T>();
                    store[state] = dictionary;
                }
                dictionary[text] = value;
            }
        }
コード例 #13
0
 public virtual void SetEditorServiceAccountEmail(IFirebaseAppPlatform app, string email)
 {
     AppConfigExtensions.SetState <string>(app, 3, email, AppConfigExtensions.SStringState);
 }
コード例 #14
0
 public virtual string GetCurrentUserId(IFirebaseAppPlatform app)
 {
     return(string.Empty);
 }
コード例 #15
0
 public virtual void AddTokenChangeListener(IFirebaseAppPlatform app, ITokenChangeListener listener)
 {
 }
コード例 #16
0
        public X509CertificateCollection Install(IFirebaseAppPlatform app)
        {
            if (!InstallRootCerts.InstallationRequired)
            {
                return(null);
            }
            object sync = InstallRootCerts.Sync;
            X509CertificateCollection result;

            lock (sync)
            {
                X509CertificateCollection x509CertificateCollection;
                if (InstallRootCerts._installedRoots.TryGetValue(app, out x509CertificateCollection))
                {
                    result = x509CertificateCollection;
                }
                else
                {
                    x509CertificateCollection = new X509CertificateCollection();
                    string text = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), ".mono"), "certs");
                    bool   flag = false;
                    try
                    {
                        flag = (Directory.Exists(text) || Directory.CreateDirectory(text) != null);
                    }
                    catch (Exception)
                    {
                    }
                    if (!flag)
                    {
                        string writeablePath = Services.AppConfig.GetWriteablePath(app);
                        if (!string.IsNullOrEmpty(writeablePath))
                        {
                            Services.Logging.LogMessage(PlatformLogLevel.Debug, string.Format("Saving root certs in {0} ({1} is not writable)", writeablePath, text));
                            Environment.SetEnvironmentVariable("XDG_CONFIG_HOME", writeablePath);
                            text = writeablePath;
                            this.HackRefreshMonoRootStore();
                        }
                    }
                    X509CertificateCollection value = InstallRootCerts.DecodeDefaultCollection();
                    X509CertificateCollection x509CertificateCollection2 = InstallRootCerts.DecodeCollection(app);
                    if (string.Equals(app.Name, FirebaseHandler.AppUtils.GetDefaultInstanceName()))
                    {
                        x509CertificateCollection2.AddRange(value);
                        x509CertificateCollection = x509CertificateCollection2;
                    }
                    else
                    {
                        x509CertificateCollection.AddRange(value);
                    }
                    InstallRootCerts._installedRoots[app] = x509CertificateCollection2;
                    if (x509CertificateCollection.Count == 0)
                    {
                        result = x509CertificateCollection;
                    }
                    else
                    {
                        InstallRootCerts.InstallDefaultCRLs("Firebase.Platform.cacrl_pem.txt", Path.Combine(text, InstallRootCerts.TrustedRoot));
                        InstallRootCerts.InstallDefaultCRLs("Firebase.Platform.caintermediatecrl_pem.txt", Path.Combine(text, InstallRootCerts.IntermediateCA));
                        Services.Logging.LogMessage(PlatformLogLevel.Debug, string.Format("Installing {0} certs", x509CertificateCollection2.Count));
                        X509Store x509Store = new X509Store(InstallRootCerts.TrustedRoot);
                        x509Store.Open(OpenFlags.ReadWrite);
                        X509CertificateCollection certificates = x509Store.Certificates;
                        X509CertificateCollection.X509CertificateEnumerator enumerator = x509CertificateCollection.GetEnumerator();
                        try
                        {
                            while (enumerator.MoveNext())
                            {
                                X509Certificate current = enumerator.Current;
                                if (!certificates.Contains(current))
                                {
                                    try
                                    {
                                        x509Store.Add((X509Certificate2)current);
                                    }
                                    catch (Exception ex)
                                    {
                                        Services.Logging.LogMessage(PlatformLogLevel.Error, ex.ToString());
                                    }
                                }
                            }
                        }
                        finally
                        {
                            IDisposable disposable;
                            if ((disposable = (enumerator as IDisposable)) != null)
                            {
                                disposable.Dispose();
                            }
                        }
                        x509Store.Close();
                        result = x509CertificateCollection;
                    }
                }
            }
            return(result);
        }
コード例 #17
0
 public void SetCertUpdateUrl(IFirebaseAppPlatform app, Uri certUrl)
 {
     AppConfigExtensions.SetState <string>(app, 6, certUrl.ToString(), AppConfigExtensions.SStringState);
 }
コード例 #18
0
 public override string GetWriteablePath(IFirebaseAppPlatform app)
 {
     return(FirebaseHandler.RunOnMainThread <string>(() => Application.persistentDataPath));
 }
コード例 #19
0
 public virtual string GetCertPemFile(IFirebaseAppPlatform app)
 {
     return(AppConfigExtensions.GetState <string>(app, 5, AppConfigExtensions.SStringState));
 }
コード例 #20
0
 public virtual string GetWriteablePath(IFirebaseAppPlatform app)
 {
     return(string.Empty);
 }
コード例 #21
0
 public X509CertificateCollection Install(IFirebaseAppPlatform app)
 {
     Services.Logging.LogMessage(PlatformLogLevel.Warning, "No certs are being installed because the platform doesn't support it.");
     return(null);
 }
コード例 #22
0
 public virtual void SetDatabaseUrl(IFirebaseAppPlatform app, string databaseUrl)
 {
     AppConfigExtensions.SetState <string>(app, 0, databaseUrl, AppConfigExtensions.SStringState);
 }
コード例 #23
0
 public virtual string GetEditorP12FileName(IFirebaseAppPlatform app)
 {
     return(AppConfigExtensions.GetState <string>(app, 1, AppConfigExtensions.SStringState));
 }
コード例 #24
0
 public virtual void SetEditorP12FileName(IFirebaseAppPlatform app, string p12Filename)
 {
     AppConfigExtensions.SetState <string>(app, 1, p12Filename, AppConfigExtensions.SStringState);
 }
コード例 #25
0
 public virtual void SetEditorP12Password(IFirebaseAppPlatform app, string p12Password)
 {
     AppConfigExtensions.SetState <string>(app, 2, p12Password, AppConfigExtensions.SStringState);
 }
コード例 #26
0
 public virtual string GetEditorServiceAccountEmail(IFirebaseAppPlatform app)
 {
     return(AppConfigExtensions.GetState <string>(app, 3, AppConfigExtensions.SStringState));
 }
コード例 #27
0
 public virtual void SetEditorAuthUserId(IFirebaseAppPlatform app, string uid)
 {
     AppConfigExtensions.SetState <string>(app, 4, uid, AppConfigExtensions.SStringState);
 }
コード例 #28
0
 public void UpdateRootCertificates(IFirebaseAppPlatform app)
 {
     Services.Logging.LogMessage(PlatformLogLevel.Warning, "No certs are being updated because the platform doesn't support it.");
 }
コード例 #29
0
 public virtual void SetCertPemFile(IFirebaseAppPlatform app, string certName)
 {
     AppConfigExtensions.SetState <string>(app, 5, certName, AppConfigExtensions.SStringState);
 }