/// <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) { CikTokenDetails cikTokenDetails = new CikTokenDetails(); DateTime currentDateTime = DateTime.Now; currentDateTime = currentDateTime.AddHours(-1); cikTokenDetails.NotBeforeTimestamp = TimeZoneInfo.ConvertTimeToUtc(currentDateTime); cikTokenDetails.NotAfterTimestamp = cikTokenDetails.NotBeforeTimestamp.AddHours(6); cikTokenDetails.ClientRequestId = clientRequestId; cikTokenDetails.Version = new Version(1, 2); cikTokenDetails.PropertyBag = new Dictionary <string, object>(); string shaInput = new JavaScriptSerializer().Serialize(cikTokenDetails); if (null == asrVaultCreds.ChannelIntegrityKey) { throw new ArgumentException(Properties.Resources.MissingChannelIntergrityKey); } HMACSHA256 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)); }
/// <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) { CikTokenDetails cikTokenDetails = new CikTokenDetails(); DateTime currentDateTime = DateTime.Now; currentDateTime = currentDateTime.AddHours(-1); cikTokenDetails.NotBeforeTimestamp = TimeZoneInfo.ConvertTimeToUtc(currentDateTime); cikTokenDetails.NotAfterTimestamp = cikTokenDetails.NotBeforeTimestamp.AddHours(6); cikTokenDetails.ClientRequestId = clientRequestId; cikTokenDetails.Version = new Version(1, 2); cikTokenDetails.PropertyBag = new Dictionary<string, object>(); string shaInput = new JavaScriptSerializer().Serialize(cikTokenDetails); if (null == asrVaultCreds.ChannelIntegrityKey) { throw new ArgumentException(Properties.Resources.MissingChannelIntergrityKey); } HMACSHA256 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); }