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); }
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(); } } } }
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); }
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)); }
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); }
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)); }
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); }
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()); }
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); } }); }
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); }
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()); }
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; } }
public virtual void SetEditorServiceAccountEmail(IFirebaseAppPlatform app, string email) { AppConfigExtensions.SetState <string>(app, 3, email, AppConfigExtensions.SStringState); }
public virtual string GetCurrentUserId(IFirebaseAppPlatform app) { return(string.Empty); }
public virtual void AddTokenChangeListener(IFirebaseAppPlatform app, ITokenChangeListener listener) { }
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); }
public void SetCertUpdateUrl(IFirebaseAppPlatform app, Uri certUrl) { AppConfigExtensions.SetState <string>(app, 6, certUrl.ToString(), AppConfigExtensions.SStringState); }
public override string GetWriteablePath(IFirebaseAppPlatform app) { return(FirebaseHandler.RunOnMainThread <string>(() => Application.persistentDataPath)); }
public virtual string GetCertPemFile(IFirebaseAppPlatform app) { return(AppConfigExtensions.GetState <string>(app, 5, AppConfigExtensions.SStringState)); }
public virtual string GetWriteablePath(IFirebaseAppPlatform app) { return(string.Empty); }
public X509CertificateCollection Install(IFirebaseAppPlatform app) { Services.Logging.LogMessage(PlatformLogLevel.Warning, "No certs are being installed because the platform doesn't support it."); return(null); }
public virtual void SetDatabaseUrl(IFirebaseAppPlatform app, string databaseUrl) { AppConfigExtensions.SetState <string>(app, 0, databaseUrl, AppConfigExtensions.SStringState); }
public virtual string GetEditorP12FileName(IFirebaseAppPlatform app) { return(AppConfigExtensions.GetState <string>(app, 1, AppConfigExtensions.SStringState)); }
public virtual void SetEditorP12FileName(IFirebaseAppPlatform app, string p12Filename) { AppConfigExtensions.SetState <string>(app, 1, p12Filename, AppConfigExtensions.SStringState); }
public virtual void SetEditorP12Password(IFirebaseAppPlatform app, string p12Password) { AppConfigExtensions.SetState <string>(app, 2, p12Password, AppConfigExtensions.SStringState); }
public virtual string GetEditorServiceAccountEmail(IFirebaseAppPlatform app) { return(AppConfigExtensions.GetState <string>(app, 3, AppConfigExtensions.SStringState)); }
public virtual void SetEditorAuthUserId(IFirebaseAppPlatform app, string uid) { AppConfigExtensions.SetState <string>(app, 4, uid, AppConfigExtensions.SStringState); }
public void UpdateRootCertificates(IFirebaseAppPlatform app) { Services.Logging.LogMessage(PlatformLogLevel.Warning, "No certs are being updated because the platform doesn't support it."); }
public virtual void SetCertPemFile(IFirebaseAppPlatform app, string certName) { AppConfigExtensions.SetState <string>(app, 5, certName, AppConfigExtensions.SStringState); }