private Transaction CreateRegistrationTransaction()
        {
            var config = new ServiceNodeRegistrationConfig
            {
                ProtocolVersion      = (int)ServiceNodeProtocolVersion.INITIAL,
                Ipv4Address          = IPAddress.Parse("127.0.0.1"),
                Port                 = 37123,
                CollateralPubKeyHash = this.walletSecret.PubKeyHash,
                RewardPubKeyHash     = this.walletSecret.PubKeyHash,
                PrivateKey           = this.walletKey,
                ServiceEndpoint      = new Uri("https://redstone.com/test")
            };

            RegistrationToken registrationToken = config.CreateRegistrationToken(this.network);

            IWalletTransactionHandler walletTransactionHandler = this.node.FullNode.NodeService <IWalletTransactionHandler>();
            Transaction transaction = TransactionUtils.BuildTransaction(
                this.network,
                walletTransactionHandler,
                config,
                registrationToken,
                WalletName,
                Account,
                Password);

            return(transaction);
        }
Exemple #2
0
        public void CheckSignatureOfRegistrationToken()
        {
            var rsa   = new RsaKey();
            var ecdsa = new Key().GetBitcoinSecret(Network.ImpleumMain);

            var token = new RegistrationToken(1,
                                              "175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W",
                                              IPAddress.Parse("172.16.1.10"),
                                              IPAddress.Parse("2001:0db8:85a3:0000:1234:8a2e:0370:7334"),
                                              "5678901234ABCDEF",
                                              "",
                                              16174,
                                              ecdsa.PubKey);

            // Only the 'header' portion of the registration token gets signed, minus the length bytes
            var message = token.GetHeaderBytes();

            var cryptoUtils = new CryptoUtils(rsa, ecdsa);

            token.RsaSignature   = cryptoUtils.SignDataRSA(message.ToArray());
            token.EcdsaSignature = cryptoUtils.SignDataECDSA(message.ToArray());

            var signature = cryptoUtils.SignDataECDSA(message.ToArray());

            Assert.True(CryptoUtils.VerifySignatureECDSA(message.ToArray(), ecdsa.PubKey, Encoding.UTF8.GetString(signature)));
            Assert.True(token.VerifySignatures());
        }
        public void RegistrationStoreAddTest()
        {
            var privateKey = new Key();
            var token      = new RegistrationToken(255,
                                                   IPAddress.Parse("127.0.0.1"),
                                                   IPAddress.Parse("2001:0db8:85a3:0000:0000:8a2e:0370:7334"),
                                                   "",
                                                   37123,
                                                   new KeyId("dbb476190a81120928763ee8ce97e4c0bcfd6624"),
                                                   new KeyId("dbb476190a81120928763ee8ce97e4c0bcfd6624"),
                                                   privateKey.PubKey,
                                                   new Uri("https://redstone.com/test"));

            token.Signature = CryptoUtils.SignData(token.GetHeaderBytes().ToArray(), privateKey);

            RegistrationRecord record = new RegistrationRecord(DateTime.Now,
                                                               Guid.NewGuid(),
                                                               "137cc93a23383252348de58e53e193db471099e78ef89edf1fdea6ff340a7261",
                                                               "0100000027c16c59051604707fcfc75e7ab33decbe72e72baff44ad2b38b78a13929eb5d092df004b20200000048473044022067c3c50f13a1b68402549c6a049a9298d8de03e176909cc6b44f9fd9d9db532502203e7416233a125264aef46698b22f429f60be9ed3b2115ec24f0a05de2a4e4cd901feffffff1d92cb2776b3c3cb3e89ad84c38c72fc72646238d23312a6b1931e7980f90f590200000049483045022100d4141e26371a198fb22347e0cc64fd0563ee11640108836e5f427873e4aa0d00022012960447890e151b46a19c2d1d480f7e81e5ceb615c9566be03189108cb08ce401feffffffa23c4e0da07acb439735e6f2a3c7a1ee15521138cc3815fdbac428e1756a3976010000004948304502210083dfda6e8a7584741c79d60a8c69c372789eb28680fdf43fe15e67eb05c7628e022041cde42e79e83c5be5902c035abcde02579e1841473efbbeb5a909d4520a8ea801fefffffff3b56cf319b4b4895beae1e047d77fddcfd8b86a3964226c0d24dda83335e40802000000484730440220219623b855cd1ac0ad43cb3b76097cb52db2d37b4a6a768a5911dfa3571ff4b602203eb843072f746e225e6c7225438f4f4bf012c18f1a1572d4ead288190d8d61cb01feffffff15209f56f6f5d1246f43057ab546be192659a3c88365529667eb3aa364ed4392000000006b483045022100a5791707155d03fb6e770c0dd0924cf08a3bd3b6e0b5713d7d3e84dc5c2e18bc02200370afce15733f5139a018d3ffc5e594e646ce372274818d9780906f9fb3699101210344e875df3990bf55d7218020b09aea6e1383206ec88344847771b3bc0d72251bfeffffff0220188fba000000001976a914b88f742a0a07af27ccfe21de8a40b9f7541f3e0088ac00e87648170000001976a914db0be998354d2139b14e06459d295de03b94fadb88ac90920000",
                                                               token,
                                                               null);
            RegistrationStore store = new RegistrationStore(Path.GetTempFileName());

            Assert.True(store.Add(record));
        }
Exemple #4
0
        public void RegistrationStoreGetOneTest()
        {
            var token = new RegistrationToken(255,
                                              "1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2",
                                              IPAddress.Parse("127.0.0.1"),
                                              IPAddress.Parse("2001:0db8:85a3:0000:0000:8a2e:0370:7334"),
                                              "0123456789ABCDEF",
                                              37123);

            token.RsaSignature   = Encoding.ASCII.GetBytes("xyz");
            token.EcdsaSignature = Encoding.ASCII.GetBytes("abc");

            RegistrationRecord record = new RegistrationRecord(DateTime.Now,
                                                               Guid.NewGuid(),
                                                               "137cc93a23383252348de58e53e193db471099e78ef89edf1fdea6ff340a7261",
                                                               "0100000027c16c59051604707fcfc75e7ab33decbe72e72baff44ad2b38b78a13929eb5d092df004b20200000048473044022067c3c50f13a1b68402549c6a049a9298d8de03e176909cc6b44f9fd9d9db532502203e7416233a125264aef46698b22f429f60be9ed3b2115ec24f0a05de2a4e4cd901feffffff1d92cb2776b3c3cb3e89ad84c38c72fc72646238d23312a6b1931e7980f90f590200000049483045022100d4141e26371a198fb22347e0cc64fd0563ee11640108836e5f427873e4aa0d00022012960447890e151b46a19c2d1d480f7e81e5ceb615c9566be03189108cb08ce401feffffffa23c4e0da07acb439735e6f2a3c7a1ee15521138cc3815fdbac428e1756a3976010000004948304502210083dfda6e8a7584741c79d60a8c69c372789eb28680fdf43fe15e67eb05c7628e022041cde42e79e83c5be5902c035abcde02579e1841473efbbeb5a909d4520a8ea801fefffffff3b56cf319b4b4895beae1e047d77fddcfd8b86a3964226c0d24dda83335e40802000000484730440220219623b855cd1ac0ad43cb3b76097cb52db2d37b4a6a768a5911dfa3571ff4b602203eb843072f746e225e6c7225438f4f4bf012c18f1a1572d4ead288190d8d61cb01feffffff15209f56f6f5d1246f43057ab546be192659a3c88365529667eb3aa364ed4392000000006b483045022100a5791707155d03fb6e770c0dd0924cf08a3bd3b6e0b5713d7d3e84dc5c2e18bc02200370afce15733f5139a018d3ffc5e594e646ce372274818d9780906f9fb3699101210344e875df3990bf55d7218020b09aea6e1383206ec88344847771b3bc0d72251bfeffffff0220188fba000000001976a914b88f742a0a07af27ccfe21de8a40b9f7541f3e0088ac00e87648170000001976a914db0be998354d2139b14e06459d295de03b94fadb88ac90920000",
                                                               token);
            RegistrationStore store = new RegistrationStore(Path.GetTempFileName());

            store.Add(record);

            var retrievedRecords = store.GetAll();

            Assert.Equal(retrievedRecords.Count, 1);

            var retrievedRecord = retrievedRecords[0].Record;

            Assert.Equal(retrievedRecord.ProtocolVersion, 255);
            Assert.Equal(retrievedRecord.ServerId, "1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2");
            Assert.Equal(retrievedRecord.Ipv4Addr, IPAddress.Parse("127.0.0.1"));
            Assert.Equal(retrievedRecord.Ipv6Addr, IPAddress.Parse("2001:0db8:85a3:0000:0000:8a2e:0370:7334"));
            Assert.Equal(retrievedRecord.OnionAddress, "0123456789ABCDEF");
            Assert.Equal(retrievedRecord.Port, 37123);
        }
Exemple #5
0
        protected static RegistrationToken _Add(TDef def, Boolean isBase, MethodBase addedBy = null)
        {
            RegistrationToken tok = null !;

            if (stage == Stage.PreInit)
            {
                tok = new(def, isBase, false);
                if (tokensRegisteredOnAdd)
                {
                    tok.Register();
                }
            }
            else if (stage == Stage.Init || (stage == Stage.Finalized && MetaRegistry.stage == Stage.Init))
            {
                tok = new(def, isBase, true);
                if (tokensRegisteredOnAdd)
                {
                    tok.Register();
                }
                pendingProceduralTokens.Enqueue(tok);
            }
            else
            {
                tok = new(def, isBase, false);
                if (tokensRegisteredOnAdd)
                {
                    tok.Register();
                }
            }
            return(tok);
        }
Exemple #6
0
        public void Constructor_PropertiesExposeConstructionValues()
        {
            var regToken = new RegistrationToken(TokenType, TokenValue);

            regToken.Type.Should().Be(TokenType);
            regToken.Token.Should().Be(TokenValue);
        }
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            var               expirationTime = _context.GlobalVariables.First().TokenExpirationDays;
            DateTime          d_time         = DateTime.Now;
            RegistrationToken regToken       = new RegistrationToken
            {
                GenerateTime   = d_time,
                ExpirationTime = d_time.AddDays(expirationTime),
                Email          = Admin.Email,
                Role           = "Admin"
            };

            _context.RegistrationToken.Add(regToken);
            await _context.SaveChangesAsync();

            var callbackUrl = Url.Page(
                "/Account/RegisterAdmin",
                pageHandler: null,
                values: new { area = "Identity", id = regToken.Token },
                protocol: Request.Scheme);

            await _emailSender.SendEmailAsync(Admin.Email, "Create account",
                                              $"Please register your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");


            return(RedirectToPage("ManageSystem"));
        }
Exemple #8
0
        public async Task <IActionResult> GenerateClientLink([FromQuery] int?roleId, [FromQuery] string email)
        {
            var role = StaticHelper.GetCurrentRole(User);

            if (roleId != 5)
            {
                roleId = 4;
            }
            if (email == null)
            {
                return(BadRequest("Email is required!"));
            }
            if (StaticHelper.IsEmailInBase(email, db))
            {
                return(BadRequest("Provided email is already registred or occupied!"));
            }
            var regLink = new RegistrationToken()
            {
                RoleId = (int)roleId,
                Type   = "Client",
                Email  = email,
                Token  = Guid.NewGuid().ToString("N"),
                Opened = DateTime.Now
            };

            db.RegistrationTokens.Add(regLink);
            await db.SaveChangesAsync();

            return(Ok(regLink));
        }
Exemple #9
0
 public string AddOrganizations(string token, Organization objOrganization)
 {
     try
     {
         if (ModelState.IsValid)
         {
             using (StudentContext db = new StudentContext())
             {
                 objOrganization.CreatedDate = DateTime.Now;
                 objOrganization.CreatedBy   = _userStatistics.UserId;
                 RegistrationToken objToken = new RegistrationToken();
                 objToken.Token     = UserStatistics.GenerateToken();
                 objToken.RoleId    = (int)UserRoles.OrganizationAdmin;
                 objToken.CreatedBy = _userStatistics.UserId;
                 if (objRep.CreateOrganization(objOrganization, objToken))
                 {
                     //objRep.CreateRegistrationToken(objToken);
                     SaveFiles(token, this.GetType().Name, objOrganization.OrganizationId);
                     EmailHandler.Utilities.SendRegistationEmail(objToken.Token, objOrganization.Email);
                     return(Convert.ToString(true));
                 }
                 return(Convert.ToString(false));
             }
         }
         return(Convert.ToString(false));
     }
     catch (Exception ex)
     {
         return(ex.Message.ToString());
     }
 }
Exemple #10
0
        public async Task <IActionResult> OnPostAsync(int id)
        {
            Token = await _context.RegistrationToken.FirstOrDefaultAsync(m => m.ID == id);

            if (Token == null)
            {
                return(NotFound());
            }
            DateTime          d_time   = DateTime.Now;
            RegistrationToken regToken = new RegistrationToken
            {
                GenerateTime   = d_time,
                ExpirationTime = d_time.AddDays(2),
                Email          = Token.Email,
                Role           = "Lecturer"
            };

            _context.RegistrationToken.Add(regToken);
            _context.RegistrationToken.Remove(Token);
            await _context.SaveChangesAsync();

            var callbackUrl = Url.Page(
                "/Account/RegisterAdmin",
                pageHandler: null,
                values: new { area = "Identity", id = regToken.Token },
                protocol: Request.Scheme);

            await _emailSender.SendEmailAsync(regToken.Email, "Create account",
                                              $"Please register your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

            return(RedirectToPage("ManageLecturers"));
        }
        public async Task <Transaction> PerformRegistrationAsync(
            IServiceNodeRegistrationConfig registrationConfig,
            string walletName,
            string walletPassword,
            string accountName)
        {
            Transaction transaction = null;

            try
            {
                RegistrationToken registrationToken = registrationConfig.CreateRegistrationToken(this.network);

                transaction = TransactionUtils.BuildTransaction(this.network,
                                                                this.walletTransactionHandler,
                                                                registrationConfig,
                                                                registrationToken,
                                                                walletName,
                                                                accountName,
                                                                walletPassword);

                await this.broadcasterManager.BroadcastTransactionAsync(transaction).ConfigureAwait(false);
            }
            catch (Exception e)
            {
                Console.WriteLine("ERROR: Unable to broadcast registration transaction");
                Console.WriteLine(e);
            }

            return(transaction);
        }
        public static Transaction BuildTransaction(
            Network network,
            IWalletTransactionHandler walletTransactionHandler,
            IServiceNodeRegistrationConfig registrationConfig,
            RegistrationToken registrationToken,
            string walletName,
            string accountName,
            string password)
        {
            var accountReference = new WalletAccountReference()
            {
                AccountName = accountName,
                WalletName  = walletName
            };

            var context = new TransactionBuildContext(network)
            {
                AccountReference = accountReference,
                Recipients       = GetRecipients(registrationConfig, registrationToken),
                Shuffle          = false,
                Sign             = true,
                OverrideFeeRate  = new FeeRate(registrationConfig.TxFeeValue),
                WalletPassword   = password
            };

            context.TransactionBuilder.CoinSelector = new DefaultCoinSelector
            {
                GroupByScriptPubKey = false
            };
            Transaction transaction = walletTransactionHandler.BuildTransaction(context);

            return(transaction);
        }
Exemple #13
0
        public void LoadSelectLists(ref RegistrationToken objToken)
        {
            SelectList            OrganizationList = null;
            List <Organization>   organizationList = new List <Organization>();
            List <Department>     depList          = new List <Department>();
            List <Course>         crsList          = new List <Course>();
            List <Class>          clsList          = new List <Class>();
            List <Section>        secList          = new List <Section>();
            List <SelectListItem> roleTypes        = Enum.GetValues(typeof(StudentTracker.Core.Utilities.UserRoles)).Cast <StudentTracker.Core.Utilities.UserRoles>().Select(v => new SelectListItem
            {
                Text  = v.ToString(),
                Value = ((int)v).ToString()
            }).ToList();

            if (User.IsInRole("SiteAdmin"))
            {
                OrganizationList  = new SelectList(repository.Organizations(), "OrganizationId", "OrganizationName", "");
                objToken.RoleList = new SelectList(roleTypes, "Value", "Text");
            }
            else
            {
                var organization = repository.Organizations(_userStatistics.OrganizationId);
                ViewBag.OrganizationId = organization.OrganizationId;
                ViewBag.Organization   = organization.OrganizationName;
                objToken.RoleList      = new SelectList(roleTypes.Skip(2), "Value", "Text");
                crsList = repository.CourseByOrganization(_userStatistics.OrganizationId);
            }

            objToken.OrganizationList = OrganizationList;
            objToken.CourseList       = new SelectList(crsList, "CourseId", "CourseName");
            objToken.ClassList        = new SelectList(clsList, "ClassId", "ClassName");
            objToken.SectionList      = new SelectList(secList, "SectionId", "SectionName");
            objToken.DepartmentList   = new SelectList(depList, "DepartmentId", "DepartmentName");
        }
Exemple #14
0
        /// <summary>
        /// Generates a validation token.
        /// </summary>
        /// <param name="member">The member.</param>
        /// <param name="club">The club.</param>
        /// <param name="daysValid">The number of days the token should remain valid.</param>
        /// <returns>RegistrationToken.</returns>
        public RegistrationToken GenerateValidationToken(Person member, Club club,
                                                         int daysValid = 365)
        {
            if (member == null || club == null)
            {
                return(null);
            }

            var vals = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

            int codeLength   = 6;
            var ran          = new Random();
            var tokenbuilder = new StringBuilder();

            for (int i = 0; i < codeLength; i++)
            {
                tokenbuilder.Append(vals[ran.Next(0, vals.Length - 1)]);
            }

            var token = new RegistrationToken
            {
                Member  = member,
                Club    = club,
                IsValid = true,
                Expires = DateTime.Now.AddDays(daysValid)
            };

            return(token);
        }
Exemple #15
0
        public ActionResult CreateToken()
        {
            RegistrationToken objToken = new RegistrationToken();

            LoadSelectLists(ref objToken);
            objToken.OrganizationId = ViewBag.OrganizationId == null ? 0 : (int)ViewBag.OrganizationId;
            return(View(objToken));
        }
Exemple #16
0
        public ActionResult RegisterUserStep2(string id = "")
        {
            ViewBag.Error = false;
            RegistrationToken objToken = new RegistrationToken();

            objToken.Token = id;
            return(View(objToken));
        }
Exemple #17
0
        public ActionResult RegisterUserStep3(Profile objProfile)
        {
            RegistrationToken Token = repository.GetRegistrationCode(objProfile.RegistrationToken);
            // RegistrationToken objToken = repository.GetRegistrationCode(objProfile.RegistrationToken);
            StudentContext context = new StudentContext();
            Student        student = new Student();
            Staff          staff   = new Staff();

            if (Token.StaffId != null)
            {
                staff = context.Staff.Find(Token.StaffId);
            }

            if (Token.StudentId != null)
            {
                student = context.Students.Find(Token.StudentId);
            }
            //objProfile.RegistrationToken=Toke
            long userId = WebSecurity.RegisterNewUser(objProfile.UserName, "none", "none", false, objProfile.FirstName, objProfile.LastName, Token.OrganizationId, Token.Token);

            if (student != null)
            {
                student.UserId = userId;
            }

            if (staff != null)
            {
                staff.UserId = userId;
            }

            context.SaveChanges();
            DBConnectionString.Profile Profile = new DBConnectionString.Profile();
            if (userId != -1)
            {
                Profile.UserId              = userId;
                Profile.Title               = objProfile.Title;
                Profile.Address1            = "none";
                Profile.Address2            = "none";
                Profile.InsertedOn          = DateTime.Now;
                Profile.EmailAddress1       = "*****@*****.**";
                Profile.HomeTelephoneNumber = DateTime.Now.Ticks.ToString();
                Profile.SecurityQuestionId  = 1;
                Profile.SecurityAnswer      = "none";
                Profile.DateOfBirth         = objProfile.DateOfBirth;
                Profile.ModifiedOn          = null;
                Profile.MobileNumber        = "none";

                int recAffected = Convert.ToInt32(Profile.Insert());

                string roleName = ((UserRoles)Convert.ToInt16(Token.RoleId)).ToString();
                Roles.AddUserToRole(objProfile.UserName, roleName);

                return(RedirectToAction("RegisterUserStep4", new { userId }));
            }
            return(View("RegisterUserStep3", new { token = Token.Token }));
        }
Exemple #18
0
        public async Task <IActionResult> OnGetAsync(int id)
        {
            Token = await _context.RegistrationToken.FirstOrDefaultAsync(m => m.ID == id);

            if (Token == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Exemple #19
0
        public ActionResult RegisterUserStep2(RegistrationToken objToken)
        {
            ViewBag.Error = false;
            RegistrationToken token = repository.GetRegistrationCode(objToken.Token);

            if (token != null && token.InsertedOn.AddDays(7) > DateTime.Now)
            {
                return(RedirectToAction("RegisterUserStep3", new { token.Token }));
            }
            ViewBag.Error = true;
            return(View());
        }
Exemple #20
0
        public async Task <IActionResult> OnPostAsync(int id)
        {
            Token = await _context.RegistrationToken.FirstOrDefaultAsync(m => m.ID == id);

            if (Token == null)
            {
                return(NotFound());
            }
            _context.RegistrationToken.Remove(Token);
            await _context.SaveChangesAsync();

            return(RedirectToPage("ManageSystem"));
        }
Exemple #21
0
        public bool SendRegistrationEmailToStaff(string importId)
        {
            try
            {
                List <Staff>   objModelList            = repository.GetImportedStaff(importId);
                StudentContext context                 = new StudentContext();
                Dictionary <string, string> parameters = new Dictionary <string, string>();
                //  RegistrationToken tokenObj = new RegistrationToken();
                foreach (var staff in objModelList)
                {
                    string token = UserStatistics.GenerateToken();

                    RegistrationToken tokenObj = new RegistrationToken();
                    tokenObj.ClassId        = staff.ClassId;
                    tokenObj.CourseId       = staff.CourseId;
                    tokenObj.DepartmentId   = staff.DepartmentId;
                    tokenObj.OrganizationId = staff.OrganizationId;
                    tokenObj.RoleId         = Convert.ToInt32(UserRoles.Student);
                    tokenObj.ImportId       = importId;
                    tokenObj.Email          = staff.Email;
                    tokenObj.SectionId      = -1;
                    tokenObj.Token          = token;
                    tokenObj.InsertedOn     = DateTime.Now;
                    tokenObj.StaffId        = staff.StaffId;
                    context.RegistrationTokens.Add(tokenObj);
                    parameters.Add(token, staff.Email);
                }

                context.SaveChanges();

                Task.Factory.StartNew(() => SendEmails(parameters));

                //SendEmails(parameters);
                return(true);
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                          ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }
        }
        /// <summary>
        /// This method should be called by the application when a new token is generated on the device.
        /// </summary>
        /// <param name="token">New device token.</param>
        /// <exception cref="AblyException">Can throw an exception if no AblyRealtime instance is associated with the MobileDevice (very unlikely).</exception>
        public static void OnNewRegistrationToken(string token)
        {
            if (_realtimeInstance is null)
            {
                throw new AblyException(
                          "No realtime instance was registered. Please initialize your instance using AndroidMobileDevice.Initialise(options, configureCallbacks).");
            }

            var logger = _realtimeInstance.Logger;

            logger.Debug($"Received OnNewRegistrationToken with token {token}");

            var pushRealtime      = _realtimeInstance.Push;
            var registrationToken = new RegistrationToken(TokenType, token);

            pushRealtime.StateMachine.UpdateRegistrationToken(Result.Ok(registrationToken));
        }
Exemple #23
0
        public ActionResult RegisterUserStep3(string token)
        {
            Profile           objProfile = new Profile();
            RegistrationToken objToken   = repository.GetRegistrationCode(token);
            StudentContext    context    = new StudentContext();
            Student           student    = context.Students.Find(objToken.StudentId);

            if (student != null)
            {
                objProfile.FirstName     = student.FullName;
                objProfile.EmailAddress1 = student.Email;
            }

            objProfile.RegistrationToken = token;
            objProfile.TitleList         = new SelectList(new[] { new { Id = "Mr.", Value = "Mr." }, new { Id = "Miss.", Value = "Miss." } }, "Id", "Value");
            return(View(objProfile));
        }
Exemple #24
0
        static void Main(string[] args)
        {
            // args[0] = registration transaction hex

            Console.WriteLine();
            Console.WriteLine("*************************************************************");
            Console.WriteLine("Decoding registration transaction HEX");
            Console.WriteLine("*************************************************************");
            Console.WriteLine();

            Console.WriteLine("Transaction HEX");
            Console.WriteLine("*************************************************************");
            Console.WriteLine(args[0]);
            Console.WriteLine();

            Transaction tx;

            try
            {
                //Set the Timestamp flag to true in order to be compatibile with Stratis transactions
                Transaction.TimeStamp = true;
                tx = Transaction.Parse(args[0]);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Cannot decode a given input into Stratis network transaction.");
                return;
            }

            Console.WriteLine("Decoded registration transaction");
            Console.WriteLine("*************************************************************");
            try
            {
                var registrationToken = new RegistrationToken();
                registrationToken.ParseTransaction(tx, Network.ImpleumMain);

                Console.WriteLine(JsonConvert.SerializeObject(registrationToken, Formatting.Indented));
            }
            catch (Exception ex)
            {
                Console.WriteLine("Given transaction HEX is not a valid registration token transaction");
            }

            Console.ReadKey();
        }
        public void CanVerifySignature()
        {
            var privateKey = new Key();

            var token = new RegistrationToken(1,
                                              IPAddress.Parse("172.16.1.10"),
                                              IPAddress.Parse("2001:0db8:85a3:0000:1234:8a2e:0370:7334"),
                                              "",
                                              16174,
                                              new KeyId("dbb476190a81120928763ee8ce97e4c0bcfd6624"),
                                              new KeyId("dbb476190a81120928763ee8ce97e4c0bcfd6624"),
                                              privateKey.PubKey,
                                              new Uri("https://redstone.com.test"));

            token.Signature = CryptoUtils.SignData(token.GetHeaderBytes().ToArray(), privateKey);

            Assert.True(token.VerifySignatures());
        }
        public void CanValidateRegistrationToken()
        {
            var privateKey = new Key();

            var token = new RegistrationToken(
                (int)ServiceNodeProtocolVersion.INITIAL,
                IPAddress.Parse("127.0.0.1"),
                IPAddress.Parse("2001:0db8:85a3:0000:0000:8a2e:0370:7334"),
                "",
                37123,
                new KeyId("dbb476190a81120928763ee8ce97e4c0bcfd6624"),
                new KeyId("dbb476190a81120928763ee8ce97e4c0bcfd6624"),
                privateKey.PubKey,
                new Uri("https://restone.com/servicetest"));

            token.Signature = CryptoUtils.SignData(token.GetHeaderBytes().ToArray(), privateKey);

            Assert.True(token.Validate(RedstoneNetworks.Main));
        }
        public void RegistrationTransactionCanBeParsed()
        {
            using (NodeBuilder builder = NodeBuilder.Create(this))
            {
                Setup(builder);

                TestHelper.MineBlocks(this.node, this.maturity + 5, true, WalletName, Password);

                CreateTransactionAndBroadcast(new Money(5, MoneyUnit.BTC));
                TestHelper.MineBlocks(this.node, 1, true, WalletName, Password);

                var         serverSecret = new BitcoinSecret(new Key(), this.node.FullNode.Network);
                Transaction transaction  = CreateRegistrationTransaction();

                var registrationToken = new RegistrationToken();
                registrationToken.ParseTransaction(transaction, this.network);
                Assert.True(registrationToken.Validate(this.network));
            }
        }
Exemple #28
0
        public async Task <RegistrationToken> CreateUserAsync(RegisterViewModel model)
        {
            var token = new RegistrationToken();
            var user  = new ApplicationUser {
                FirstName = model.FirstName, LastName = model.LastName, UserName = model.Email, Email = model.Email, EmailConfirmed = true
            };
            var result = await _userManager.CreateAsync(user, GeneratePassword());

            if (result.Succeeded)
            {
                await _userManager.AddToRoleAsync(user, "Student");

                token.Results = true;
                token.EmailConfimationToken = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                token.User = user;
            }

            return(token);
        }
Exemple #29
0
        public void CanVerifySignature()
        {
            var rsa   = new RsaKey();
            var ecdsa = new Key().GetBitcoinSecret(Network.ImpleumMain);

            var token = new RegistrationToken(1,
                                              "175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W",
                                              IPAddress.Parse("172.16.1.10"),
                                              IPAddress.Parse("2001:0db8:85a3:0000:1234:8a2e:0370:7334"),
                                              "5678901234ABCDEF",
                                              "",
                                              16174,
                                              ecdsa.PubKey);

            var cryptoUtils = new CryptoUtils(rsa, ecdsa);

            token.EcdsaSignature = cryptoUtils.SignDataECDSA(token.GetHeaderBytes().ToArray());

            Assert.True(token.VerifySignatures());
        }
Exemple #30
0
        private int CreateRegistrationToken(RegistrationToken objToken, IDbConnection connection)
        {
            var parameters = new
            {
                Token          = objToken.Token,
                OrganizationId = objToken.OrganizationId,
                DepartmentId   = 0,
                CourseId       = objToken.CourseId,
                ClassId        = objToken.ClassId,
                SectionId      = objToken.SectionId,
                RoleId         = objToken.RoleId,
                CreatedBy      = objToken.CreatedBy,
                Email          = objToken.Email
            };
            const string storedProcedure = "usp_AddRegistrationToken";
            int          rowsAffected    = connection.Execute(storedProcedure, parameters, commandType: CommandType.StoredProcedure);

            //SetIdentity<int>(connection, id => objToken.TokenId = id);
            return(rowsAffected);
        }