public void Test() { var g = MagicKey.Generate(); var magicKey = new MagicKey(g.PrivateKey); Assert.IsNotNull(magicKey); }
public async Task Render(HttpRequest request, HttpResponse response, APEntity toRender) { response.ContentType = "application/atom+xml"; var user = await _entityStore.GetEntity(toRender.Data["actor"].Single().Id, false); var key = await _keyService.GetKey(user.Id); var magicKey = key != null ? new MagicKey(key.PrivateKey) : MagicKey.Generate(); var doc = await _entryGenerator.Build(toRender.Data); var enveloped = new MagicEnvelope(doc.ToString(), "application/atom+xml", magicKey); await response.WriteAsync(enveloped.Build().ToString()); }
public MagicKey GetMagicKey() { //Cached key if (_magicKey != null) { return(_magicKey); } //Generate key if needed if (!File.Exists(Path)) { var key = MagicKey.Generate(); File.WriteAllText(Path, key.PrivateKey); } //Load and return key var serializedKey = File.ReadAllText(Path); _magicKey = new MagicKey(serializedKey); return(_magicKey); }
public async Task Test() { var g = MagicKey.Generate(); var magicKey = new MagicKey(g.PrivateKey); }
public override async Task <bool> Handle() { if (MainObject.Type != "Create") { return(true); } var activityData = MainObject.Data; var objectEntity = await EntityStore.GetEntity((string)activityData["object"].First().Primitive, false); if (!_entityData.IsActor(objectEntity.Data)) { return(true); } var objectData = objectEntity.Data; var id = objectEntity.Id; await AddCollection(objectData, "inbox", id); await AddCollection(objectData, "outbox", id); await AddCollection(objectData, "following", id); await AddCollection(objectData, "followers", id); await AddCollection(objectData, "likes", id); var blocks = await AddCollection(objectData, "blocks", id); var blocked = await _collection.NewCollection(EntityStore, null, "_blocked", blocks.Id); var blocksData = blocks.Data; blocksData["_blocked"].Add(new ASTerm(blocked.Id)); blocks.Data = blocksData; objectEntity.Data = objectData; await EntityStore.StoreEntity(blocked); await EntityStore.StoreEntity(blocks); await EntityStore.StoreEntity(objectEntity); var userId = User.FindFirst(ClaimTypes.NameIdentifier).Value; _context.UserActorPermissions.Add(new UserActorPermission { UserId = userId, ActorId = objectEntity.Id, IsAdmin = true }); var key = new SalmonKey(); var salmon = MagicKey.Generate(); key.EntityId = objectEntity.Id; key.PrivateKey = salmon.PrivateKey; _context.SalmonKeys.Add(key); if (!activityData["locked"].Any() && !activityData["_:locked"].Any()) { activityData.Replace("_:locked", new ASTerm(false)); } if (!activityData["actor"].Any()) { activityData["actor"].Add(new ASTerm(objectEntity.Id)); } MainObject.Data = activityData; await EntityStore.StoreEntity(MainObject); await EntityStore.CommitChanges(); await _context.SaveChangesAsync(); return(true); }