public void ProcessMessage(IHandlerContext <RegisterArgumentCommand> context) { var message = context.Message; if (string.IsNullOrEmpty(message.Name) || string.IsNullOrEmpty(message.DataTypeName)) { return; } using (_databaseContextFactory.Create()) { var key = Argument.Key(message.Name); var existingId = _keyStore.Get(key); if (!message.Id.Equals(existingId ?? message.Id)) { return; } var stream = _eventStore.Get(message.Id); var argument = new Argument(stream.Id); stream.Apply(argument); _keyStore.Remove(Argument.Key(argument.Name)); stream.AddEvent(argument.Register(message.Name, message.DataTypeName)); _eventStore.Save(stream); _keyStore.Add(argument.Id, key); } }
public void ProcessMessage(IHandlerContext <RegisterFormulaCommand> context) { var message = context.Message; using (_databaseContextFactory.Create()) { var key = Formula.Key(message.Name); var existingId = _keyStore.Get(key); if (!message.Id.Equals(existingId ?? message.Id)) { return; } var stream = _eventStore.Get(message.Id); var formula = new Formula(stream.Id); stream.Apply(formula); _keyStore.Remove(Formula.Key(formula.Name)); stream.AddEvent(formula.Register(message.Name)); _eventStore.Save(stream); _keyStore.Add(formula.Id, key); } }
public void ProcessMessage(IHandlerContext <AddRoleCommand> context) { var message = context.Message; if (string.IsNullOrEmpty(message.Name)) { return; } using (_databaseContextFactory.Create()) { var key = Role.Key(message.Name); if (_keyStore.Contains(key)) { return; } var id = Guid.NewGuid(); _keyStore.Add(id, key); var role = new Role(id); var stream = _eventStore.CreateEventStream(id); stream.AddEvent(role.Add(message.Name)); _eventStore.Save(stream); } }
/****************************************************************************/ public async Task <IKey> GetEncryptionKey() { try { // Get all keys in encryption store var keys = await _encryptStore.GetAll(); if (keys != null) { var expiredKeys = new List <Guid>(); try { // Find one that isn't expired foreach (var key in keys) { if (!key.Policy.IsExpired) { return(key); } expiredKeys.Add(key.Id); } } finally { // If we found expired keys then remove them if (expiredKeys.Count > 0) { var tasks = new List <Task>(); foreach (var id in expiredKeys) { tasks.Add(RemoveKey(id)); } await Task.WhenAll(tasks); } } } } catch (Exception ex) { _ = ex; } // Create a brand new key var newKey = new Key(_policyTemplate.Clone(_expires)); newKey.Policy.IsReadOnly = true; // Save to both stores await _decryptStore.Add(newKey); // Make sure it's saved here successfully before putting it in encrypt store await _encryptStore.Add(newKey); return(newKey); }
public void Remove_WithNoPassphrase(string passphrase, string inputPassphrase) { PrivateKey privateKey = new PrivateKey(); Guid keyId = _keyStore.Add(ProtectedPrivateKey.Protect(privateKey, passphrase)); Assert.Contains(keyId, _keyStore.ListIds()); _keyCommand.Remove(keyId, passphrase: inputPassphrase, noPassphrase: true); Assert.DoesNotContain(keyId, _keyStore.ListIds()); }
public void ProcessMessage(IHandlerContext <RegisterMatrixCommand> context) { var message = context.Message; using (_databaseContextFactory.Create()) { Matrix matrix; var key = Matrix.Key(message.Name); EventStream stream; if (message.Id.Equals(Guid.Empty)) { stream = _eventStore.CreateEventStream(); matrix = new Matrix(stream.Id); _keyStore.Add(matrix.Id, key); } else { stream = _eventStore.Get(message.Id); matrix = new Matrix(stream.Id); stream.Apply(matrix); if (!matrix.IsNamed(message.Name) && !_keyStore.Contains(key)) { _keyStore.Remove(Matrix.Key(message.Name)); _keyStore.Add(matrix.Id, key); } } stream.AddEvent(matrix.Register( message.Name, message.RowArgumentId, message.ColumnArgumentId, message.DataTypeName)); _eventStore.Save(stream); } }
private void CreateProtectedPrivateKey(PrivateKey privateKey) { var ppk = ProtectedPrivateKey.Protect(privateKey, passPhraseField.text); KeyStore.Add(ppk); _privateKey = privateKey; //[TentuPlay] 가입 기록 TPStashEvent MyStashEvent = new TPStashEvent(); MyStashEvent.Join(player_uuid: _privateKey.PublicKey.ToAddress().ToHex()); MyStashEvent.PlayerLogin(player_uuid: _privateKey.PublicKey.ToAddress().ToHex()); }
public void ProcessMessage(IHandlerContext <RegisterUserCommand> context) { var message = context.Message; var id = Guid.NewGuid(); Registered registered; using (_databaseContextFactory.Create()) { var key = User.Key(message.EMail); if (_keyStore.Contains(key)) { if (!message.EMail.Equals("shuttle", StringComparison.InvariantCultureIgnoreCase)) { context.Send(new SendEMailCommand { Body = string.Format("<p>Hello,</p><br/><p>Unfortunately e-mail '{0}' has been assigned before your user could be registered. Please register again.</p><br/><p>Regards</p>", message.EMail), Subject = "User registration failure", IsBodyHtml = true, To = message.EMail }); } return; } _keyStore.Add(id, key); var user = new User(id); var stream = new EventStream(id); registered = user.Register(message.EMail, message.PasswordHash, message.RegisteredBy); stream.AddEvent(registered); _eventStore.SaveEventStream(stream); } context.Publish(new UserRegisteredEvent { Id = id, EMail = message.EMail, RegisteredBy = message.RegisteredBy, DateRegistered = registered.DateRegistered }); }
public void ProcessMessage(IHandlerContext <RegisterUserCommand> context) { var message = context.Message; if (string.IsNullOrEmpty(message.Username)) { return; } if (string.IsNullOrEmpty(message.RegisteredBy)) { return; } var id = Guid.NewGuid(); using (_databaseContextFactory.Create()) { var key = User.Key(message.Username); if (_keyStore.Contains(key)) { return; } var count = _systemUserQuery.Count(); _keyStore.Add(id, key); var user = new User(id); var stream = _eventStore.CreateEventStream(id); var registered = user.Register(message.Username, message.PasswordHash, message.RegisteredBy); if (count == 0) { stream.AddEvent(user.AddRole("administrator")); } stream.AddEvent(registered); _eventStore.Save(stream); } }
public void ProcessMessage(IHandlerContext <RegisterTestCommand> context) { var message = context.Message; using (_databaseContextFactory.Create()) { var key = Test.Key(message.Name); if (_keyStore.Contains(key)) { return; } var test = new Test(Guid.NewGuid()); var stream = _eventStore.CreateEventStream(test.Id); stream.AddEvent(test.Register(message.Name, message.FormulaId, message.ExpectedResult, message.ExpectedResultDataTypeName, message.Comparison)); _eventStore.Save(stream); _keyStore.Add(test.Id, key); } }
/// <summary> /// Configure the AES instance /// </summary> /// <param name="streamId">Id of the stream to obtain the encryption key for</param> /// <param name="create">Whether to create a new key in case there is none in the key store</param> /// <returns>The configured AES instance</returns> private async Task <Aes> GetAes(string streamId, bool create = false) { var aes = new AesManaged { Mode = CipherMode.CBC, Padding = PaddingMode.PKCS7 }; if (!_keyCache.ContainsKey(streamId)) { if (!await _keyStore.Contains(streamId)) { if (create) { aes.GenerateKey(); await _keyStore.Add(streamId, aes.Key); _keyCache.Add(streamId, aes.Key); } else { throw new KeyDeletedException("The encryption key has been deleted"); } } else { var value = await _keyStore.Get(streamId); _keyCache.Add(streamId, value); } } aes.Key = _keyCache[streamId]; return(aes); }
void OnGUI() { _showPrivateKey = EditorGUILayout.Foldout(_showPrivateKey, "Private Key"); if (_showPrivateKey) { _selectedPrivateKeyIndex = EditorGUILayout.Popup( "Private Key", _selectedPrivateKeyIndex, _privateKeyOptions); if (_selectedPrivateKeyIndex == _privateKeyOptions.Length - 1) { _toggledOnTypePrivateKey = EditorGUILayout.Toggle( "Type New Private Key", _toggledOnTypePrivateKey); if (_toggledOnTypePrivateKey) { _privateKey = EditorGUILayout.PasswordField("New Private Key", _privateKey) ?? string.Empty; ShowError(_privateKey.Any() ? null : "New private key is empty."); } } _privateKeyPassphrase = EditorGUILayout.PasswordField("Passphrase", _privateKeyPassphrase) ?? string.Empty; ShowError(_privateKeyPassphrase.Any() ? null : "Passphrase is empty."); if (_selectedPrivateKeyIndex == _privateKeyOptions.Length - 1) { EditorGUI.BeginDisabledGroup(!_privateKeyPassphrase.Any()); if (GUILayout.Button("Create")) { var privateKey = _toggledOnTypePrivateKey ? new PrivateKey(ByteUtil.ParseHex(_privateKey)) : new PrivateKey(); var ppk = ProtectedPrivateKey.Protect(privateKey, _privateKeyPassphrase); _keyStore.Add(ppk); RefreshPrivateKeys(); _selectedPrivateKeyIndex = Array.IndexOf(_privateKeys, privateKey); } EditorGUI.EndDisabledGroup(); } } HorizontalLine(); _showParameters = EditorGUILayout.Foldout(_showParameters, "Parameters"); if (_showParameters) { _versionString = EditorGUILayout.TextField("Version", _versionString); try { version = int.Parse(_versionString, CultureInfo.InvariantCulture); } catch (Exception e) { ShowError(e.Message); } macOSBinaryUrl = EditorGUILayout.TextField("macOS Binary URL", macOSBinaryUrl); windowsBinaryUrl = EditorGUILayout.TextField("Windows Binary URL", windowsBinaryUrl); } HorizontalLine(); EditorGUI.BeginDisabledGroup( !(_privateKeyPassphrase.Any() && _selectedPrivateKeyIndex < _privateKeyOptions.Length - 1)); if (GUILayout.Button("Sign")) { var appProtocolVersionExtra = new AppProtocolVersionExtra(macOSBinaryUrl, windowsBinaryUrl, _timestamp); PrivateKey key; try { key = _privateKeys[_selectedPrivateKeyIndex].Item2 .Unprotect(_privateKeyPassphrase); } catch (IncorrectPassphraseException) { EditorUtility.DisplayDialog( "Unmatched passphrase", "Private key passphrase is incorrect.", "Retype passphrase" ); _privateKeyPassphrase = string.Empty; return; } _appProtocolVersion = AppProtocolVersion.Sign( key, version, appProtocolVersionExtra.Serialize()); } EditorGUI.EndDisabledGroup(); if (_appProtocolVersion is AppProtocolVersion v) { GUILayout.TextArea(v.Token); } }