コード例 #1
0
        public static Token GetTokenFromResponse(GetSharedSecretResponse response)
        {
            var unixTime = UnixTimestampHelper.ConvertToUnixTimeStamp(DateTime.UtcNow);

            var token = new Token()
            {
                TimeSkew       = unixTime - long.Parse(response.UTCTimestamp),
                Salt           = Base64Helper.Base64DecodeBytes(response.SecretContainer.EncryptionMethod.PBESalt),
                IterationCount = int.Parse(response.SecretContainer.EncryptionMethod.PBEIterationCount),
                Iv             = Base64Helper.Base64DecodeBytes(response.SecretContainer.EncryptionMethod.IV),
                Id             = response.SecretContainer.Device.Secret.Id,
                Cipher         = Base64Helper.Base64DecodeBytes(response.SecretContainer.Device.Secret.Data.Cipher),
                Digest         = Base64Helper.Base64DecodeBytes(response.SecretContainer.Device.Secret.Data.Digest.Text),
                Expiry         = response.SecretContainer.Device.Secret.Expiry,
                Period         = int.Parse(response.SecretContainer.Device.Secret.Usage.TimeStep),
                Counter        = int.Parse(response.SecretContainer.Device.Secret.Usage.Counter ?? "0")
            };

            var alg         = response.SecretContainer.Device.Secret.Usage.AI.Type;
            var algSplitted = alg.Split('-');

            if (algSplitted.Length == 4 && algSplitted[0] == "HMAC" && algSplitted[2] == "TRUNC" && algSplitted[3].EndsWith("DIGITS"))
            {
                token.Algorithm = algSplitted[1].ToLowerInvariant();
                token.Digits    = int.Parse(algSplitted[3].Substring(0, algSplitted[3].Length - 6));
            }
            else
            {
                throw new InvalidOperationException($"Unknown algorithm: {alg}");
            }

            return(token);
        }
コード例 #2
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (reader.TokenType != JsonToken.Integer)
            {
                throw new Exception("Wrong Token Type");
            }

            long ticks = (long)reader.Value;

            // Steam returns date/times as the number of seconds since 1/1/1970 (aka, unix timestamp).
            return(UnixTimestampHelper.FromUnixTimestamp(ticks));
        }
コード例 #3
0
        public SymantecRequest(Random random, DateTime utcTime)
        {
            timestamp = UnixTimestampHelper.ConvertToUnixTimeStamp(utcTime);
            var default_model = $"MacBookPro{random.Next(1, 12)},{random.Next(1, 4)}";

            model     = default_model;
            serial    = RandomHelper.GenerateRandomStringOfLength(random, CharacterHelper.AllDigits + CharacterHelper.AllUpperCase, 12);
            client_id = $"Mac-{RandomHelper.GenerateRandomStringOfLength(random, CharacterHelper.HexCharacters, 16)}";
            os        = default_model;

            var data_before_hmac      = $"{timestamp}{timestamp}{client_id_type}{client_id}{dist_channel}";
            var data_before_hmac_utf8 = StringHelper.ToUtf8(data_before_hmac);

            var digesthmac = HMACHelper.HashHMACSHA256(HMAC_KEY, data_before_hmac_utf8);
            var base64hmac = Convert.ToBase64String(digesthmac);

            data = base64hmac;
        }
コード例 #4
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            DateTime dt = (DateTime)value;

            writer.WriteValue(UnixTimestampHelper.ToUnixTimestamp(dt));
        }