Example #1
0
        /// <summary>
        /// Attempts to generate the key and returns the result.
        /// </summary>
        /// <param name="client">The remote client.</param>
        /// <param name="channel">The full channel string.</param>
        /// <param name="message">The message to publish.</param>
        public static EmitterResponse Process(IClient client, EmitterChannel channel, KeyGenRequest request)
        {
            // Parse the channel
            EmitterChannel info;

            if (!EmitterChannel.TryParse(request.Channel, false, out info))
            {
                return(EmitterError.BadRequest);
            }

            // Should be a static (non-wildcard) channel string.
            if (info.Type != ChannelType.Static)
            {
                return(EmitterError.BadRequest);
            }

            // Attempt to parse the key, this should be a master key
            SecurityKey masterKey;

            if (!SecurityKey.TryParse(request.Key, out masterKey) || !masterKey.IsMaster || masterKey.IsExpired)
            {
                return(EmitterError.Unauthorized);
            }

            // Attempt to fetch the contract using the key. Underneath, it's cached.
            var contract = Services.Contract.GetByKey(masterKey.Contract) as EmitterContract;

            if (contract == null)
            {
                return(EmitterError.NotFound);
            }

            // Validate the contract
            if (!contract.Validate(ref masterKey))
            {
                return(EmitterError.Unauthorized);
            }

            // Generate the key
            var key = SecurityKey.Create();

            key.Master      = masterKey.Master;
            key.Contract    = contract.Oid;
            key.Signature   = contract.Signature;
            key.Permissions = request.Access;
            key.Target      = SecurityHash.GetHash(request.Channel);
            key.Expires     = request.Expires;

            return(new KeyGenResponse()
            {
                Key = key.Value,
                Channel = request.Channel
            });
        }
Example #2
0
        public ActionResult <IEnumerable <string> > Get(string key)
        {
            SecurityHash locker = new SecurityHash();
            string       salt   = locker.HashCreate();

            string encryptKey = locker.HashCreate(key, salt);

            string getEncryptKey = encryptKey.Split('æ')[0];
            string getSalt       = encryptKey.Split('æ')[1];
            string result        = locker.ValidateHash(key, getSalt, getEncryptKey).ToString();

            return(new string[] { encryptKey, result, salt });
        }