Ejemplo n.º 1
0
        /// <summary>
        /// Loads identity from folder.
        /// </summary>
        private static async Task <PrivateIdentity> LoadIdentity(string folder)
        {
            var file = Path.Combine(folder, "node.identity");

            // If file doesn't exist, create and save a new identity.
            if (!File.Exists(file))
            {
                var identity = PrivateIdentity.Create();
                var bytes    = Transcoder.HexFromBytes(PrivateIdentity.Export(identity));
                await File.WriteAllTextAsync(file, bytes);

                Console.WriteLine($"No identity found at {file}, so identity {identity.ID} was created.");
                return(identity);
            }

            // Otherwise, attempt to load the identity from the file.
            var hex = await File.ReadAllTextAsync(file);

            var importedIdentity = PrivateIdentity.Import(Transcoder.BytesFromHex(hex));

            if (importedIdentity.IsError)
            {
                Console.WriteLine($"Failed to load identity at {file}.");
                throw new Exception(importedIdentity.Error.GetType().ToString());
            }
            Console.WriteLine($"Found identity {importedIdentity.Value.ID} at {file}, loaded successfully.");
            return(importedIdentity.Value);
        }
Ejemplo n.º 2
0
 private AddressHandler(SQLiteAsyncConnection conn, UserHandler users, int port, PrivateIdentity self)
 {
     this.conn  = conn;
     this.users = users;
     this.port  = port;
     this.self  = self;
 }
Ejemplo n.º 3
0
 public Runner(ServiceIdentity i_serviceIdentity, PrivateIdentity i_privateIdentity, Params ps)
 {
     serviceIdentity = i_serviceIdentity;
     privateIdentity = i_privateIdentity;
     scheduler       = IoScheduler.CreateServer(privateIdentity, ps.LocalHostNameOrAddress, ps.LocalPort,
                                                serviceIdentity.Servers, ps.Verbose);
 }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            Console.WriteLine("IronSHTServer program started");

            Console.WriteLine("Processing command-line arguments");

            Params ps = new Params();

            foreach (var arg in args)
            {
                if (!ps.ProcessCommandLineArgument(arg))
                {
                    usage();
                    return;
                }
            }

            if (!ps.Validate())
            {
                usage();
                return;
            }

            ServiceIdentity serviceIdentity = ServiceIdentity.ReadFromFile(ps.ServiceFileName);

            if (serviceIdentity == null)
            {
                return;
            }
            if (serviceIdentity.ServiceType != "IronSHT")
            {
                Console.Error.WriteLine("ERROR - Service described by {0} is of type {1}, not IronSHT", ps.ServiceFileName,
                                        serviceIdentity.ServiceType);
                return;
            }

            PrivateIdentity privateIdentity = PrivateIdentity.ReadFromFile(ps.PrivateKeyFileName);

            if (privateIdentity == null)
            {
                return;
            }

            Native____Io__s_Compile.PrintParams.SetParameters(ps.Profile, i_shouldPrintProgress: false);

            var nc = Native____Io__s_Compile.NetClient.Create(privateIdentity, ps.LocalHostNameOrAddress, ps.LocalPort,
                                                              serviceIdentity.Servers, ps.Verbose);

            Dafny.ISequence <byte>[] serverPublicKeys =
                serviceIdentity.Servers.Select(server => Dafny.Sequence <byte> .FromArray(server.PublicKey)).ToArray();
            var ironArgs = Dafny.Sequence <Dafny.ISequence <byte> > .FromArray(serverPublicKeys);

            Profiler.Initialize();
            Native____Io__s_Compile.Time.Initialize();
            Console.WriteLine("IronFleet program started.");
            Console.WriteLine("[[READY]]");
            Main__i_Compile.__default.IronfleetMain(nc, ironArgs);
            Console.WriteLine("[[EXIT]]");
        }
Ejemplo n.º 5
0
        public RPTester()
        {
            var serverEndpoint = new IPEndPoint(IPAddress.Loopback, 12000);
            var serverID       = PrivateIdentity.Create();

            server    = new RPServer(serverID, serverEndpoint, this);
            listening = server.ListenForClients();

            var clientID = PrivateIdentity.Create();

            client = RPClient.CreateAndConnect(serverID.ID, serverEndpoint, clientID).Result;
        }
Ejemplo n.º 6
0
        public async Task AuthenticateValid()
        {
            var serverPrivID = PrivateIdentity.Create();
            var serverPubID  = new PublicIdentity(serverPrivID.PublicIdentityInfo);
            var clientPrivID = PrivateIdentity.Create();

            var serverAuthenticator = new Authenticator(serverPrivID);
            var clientAuthenticator = new Authenticator(clientPrivID);

            var a = serverAuthenticator.AuthenticateClient(protected1);
            var b = clientAuthenticator.AuthenticateServer(protected2, serverPubID.ID);

            await Task.WhenAll(a, b);
        }
Ejemplo n.º 7
0
        public async void OnConnect(string folder, IPEndPoint endpoint)
        {
            var             file = Path.Combine(folder, "client.identity");
            PrivateIdentity identity;

            if (!Env.CheckFile(file))
            {
                if (!Env.Confirm($"No identity was found at {file}. Do you want to create a new one?"))
                {
                    return;
                }
                identity = PrivateIdentity.Create();
                var hex = Transcoder.HexFromBytes(PrivateIdentity.Export(identity));
                await Env.WriteFile(file, hex);
            }
            else
            {
                var hex    = Transcoder.BytesFromHex(await Env.ReadFile(file));
                var result = PrivateIdentity.Import(hex);
                if (result.IsError)
                {
                    Env.Alert("Could not load identity!!");
                    return;
                }
                identity = result.Value;
            }

            APITranslatorClient nodeConnection;

            try
            {
                nodeConnection = await APITranslatorClient.CreateAndConnect(new APITranslatorClient.ConnectionArgs
                {
                    Self     = identity,
                    ServerID = identity.ID,
                    Address  = endpoint.Address,
                    Port     = endpoint.Port
                });
            }
            catch
            {
                Env.Alert("Unable to connect to your node!");
                return;
            }

            Resources = new ResourceManager(identity, nodeConnection, OnDisconnect);
            VM        = new ConnectedViewModel(OnDisconnect);
        }
Ejemplo n.º 8
0
        public static async Task <APIGateway> Create(string path, PrivateIdentity self, int port)
        {
            var conn = new SQLiteAsyncConnection(path, SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create | SQLiteOpenFlags.FullMutex);

            var users = await UserHandler.Create(conn, self.ID);

            var images = await ImageHandler.Create(conn, users);

            var posts = await PostHandler.Create(conn, users);

            var profiles = await ProfileHandler.Create(conn, users);

            var addresses = await AddressHandler.Create(conn, users, port, self);

            return(new APIGateway(users, images, posts, profiles, addresses));
        }
Ejemplo n.º 9
0
 public static NetClient Create(PrivateIdentity myIdentity, string localHostNameOrAddress, int localPort,
                                List <PublicIdentity> knownIdentities, bool verbose, int maxSendRetries = 3)
 {
     try
     {
         var scheduler = IoScheduler.CreateServer(myIdentity, localHostNameOrAddress, localPort, knownIdentities,
                                                  verbose, maxSendRetries);
         var myPublicKey = IoScheduler.GetCertificatePublicKey(scheduler.MyCert);
         if (myPublicKey.Length > MaxPublicKeySize)
         {
             System.Console.Error.WriteLine("ERROR:  The provided public key for my identity is too big ({0} > {1} bytes)",
                                            myPublicKey.Length, MaxPublicKeySize);
             return(null);
         }
         return(new NetClient(scheduler));
     }
     catch (Exception e)
     {
         System.Console.Error.WriteLine(e);
         return(null);
     }
 }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            Params ps = new Params();

            foreach (var arg in args)
            {
                if (!ps.ProcessCommandLineArgument(arg))
                {
                    usage();
                    return;
                }
            }

            if (!ps.Validate())
            {
                return;
            }

            ServiceIdentity serviceIdentity = ServiceIdentity.ReadFromFile(ps.ServiceFileName);

            if (serviceIdentity == null)
            {
                return;
            }

            PrivateIdentity privateIdentity = PrivateIdentity.ReadFromFile(ps.PrivateKeyFileName);

            if (privateIdentity == null)
            {
                return;
            }

            var runner = new Runner(serviceIdentity, privateIdentity, ps);

            runner.Run();
        }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
            Console.WriteLine("IronRSL{0}Server program started", Service.Name);

            Console.WriteLine("Processing command-line arguments");

            Params ps = new Params();

            foreach (var arg in args)
            {
                if (!ps.ProcessCommandLineArgument(arg))
                {
                    usage();
                    return;
                }
            }

            if (!ps.Validate())
            {
                usage();
                return;
            }

            ServiceIdentity serviceIdentity = ServiceIdentity.ReadFromFile(ps.ServiceFileName);

            if (serviceIdentity == null)
            {
                return;
            }
            if (serviceIdentity.ServiceType != "IronRSL" + Service.Name)
            {
                Console.Error.WriteLine("Provided service identity has type {0}, not IronRSL{1}.",
                                        serviceIdentity.ServiceType, Service.Name);
                return;
            }

            PrivateIdentity privateIdentity = PrivateIdentity.ReadFromFile(ps.PrivateKeyFileName);

            if (privateIdentity == null)
            {
                return;
            }

            Native____Io__s_Compile.PrintParams.SetParameters(ps.Profile, ps.Progress);

            if (ps.Safeguard)
            {
                File.Delete(ps.PrivateKeyFileName);
                Console.WriteLine("Deleted private key file after reading it since RSL servers should never run twice.");
            }
            else
            {
                Console.WriteLine(@"
  *** DANGER:  Because you specified safeguard=false, we didn't delete the ***
  *** private key file to prevent you from running the RSL server twice.   ***
  *** Hopefully, you're just testing things.                               ***
");
            }

            var nc = Native____Io__s_Compile.NetClient.Create(privateIdentity, ps.LocalHostNameOrAddress, ps.LocalPort,
                                                              serviceIdentity.Servers, ps.Verbose);

            Dafny.ISequence <byte>[] serverPublicKeys =
                serviceIdentity.Servers.Select(server => Dafny.Sequence <byte> .FromArray(server.PublicKey)).ToArray();
            var ironArgs = Dafny.Sequence <Dafny.ISequence <byte> > .FromArray(serverPublicKeys);

            Profiler.Initialize();
            Native____Io__s_Compile.Time.Initialize();
            Console.WriteLine("[[READY]]");
            Main__i_Compile.__default.IronfleetMain(nc, ironArgs);
            Console.WriteLine("[[EXIT]]");
        }
Ejemplo n.º 12
0
        public void TestImportExport()
        {
            var newIdentity = PrivateIdentity.Import(PrivateIdentity.Export(privateIdentity)).Value;

            Assert.AreEqual(privateIdentity.ID, newIdentity.ID);
        }
Ejemplo n.º 13
0
 public IdentityTester()
 {
     privateIdentity = PrivateIdentity.Create();
     publicIdentity  = new PublicIdentity(privateIdentity.PublicIdentityInfo);
 }
Ejemplo n.º 14
0
        public static async Task <AddressHandler> Create(SQLiteAsyncConnection conn, UserHandler users, int port, PrivateIdentity self)
        {
            // Create the table if it doesn't exist.
            await conn.CreateTableAsync <Address>();

            var handler = new AddressHandler(conn, users, port, self);

            var _ = handler.Bootstrap();

            return(handler);
        }
Ejemplo n.º 15
0
 /// <summary>
 /// Creates a new instance of a LocalAPIGateway.
 /// </summary>
 public APITranslationServer(PrivateIdentity self, IPEndPoint endPoint, API gateway)
 {
     server   = new RPServer(self, endPoint, this);
     this.api = gateway;
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Creates a new Authenticator from a Private Identity.
 /// </summary>
 public Authenticator(PrivateIdentity self) => this.self = self;
Ejemplo n.º 17
0
 /// <summary>
 /// Creates a new instance of a Node.
 /// </summary>
 private Node(PrivateIdentity identity, IPEndPoint endpoint, APIGateway dataBaseHandler)
 {
     databaseHandler = dataBaseHandler;
     gateway         = new APITranslationServer(identity, endpoint, databaseHandler);
 }