public void Create_WhenGivenValidString_ReturnsHash(int saltByteSize, string text) { var p = new SHA2CryptoProvider(Sentinel.OAuth.Core.Constants.HashAlgorithm.SHA512, saltByteSize); var hash = p.CreateHash(text); Console.WriteLine("Hash: {0}", hash); Assert.IsNotNullOrEmpty(hash); }
public void Create_WhenGivenValidLength_ReturnsValidHash(int size) { var p = new SHA2CryptoProvider((HashAlgorithm)Enum.Parse(typeof(HashAlgorithm), size.ToString())); var hash = p.CreateHash(size); var raw = Convert.FromBase64String(hash); Console.WriteLine($"Hash: {hash}"); Console.WriteLine($"Hash Size: {size / 8} bits"); Console.WriteLine($"Raw Size: {raw.Length} bits"); Assert.AreEqual(size / 8, raw.Length); }
public void Validate_WhenGivenAutoGeneratedString_ReturnsValid(int saltByteSize) { var p = new SHA2CryptoProvider(Sentinel.OAuth.Core.Constants.HashAlgorithm.SHA512, saltByteSize); var csprng = new RNGCryptoServiceProvider(); var arr = new byte[64]; csprng.GetBytes(arr); var text = Encoding.UTF8.GetString(arr); Console.WriteLine("Text: {0}", text); var hash = p.CreateHash(text); Console.WriteLine("Hash: {0}", hash); var valid = p.ValidateHash(text, hash); Assert.IsTrue(valid); }
public override void TestFixtureSetUp() { base.TestFixtureSetUp(); var client = new Client() { ClientId = "NUnit", ClientSecret = this.PasswordCryptoProvider.CreateHash("PFJTQUtleVZhbHVlPjxNb2R1bHVzPnFKMEtXaXZWSjUxUWtKWGdIU1hidkxOTEJsa09rOE9uSWtvRTljU1FrRzhOZm5VYXBrWHpkTlEvb3FLZE9BSWxYK1hFMnNwN0xFcS9KRnJMaDRNblhRPT08L01vZHVsdXM+PEV4cG9uZW50PkFRQUI8L0V4cG9uZW50PjxQPnljRXBJUDJseG1oa0hRMGRrKzRBVk1lZDhWRUFFVHN5TXgvL3NaNS9TbFU9PC9QPjxRPjFmTEVGWU1JMk1TMUJQbzYwcnYyQmhkYWNBaTI2d2Z0V1N2OVl0aUdnT2s9PC9RPjxEUD5uZ0dYTW0wejdXVklNckJZMzhmZm5vWVBIalR2dG84RHk2SmQ0RDlmTlZrPTwvRFA+PERRPk5FZEQzclhNSFp2RFY5b0ZNYVU0TXJqV0luWWVyRU9kbmFLQUlmMGlzTEU9PC9EUT48SW52ZXJzZVE+ZGQzNVh6T0RvUlZQaXQxb2REL0lKRHpXdUtYMXZrb2NjcXQ4REZGVTlwVT08L0ludmVyc2VRPjxEPkFBcC80VW1oSmFJcm9DcWJ5eXdRbDViY0xFMXNSSkwxek50dllkdGxNTCsxWVFRdWx6YzVPRkh1WUcxQW56OE8vbXU2MXNDN0dNVm04ZTVqSUp6SldRPT08L0Q+PC9SU0FLZXlWYWx1ZT4="), //ClientSecret = "10000:gW7zpVeugKl8IFu7TcpPskcgQjy4185eAwBk9fFlZK6JNd1I45tLyCYtJrzWzE+kVCUP7lMSY8o808EjUgfavBzYU/ZtWypcdCdCJ0BMfMcf8Mk+XIYQCQLiFpt9Rjrf5mAY86NuveUtd1yBdPjxX5neMXEtquNYhu9I6iyzcN4=:Lk2ZkpmTDkNtO/tsB/GskMppdAX2bXehP+ED4oLis0AAv3Q1VeI8KL0SxIIWdxjKH0NJKZ6qniRFkfZKZRS2hS4SB8oyB34u/jyUlmv+RZGZSt9nJ9FYJn1percd/yFA7sSQOpkGljJ6OTwdthe0Bw0A/8qlKHbO2y2M5BFgYHY=", PublicKey = "PFJTQUtleVZhbHVlPjxNb2R1bHVzPnFKMEtXaXZWSjUxUWtKWGdIU1hidkxOTEJsa09rOE9uSWtvRTljU1FrRzhOZm5VYXBrWHpkTlEvb3FLZE9BSWxYK1hFMnNwN0xFcS9KRnJMaDRNblhRPT08L01vZHVsdXM+PEV4cG9uZW50PkFRQUI8L0V4cG9uZW50PjwvUlNBS2V5VmFsdWU+", RedirectUri = "http://localhost", Enabled = true }; var user = new User() { UserId = "azzlack", Password = this.PasswordCryptoProvider.CreateHash("aabbccddee"), //Password = "******", FirstName = "Ove", LastName = "Andersen", Enabled = true }; var userApiKeys = new List <IUserApiKey>() { new UserApiKey() { UserId = "azzlack", ApiKey = "PFJTQUtleVZhbHVlPjxNb2R1bHVzPnlidFpyM0pWS0p1L2hlUFMrV0Zla1kyYmRYVDlJMU1MeHZheTlIMW9IenRwRmI4QzJtQmUzY1EzVDhjUzE0ajJ4bk9lRkt2YVZ4Ukw5S2ozd0tOL1B3PT08L01vZHVsdXM+PEV4cG9uZW50PkFRQUI8L0V4cG9uZW50PjwvUlNBS2V5VmFsdWU+" } }; var clientRepository = new Mock <IClientRepository>(); clientRepository.Setup(x => x.GetClient("NUnit")).ReturnsAsync(client); clientRepository.Setup(x => x.GetClients()).ReturnsAsync(new List <IClient>() { client }); var userRepository = new Mock <IUserRepository>(); userRepository.Setup(x => x.GetUser("azzlack")).ReturnsAsync(user); userRepository.Setup(x => x.GetUsers()).ReturnsAsync(new List <IUser>() { user }); var userApiKeyRepository = new Mock <IUserApiKeyRepository>(); userApiKeyRepository.Setup(x => x.GetForUser("azzlack")).ReturnsAsync(userApiKeys); var cryptoProvider = new SHA2CryptoProvider(HashAlgorithm.SHA256); var issuerUri = new Uri("https://sentinel.oauth"); this.SymmetricKey = cryptoProvider.CreateHash(256); this.Server = TestServer.Create( app => { app.UseSentinelAuthorizationServer(new SentinelAuthorizationServerOptions() { RequireSecureConnection = false, EnableBasicAuthentication = true, EnableSignatureAuthentication = true, ClientRepository = clientRepository.Object, UserRepository = userRepository.Object, UserApiKeyRepository = userApiKeyRepository.Object, IssuerUri = issuerUri, TokenProvider = new JwtTokenProvider(new JwtTokenProviderConfiguration(cryptoProvider, issuerUri, this.SymmetricKey)) }); // Start up web api var httpConfig = new HttpConfiguration(); httpConfig.MapHttpAttributeRoutes(); // Configure Web API to use only Bearer token authentication. httpConfig.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType)); httpConfig.EnsureInitialized(); app.UseWebApi(httpConfig); }); }
public override void TestFixtureSetUp() { var cryptoProvider = new SHA2CryptoProvider(HashAlgorithm.SHA256); this.TokenProvider = new JwtTokenProvider(new JwtTokenProviderConfiguration(cryptoProvider, new Uri("https://sentinel.oauth"), cryptoProvider.CreateHash(256))); base.TestFixtureSetUp(); }
public override void TestFixtureSetUp() { var client = new Client() { ClientId = "NUnit", ClientSecret = "10000:gW7zpVeugKl8IFu7TcpPskcgQjy4185eAwBk9fFlZK6JNd1I45tLyCYtJrzWzE+kVCUP7lMSY8o808EjUgfavBzYU/ZtWypcdCdCJ0BMfMcf8Mk+XIYQCQLiFpt9Rjrf5mAY86NuveUtd1yBdPjxX5neMXEtquNYhu9I6iyzcN4=:Lk2ZkpmTDkNtO/tsB/GskMppdAX2bXehP+ED4oLis0AAv3Q1VeI8KL0SxIIWdxjKH0NJKZ6qniRFkfZKZRS2hS4SB8oyB34u/jyUlmv+RZGZSt9nJ9FYJn1percd/yFA7sSQOpkGljJ6OTwdthe0Bw0A/8qlKHbO2y2M5BFgYHY=", RedirectUri = "http://localhost", Enabled = true }; var user = new User() { UserId = "azzlack", Password = "******", FirstName = "Ove", LastName = "Andersen", Enabled = true }; var clientRepository = new Mock <IClientRepository>(); clientRepository.Setup(x => x.GetClient("NUnit")).ReturnsAsync(client); clientRepository.Setup(x => x.GetClients()).ReturnsAsync(new List <IClient>() { client }); var userRepository = new Mock <IUserRepository>(); userRepository.Setup(x => x.GetUser("azzlack")).ReturnsAsync(user); userRepository.Setup(x => x.GetUsers()).ReturnsAsync(new List <IUser>() { user }); var cryptoProvider = new SHA2CryptoProvider(HashAlgorithm.SHA256); var issuerUri = new Uri("https://sentinel.oauth"); this.SymmetricKey = cryptoProvider.CreateHash(256); this.Server = TestServer.Create( app => { app.UseSentinelAuthorizationServer(new SentinelAuthorizationServerOptions() { ClientRepository = clientRepository.Object, UserRepository = userRepository.Object, IssuerUri = issuerUri, TokenProvider = new JwtTokenProvider(new JwtTokenProviderConfiguration(cryptoProvider, issuerUri, this.SymmetricKey)) }); // Start up web api var httpConfig = new HttpConfiguration(); httpConfig.MapHttpAttributeRoutes(); // Configure Web API to use only Bearer token authentication. httpConfig.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType)); httpConfig.EnsureInitialized(); app.UseWebApi(httpConfig); }); base.TestFixtureSetUp(); }