コード例 #1
0
ファイル: OpCore.cs プロジェクト: nandub/DeOps
        public static InvitePackage OpenInvite(byte[] decrypted, G2Protocol protocol)
        {
            // if we get down here, opening invite was success

            MemoryStream mem    = new MemoryStream(decrypted);
            PacketStream stream = new PacketStream(mem, protocol, FileAccess.Read);

            InvitePackage package = new InvitePackage();

            G2Header root = null;

            while (stream.ReadPacket(ref root))
            {
                if (root.Name == InvitePacket.Info)
                {
                    package.Info = OneWayInvite.Decode(root);
                }

                if (root.Name == InvitePacket.Contact)
                {
                    package.Contacts.Add(DhtContact.ReadPacket(root));
                }

                if (root.Name == InvitePacket.WebCache)
                {
                    package.Caches.Add(WebCache.Decode(root));
                }
            }

            return(package);
        }
コード例 #2
0
ファイル: OpCore.cs プロジェクト: nandub/DeOps
        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));
        }
コード例 #3
0
ファイル: OpCore.cs プロジェクト: swax/DeOps
        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);
        }