public static IdentityLink Decode(string link) { if (link.StartsWith("deops://")) { link = link.Substring(8); } else { throw new Exception("Invalid Link"); } string[] mainParts = link.Split('/', ':'); if (mainParts.Length < 4 || mainParts[1] != "identity") { throw new Exception("Invalid Link"); } IdentityLink ident = new IdentityLink(); ident.OpName = HttpUtility.UrlDecode(mainParts[0]); ident.Name = HttpUtility.UrlDecode(mainParts[2]); ident.PublicOpID = Utilities.HextoBytes(mainParts[3]); ident.PublicKey = Utilities.HextoBytes(mainParts[4]); return(ident); }
public string GenerateInvite(string pubLink, out string name) { IdentityLink ident = IdentityLink.Decode(pubLink); // dont check opID, because invites come from different ops name = ident.Name; // deops://firesoft/invite/person@GlobalIM/originalopID~invitedata {op key web caches ips} string link = string.Format("deops://{0}/invite/{1}@{2}/", HttpUtility.UrlEncode(User.Settings.Operation), HttpUtility.UrlEncode(ident.Name), HttpUtility.UrlEncode(ident.OpName)); // encode invite info in user's public key byte[] data = new byte[4096]; MemoryStream mem = new MemoryStream(data); PacketStream stream = new PacketStream(mem, GuiProtocol, FileAccess.Write); // write invite OneWayInvite invite = new OneWayInvite(); invite.UserName = ident.Name; invite.OpName = User.Settings.Operation; invite.OpAccess = User.Settings.OpAccess; invite.OpID = User.Settings.OpKey; stream.WritePacket(invite); // write some contacts foreach (DhtContact contact in Network.Routing.GetCacheArea()) { byte[] bytes = contact.Encode(GuiProtocol, InvitePacket.Contact); mem.Write(bytes, 0, bytes.Length); } // write web caches foreach (WebCache cache in Network.Cache.GetLastSeen(3)) { stream.WritePacket(new WebCache(cache, InvitePacket.WebCache)); } mem.WriteByte(0); // end packets byte[] packets = Utilities.ExtractBytes(data, 0, (int)mem.Position); byte[] encrypted = Utilities.KeytoRsa(ident.PublicKey).Encrypt(packets, false); // ensure that this link is opened from the original operation remote's public key came from byte[] final = Utilities.CombineArrays(ident.PublicOpID, encrypted); return(link + Utilities.BytestoHex(final)); }
public string GetIdentity(ulong user) { if (!KeyMap.ContainsKey(user)) { return("User Public Key Unknown"); } IdentityLink link = new IdentityLink() { Name = GetName(user), OpName = User.Settings.Operation, PublicOpID = User.Settings.PublicOpID, PublicKey = KeyMap[user] }; string test = link.Encode(); IdentityLink check = IdentityLink.Decode(test); Debug.Assert(Utilities.MemCompare(link.PublicOpID, check.PublicOpID) && Utilities.MemCompare(link.PublicKey, check.PublicKey)); return(link.Encode()); }
public string GetIdentity(ulong user) { if (!KeyMap.ContainsKey(user)) return "User Public Key Unknown"; IdentityLink link = new IdentityLink() { Name = GetName(user), OpName = User.Settings.Operation, PublicOpID = User.Settings.PublicOpID, PublicKey = KeyMap[user] }; string test = link.Encode(); IdentityLink check = IdentityLink.Decode(test); Debug.Assert(Utilities.MemCompare(link.PublicOpID, check.PublicOpID) && Utilities.MemCompare(link.PublicKey, check.PublicKey)); return link.Encode(); }
public static IdentityLink Decode(string link) { if (link.StartsWith("deops://")) link = link.Substring(8); else throw new Exception("Invalid Link"); string[] mainParts = link.Split('/', ':'); if (mainParts.Length < 4 || mainParts[1] != "identity") throw new Exception("Invalid Link"); IdentityLink ident = new IdentityLink(); ident.OpName = HttpUtility.UrlDecode(mainParts[0]); ident.Name = HttpUtility.UrlDecode(mainParts[2]); ident.PublicOpID = Utilities.HextoBytes(mainParts[3]); ident.PublicKey = Utilities.HextoBytes(mainParts[4]); return ident; }