Exemple #1
0
 public QuestionRepository(
     IQuestionClient questionClient,
     IJsonMapper jsonMapper)
 {
     _questionClient = questionClient ?? throw new ArgumentNullException(nameof(questionClient));
     _jsonMapper     = jsonMapper;
 }
Exemple #2
0
        /// <summary>
        /// Parse serialized token
        /// </summary>
        public static JweToken FromString(string token, IJsonMapper jsonMapper = null)
        {
            bool isJsonEncoded = token.Trim().StartsWith("{", StringComparison.Ordinal);

            return(isJsonEncoded
                ? ParseJson(jsonMapper.Parse <IDictionary <string, object> >(token))
                : ParseCompact(token));
        }
Exemple #3
0
        private MapperWrapper <T> BuildMapperWrapperSync <T>()
        {
            IRuntimeMapperBuilder builder = GetBuilderSync <T>();
            IJsonMapper <T>       mapper  = builder.Build <T>(this);

            mapper.Init(this);
            return(new MapperWrapper <T>(this, mapper, builder));
        }
        /// <summary>
        /// Adds json mapper instance to the container
        /// </summary>
        /// <typeparam name="T">Object type</typeparam>
        /// <param name="mapper">Json mapper instance</param>
        public void AddMapper <T>(IJsonMapper <T> mapper)
        {
            if (mapper == null)
            {
                throw new ArgumentNullException("mapper");
            }

            _configurations[typeof(T)] = mapper;
        }
        protected ControllerBase(ActionInvoker actionInvoker, WebSocketServerBase server,
                                 DataContext dataContext, JsonMapperManager jsonMapperManager) :
            base(actionInvoker, server)
        {
            _dataContext = dataContext;

            _commandMapper      = jsonMapperManager.GetMapper <DeviceCommand>();
            _notificationMapper = jsonMapperManager.GetMapper <DeviceNotification>();
        }
Exemple #6
0
 public Property(Func <object, object> getter,
                 Action <object, object> setter,
                 IPropertyValidator validator,
                 IJsonMapper mapper)
 {
     Getter    = getter ?? throw new ArgumentNullException(nameof(getter));
     Setter    = setter;
     Validator = validator ?? throw new ArgumentNullException(nameof(validator));
     Mapper    = mapper ?? throw new ArgumentNullException(nameof(mapper));
 }
Exemple #7
0
        static JWT()
        {
#if NET40 || NET461
            JsonMapper = new JSSerializerMapper();
#elif NETSTANDARD1_4
            JsonMapper = new NewtonsoftMapper();
#endif
            HashAlgorithms = new Dictionary <JwsAlgorithm, IJwsAlgorithm>
            {
                { JwsAlgorithm.none, new Plaintext() },
Exemple #8
0
 internal override void ToJson(
     IJsonContext context, IJsonWriter writer, IJsonMapper <JsonElement> elMapper)
 {
     if (_value == null)
     {
         writer.WriteRaw(JsonLiterals.Null);
     }
     else
     {
         writer.EncodeAndWrite(_value);
     }
 }
Exemple #9
0
 protected DictionaryMapperBase(
     IJsonSerializator <TKey> keySerializator, IJsonSerializator <TValue> valueSerializator,
     char startLiteral, char endLiteral, JsonToken startToken, JsonToken emptyToken, JsonToken endToken)
 {
     _keyMapper    = keySerializator.Mapper;
     _valueMapper  = valueSerializator.Mapper;
     _startLiteral = startLiteral;
     _emptyToken   = emptyToken;
     _endLiteral   = endLiteral;
     _startToken   = startToken;
     _endToken     = endToken;
 }
Exemple #10
0
        /// <summary>
        /// Serialize token according to serialization mode
        /// </summary>
        public string AsString(IJsonMapper mapper = null)
        {
            if (Encoding == SerializationMode.Compact)
            {
                return(Compact.Serialize(ProtectedHeaderBytes, Recipients[0].EncryptedCek, Iv, Ciphertext, AuthTag));
            }

            var json = new Dictionary <string, object>()
            {
                { "ciphertext", Base64Url.Encode(Ciphertext) },
                { "protected", Base64Url.Encode(ProtectedHeaderBytes) },
                { "iv", Base64Url.Encode(Iv) },
                { "tag", Base64Url.Encode(AuthTag) }
            };

            if (Aad != null)
            {
                json["aad"] = Base64Url.Encode(Aad);
            }

            if (UnprotectedHeader != null)
            {
                json["unprotected"] = UnprotectedHeader;
            }


            if (Recipients.Count == 1)
            {
                json["header"]        = Recipients[0].Header;
                json["encrypted_key"] = Base64Url.Encode(Recipients[0].EncryptedCek);
            }
            else
            {
                var recipientList = new List <object>();


                foreach (var recipient in Recipients)
                {
                    recipientList.Add(
                        new Dictionary <string, object> {
                        { "header", recipient.Header },
                        { "encrypted_key", Base64Url.Encode(recipient.EncryptedCek) }
                    }
                        );
                }

                json["recipients"] = recipientList;
            }

            return(mapper.Serialize(json));
        }
        public DeviceController(ActionInvoker actionInvoker, WebSocketServerBase server,
            DataContext dataContext, JsonMapperManager jsonMapperManager,
            [Named("DeviceCommand")] DeviceSubscriptionManager subscriptionManager,
            MessageBus messageBus, IMessageManager messageManager,
            DeviceService deviceService) :
            base(actionInvoker, server, dataContext, jsonMapperManager)
        {
            _subscriptionManager = subscriptionManager;
            _messageBus = messageBus;
            _messageManager = messageManager;
            _deviceService = deviceService;

            _deviceMapper = jsonMapperManager.GetMapper<Device>();
        }
        public DeviceController(ActionInvoker actionInvoker, WebSocketServerBase server,
                                DataContext dataContext, JsonMapperManager jsonMapperManager,
                                [Named("DeviceCommand")] DeviceSubscriptionManager subscriptionManager,
                                MessageBus messageBus, IMessageManager messageManager,
                                DeviceService deviceService) :
            base(actionInvoker, server, dataContext, jsonMapperManager)
        {
            _subscriptionManager = subscriptionManager;
            _messageBus          = messageBus;
            _messageManager      = messageManager;
            _deviceService       = deviceService;

            _deviceMapper = jsonMapperManager.GetMapper <Device>();
        }
Exemple #13
0
 internal override void ToJson(
     IJsonContext context, IJsonWriter writer, IJsonMapper <JsonElement> elMapper)
 {
     writer.WriteRaw(JsonLiterals.ArrayStart);
     if (_elements.Count > 0)
     {
         elMapper.ToJson(context, writer, _elements[0]);
         for (var i = 1; i < _elements.Count; i++)
         {
             writer.WriteRaw(JsonLiterals.Comma);
             elMapper.ToJson(context, writer, _elements[i]);
         }
     }
     writer.WriteRaw(JsonLiterals.ArrayEnd);
 }
Exemple #14
0
        internal bool RegisterMapper <T>(IJsonMapper <T> mapper)
        {
            if (mapper == null)
            {
                return(false);
            }
            lock (_lock)
            {
                if (_frozen || _disposed)
                {
                    return(false);
                }
                UnregisterMapperSync <T>();
                MapperWrapper <T> wrapper = new MapperWrapper <T>(this, mapper);
                JsonSerializatorCache <T> .Register(wrapper);

                _mapperWrappers.Add(wrapper);
                return(true);
            }
        }
Exemple #15
0
 internal override void ToJson(
     IJsonContext context, IJsonWriter writer, IJsonMapper <JsonElement> elMapper)
 {
     writer.WriteRaw(JsonLiterals.ObjectStart);
     if (_objectMembers.Count > 0)
     {
         var addComma = false;
         foreach (var member in _objectMembers)
         {
             if (addComma)
             {
                 writer.WriteRaw(JsonLiterals.Comma);
             }
             else
             {
                 addComma = true;
             }
             writer.WriteRaw(member.Key.EncodeToJsonString());
             writer.WriteRaw(JsonLiterals.Colon);
             elMapper.ToJson(context, writer, member.Value);
         }
     }
     writer.WriteRaw(JsonLiterals.ObjectEnd);
 }
Exemple #16
0
 public void Init(IJsonContext context)
 {
     _jsonMapper = context.GetSerializator <TProp>().Mapper;
 }
Exemple #17
0
 internal JsonSerializator(JsonContext context, IJsonMapper <T> mapper, IRuntimeMapperBuilder builder)
 {
     Context = context;
     Mapper  = mapper;
     Builder = builder;
 }
Exemple #18
0
 public string ToJson(IJsonMapper mapper = null)
 {
     return(mapper.Serialize(ToDictionary()));
 }
Exemple #19
0
 public NullableJsonMapper(IJsonSerializator <T> serializator)
 {
     _mapper = serializator.Mapper;
 }
Exemple #20
0
 internal override void ToJson(
     IJsonContext context, IJsonWriter writer, IJsonMapper <JsonElement> elMapper)
 {
     writer.WriteRaw(JsonLiterals.Null);
 }
Exemple #21
0
 public static JwkSet FromJson(string json, IJsonMapper mapper = null)
 {
     return(JwkSet.FromDictionary(
                mapper.Parse <IDictionary <string, object> >(json)
                ));
 }
Exemple #22
0
        static JWT()
        {
#if NET40
            JsonMapper = new JSSerializerMapper();
#elif NETSTANDARD1_4
            JsonMapper = new NewtonsoftMapper();
#endif
            HashAlgorithms = new Dictionary <JwsAlgorithm, IJwsAlgorithm>
            {
                { JwsAlgorithm.none, new Plaintext() },
                { JwsAlgorithm.HS256, new HmacUsingSha("SHA256") },
                { JwsAlgorithm.HS384, new HmacUsingSha("SHA384") },
                { JwsAlgorithm.HS512, new HmacUsingSha("SHA512") },

                { JwsAlgorithm.RS256, new RsaUsingSha("SHA256") },
                { JwsAlgorithm.RS384, new RsaUsingSha("SHA384") },
                { JwsAlgorithm.RS512, new RsaUsingSha("SHA512") },

                { JwsAlgorithm.ES256, new EcdsaUsingSha(256) },
                { JwsAlgorithm.ES384, new EcdsaUsingSha(384) },
                { JwsAlgorithm.ES512, new EcdsaUsingSha(521) }
            };

            JwsAlgorithms[JwsAlgorithm.none]  = "none";
            JwsAlgorithms[JwsAlgorithm.HS256] = "HS256";
            JwsAlgorithms[JwsAlgorithm.HS384] = "HS384";
            JwsAlgorithms[JwsAlgorithm.HS512] = "HS512";
            JwsAlgorithms[JwsAlgorithm.RS256] = "RS256";
            JwsAlgorithms[JwsAlgorithm.RS384] = "RS384";
            JwsAlgorithms[JwsAlgorithm.RS512] = "RS512";
            JwsAlgorithms[JwsAlgorithm.ES256] = "ES256";
            JwsAlgorithms[JwsAlgorithm.ES384] = "ES384";
            JwsAlgorithms[JwsAlgorithm.ES512] = "ES512";

            HashAlgorithms[JwsAlgorithm.PS256] = new RsaPssUsingSha(32);
            HashAlgorithms[JwsAlgorithm.PS384] = new RsaPssUsingSha(48);
            HashAlgorithms[JwsAlgorithm.PS512] = new RsaPssUsingSha(64);

            JwsAlgorithms[JwsAlgorithm.PS256] = "PS256";
            JwsAlgorithms[JwsAlgorithm.PS384] = "PS384";
            JwsAlgorithms[JwsAlgorithm.PS512] = "PS512";

            EncAlgorithms = new Dictionary <JweEncryption, IJweAlgorithm>
            {
                { JweEncryption.A128CBC_HS256, new AesCbcHmacEncryption(HashAlgorithms[JwsAlgorithm.HS256], 256) },
                { JweEncryption.A192CBC_HS384, new AesCbcHmacEncryption(HashAlgorithms[JwsAlgorithm.HS384], 384) },
                { JweEncryption.A256CBC_HS512, new AesCbcHmacEncryption(HashAlgorithms[JwsAlgorithm.HS512], 512) }
            };

            JweEncryptionMethods[JweEncryption.A128CBC_HS256] = "A128CBC-HS256";
            JweEncryptionMethods[JweEncryption.A192CBC_HS384] = "A192CBC-HS384";
            JweEncryptionMethods[JweEncryption.A256CBC_HS512] = "A256CBC-HS512";

            // for compatibility with services still using a Draft 7 version of these names
            JweEncryptionMethodAliases["A128CBC+HS256"] = JweEncryption.A128CBC_HS256;
            JweEncryptionMethodAliases["A192CBC+HS384"] = JweEncryption.A192CBC_HS384;
            JweEncryptionMethodAliases["A256CBC+HS512"] = JweEncryption.A256CBC_HS512;

            EncAlgorithms[JweEncryption.A128GCM] = new AesGcmEncryption(128);
            EncAlgorithms[JweEncryption.A192GCM] = new AesGcmEncryption(192);
            EncAlgorithms[JweEncryption.A256GCM] = new AesGcmEncryption(256);

            JweEncryptionMethods[JweEncryption.A128GCM] = "A128GCM";
            JweEncryptionMethods[JweEncryption.A192GCM] = "A192GCM";
            JweEncryptionMethods[JweEncryption.A256GCM] = "A256GCM";

            KeyAlgorithms = new Dictionary <JweAlgorithm, IKeyManagement>
            {
                { JweAlgorithm.RSA_OAEP, new RsaKeyManagement(true) },
                { JweAlgorithm.RSA_OAEP_256, new RsaOaep256KeyManagement() },
                { JweAlgorithm.RSA1_5, new RsaKeyManagement(false) },
                { JweAlgorithm.DIR, new DirectKeyManagement() },
                { JweAlgorithm.A128KW, new AesKeyWrapManagement(128) },
                { JweAlgorithm.A192KW, new AesKeyWrapManagement(192) },
                { JweAlgorithm.A256KW, new AesKeyWrapManagement(256) },
                { JweAlgorithm.ECDH_ES, new EcdhKeyManagement(true) },
                { JweAlgorithm.ECDH_ES_A128KW, new EcdhKeyManagementWithAesKeyWrap(128, new AesKeyWrapManagement(128)) },
                { JweAlgorithm.ECDH_ES_A192KW, new EcdhKeyManagementWithAesKeyWrap(192, new AesKeyWrapManagement(192)) },
                { JweAlgorithm.ECDH_ES_A256KW, new EcdhKeyManagementWithAesKeyWrap(256, new AesKeyWrapManagement(256)) },
                { JweAlgorithm.PBES2_HS256_A128KW, new Pbse2HmacShaKeyManagementWithAesKeyWrap(128, new AesKeyWrapManagement(128)) },
                { JweAlgorithm.PBES2_HS384_A192KW, new Pbse2HmacShaKeyManagementWithAesKeyWrap(192, new AesKeyWrapManagement(192)) },
                { JweAlgorithm.PBES2_HS512_A256KW, new Pbse2HmacShaKeyManagementWithAesKeyWrap(256, new AesKeyWrapManagement(256)) },
                { JweAlgorithm.A128GCMKW, new AesGcmKeyWrapManagement(128) },
                { JweAlgorithm.A192GCMKW, new AesGcmKeyWrapManagement(192) },
                { JweAlgorithm.A256GCMKW, new AesGcmKeyWrapManagement(256) }
            };

            JweAlgorithms[JweAlgorithm.RSA1_5]             = "RSA1_5";
            JweAlgorithms[JweAlgorithm.RSA_OAEP]           = "RSA-OAEP";
            JweAlgorithms[JweAlgorithm.RSA_OAEP_256]       = "RSA-OAEP-256";
            JweAlgorithms[JweAlgorithm.DIR]                = "dir";
            JweAlgorithms[JweAlgorithm.A128KW]             = "A128KW";
            JweAlgorithms[JweAlgorithm.A192KW]             = "A192KW";
            JweAlgorithms[JweAlgorithm.A256KW]             = "A256KW";
            JweAlgorithms[JweAlgorithm.ECDH_ES]            = "ECDH-ES";
            JweAlgorithms[JweAlgorithm.ECDH_ES_A128KW]     = "ECDH-ES+A128KW";
            JweAlgorithms[JweAlgorithm.ECDH_ES_A192KW]     = "ECDH-ES+A192KW";
            JweAlgorithms[JweAlgorithm.ECDH_ES_A256KW]     = "ECDH-ES+A256KW";
            JweAlgorithms[JweAlgorithm.PBES2_HS256_A128KW] = "PBES2-HS256+A128KW";
            JweAlgorithms[JweAlgorithm.PBES2_HS384_A192KW] = "PBES2-HS384+A192KW";
            JweAlgorithms[JweAlgorithm.PBES2_HS512_A256KW] = "PBES2-HS512+A256KW";
            JweAlgorithms[JweAlgorithm.A128GCMKW]          = "A128GCMKW";
            JweAlgorithms[JweAlgorithm.A192GCMKW]          = "A192GCMKW";
            JweAlgorithms[JweAlgorithm.A256GCMKW]          = "A256GCMKW";

            CompressionAlgorithms = new Dictionary <JweCompression, ICompression>
            {
                { JweCompression.DEF, new DeflateCompression() }
            };

            JweCompressionMethods[JweCompression.DEF] = "DEF";
        }
Exemple #23
0
 public void Init(IJsonContext context)
 {
     JsonElementMapper = context.GetSerializator <JsonElement>().Mapper;
     JsonArrayMapper   = context.GetSerializator <JsonArray>().Mapper;
     JsonObjectMapper  = context.GetSerializator <JsonObject>().Mapper;
 }
Exemple #24
0
        static JWT()
        {
            JsonMapper = new NewtonsoftJsonMapper();

            HashAlgorithms = new Dictionary <JwsAlgorithm, IJwsAlgorithm>
            {
                //{JwsAlgorithm.none, new Plaintext()},
                //{JwsAlgorithm.HS256, new HmacUsingSha("SHA256")},
                //{JwsAlgorithm.HS384, new HmacUsingSha("SHA384")},
                //{JwsAlgorithm.HS512, new HmacUsingSha("SHA512")},

                { JwsAlgorithm.RS256, new RsaUsingSha("SHA256") },
                { JwsAlgorithm.RS384, new RsaUsingSha("SHA384") },
                { JwsAlgorithm.RS512, new RsaUsingSha("SHA512") },

                //{JwsAlgorithm.ES256, new EcdsaUsingSha(256)},
                //{JwsAlgorithm.ES384, new EcdsaUsingSha(384)},
                //{JwsAlgorithm.ES512, new EcdsaUsingSha(521)}
            };

            //JwsAlgorithms[JwsAlgorithm.none] = "none";
            //JwsAlgorithms[JwsAlgorithm.HS256] = "HS256";
            //JwsAlgorithms[JwsAlgorithm.HS384] = "HS384";
            //JwsAlgorithms[JwsAlgorithm.HS512] = "HS512";
            JwsAlgorithms[JwsAlgorithm.RS256] = "RS256";
            //JwsAlgorithms[JwsAlgorithm.RS384] = "RS384";
            //JwsAlgorithms[JwsAlgorithm.RS512] = "RS512";
            //JwsAlgorithms[JwsAlgorithm.ES256] = "ES256";
            //JwsAlgorithms[JwsAlgorithm.ES384] = "ES384";
            //JwsAlgorithms[JwsAlgorithm.ES512] = "ES512";

            //HashAlgorithms[JwsAlgorithm.PS256] = new RsaPssUsingSha(32);
            //HashAlgorithms[JwsAlgorithm.PS384] = new RsaPssUsingSha(48);
            //HashAlgorithms[JwsAlgorithm.PS512] = new RsaPssUsingSha(64);

            //JwsAlgorithms[JwsAlgorithm.PS256] = "PS256";
            //JwsAlgorithms[JwsAlgorithm.PS384] = "PS384";
            //JwsAlgorithms[JwsAlgorithm.PS512] = "PS512";

            EncAlgorithms = new Dictionary <JweEncryption, IJweAlgorithm>
            {
                //{ JweEncryption.A128CBC_HS256, new AesCbcHmacEncryption(HashAlgorithms[JwsAlgorithm.HS256], 256) },
                //{ JweEncryption.A192CBC_HS384, new AesCbcHmacEncryption(HashAlgorithms[JwsAlgorithm.HS384], 384) },
                //{ JweEncryption.A256CBC_HS512, new AesCbcHmacEncryption(HashAlgorithms[JwsAlgorithm.HS512], 512) }
            };

            JweEncryptionMethods[JweEncryption.A128CBC_HS256] = "A128CBC-HS256";
            JweEncryptionMethods[JweEncryption.A192CBC_HS384] = "A192CBC-HS384";
            JweEncryptionMethods[JweEncryption.A256CBC_HS512] = "A256CBC-HS512";

            //EncAlgorithms[JweEncryption.A128GCM] = new AesGcmEncryption(128);
            //EncAlgorithms[JweEncryption.A192GCM] = new AesGcmEncryption(192);
            //EncAlgorithms[JweEncryption.A256GCM] = new AesGcmEncryption(256);

            JweEncryptionMethods[JweEncryption.A128GCM] = "A128GCM";
            JweEncryptionMethods[JweEncryption.A192GCM] = "A192GCM";
            JweEncryptionMethods[JweEncryption.A256GCM] = "A256GCM";

            KeyAlgorithms = new Dictionary <JweAlgorithm, IKeyManagement>();
            //{
            //{ JweAlgorithm.RSA_OAEP, new RsaKeyManagement(true) },
            //{ JweAlgorithm.RSA1_5, new RsaKeyManagement(false) },
            //{ JweAlgorithm.DIR, new DirectKeyManagement() },
            //{ JweAlgorithm.A128KW, new AesKeyWrapManagement(128) },
            //{ JweAlgorithm.A192KW, new AesKeyWrapManagement(192) },
            //{ JweAlgorithm.A256KW, new AesKeyWrapManagement(256) },
            //{ JweAlgorithm.ECDH_ES, new EcdhKeyManagement(true) },
            //{ JweAlgorithm.ECDH_ES_A128KW, new EcdhKeyManagementWithAesKeyWrap(128, new AesKeyWrapManagement(128))},
            //{ JweAlgorithm.ECDH_ES_A192KW, new EcdhKeyManagementWithAesKeyWrap(192, new AesKeyWrapManagement(192))},
            //{ JweAlgorithm.ECDH_ES_A256KW, new EcdhKeyManagementWithAesKeyWrap(256, new AesKeyWrapManagement(256))},
            //{ JweAlgorithm.PBES2_HS256_A128KW, new Pbse2HmacShaKeyManagementWithAesKeyWrap(128, new AesKeyWrapManagement(128))},
            //{ JweAlgorithm.PBES2_HS384_A192KW, new Pbse2HmacShaKeyManagementWithAesKeyWrap(192, new AesKeyWrapManagement(192))},
            //{ JweAlgorithm.PBES2_HS512_A256KW, new Pbse2HmacShaKeyManagementWithAesKeyWrap(256, new AesKeyWrapManagement(256))},
            //{ JweAlgorithm.A128GCMKW, new AesGcmKeyWrapManagement(128)},
            //{ JweAlgorithm.A192GCMKW, new AesGcmKeyWrapManagement(192)},
            //{ JweAlgorithm.A256GCMKW, new AesGcmKeyWrapManagement(256)}
            //};

            JweAlgorithms[JweAlgorithm.RSA1_5]             = "RSA1_5";
            JweAlgorithms[JweAlgorithm.RSA_OAEP]           = "RSA-OAEP";
            JweAlgorithms[JweAlgorithm.DIR]                = "dir";
            JweAlgorithms[JweAlgorithm.A128KW]             = "A128KW";
            JweAlgorithms[JweAlgorithm.A192KW]             = "A192KW";
            JweAlgorithms[JweAlgorithm.A256KW]             = "A256KW";
            JweAlgorithms[JweAlgorithm.ECDH_ES]            = "ECDH-ES";
            JweAlgorithms[JweAlgorithm.ECDH_ES_A128KW]     = "ECDH-ES+A128KW";
            JweAlgorithms[JweAlgorithm.ECDH_ES_A192KW]     = "ECDH-ES+A192KW";
            JweAlgorithms[JweAlgorithm.ECDH_ES_A256KW]     = "ECDH-ES+A256KW";
            JweAlgorithms[JweAlgorithm.PBES2_HS256_A128KW] = "PBES2-HS256+A128KW";
            JweAlgorithms[JweAlgorithm.PBES2_HS384_A192KW] = "PBES2-HS384+A192KW";
            JweAlgorithms[JweAlgorithm.PBES2_HS512_A256KW] = "PBES2-HS512+A256KW";
            JweAlgorithms[JweAlgorithm.A128GCMKW]          = "A128GCMKW";
            JweAlgorithms[JweAlgorithm.A192GCMKW]          = "A192GCMKW";
            JweAlgorithms[JweAlgorithm.A256GCMKW]          = "A256GCMKW";

            CompressionAlgorithms = new Dictionary <JweCompression, ICompression>
            {
                { JweCompression.DEF, new DeflateCompression() }
            };

            JweCompressionMethods[JweCompression.DEF] = "DEF";
        }
Exemple #25
0
 public StormglassioParametersFiller()
 {
     RequestURLFiller = new StormglassioRequestURLFiller();
     JsonMapper       = new StormglassioMapper();
 }
Exemple #26
0
 internal abstract void ToJson(
     IJsonContext context, IJsonWriter writer, IJsonMapper <JsonElement> elMapper);
 public bool RegisterMapper <T>(IJsonMapper <T> mapper)
 {
     return(_context.RegisterMapper(mapper));
 }
Exemple #28
0
 static JWT()
 {
     JWT.JweAlgorithms              = new Dictionary <JweAlgorithm, string>();
     JWT.JweEncryptionMethods       = new Dictionary <JweEncryption, string>();
     JWT.JweCompressionMethods      = new Dictionary <JweCompression, string>();
     JWT.JwsAlgorithms              = new Dictionary <JwsAlgorithm, string>();
     JWT.JweEncryptionMethodAliases = new Dictionary <string, JweEncryption>();
     JWT.JsonMapper     = new JSSerializerMapper();
     JWT.HashAlgorithms = new Dictionary <JwsAlgorithm, IJwsAlgorithm>()
     {
         { JwsAlgorithm.none, new Plaintext() },
         { JwsAlgorithm.HS256, new HmacUsingSha("SHA256") },
         { JwsAlgorithm.HS384, new HmacUsingSha("SHA384") },
         { JwsAlgorithm.HS512, new HmacUsingSha("SHA512") },
         { JwsAlgorithm.RS256, new RsaUsingSha("SHA256") },
         { JwsAlgorithm.RS384, new RsaUsingSha("SHA384") },
         { JwsAlgorithm.RS512, new RsaUsingSha("SHA512") },
         { JwsAlgorithm.ES256, new EcdsaUsingSha(256) },
         { JwsAlgorithm.ES384, new EcdsaUsingSha(384) },
         { JwsAlgorithm.ES512, new EcdsaUsingSha(521) }
     };
     JWT.JwsAlgorithms[JwsAlgorithm.none]   = "none";
     JWT.JwsAlgorithms[JwsAlgorithm.HS256]  = "HS256";
     JWT.JwsAlgorithms[JwsAlgorithm.HS384]  = "HS384";
     JWT.JwsAlgorithms[JwsAlgorithm.HS512]  = "HS512";
     JWT.JwsAlgorithms[JwsAlgorithm.RS256]  = "RS256";
     JWT.JwsAlgorithms[JwsAlgorithm.RS384]  = "RS384";
     JWT.JwsAlgorithms[JwsAlgorithm.RS512]  = "RS512";
     JWT.JwsAlgorithms[JwsAlgorithm.ES256]  = "ES256";
     JWT.JwsAlgorithms[JwsAlgorithm.ES384]  = "ES384";
     JWT.JwsAlgorithms[JwsAlgorithm.ES512]  = "ES512";
     JWT.HashAlgorithms[JwsAlgorithm.PS256] = new RsaPssUsingSha(32);
     JWT.HashAlgorithms[JwsAlgorithm.PS384] = new RsaPssUsingSha(48);
     JWT.HashAlgorithms[JwsAlgorithm.PS512] = new RsaPssUsingSha(64);
     JWT.JwsAlgorithms[JwsAlgorithm.PS256]  = "PS256";
     JWT.JwsAlgorithms[JwsAlgorithm.PS384]  = "PS384";
     JWT.JwsAlgorithms[JwsAlgorithm.PS512]  = "PS512";
     JWT.EncAlgorithms = new Dictionary <JweEncryption, IJweAlgorithm>()
     {
         { JweEncryption.A128CBC_HS256, new AesCbcHmacEncryption(JWT.HashAlgorithms[JwsAlgorithm.HS256], 256) },
         { JweEncryption.A192CBC_HS384, new AesCbcHmacEncryption(JWT.HashAlgorithms[JwsAlgorithm.HS384], 384) },
         { JweEncryption.A256CBC_HS512, new AesCbcHmacEncryption(JWT.HashAlgorithms[JwsAlgorithm.HS512], 512) }
     };
     JWT.JweEncryptionMethods[JweEncryption.A128CBC_HS256] = "A128CBC-HS256";
     JWT.JweEncryptionMethods[JweEncryption.A192CBC_HS384] = "A192CBC-HS384";
     JWT.JweEncryptionMethods[JweEncryption.A256CBC_HS512] = "A256CBC-HS512";
     JWT.JweEncryptionMethodAliases["A128CBC+HS256"]       = JweEncryption.A128CBC_HS256;
     JWT.JweEncryptionMethodAliases["A192CBC+HS384"]       = JweEncryption.A192CBC_HS384;
     JWT.JweEncryptionMethodAliases["A256CBC+HS512"]       = JweEncryption.A256CBC_HS512;
     JWT.EncAlgorithms[JweEncryption.A128GCM]        = new AesGcmEncryption(128);
     JWT.EncAlgorithms[JweEncryption.A192GCM]        = new AesGcmEncryption(192);
     JWT.EncAlgorithms[JweEncryption.A256GCM]        = new AesGcmEncryption(256);
     JWT.JweEncryptionMethods[JweEncryption.A128GCM] = "A128GCM";
     JWT.JweEncryptionMethods[JweEncryption.A192GCM] = "A192GCM";
     JWT.JweEncryptionMethods[JweEncryption.A256GCM] = "A256GCM";
     JWT.KeyAlgorithms = new Dictionary <JweAlgorithm, IKeyManagement>()
     {
         { JweAlgorithm.RSA_OAEP, new RsaKeyManagement(true, false) },
         { JweAlgorithm.RSA_OAEP_256, new RsaKeyManagement(true, true) },
         { JweAlgorithm.RSA1_5, new RsaKeyManagement(false, false) },
         { JweAlgorithm.DIR, new DirectKeyManagement() },
         { JweAlgorithm.A128KW, new AesKeyWrapManagement(128) },
         { JweAlgorithm.A192KW, new AesKeyWrapManagement(192) },
         { JweAlgorithm.A256KW, new AesKeyWrapManagement(256) },
         { JweAlgorithm.ECDH_ES, new EcdhKeyManagement(true) },
         { JweAlgorithm.ECDH_ES_A128KW, new EcdhKeyManagementWithAesKeyWrap(128, new AesKeyWrapManagement(128)) },
         { JweAlgorithm.ECDH_ES_A192KW, new EcdhKeyManagementWithAesKeyWrap(192, new AesKeyWrapManagement(192)) },
         { JweAlgorithm.ECDH_ES_A256KW, new EcdhKeyManagementWithAesKeyWrap(256, new AesKeyWrapManagement(256)) },
         { JweAlgorithm.PBES2_HS256_A128KW, new Pbse2HmacShaKeyManagementWithAesKeyWrap(128, new AesKeyWrapManagement(128)) },
         { JweAlgorithm.PBES2_HS384_A192KW, new Pbse2HmacShaKeyManagementWithAesKeyWrap(192, new AesKeyWrapManagement(192)) },
         { JweAlgorithm.PBES2_HS512_A256KW, new Pbse2HmacShaKeyManagementWithAesKeyWrap(256, new AesKeyWrapManagement(256)) },
         { JweAlgorithm.A128GCMKW, new AesGcmKeyWrapManagement(128) },
         { JweAlgorithm.A192GCMKW, new AesGcmKeyWrapManagement(192) },
         { JweAlgorithm.A256GCMKW, new AesGcmKeyWrapManagement(256) }
     };
     JWT.JweAlgorithms[JweAlgorithm.RSA1_5]             = "RSA1_5";
     JWT.JweAlgorithms[JweAlgorithm.RSA_OAEP]           = "RSA-OAEP";
     JWT.JweAlgorithms[JweAlgorithm.RSA_OAEP_256]       = "RSA-OAEP-256";
     JWT.JweAlgorithms[JweAlgorithm.DIR]                = "dir";
     JWT.JweAlgorithms[JweAlgorithm.A128KW]             = "A128KW";
     JWT.JweAlgorithms[JweAlgorithm.A192KW]             = "A192KW";
     JWT.JweAlgorithms[JweAlgorithm.A256KW]             = "A256KW";
     JWT.JweAlgorithms[JweAlgorithm.ECDH_ES]            = "ECDH-ES";
     JWT.JweAlgorithms[JweAlgorithm.ECDH_ES_A128KW]     = "ECDH-ES+A128KW";
     JWT.JweAlgorithms[JweAlgorithm.ECDH_ES_A192KW]     = "ECDH-ES+A192KW";
     JWT.JweAlgorithms[JweAlgorithm.ECDH_ES_A256KW]     = "ECDH-ES+A256KW";
     JWT.JweAlgorithms[JweAlgorithm.PBES2_HS256_A128KW] = "PBES2-HS256+A128KW";
     JWT.JweAlgorithms[JweAlgorithm.PBES2_HS384_A192KW] = "PBES2-HS384+A192KW";
     JWT.JweAlgorithms[JweAlgorithm.PBES2_HS512_A256KW] = "PBES2-HS512+A256KW";
     JWT.JweAlgorithms[JweAlgorithm.A128GCMKW]          = "A128GCMKW";
     JWT.JweAlgorithms[JweAlgorithm.A192GCMKW]          = "A192GCMKW";
     JWT.JweAlgorithms[JweAlgorithm.A256GCMKW]          = "A256GCMKW";
     JWT.CompressionAlgorithms = new Dictionary <JweCompression, ICompression>()
     {
         { JweCompression.DEF, new DeflateCompression() }
     };
     JWT.JweCompressionMethods[JweCompression.DEF] = "DEF";
 }
Exemple #29
0
 public StormglassioParametersFiller(IRequestURLFiller requestFiller, IJsonMapper <StormglassDataHolder> jsonMapper)
 {
     RequestURLFiller = requestFiller;
     JsonMapper       = jsonMapper;
 }
Exemple #30
0
 internal override void ToJson(
     IJsonContext context, IJsonWriter writer, IJsonMapper <JsonElement> elMapper)
 {
     writer.WriteRaw(_value);
 }
        /// <summary>
        /// Serialize token according to serialization mode
        /// </summary>
        public string AsString(IJsonMapper mapper = null)
        {
            if (Encoding == SerializationMode.Compact)
            {
                return(Compact.Serialize(ProtectedHeaderBytes, Recipients[0].EncryptedCek, Iv, Ciphertext, AuthTag));
            }

            var json = new Dictionary <string, object>()
            {
                { "ciphertext", Base64Url.Encode(Ciphertext) },
                { "protected", Base64Url.Encode(ProtectedHeaderBytes) },
                { "iv", Base64Url.Encode(Iv) },
                { "tag", Base64Url.Encode(AuthTag) }
            };

            if (Aad != null)
            {
                json["aad"] = Base64Url.Encode(Aad);
            }

            if (UnprotectedHeader != null)
            {
                json["unprotected"] = UnprotectedHeader;
            }


            var recipientList = new List <object>();

            foreach (var recipient in Recipients)
            {
                recipientList.Add(
                    new Dictionary <string, object> {
                    //{ "header", recipient.Header },
                    { "encrypted_key", Base64Url.Encode(recipient.EncryptedCek) }
                }
                    );
            }

            json["recipients"] = recipientList;


            #region commecnted actual code and added same patch as per modification response
            //if (Recipients.Count == 1)
            //{
            //    json["header"] = Recipients[0].Header;
            //    json["encrypted_key"] = Base64Url.Encode(Recipients[0].EncryptedCek);
            //}
            //else
            //{
            //    var recipientList = new List<object>();


            //    foreach (var recipient in Recipients)
            //    {
            //        recipientList.Add(
            //            new Dictionary<string, object> {
            //                //{ "header", recipient.Header },
            //                { "encrypted_key", Base64Url.Encode(recipient.EncryptedCek) }
            //            }
            //        );
            //    }

            //    json["recipients"] = recipientList;
            //}
            #endregion
            return(mapper.Serialize(json));
        }