private void GetDeviceTimeInfo(object sender, RoutedEventArgs e) { if (SiteHardwareList.Items != null && SiteHardwareList.Items.Count > 0) { string hid = null; for (int i = 0; i < SiteHardwareList.Items.Count; i++) { TextBlock hwText = SiteHardwareList.Items[i] as TextBlock; if (hwText != null) { hid = hwText.Text; } if (string.IsNullOrEmpty(hid)) { CheckBox hwCheck = SiteHardwareList.Items[i] as CheckBox; if (hwCheck != null) { if (hwCheck.IsChecked == true) { HardwareComplete hc = hwCheck.Tag as HardwareComplete; if (hc != null) { hid = hc.HardwareID.ToString(); } else { hid = hwCheck.Content as string; } } } } } if (string.IsNullOrEmpty(hid)) { AddMessage("*** hardware not specified"); return; } TimestampResult result = api.GetTimestamp(login.SessionID, hid); if ((AEResultCodes)result.Code == AEResultCodes.OK) { AddMessage("*** TimestampResult OK"); AddMessage(string.Format("*** TimestampResult ({0}), ServerUTC : {1}", hid, result.ServerUTC.ToString())); AddMessage(string.Format("*** LastData: {0}", result.LastData.ToString())); AddMessage(string.Format("*** LastUpdate: {0}", result.LastUpdate.ToString())); } else { AddMessage(string.Format("*** TimestampResult ({0}) returned {1}", hid, result.ResultCodeString())); } } }
private TimestampResult GetTimestamp(byte[] contentToTimeStamp, string fileName) { if (string.IsNullOrWhiteSpace(fileName)) { fileName = DefaultFileName; } var credentials = new UserCredentials(this._authorityCert); TimestampResult result = Utils.RequestTimeStamp(_authorityServiceUrl, contentToTimeStamp, fileName, HashAlg, true, credentials, AppendLog, true); return(result); }
internal static TimestampResult RequestTimeStamp(string tsaService, string fileName, string hashAlg, bool certReq, UserCredentials credentials, LogDelegate logger, bool logExceptions) { string policy = ""; byte[] nonceBytes = GenerateNonceBytes(); string nonce = BytesToHexString(nonceBytes); TimestampResult result = InitializeResult(nonceBytes); result.FileName = fileName; TimeStampToken token = RequestTimeStamp(tsaService, fileName, GetHashAlgorithm(hashAlg), policy, nonce, certReq, credentials, logger, logExceptions, result); result.TimeStampResponse = token; return(result); }
private static TimeStampToken RequestTST(byte[] contentToTimestamp, string tsaService, Oid hashAlg, string policy, string nonce, bool certReq, UserCredentials credentials, TimestampResult result) { byte[] nonceBytes = null; byte[] hashedMessage = DigestUtils.ComputeDigest(contentToTimestamp, hashAlg); if (!string.IsNullOrEmpty(nonce)) { nonceBytes = HexStringToBytes(nonce); } var request = new Request(hashedMessage, hashAlg, nonceBytes, policy, certReq); result.TimeStampRequest = request; result.Tsq = request.ToByteArray(); return(TimeStampClient.RequestTimeStampToken(tsaService, request, credentials)); }
private static TimeStampToken RequestTimeStamp(string tsaAddress, byte[] contentToTimestamp, Oid hashAlg, string requestedPolicy, string nonce, bool certReq, UserCredentials credentials, LogDelegate logger, bool logExceptions, TimestampResult result) { try { if (logger == null) { return(null); } logger(string.Format("=== {0:" + DateTimeFormat + "} =============================================", DateTime.UtcNow)); logger($"Requesting time stamp from {tsaAddress}"); TimeStampToken token = RequestTST(contentToTimestamp, tsaAddress, hashAlg, requestedPolicy, nonce, certReq, credentials, result); if (null == token) { var msg = "Empty response token"; logger(msg); throw new Exception(msg); } result.Tsr = token.ToByteArray(); logger("Time stamp successfully received:"); var timeStampSerNum = BytesToHexString(token.SerialNumber); logger($" Serial number: {timeStampSerNum}"); result.SerialNumber = timeStampSerNum; var localTime = (token.Time).ToLocalTime(); result.TimeUTC = token.Time; result.TimeLocal = localTime; logger($" UTCTime: {token.Time:dd MMM yyyy HH':'mm':'ss}"); logger($" Time: {localTime:dd MMM yyyy HH':'mm':'ss}"); logger("TSA certificate:"); var issuerName = token.TsaInformation?.TsaCertIssuerName?.Name ?? ""; result.TSAName = issuerName; logger($" Issuer: {issuerName}"); logger($" Serial: {BytesToHexString(token.TsaInformation?.TsaCertSerialNumber ?? new byte[0])}"); if (null != token.TsaInformation?.TsaCert) { logger($" Subject: {token.TsaInformation.TsaCert.Subject}"); logger($" Valid from: {token.TsaInformation.TsaCert.NotBefore}"); logger($" Valid to: {token.TsaInformation.TsaCert.NotAfter}"); } if (null != token.PolicyOid) { result.Policy = token.PolicyOid; } return(token); } catch (Exception e) { logger("Error occurred:"); logger(logExceptions ? e.ToString() : e.Message); throw; } }