Esempio n. 1
0
 /// <summary>Initializes a new instance of the <see cref="BinaryJweDescriptor"/> class.</summary>
 public BinaryJweDescriptor(Jwk encryptionKey, KeyManagementAlgorithm alg, EncryptionAlgorithm enc, CompressionAlgorithm?zip = null, string?typ = JwtMediaTypeValues.OctetStream, string?cty = null)
     : base(encryptionKey, alg, enc, zip, typ, cty)
 {
 }
Esempio n. 2
0
 public JwsHeader(string algorithm, Jwk key)
 {
     Algorithm = algorithm;
     Key       = key;
 }
Esempio n. 3
0
 public override void IsSupportedSignature_Success(Jwk key, SignatureAlgorithm alg)
 {
     base.IsSupportedSignature_Success(key, alg);
 }
Esempio n. 4
0
 public AccessTokenDescriptor(SignatureAlgorithm alg, Jwk signingKey)
     : base(signingKey, alg)
 {
 }
Esempio n. 5
0
 public override KeyWrapper CreateKeyWrapper_Succeed(Jwk key, EncryptionAlgorithm enc, KeyManagementAlgorithm alg)
 {
     return(base.CreateKeyWrapper_Succeed(key, enc, alg));
 }
Esempio n. 6
0
 public override void IsSupportedKeyWrapping_Success(Jwk key, EncryptionAlgorithm enc, KeyManagementAlgorithm alg)
 {
     Assert.False(key.SupportEncryption(enc));
     Assert.True(key.SupportKeyManagement(alg));
 }
Esempio n. 7
0
 public override void IsSupportedKeyWrapping_Success(Jwk key, EncryptionAlgorithm enc, KeyManagementAlgorithm alg)
 {
     base.IsSupportedKeyWrapping_Success(key, enc, alg);
 }
Esempio n. 8
0
 public virtual void IsSupportedEncryption_Success(Jwk key, EncryptionAlgorithm enc)
 {
     Assert.True(key.SupportEncryption(enc));
 }
Esempio n. 9
0
        private static JwsDescriptor CreateJws(Jwk signingKey, JObject descriptor, TokenValidationStatus status, string?claim = null)
        {
            var payload = new JwtPayload();

            foreach (var kvp in descriptor)
            {
                switch (status)
                {
                case TokenValidationStatus.InvalidClaim:
                    if (kvp.Key == "aud" && claim == "aud")
                    {
                        payload.Add(kvp.Key, kvp.Value + "XXX");
                        continue;
                    }
                    if (kvp.Key == "iss" && claim == "iss")
                    {
                        payload.Add(kvp.Key, kvp.Value + "XXX");
                        continue;
                    }
                    break;

                case TokenValidationStatus.MissingClaim:
                    if (kvp.Key == "exp" & claim == "exp")
                    {
                        continue;
                    }
                    if (kvp.Key == "aud" & claim == "aud")
                    {
                        continue;
                    }
                    if (kvp.Key == "iss" && claim == "iss")
                    {
                        continue;
                    }
                    break;

                case TokenValidationStatus.Expired:
                    if (kvp.Key == "exp")
                    {
                        payload.Add(kvp.Key, 1500000000);
                        continue;
                    }
                    if (kvp.Key == "nbf")
                    {
                        payload.Add(kvp.Key, 1400000000);
                        continue;
                    }
                    break;

                case TokenValidationStatus.NotYetValid:
                    if (kvp.Key == "exp")
                    {
                        payload.Add(kvp.Key, 2100000000);
                        continue;
                    }
                    if (kvp.Key == "nbf")
                    {
                        payload.Add(kvp.Key, 2000000000);
                        continue;
                    }
                    break;
                }


                switch (kvp.Value.Type)
                {
                case JTokenType.Object:
                    payload.Add(kvp.Key, (object)kvp.Value);
                    break;

                case JTokenType.Array:
                    payload.Add(kvp.Key, (object[])(object)kvp.Value);
                    break;

                case JTokenType.Integer:
                    payload.Add(kvp.Key, (long)kvp.Value);
                    break;

                case JTokenType.Float:
                    payload.Add(kvp.Key, (double)kvp.Value);
                    break;

                case JTokenType.String:
                    payload.Add(kvp.Key, (string)kvp.Value);
                    break;

                case JTokenType.Boolean:
                    payload.Add(kvp.Key, (bool)kvp.Value);
                    break;

                case JTokenType.Null:
                    payload.Add(kvp.Key, (object)kvp.Value);
                    break;
                }
            }

            var d = new JwsDescriptor(signingKey, SignatureAlgorithm.HS256);

            d.Payload = payload;
            return(d);
        }
Esempio n. 10
0
 public DirectKeyWrapper(Jwk key, EncryptionAlgorithm encryptionAlgorithm, KeyManagementAlgorithm algorithm)
     : base(key, encryptionAlgorithm, algorithm)
 {
 }
Esempio n. 11
0
 /// <summary>Initializes a new instance of <see cref="JweDescriptor"/>.</summary>
 public JweDescriptorBase(Jwk encryptionKey, KeyManagementAlgorithm alg, EncryptionAlgorithm enc, CompressionAlgorithm?zip = null, string?typ = null, string?cty = JwtContentTypeValues.Jwt)
     : base(encryptionKey, alg, enc, zip, typ, cty)
 {
 }
Esempio n. 12
0
 public override bool IsValidKey(Jwk key)
 {
     return(key.X.IsNotEmpty() && key.Y.IsNotEmpty() && key.Crv.IsNotEmpty());
 }
Esempio n. 13
0
        private static JwsDescriptor CreateJws(Jwk signingKey, Dictionary <string, object> descriptor, TokenValidationStatus status, string claim = null)
        {
            var payload = new JwtPayload();

            foreach (var kvp in descriptor)
            {
                switch (status)
                {
                case TokenValidationStatus.InvalidClaim:
                    if (kvp.Key == "aud" && claim == "aud")
                    {
                        payload.Add(kvp.Key, kvp.Value + "XXX");
                        continue;
                    }
                    if (kvp.Key == "iss" && claim == "iss")
                    {
                        payload.Add(kvp.Key, kvp.Value + "XXX");
                        continue;
                    }
                    break;

                case TokenValidationStatus.MissingClaim:
                    if (kvp.Key == "exp" & claim == "exp")
                    {
                        continue;
                    }
                    if (kvp.Key == "aud" & claim == "aud")
                    {
                        continue;
                    }
                    if (kvp.Key == "iss" && claim == "iss")
                    {
                        continue;
                    }
                    break;

                case TokenValidationStatus.Expired:
                    if (kvp.Key == "exp")
                    {
                        payload.Add(kvp.Key, 1500000000);
                        continue;
                    }
                    if (kvp.Key == "nbf")
                    {
                        payload.Add(kvp.Key, 1400000000);
                        continue;
                    }
                    break;

                case TokenValidationStatus.NotYetValid:
                    if (kvp.Key == "exp")
                    {
                        payload.Add(kvp.Key, 2100000000);
                        continue;
                    }
                    if (kvp.Key == "nbf")
                    {
                        payload.Add(kvp.Key, 2000000000);
                        continue;
                    }
                    break;
                }

                payload.Add(kvp.Key, kvp.Value);
            }

            var d = new JwsDescriptor(signingKey, signingKey.SignatureAlgorithm)
            {
                Payload = payload
            };

            return(d);
        }
Esempio n. 14
0
 public JwtService(X509Certificate2 certificate, IConfiguration configuration)
 {
     _configuration = configuration;
     _key           = Jwk.FromX509Certificate(certificate, true);
 }
Esempio n. 15
0
 public override bool IsValidKey(Jwk key)
 {
     return(key.K.IsNotEmpty());
 }
Esempio n. 16
0
 public EncryptedAccesTokenDescriptor(Jwk encryptionKey, KeyManagementAlgorithm alg, EncryptionAlgorithm enc, CompressionAlgorithm?zip = null)
     : base(encryptionKey, alg, enc, zip)
 {
 }
 public Task <Account?> FindAccountAsync(Jwk jwk, CancellationToken cancellationToken)
 {
     throw new NotImplementedException();
 }
Esempio n. 18
0
 public virtual void IsSupportedKeyWrapping_Success(Jwk key, EncryptionAlgorithm enc, KeyManagementAlgorithm alg)
 {
     Assert.True(key.SupportKeyManagement(alg));
 }
Esempio n. 19
0
 public StateDescriptor(SignatureAlgorithm alg, Jwk signingKey)
     : base(signingKey, alg)
 {
 }
Esempio n. 20
0
 public override Signer CreateSigner_Succeed(Jwk key, SignatureAlgorithm alg)
 {
     return(base.CreateSigner_Succeed(key, alg));
 }
Esempio n. 21
0
        public void TryWrapKey_WithoutStaticKey_Success(EncryptionAlgorithm enc, KeyManagementAlgorithm alg)
        {
            Jwk cek = TryWrapKey_Success(null, enc, alg);

            Assert.NotNull(cek);
        }
Esempio n. 22
0
 public override void IsSupportedSignature_Success(Jwk key, SignatureAlgorithm alg)
 {
     Assert.True(key.SupportSignature(alg));
 }
Esempio n. 23
0
 public override void IsSupportedEncryption_Success(Jwk key, EncryptionAlgorithm enc)
 {
     base.IsSupportedEncryption_Success(key, enc);
 }