Exemplo n.º 1
0
        public void Test_expValidationPositive()
        {
            options.AddCustomTimeValidationClaim("exp", "2030/07/07 10:15:20", "20");
            string token      = jwt.DoCreate("HS256", claims, options);
            bool   validation = jwt.DoVerify(token, "HS256", claims, options);

            Assert.IsTrue(validation);
        }
        public void GenerateToken()
        {
            string hexaKey = keyGen.doGenerateKey("GENERICRANDOM", 256);

            options.SetSecret(hexaKey);
            token = jwt.DoCreate("HS256", claims, options);
            Assert.IsFalse(jwt.HasError());
            bool verification = jwt.DoVerify(token, "HS256", claims, options);

            True(verification, jwt);
        }
        private void bulkTest_shouldWork(PrivateKeyManager key, CertificateX509 cert, string alg, string curve)
        {
            options.SetPrivateKey(key);
            options.SetCertificate(cert);
            string token = jwt.DoCreate(alg, claims, options);

            Assert.IsFalse(jwt.HasError());
            bool verification = jwt.DoVerify(token, alg, claims, options);

            True(verification, jwt);
        }
        public virtual void SetUp()
        {
            jwt     = new JWTCreator();
            options = new JWTOptions();
            du      = new DateUtil();
            keyGen  = new SymmetricKeyGenerator();
            claims  = new PrivateClaims();

            currentDate = du.GetCurrentDate();
            hexaKey     = keyGen.doGenerateKey("GENERICRANDOM", 256);

            options.AddRegisteredClaim("aud", "jitsi");
            options.AddRegisteredClaim("iss", "my_client");
            options.AddRegisteredClaim("sub", "meet.jit.si");
            string expiration = du.CurrentPlusSeconds(200);

            options.AddCustomTimeValidationClaim("exp", expiration, "20");

            claims.setClaim("hola", "hola");

            options.AddHeaderParameter("cty", "twilio-fpa;v=1");
            options.SetSecret(hexaKey);

            token = jwt.DoCreate("HS256", claims, options);
        }
        public virtual void SetUp()
        {
            jwt     = new JWTCreator();
            options = new JWTOptions();

            keyGen       = new SymmetricKeyGenerator();
            claimslevel1 = new PrivateClaims();
            claimslevel2 = new PrivateClaims();
            claimslevel3 = new PrivateClaims();


            hexaKey = keyGen.doGenerateKey("GENERICRANDOM", 256);

            options.AddRegisteredClaim("aud", "jitsi");
            options.AddRegisteredClaim("iss", "my_client");
            options.AddRegisteredClaim("sub", "meet.jit.si");


            claimslevel1.setClaim("room", "*");

            claimslevel1.setClaim("context", claimslevel2);

            claimslevel2.setClaim("user", claimslevel3);
            claimslevel3.setClaim("avatar", "https:/gravatar.com/avatar/abc123");
            claimslevel3.setClaim("name", "John Doe");
            claimslevel3.setClaim("email", "*****@*****.**");
            claimslevel3.setClaim("id", "abcd:a1b2c3-d4e5f6-0abc1-23de-abcdef01fedcba");
            claimslevel2.setClaim("group", "a123-123-456-789");

            options.SetSecret(hexaKey);
            token = jwt.DoCreate("HS256", claimslevel1, options);
        }
        public virtual void SetUp()
        {
            jwt     = new JWTCreator();
            options = new JWTOptions();
            keyGen  = new SymmetricKeyGenerator();
            claims  = new PrivateClaims();
            rList   = new RevocationList();



            options.AddRegisteredClaim("iss", "GXSA");
            options.AddRegisteredClaim("sub", "subject1");
            options.AddRegisteredClaim("aud", "audience1");
            ID = "0696bb20-6223-4a1c-9ebf-e15c74387b9c, 0696bb20-6223-4a1c-9ebf-e15c74387b9c";            //&guid.Generate()
            options.AddRegisteredClaim("jti", ID);
            claims.setClaim("hola1", "hola1");
            claims.setClaim("hola2", "hola2");

            String hexaKey = keyGen.doGenerateKey("GENERICRANDOM", 256);

            options.SetSecret(hexaKey);
            options.AddRevocationList(rList);

            token = jwt.DoCreate("HS256", claims, options);
        }
Exemplo n.º 7
0
        public virtual void SetUp()
        {
            options1 = new JWTOptions();
            options2 = new JWTOptions();
            jwt      = new JWTCreator();
            claims   = new PrivateClaims();
            claims.setClaim("hola1", "hola1");
            path_RSA_sha256_1024 = Path.Combine(BASE_PATH, "dummycerts", "RSA_sha256_1024");

            String            pathKey  = Path.Combine(path_RSA_sha256_1024, "sha256d_key.pem");
            String            pathCert = Path.Combine(path_RSA_sha256_1024, "sha256_cert.crt");
            PrivateKeyManager key      = new PrivateKeyManager();
            CertificateX509   cert     = new CertificateX509();

            key.Load(pathKey);
            cert.Load(pathCert);

            options1.SetCertificate(cert);
            options1.SetPrivateKey(key);
            options1.AddRegisteredClaim("iss", "GXSA");
            options1.AddRegisteredClaim("sub", "subject1");
            options1.AddRegisteredClaim("aud", "audience1");

            options2.AddRegisteredClaim("iss", "GXSA");
            options2.AddRegisteredClaim("sub", "subject1");
            options2.AddRegisteredClaim("aud", "audience1");
            options2.SetCertificate(cert);

            token = jwt.DoCreate("RS256", claims, options1);
        }
Exemplo n.º 8
0
        public virtual void SetUp()
        {
            cert    = new CertificateX509();
            key     = new PrivateKeyManager();
            options = new JWTOptions();
            claims  = new PrivateClaims();
            du      = new DateUtil();
            jwt     = new JWTCreator();


            cert.Load(BASE_PATH + "dummycerts\\RSA_sha256_1024\\sha256_cert.crt");
            options.SetCertificate(cert);


            key.Load(BASE_PATH + "dummycerts\\RSA_sha256_1024\\sha256d_key.pem");
            options.SetPrivateKey(key);
            //
            // carga de privateClaim (es parte del Payload)
            claims.setClaim("GeneXus", "Viglia");


            // Carga de Registered Claims
            options.AddRegisteredClaim("iss", "Martin");
            options.AddRegisteredClaim("sub", "Martin1");
            options.AddRegisteredClaim("aud", "martivigliadoocebbooyo.docebosaas.com");
            options.AddCustomTimeValidationClaim("iat", du.GetCurrentDate(), "20");
            options.AddCustomTimeValidationClaim("exp", du.CurrentPlusSeconds(3600), "20");
            options.AddPublicClaim("client_id", "Martin");

            token    = jwt.DoCreate("RS256", claims, options);
            expected = "{\"alg\":\"RS256\",\"typ\":\"JWT\"}";
        }
        public void TestDomains()
        {
            options.SetSecret(hexaKey);
            string token = jwt.DoCreate("HS256 ", claims, options);

            Assert.IsFalse(jwt.HasError());
            bool verification = jwt.DoVerifyJustSignature(token, " HS256", options);

            True(verification, jwt);
        }
        public void Test_sha256_1024_PEM()
        {
            String            pathKey = Path.Combine(path_RSA_sha256_1024, "sha256d_key.pem");
            PrivateKeyManager key     = new PrivateKeyManager();

            key.Load(pathKey);
            options.SetPrivateKey(key);
            String alg   = "RS256";
            String token = jwt.DoCreate(alg, claims, options);

            Assert.IsFalse(SecurityUtils.compareStrings("", token));
            Assert.IsFalse(jwt.HasError());
        }
        public virtual void SetUp()
        {
            jwt     = new JWTCreator();
            options = new JWTOptions();
            keyGen  = new SymmetricKeyGenerator();
            claims  = new PrivateClaims();

            options.AddCustomTimeValidationClaim("exp", "2020/07/20 17:56:51", "20");
            options.AddCustomTimeValidationClaim("iat", "2020/07/20 17:56:51", "20");
            options.AddCustomTimeValidationClaim("nbf", "2020/07/20 17:56:51", "20");
            claims.setClaim("hola1", "hola1");
            string hexaKey = keyGen.doGenerateKey("GENERICRANDOM", 256);

            options.SetSecret(hexaKey);
            string token = jwt.DoCreate("HS256", claims, options);

            payload = jwt.GetPayload(token);


            expected = "{\"hola1\":\"hola1\",\"exp\":1595267811,\"iat\":1595267811,\"nbf\":1595267811}";
        }
        public virtual void SetUp()
        {
            jwt     = new JWTCreator();
            options = new JWTOptions();
            du      = new DateUtil();
            keyGen  = new SymmetricKeyGenerator();
            claims  = new PrivateClaims();



            hexaKey = keyGen.doGenerateKey("GENERICRANDOM", 256);

            options.AddRegisteredClaim("aud", "jitsi");
            options.AddRegisteredClaim("iss", "my_client");
            options.AddRegisteredClaim("sub", "meet.jit.si");


            claims.setClaim("hola", "hola");

            options.AddHeaderParameter("cty", "twilio-fpa;v=1");
            options.SetSecret(hexaKey);

            token = jwt.DoCreate("HS256", claims, options);
        }