public void LergacyUseDeprecatedHmacAlgoTest() { KsiService service = GetService(PduVersion.v1, HashAlgorithm.Sha2256, HashAlgorithm.Sha1); HashingException ex = Assert.Throws <HashingException>(delegate { service.Extend(1510056000L); }); Assert.That(ex.Message.StartsWith("Hash algorithm SHA1 is deprecated since 2016-07-01 and can not be used for HMAC"), "Unexpected inner exception message: " + ex.Message); }
/// <summary> /// Get extended calendar hash chain from given publication time. /// </summary> /// <param name="publicationTime">publication time</param> /// <returns>extended calendar hash chain</returns> public CalendarHashChain GetExtendedCalendarHashChain(ulong?publicationTime) { if (KsiService == null) { throw new KsiVerificationException("Invalid KSI service in context: null."); } if (Signature == null) { throw new KsiVerificationException("Invalid KSI signature in context: null."); } ulong cacheKey = publicationTime ?? 0; lock (_cacheLock) { if (_calendarHashChainCache == null) { _calendarHashChainCache = new Dictionary <ulong, CalendarHashChain>(); } else if (_calendarHashChainCache.ContainsKey(cacheKey)) { // when getting latest calendar hash chain and last extend is more than 1 sec ago then do not take from cache // otherwise take from cache if (publicationTime != null || _latestCalendarGetTime + 10000000 > DateTime.Now.Ticks) { return(_calendarHashChainCache[cacheKey]); } _calendarHashChainCache.Remove(cacheKey); } } CalendarHashChain calendarHashChain = publicationTime == null ? KsiService.Extend(Signature.AggregationTime) : KsiService.Extend(Signature.AggregationTime, publicationTime.Value); lock (_cacheLock) { _calendarHashChainCache[cacheKey] = calendarHashChain; if (publicationTime == null) { _latestCalendarGetTime = DateTime.Now.Ticks; } } return(calendarHashChain); }
public void ExtendInvalidPduFormatTest() { KsiService service = GetHttpKsiService(PduVersion.v2); try { service.Extend(1455494400); } // if new aggregator then no exception catch (Exception ex) { Assert.That(ex.Message.StartsWith("Received PDU v1 response to PDU v2 request. Configure the SDK to use PDU v1 format for the given Extender"), "Unexpected exception message: " + ex.Message); } }