private bool setupEncryption(PendingOperation pendingOperation) { if (generatingKeyPair || requestingEncryptionKey) { pendingOperations.Enqueue(pendingOperation); return(false); } if (!haveKeyPair()) { pendingOperations.Enqueue(pendingOperation); generatingKeyPair = true; clubPenguinClient.GenerateKeyPair(delegate(RSAParameters rsaParams) { generatingKeyPair = false; clubPenguinClient.CPKeyValueDatabase.SetRsaParameters(rsaParams); sendPendingOperations(); }, delegate { generatingKeyPair = false; failPendingOperations(); }); return(false); } if (!haveEncryptionKey()) { pendingOperations.Enqueue(pendingOperation); requestingEncryptionKey = true; RSAParameters rsaParameters = clubPenguinClient.CPKeyValueDatabase.GetRsaParameters().Value; string publicKeyExponent = Convert.ToBase64String(rsaParameters.Exponent); string publicKeyModulus = Convert.ToBase64String(rsaParameters.Modulus); APICall <GetEncryptionKeyOperation> encryptionKey = clubPenguinClient.EncryptionApi.GetEncryptionKey(publicKeyExponent, publicKeyModulus); encryptionKey.OnResponse += delegate(GetEncryptionKeyOperation op, HttpResponse resp) { requestingEncryptionKey = false; try { string keyId = op.ResponseBody.keyId; byte[] ciphertext = Convert.FromBase64String(op.ResponseBody.encryptedSymmetricKey); byte[] symmetricEncryptionKey = RsaEncryptor.Decrypt(ciphertext, rsaParameters); updateEncryptionKey(keyId, symmetricEncryptionKey); sendPendingOperations(); } catch (Exception ex) { Log.LogErrorFormatted(this, "Failed to decrypt symmetric key from server. Operations requiring encryption will fail. Exception: {0}", ex); failPendingOperations(); } }; encryptionKey.OnError += delegate { requestingEncryptionKey = false; failPendingOperations(); }; encryptionKey.Execute(); return(false); } return(true); }
public void LogFlush() { if (!clubPenguinClient.OfflineMode) { APICall <PostDiagnosticsLogOperation> aPICall = PostDiagnosticsLog(logParametersList); aPICall.OnComplete += onPostDiagnosticsLog; aPICall.Execute(); } }
public void LogImmediate(Log.PriorityFlags logLevel, StructuredLogObject logObject, LogChannelType channel = LogChannelType.Default) { if (!clubPenguinClient.OfflineMode) { LogParameters logParameters = new LogParameters(); logParameters.logName = channel.ToString(); logParameters.severity = logLevelsToString[logLevel]; logParameters.message = Service.Get <JsonService>().Serialize(logObject); logParametersList.Add(logParameters); APICall <PostDiagnosticsLogOperation> aPICall = PostDiagnosticsLog(logParametersList); aPICall.OnComplete += onPostDiagnosticsLog; aPICall.Execute(); } }