/// <summary> /// Internally calls the Init() method. If the user hasn't logged in /// to the service, a login UI will popup. Otherwise, it will initialize silently. /// On iOS, the OS automatically shows the login popup when the app gets focus for the first 3 times. /// Subsequent init calls will be ignored. /// On Android, if the user dismisses the login popup for a number of times determined /// by AndroidMaxLoginRequests, we'll stop showing it (all subsequent init calls will be ignored). /// </summary> public static void ManagedInit() { #if UNITY_IOS if (!IsInitialized()) { Init(); } #elif UNITY_ANDROID if (!IsInitialized()) { int loginRequestNumber = StorageUtil.GetInt(ANDROID_LOGIN_REQUEST_NUMBER_PPKEY, 0); if (loginRequestNumber < EM_Settings.GameServices.AndroidMaxLoginRequests || EM_Settings.GameServices.AndroidMaxLoginRequests <= 0) { loginRequestNumber++; StorageUtil.SetInt(ANDROID_LOGIN_REQUEST_NUMBER_PPKEY, loginRequestNumber); StorageUtil.Save(); Init(); } else { Debug.Log("Failed to initialize Game Services module: AndroidMaxLoginRequests exceeded. Requests attempted: " + loginRequestNumber); } } #endif }
public static object LogDomainCertificates(object[] args) { byte[] domainCertListStorageKey = (byte[])args[0]; Logger.log("Log Domain Certificates started. Domain: ", domainCertListStorageKey); byte[] trustedRootCAListHashMapEntrySerialized = StorageUtil.readFromStorage(domainCertListStorageKey); if (trustedRootCAListHashMapEntrySerialized != null) { Logger.log("Certificates for domain exists in Storage. Domain: ", domainCertListStorageKey); CertificateHashMapEntry certificateHashMapEntry = (CertificateHashMapEntry)SerializationUtil.Deserialize(trustedRootCAListHashMapEntrySerialized); Logger.log("Certificate Count: "); Logger.log(certificateHashMapEntry.certificateHashArray.Length); for (int i = 0; i < certificateHashMapEntry.certificateHashArray.Length; i++) { byte[] certificateHashEntrySerialized = certificateHashMapEntry.certificateHashArray[i]; CertificateHashEntry certificateHashEntry = (CertificateHashEntry)SerializationUtil.Deserialize(certificateHashEntrySerialized); Logger.log("IsCa: ", certificateHashEntry.IsCa); Logger.log(certificateHashEntry.CertificateHash); LogSSLCertificateWithCertificateHashValue(certificateHashEntry.CertificateHash); } } else { Logger.log("There isn't any certificate for Domain: ", domainCertListStorageKey); } Logger.log("Log Domain Certificates completed. Domain: ", domainCertListStorageKey); return(true); }
private static void AddToDomainCertificateHash(byte[] domainName, byte[] certificateHash) { CertificateHashMapEntry certHashMapEntry; byte[] certHashMapEntrySerialized = StorageUtil.readFromStorage(domainName); if (certHashMapEntrySerialized == null) { certHashMapEntry = new CertificateHashMapEntry(); certHashMapEntry.CertificateHashList = new List <CertificateHashEntry>(); } else { certHashMapEntry = (CertificateHashMapEntry)SerializationUtil.Deserialize(certHashMapEntrySerialized); } foreach (var certificateHashEntry in certHashMapEntry.CertificateHashList) { if (ArrayUtil.AreEqual(certificateHashEntry.CertificateHash, certificateHash)) { return; } } CertificateHashEntry newCertHashEntry = new CertificateHashEntry(); newCertHashEntry.CertificateHash = certificateHash; newCertHashEntry.IsCa = false; certHashMapEntry.CertificateHashList.Add(newCertHashEntry); //certHashMapEntry.Count += 1; certHashMapEntrySerialized = SerializationUtil.Serialize(certHashMapEntry); StorageUtil.saveToStorage(domainName, certHashMapEntrySerialized); }
private static void AddCertificateToCaIssuedCertificateList(Certificate certificate, byte[] certificateHash) { CertificateHashMapEntry certHashMapEntry; byte[] storageKey = ArrayUtil.Concat(ELEMENT_LIST, certificate.AuthorityKeyIdentifier.keyIdentifier); byte[] certHashMapEntrySerialized = StorageUtil.readFromStorage(storageKey); if (certHashMapEntrySerialized == null) { certHashMapEntry = new CertificateHashMapEntry(); certHashMapEntry.CertificateHashList = new List <CertificateHashEntry>(); //certHashMapEntry.Count = 0; } else { certHashMapEntry = (CertificateHashMapEntry)SerializationUtil.Deserialize(certHashMapEntrySerialized); } CertificateHashEntry newCertHashEntry = new CertificateHashEntry(); newCertHashEntry.CertificateHash = certificateHash; newCertHashEntry.IsCa = certificate.BasicConstraints.IsCa; certHashMapEntry.CertificateHashList.Add(newCertHashEntry); // certHashMapEntry.Count += 1; certHashMapEntrySerialized = SerializationUtil.Serialize(certHashMapEntry); StorageUtil.saveToStorage(storageKey, certHashMapEntrySerialized); }
private static void AddRootCaCertificateToRootCaList(byte[] rootCACertificateHash) { CertificateHashMapEntry trustedRootCaHashMapEntry; byte[] trustedRootCAListHashMapEntrySerialized = StorageUtil.readFromStorage(TRUSTED_ROOT_CA_LIST_STORAGE_KEY); if (trustedRootCAListHashMapEntrySerialized == null) { trustedRootCaHashMapEntry = new CertificateHashMapEntry(); trustedRootCaHashMapEntry.CertificateHashList = new List <CertificateHashEntry>(); //trustedRootCaHashMapEntry.Count = 0; } else { trustedRootCaHashMapEntry = (CertificateHashMapEntry)SerializationUtil.Deserialize(trustedRootCAListHashMapEntrySerialized); } CertificateHashEntry newCertHashEntry = new CertificateHashEntry(); newCertHashEntry.CertificateHash = rootCACertificateHash; newCertHashEntry.IsCa = true; trustedRootCaHashMapEntry.CertificateHashList.Add(newCertHashEntry); //trustedRootCaHashMapEntry.Count += 1; trustedRootCAListHashMapEntrySerialized = SerializationUtil.Serialize(trustedRootCaHashMapEntry); StorageUtil.saveToStorage(TRUSTED_ROOT_CA_LIST_STORAGE_KEY, trustedRootCAListHashMapEntrySerialized); }
/// <summary> /// Initializes the Easy Mobile runtime. Always do this before /// accessing Easy Mobile API. It's recommended to initialize as /// early as possible, ideally as soon as the app launches. This /// method is a no-op if the runtime has been initialized before, so it's /// safe to be called multiple times. This method must be called on /// the main thread. /// </summary> public static void Init() { if (mIsInitialized) { return; } if (Application.isPlaying) { // Initialize runtime Helper. RuntimeHelper.Init(); // Add an 'EasyMobile' game object to the current scene // which is the main object responsible for all runtime // activities of EM. var go = new GameObject("EasyMobile"); Configure(go); // Store the timestamp of the *first* init which can be used // as a rough approximation of the installation time. if (StorageUtil.GetTime(APP_INSTALLATION_TIMESTAMP_PPKEY, Util.UnixEpoch) == Util.UnixEpoch) { StorageUtil.SetTime(APP_INSTALLATION_TIMESTAMP_PPKEY, DateTime.Now); } // Done init. mIsInitialized = true; Debug.Log("Easy Mobile runtime has been initialized."); } }
private static void AddCaCertificateToStorage(Certificate certificate, byte[] certificateHash, byte[] encodedCert, bool isRootCA) { CaCertificateEntry caCertificateEntry = new CaCertificateEntry(); caCertificateEntry.CertificateValue = encodedCert; if (isRootCA) { caCertificateEntry.IsTrusted = true; caCertificateEntry.IsRevoked = false; } else { caCertificateEntry.IsTrusted = false; caCertificateEntry.IsRevoked = false; } byte[] caCertificateEntrySerialized = SerializationUtil.Serialize(caCertificateEntry); StorageUtil.saveToStorage(certificateHash, caCertificateEntrySerialized); CaCertificateSubjectKeyIdEntry cACertificateSubjectKeyIdEntry = new CaCertificateSubjectKeyIdEntry(); cACertificateSubjectKeyIdEntry.CertificateHash = certificateHash; cACertificateSubjectKeyIdEntry.IsRootCa = isRootCA; byte[] cACertificateSubjectKeyIdEntrySerialized = SerializationUtil.Serialize(cACertificateSubjectKeyIdEntry); StorageUtil.saveToStorage(certificate.SubjectKeyIdentifier.keyIdentifier, cACertificateSubjectKeyIdEntrySerialized); }
public static object ResetStorage() { Logger.log("Deleting all storage entries"); StorageUtil.clearStorage(); Logger.log("Deleted all storage entries"); return(true); }
// This function gets called when Authenticate completes // Note that if the operation is successful, Social.localUser will contain data from the server. static void ProcessAuthentication(bool success) { if (success) { if (UserLoginSucceeded != null) { UserLoginSucceeded(); } #if UNITY_ANDROID // Reset login request number StorageUtil.SetInt(ANDROID_LOGIN_REQUEST_NUMBER_PPKEY, 0); StorageUtil.Save(); #endif // Set GPGS popup gravity, this needs to be done after authentication. #if UNITY_ANDROID && EM_GPGS PlayGamesPlatform.Instance.SetGravityForPopups(ToGpgsGravity(EM_Settings.GameServices.GpgsPopupGravity)); #endif } else { if (UserLoginFailed != null) { UserLoginFailed(); } } }
protected QueueTest(string connectionStringName) { var connectionStringBuilder = new SqlConnectionStringBuilder(ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString); var databaseName = connectionStringBuilder.InitialCatalog; connectionStringBuilder.InitialCatalog = "master"; using (var connection = new SqlConnection(connectionStringBuilder.ConnectionString)) { connection.Open(); using (var createCommand = new SqlCommand( @" IF ((SELECT DB_ID ('<databasename, sysname, queuedb>')) IS NULL) BEGIN CREATE DATABASE [<databasename, sysname, queuedb>] END" .Replace("<databasename, sysname, queuedb>", databaseName), connection)) { createCommand.CommandType = CommandType.Text; createCommand.ExecuteNonQuery(); } } try { var storage = new QueueStorage(connectionStringName); storage.Initialize(); } catch (SqlException) { new SchemaCreator().Create(connectionStringName, 2204); } StorageUtil.PurgeAll(connectionStringName); }
private static bool IsRulePassDevicesMustNotRepeat(ReadOnlyCollection <SnapShotSource> sources) { List <string> roots = new List <string>(); try { foreach (SnapShotSource source in sources) { string root = string.Empty; try { root = StorageUtil.GetPathRoot(source.DirSource); } catch (Exception ex) { Log.Warn(ex, @"Path could not be checked: "); } if (roots.Contains(root)) { return(false); // a data source overlaps } roots.Add(root); } } catch (Exception ex) { Log.Error(ex, @"Path could not be checked:"); return(false); } return(true); }
/// <summary> /// Saves the consent status with the given key into the persistent storage. /// </summary> /// <param name="key">Key.</param> /// <param name="consent">Consent.</param> public static void SaveConsent(string key, ConsentStatus consent) { var consentInt = consent == ConsentStatus.Unknown ? UnknownConsentStoredValue : consent == ConsentStatus.Revoked ? RevokedConsentStoredValue : GrantedConsentStoredValue; StorageUtil.SetInt(key, consentInt); }
/// <summary> /// Reads the consent status with given key from the persistent storage. /// Returns <c>ConsentStatus.Unknown</c> if no saved value found. /// </summary> /// <returns>The consent status.</returns> /// <param name="key">Key.</param> public static ConsentStatus ReadConsent(string key) { var consentInt = StorageUtil.GetInt(key, UnknownConsentStoredValue); return(consentInt == UnknownConsentStoredValue ? ConsentStatus.Unknown : consentInt == RevokedConsentStoredValue ? ConsentStatus.Revoked : ConsentStatus.Granted); }
/// <summary> /// Resets the ads removal status and allows showing ads again. /// This is intended for testing purpose only. Note that this method /// doesn't restore the data privacy consent of the Advertising module /// and the supported networks. /// </summary> public static void ResetRemoveAds() { // Update ad removal status. StorageUtil.SetInt(AD_REMOVE_STATUS_PPKEY, AD_ENABLED); StorageUtil.Save(); Debug.Log("Ads were re-enabled."); }
private static async Task <string> SaveFile(StorageFile file, string folderName, int id, string extension) { var folder = await StorageUtil.OpenOrCreateFolder(folderName); var path = string.Format("{0}.{1}", id, extension); var copiedFile = await file.CopyAsync(folder, path, NameCollisionOption.ReplaceExisting); return(path); }
static string NextLocalNotificationId() { int currentId = StorageUtil.GetInt(LOCAL_NOTIF_CURRENT_ID_PPKEY, 0); int nextId = currentId == int.MaxValue ? 1 : currentId + 1; StorageUtil.SetInt(LOCAL_NOTIF_CURRENT_ID_PPKEY, nextId); StorageUtil.Save(); return(LOCAL_NOTIF_ID_PREFIX + nextId.ToString()); }
public AuthorizationBase() { TokenInfo tokenInfo; if (StorageUtil.TryGetJsonObj(LoginDataKey, out tokenInfo)) { TokenInfo = tokenInfo; } }
private static void UpdateLoginInfo(LoginType loginType, RiBaoAuthoInfo info) { StorageInfo.Instance.LoginType = loginType; StorageInfo.Instance.ZhiHuAuthoInfo = info; StorageUtil.UpdateStorageInfo(); IsLogin = true; SetHttpAuthorization(); }
public SinaAuthorization() { LoginData loginData; if (StorageUtil.TryGetJsonObj(LoginDataKey, out loginData)) { LoginData = loginData; } }
void OnGUI() { if (GUI.Button(new Rect(50f, 50f, 200f, 150f), "Available Storage")) { Debug.Log("CHECK DEVICE STORAGE"); Debug.Log(" |__ AVAILABLE STORAGE : " + StorageUtil.GetAvailableStorageMB() + " MB"); Debug.Log(" |__ TOTAL STORAGE : " + StorageUtil.GetTotalStorageMB() + " MB"); } }
public static void MarkRootCaCertificateUntrustedInStorage(Certificate rootCACertificate, byte[] certificateHash) { byte[] cACertificateEntrySerialized = StorageUtil.readFromStorage(certificateHash); CaCertificateEntry cACertificateEntry = (CaCertificateEntry)SerializationUtil.Deserialize(cACertificateEntrySerialized); cACertificateEntry.IsTrusted = false; cACertificateEntrySerialized = SerializationUtil.Serialize(cACertificateEntry); StorageUtil.saveToStorage(certificateHash, cACertificateEntrySerialized); MarkAllCertificatesAsRevokedForCa(rootCACertificate); }
private static CaCertificateEntry FindCaCertificatewithCertificateHash(byte[] certificateHash) { byte[] caCertificateEnrtySerialized = StorageUtil.readFromStorage(certificateHash); if (caCertificateEnrtySerialized != null) { return((CaCertificateEntry)SerializationUtil.Deserialize(caCertificateEnrtySerialized)); } else { return(new CaCertificateEntry()); } }
private static CaCertificateSubjectKeyIdEntry FindCaCertificateHashEntry(byte[] subjectKeyIdentifier) { byte[] cACertificateSubjectKeyIdEntrySerialiazed = StorageUtil.readFromStorage(subjectKeyIdentifier); if (cACertificateSubjectKeyIdEntrySerialiazed != null) { return((CaCertificateSubjectKeyIdEntry)SerializationUtil.Deserialize(cACertificateSubjectKeyIdEntrySerialiazed)); } else { return(new CaCertificateSubjectKeyIdEntry()); } }
public void Should_UnTrusted_Root_Certificate_When_Any_SubCA_And_Ssl_Certificate_Is_Not_Exist() { string rootCertFilePath = "../../../test-data/certs/test-ca/Test-Root-CA-RSA-2048.cer"; byte[] rootCertEncoded = File.ReadAllBytes(rootCertFilePath); byte[] rootCertDigest = DigestUtilities.CalculateDigest("SHA_256", rootCertEncoded); byte[] requestSignature = SignUtil.generateAddTrustedRootCAOperationRequestSignature(rootCertEncoded); bool result = RootCaCertificateHandler.AddTrustedRootCaCertificate(rootCertDigest, rootCertEncoded, requestSignature); Assert.True(result); Certificate rootCertificate = CertificateParser.Parse(rootCertEncoded); byte[] rootCACertificateEntryByte = StorageUtil.readFromStorage(rootCertDigest); CaCertificateEntry caCertificateEntry = (CaCertificateEntry)SerializationUtil.Deserialize(rootCACertificateEntryByte); Assert.True(caCertificateEntry.IsTrusted); Assert.False(caCertificateEntry.IsRevoked); Assert.Equal(caCertificateEntry.CertificateValue, rootCertEncoded); byte[] cACertificateSubjectKeyIdEntrySerialized = StorageUtil.readFromStorage(rootCertificate.SubjectKeyIdentifier.keyIdentifier); CaCertificateSubjectKeyIdEntry cACertificateSubjectKeyIdEntry = (CaCertificateSubjectKeyIdEntry)SerializationUtil.Deserialize( cACertificateSubjectKeyIdEntrySerialized); Assert.True(cACertificateSubjectKeyIdEntry.IsRootCa); Assert.Equal(cACertificateSubjectKeyIdEntry.CertificateHash, rootCertDigest); byte[] certificateHashMapEntrySerialized = StorageUtil.readFromStorage(CertificateStorageManager.TRUSTED_ROOT_CA_LIST_STORAGE_KEY); CertificateHashMapEntry trustedRootCAListHashMapEntry = (CertificateHashMapEntry)SerializationUtil.Deserialize(certificateHashMapEntrySerialized); Assert.Equal(1, trustedRootCAListHashMapEntry.certificateHashArray.Length); byte[] certificateHashEntrySerialized = trustedRootCAListHashMapEntry.certificateHashArray[0]; CertificateHashEntry certificateHashEntry = (CertificateHashEntry)SerializationUtil.Deserialize(certificateHashEntrySerialized); Assert.True(certificateHashEntry.IsCa); Assert.Equal(rootCertDigest, certificateHashEntry.CertificateHash); requestSignature = SignUtil.generateUntrustRootCAOperationRequestSignature(rootCertEncoded); result = RootCaCertificateHandler.UntrustRootCaCertificate(rootCertDigest, rootCertEncoded, requestSignature); Assert.True(result); rootCACertificateEntryByte = StorageUtil.readFromStorage(rootCertDigest); caCertificateEntry = (CaCertificateEntry)SerializationUtil.Deserialize(rootCACertificateEntryByte); Assert.False(caCertificateEntry.IsTrusted); Assert.False(caCertificateEntry.IsRevoked); }
void Start() { // Init the module if automatic init is enabled. if (!EM_Settings.GameServices.IsAutoInit) { return; } if (!EM_Settings.GameServices.IsAutoInitAfterUserLogout && StorageUtil.GetInt(USER_CALLED_LOG_OUT_IN_PREVIOUS_SESSION, 0) == 1) { return; } StartCoroutine(CRAutoInit(EM_Settings.GameServices.AutoInitDelay)); }
public static void AddEndEntityCertificateToStorage(Certificate certificate, byte[] certificateHash, byte[] encodedCert) { EndEntityCertificateEntry endEntityCertificateEntry = new EndEntityCertificateEntry(); endEntityCertificateEntry.CertificateValue = encodedCert; endEntityCertificateEntry.IsRevoked = false; byte[] endEntityCertificateEntrySerialized = SerializationUtil.Serialize(endEntityCertificateEntry); StorageUtil.saveToStorage(certificateHash, endEntityCertificateEntrySerialized); AddCertificateToCaIssuedCertificateList(certificate, certificateHash); AddCertificateToDomainCertificateList(certificate, certificateHash); }
public void Should_Revoke_SSL_Certificate_When_Request_Signed_With_Issuer_Private_Key() { { string rootCertFilePath = "../../../test-data/certs/test-ca/Test-Root-CA-RSA-2048.cer"; byte[] rootCertEncoded = File.ReadAllBytes(rootCertFilePath); byte[] rootCertDigest = DigestUtilities.CalculateDigest("SHA_256", rootCertEncoded); byte[] requestSignature = SignUtil.generateAddTrustedRootCAOperationRequestSignature(rootCertEncoded); bool result = RootCaCertificateHandler.AddTrustedRootCaCertificate(rootCertDigest, rootCertEncoded, requestSignature); Assert.True(result); } { string subCaCertFilePath = "../../../test-data/certs/test-ca/Test-Sub-CA-RSA-2048.cer"; byte[] subCaCertEncoded = File.ReadAllBytes(subCaCertFilePath); byte[] subCaCertificateHash = DigestUtilities.CalculateDigest("SHA_256", subCaCertEncoded); byte[] subCaAddRequestSignature = null; bool result = SubCaCertificateHandler.AddSubCaCertificate(subCaCertificateHash, subCaCertEncoded, subCaAddRequestSignature); Assert.True(result); } string sSLCertFilePath = "../../../test-data/certs/test-ca/Test-SSL-RSA-2048.cer"; byte[] sSLCertEncoded = File.ReadAllBytes(sSLCertFilePath); byte[] sSLCertHash = DigestUtilities.CalculateDigest("SHA_256", sSLCertEncoded); bool sslCertAddResult = SslCertificateHandler.AddSslCertificate(sSLCertHash, sSLCertEncoded); Assert.True(sslCertAddResult); string sSLCertIssuerPkcs8PrivateKeyFilePath = "../../../test-data/certs/test-ca/Test-Sub-CA-RSA-2048.pk8"; byte[] revokeSSLCertificateRequestSignature = SignUtil.generateRevokeSSLCertificateOperationRequestRSAPSSSignature(sSLCertEncoded, sSLCertIssuerPkcs8PrivateKeyFilePath); Certificate sslCertificate = CertificateParser.Parse(sSLCertEncoded); bool revokeSSLCertificateResult = SslCertificateHandler.RevokeSslCertificate(sSLCertHash, sSLCertEncoded, revokeSSLCertificateRequestSignature); Assert.True(revokeSSLCertificateResult); byte[] sSLCertificateEntryByte = StorageUtil.readFromStorage(sSLCertHash); EndEntityCertificateEntry sSLCertificateEntry = (EndEntityCertificateEntry)SerializationUtil.Deserialize(sSLCertificateEntryByte); Assert.True(sSLCertificateEntry.IsRevoked); Assert.Equal(sSLCertificateEntry.CertificateValue, sSLCertEncoded); }
private void UpdateLoginData(SdkAuth2Res res) { if (LoginData == null) { LoginData = new LoginData(); } LoginData.access_token = res.AccessToken; LoginData.expires_in = int.Parse(res.ExpriesIn); LoginData.refresh_token = res.RefreshToken; LoginData.source = LoginType.Sina.Convert(); LoginData.user = res.Uid; StorageUtil.AddObject(LoginDataKey, LoginData); }
private static void MarkEndEntityCertificateRevokedInStore(byte[] certificateHash) { byte[] endEntityCertificateEntrySerialized = StorageUtil.readFromStorage(certificateHash); if (endEntityCertificateEntrySerialized == null) { return; } EndEntityCertificateEntry entityCertificateEntry = (EndEntityCertificateEntry)SerializationUtil.Deserialize(endEntityCertificateEntrySerialized); entityCertificateEntry.IsRevoked = true; endEntityCertificateEntrySerialized = SerializationUtil.Serialize(entityCertificateEntry); StorageUtil.saveToStorage(certificateHash, endEntityCertificateEntrySerialized); }
public static bool MarkSubCaCertificateRevokedInStore(Certificate subCACertificate, byte[] certificateHash) { byte[] cACertificateEntrySerialized = StorageUtil.readFromStorage(certificateHash); CaCertificateEntry cACertificateEntry = (CaCertificateEntry)SerializationUtil.Deserialize(cACertificateEntrySerialized); if (cACertificateEntry.IsRevoked || cACertificateEntry.IsTrusted) { return(false); } cACertificateEntry.IsRevoked = true; cACertificateEntrySerialized = SerializationUtil.Serialize(cACertificateEntry); StorageUtil.saveToStorage(certificateHash, cACertificateEntrySerialized); MarkAllCertificatesAsRevokedForCa(subCACertificate); return(true); }