コード例 #1
0
ファイル: MyClass.cs プロジェクト: IDWMaster/OpenServer
 public NetProvider(VMExecutionEngine engine)
 {
     instance = this;
     _engine = engine;
     if(!File.Exists("OpenNetDB")) {
     File.Create("OpenNetDB").Dispose();
         try {
         File.Encrypt("OpenNetDB");
         }catch(Exception) {
         Console.WriteLine("WARN: File system encryption is not supported on your computer. the private key will remain in un-encrypted format");
         }
     }
     db = new PubKeyDatabase("default",File.Open("OpenNetDB",FileMode.Open));
     if(db.Length == 0) {
     db.AddPublicKey(db.GenPublicPrivateKey(2048));
     db.GetPublicKeyOnly(db[0]);
     }
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: IDWMaster/OpenServer
        static void Main(string[] args)
        {
            Console.WriteLine("Opening HTTP request");
            HttpWebRequest request = HttpWebRequest.Create("http://127.0.0.1/OpenNetProvider") as HttpWebRequest;
            request.AllowWriteStreamBuffering = false;
            Stream receiver = new TrashyStream(request.GetResponse().GetResponseStream());
            BinaryReader mreader = new BinaryReader(receiver);
            byte[] guid = mreader.ReadBytes(16);
            Console.WriteLine(BitConverter.ToString(guid));
            request = HttpWebRequest.Create("http://127.0.0.1/OpenNetProvider") as HttpWebRequest;
            request.Method = "POST";
            request.ContentLength = 9999999999;
            request.AllowWriteStreamBuffering = false;
            Stream sender = new TrashyStream(request.GetRequestStream());
            BinaryWriter mwriter = new BinaryWriter(sender);
            mwriter.Write(guid);
            mwriter.Flush();
            byte[] theirpubkey = mreader.ReadBytes(mreader.ReadInt32());
            Stream dbStr = File.Open("keyDB.db", FileMode.OpenOrCreate);
            Console.WriteLine("Enter system password");
            PubKeyDatabase db = new PubKeyDatabase(ReadPassword(), dbStr);
            if (db.Length == 0)
            {
                db.AddPublicKey(db.GenPublicPrivateKey(2048));
            }
            byte[] ourpublickey = db.GetPublicKeyOnly(db[0]);
            byte[] ourprivatekey = db[0];
            mwriter.Write(ourpublickey.Length);
            mwriter.Write(ourpublickey);
            mwriter.Flush();
            db.AddPublicKey(theirpubkey);
            Stream securedStream = new TrashyStream(db.CreateAuthenticatedStream(ourprivatekey, new DualStream(sender, receiver), 32));

            Console.WriteLine("Secure stream negotiated");

               driver  = new OpenNetProvider.OpenNetProtocolDriver(securedStream);
            Console.WriteLine("Driver initialized");
            driver.OpenStream();

            driver.onConnectionEstablished += new OpenNetProvider.OpenNetProtocolDriver.ConnectionEstablishedEventArgs(driver_onConnectionEstablished);
        }