public static UpdateInfo LoadUpdate(LookupSettings config) { UpdateInfo info = config.ReadUpdateInfo(); if (info == null) { return(null); } if (!File.Exists(config.UpdatePath)) { return(null); } using (FileStream stream = new FileStream(config.UpdatePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { byte[] check = new byte[info.Beginning.Length]; stream.Read(check, 0, check.Length); if (stream.Length == info.Size && Utilities.MemCompare(check, info.Beginning)) { info.Loaded = true; } } return(info); }
public DhtNetwork(OpCore core, bool lookup) { Core = core; IsLookup = lookup; Cache = new OpCache(this); // lookup config loads cache entries if (IsLookup) { Core.Context.LookupConfig.Load(this); Lookup = Core.Context.LookupConfig; } Local = new DhtClient(); Local.UserID = IsLookup ? Lookup.Ports.UserID : Utilities.KeytoID(Core.User.Settings.KeyPublic); Local.ClientID = (ushort)Core.RndGen.Next(1, ushort.MaxValue); OpID = Utilities.KeytoID(IsLookup ? LookupKey : Core.User.Settings.OpKey); OpCrypt = new RijndaelManaged(); // load encryption if (IsLookup) { OpCrypt.Key = LookupKey; } else { OpCrypt.Key = Core.User.Settings.OpKey; } LocalAugmentedKey = GetAugmentedKey(Local.UserID); Protocol = new G2Protocol(); TcpControl = new TcpHandler(this); UdpControl = new UdpHandler(this); LanControl = new LanHandler(this); RudpControl = new RudpHandler(this); LightComm = new LightCommHandler(this); UPnPControl = new UPnPHandler(this); Routing = new DhtRouting(this); Store = new DhtStore(this); Searches = new DhtSearchControl(this); }
public UpdateService(OpCore core) { Core = core; Core.Update = this; LookupConfig = core.Context.LookupConfig; // gen key pair /*RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); * * string pub = rsa.ToXmlString(false); * * byte[] priv = UTF8Encoding.UTF8.GetBytes(rsa.ToXmlString(true)); * byte[] pass = Utilities.GetPasswordKey("password", new byte[] { 0x7A, 0x0D }); * * string safe = Convert.ToBase64String(Utilities.EncryptBytes(priv, pass)); * * * // check * byte[] check = Convert.FromBase64String(safe); * byte[] test = Utilities.DecryptBytes(check, check.Length, pass); * string priv2 = UTF8Encoding.UTF8.GetString(test); * * bool good = Utilities.MemCompare(priv, test);*/ #if DEBUG //SignNewUpdate(); #endif Core.Network.Searches.SearchEvent[ServiceID, 0] += new SearchRequestHandler(Search_Local); Core.Transfers.FileSearch[ServiceID, 0] += new FileSearchHandler(Transfers_FileSearch); Core.Transfers.FileRequest[ServiceID, 0] += new FileRequestHandler(Transfers_FileRequest); }
public DhtNetwork(OpCore core, bool lookup) { Core = core; IsLookup = lookup; Cache = new OpCache(this); // lookup config loads cache entries if (IsLookup) { Core.Context.LookupConfig.Load(this); Lookup = Core.Context.LookupConfig; } Local = new DhtClient(); Local.UserID = IsLookup ? Lookup.Ports.UserID : Utilities.KeytoID(Core.User.Settings.KeyPublic); Local.ClientID = (ushort)Core.RndGen.Next(1, ushort.MaxValue); OpID = Utilities.KeytoID(IsLookup ? LookupKey : Core.User.Settings.OpKey); OpCrypt = new RijndaelManaged(); // load encryption if (IsLookup) OpCrypt.Key = LookupKey; else OpCrypt.Key = Core.User.Settings.OpKey; LocalAugmentedKey = GetAugmentedKey(Local.UserID); Protocol = new G2Protocol(); TcpControl = new TcpHandler(this); UdpControl = new UdpHandler(this); LanControl = new LanHandler(this); RudpControl = new RudpHandler(this); LightComm = new LightCommHandler(this); UPnPControl = new UPnPHandler(this); Routing = new DhtRouting(this); Store = new DhtStore(this); Searches = new DhtSearchControl(this); }
public static UpdateInfo LoadUpdate(LookupSettings config) { UpdateInfo info = config.ReadUpdateInfo(); if (info == null) return null; if (!File.Exists(config.UpdatePath)) return null; using (FileStream stream = new FileStream(config.UpdatePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { byte[] check = new byte[info.Beginning.Length]; stream.Read(check, 0, check.Length); if (stream.Length == info.Size && Utilities.MemCompare(check, info.Beginning)) { info.Loaded = true; } } return info; }
public UpdateService(OpCore core) { Core = core; Core.Update = this; LookupConfig = core.Context.LookupConfig; // gen key pair /*RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); string pub = rsa.ToXmlString(false); byte[] priv = UTF8Encoding.UTF8.GetBytes(rsa.ToXmlString(true)); byte[] pass = Utilities.GetPasswordKey("password", new byte[] { 0x7A, 0x0D }); string safe = Convert.ToBase64String(Utilities.EncryptBytes(priv, pass)); // check byte[] check = Convert.FromBase64String(safe); byte[] test = Utilities.DecryptBytes(check, check.Length, pass); string priv2 = UTF8Encoding.UTF8.GetString(test); bool good = Utilities.MemCompare(priv, test);*/ #if DEBUG //SignNewUpdate(); #endif Core.Network.Searches.SearchEvent[ServiceID, 0] += new SearchRequestHandler(Search_Local); Core.Transfers.FileSearch[ServiceID, 0] += new FileSearchHandler(Transfers_FileSearch); Core.Transfers.FileRequest[ServiceID, 0] += new FileRequestHandler(Transfers_FileRequest); }
public UriComposer(LookupSettings lookupSettings) => _lookupSettings = lookupSettings;