예제 #1
0
        /// <summary>
        ///     Site Recovery requests that go to on-premise components (like the Provider installed
        ///     in VMM) require an authentication token that is signed with the vault key to indicate
        ///     that the request indeed originated from the end-user client.
        ///     Generating that authentication token here and sending it via http headers.
        /// </summary>
        /// <param name="clientRequestId">Unique identifier for the client's request</param>
        /// <returns>The authentication token for the provider</returns>
        public string GenerateAgentAuthenticationHeader(
            string clientRequestId)
        {
            var cikTokenDetails = new CikTokenDetails();

            var currentDateTime = DateTime.Now;

            currentDateTime = currentDateTime.AddHours(-1);
            cikTokenDetails.NotBeforeTimestamp = TimeZoneInfo.ConvertTimeToUtc(currentDateTime);
            cikTokenDetails.NotAfterTimestamp  = cikTokenDetails.NotBeforeTimestamp.AddDays(7);
            cikTokenDetails.ClientRequestId    = clientRequestId;
            cikTokenDetails.Version            = new Version(
                1,
                2);
            cikTokenDetails.PropertyBag = new Dictionary <string, object>();

            var shaInput = new JavaScriptSerializer().Serialize(cikTokenDetails);

            if (null == asrVaultCreds.ChannelIntegrityKey)
            {
                throw new ArgumentException(Resources.MissingChannelIntergrityKey);
            }

            var sha = new HMACSHA256(Encoding.UTF8.GetBytes(asrVaultCreds.ChannelIntegrityKey));

            cikTokenDetails.Hmac =
                Convert.ToBase64String(sha.ComputeHash(Encoding.UTF8.GetBytes(shaInput)));
            cikTokenDetails.HashFunction = CikSupportedHashFunctions.HMACSHA256.ToString();

            return(new JavaScriptSerializer().Serialize(cikTokenDetails));
        }
예제 #2
0
        /// <summary>
        ///     Site Recovery requests that go to on-premise components (like the Provider installed
        ///     in VMM) require an authentication token that is signed with the vault key to indicate
        ///     that the request indeed originated from the end-user client.
        ///     Generating that authentication token here and sending it via http headers.
        /// </summary>
        /// <param name="clientRequestId">Unique identifier for the client's request</param>
        /// <param name="dateTime">Optional , datetime used for header genertion</param>
        /// <returns>The authentication token for the provider</returns>
        public static string GenerateAgentAuthenticationHeader(
            string clientRequestId,
            DateTime?dateTime = null)
        {
            var cikTokenDetails = new CikTokenDetails();

            var currentDateTime = dateTime == null ? DateTime.Now : dateTime.Value;

            currentDateTime = currentDateTime.AddHours(-1);
            cikTokenDetails.NotBeforeTimestamp = TimeZoneInfo.ConvertTimeToUtc(currentDateTime);
            cikTokenDetails.NotAfterTimestamp  = cikTokenDetails.NotBeforeTimestamp.AddDays(7);
            cikTokenDetails.ClientRequestId    = clientRequestId;
            cikTokenDetails.Version            = new Version(
                1,
                2);
            cikTokenDetails.PropertyBag = new Dictionary <string, object>();

            JsonSerializerSettings microsoftDateFormatSettings = new JsonSerializerSettings
            {
                DateFormatHandling = DateFormatHandling.MicrosoftDateFormat
            };

            var shaInput = JsonConvert.SerializeObject(cikTokenDetails, microsoftDateFormatSettings);

            if (null == asrVaultCreds.ChannelIntegrityKey)
            {
                throw new ArgumentException(Resources.MissingChannelIntergrityKey);
            }

            var sha = new HMACSHA256(Encoding.UTF8.GetBytes(asrVaultCreds.ChannelIntegrityKey));

            cikTokenDetails.Hmac =
                Convert.ToBase64String(sha.ComputeHash(Encoding.UTF8.GetBytes(shaInput)));
            cikTokenDetails.HashFunction = CikSupportedHashFunctions.HMACSHA256.ToString();

            return(JsonConvert.SerializeObject(cikTokenDetails, microsoftDateFormatSettings));
        }