private async Task <DownloadVersion> CheckWebForNewVersionAsync(Uri updateWebpageUrl, string cultureName) { Version newVersion = DownloadVersion.VersionUnknown; try { ClientPlatformKind platform = ClientPlatformKind.WindowsDesktop; switch (OS.Current.Platform) { case Runtime.Platform.WindowsDesktop: platform = ClientPlatformKind.WindowsDesktop; break; case Runtime.Platform.MacOsx: platform = ClientPlatformKind.Mac; break; default: throw new NotSupportedException($"App doesn't support updating on {OS.Current.Platform} platform"); } AxCryptVersion axCryptVersion = await New <AxCryptApiClient>().AxCryptUpdateAsync(_currentVersion, cultureName, platform).Free(); if (!axCryptVersion.IsEmpty) { if (Resolve.Log.IsInfoEnabled) { Resolve.Log.LogInfo("Update check reports most recent version {0} at web page {1}".InvariantFormat(newVersion, updateWebpageUrl)); } } return(axCryptVersion.DownloadVersion); } catch (ApiException aex) { await aex.HandleApiExceptionAsync(); } catch (Exception ex) { New <IReport>().Exception(ex); if (Resolve.Log.IsWarningEnabled) { Resolve.Log.LogWarning("Failed call to check for new version with exception {0}.".InvariantFormat(ex)); } } return(new DownloadVersion(updateWebpageUrl, DownloadVersion.VersionUnknown)); }
public async Task <AxCryptVersion> AxCryptUpdateAsync(Version currentVersion, string cultureName, ClientPlatformKind platform) { string platformParameter = string.Empty; switch (platform) { case ClientPlatformKind.WindowsDesktop: platformParameter = "windowsdesktop"; break; case ClientPlatformKind.Mac: platformParameter = "mac"; break; default: throw new NotSupportedException($"App doesn't support updating on {platform} platform"); } Uri resource; if (Identity.IsEmpty) { resource = BaseUrl.PathCombine($"global/axcrypt/version/{platformParameter}?version={currentVersion?.ToString() ?? string.Empty}"); } else { resource = BaseUrl.PathCombine($"users/axcrypt/version/{platformParameter}?version={currentVersion?.ToString() ?? string.Empty}&culture={cultureName}"); } if (New <AxCryptOnlineState>().IsOffline) { return(AxCryptVersion.Empty); } RestResponse restResponse = await Caller.RestAsync(Identity, new RestRequest(resource, Timeout)).Free(); ApiCaller.EnsureStatusOk(restResponse); AxCryptVersion axCryptVersion = Serializer.Deserialize <AxCryptVersion>(restResponse.Content); return(axCryptVersion); }
private bool VerifyInternalUnsafe() { if (!_inputStream.Locate(_axCrypt1GuidBytes)) { return(FailWithStatusReport("Not an AxCrypt file, No magic Guid was found.")); } _statusReport.Add($"{nameof(AxCryptItemType.MagicGuid)} Ok with length {0}".InvariantFormat(AxCrypt1Guid.Length)); AxCryptVersion version = AxCryptVersion.Unknown; ulong encryptedDataLength = 0; int dataBlocks = 0; while (true) { byte[] lengthBytes = new byte[sizeof(Int32)]; if (_inputStream.Read(lengthBytes, 0, lengthBytes.Length) != lengthBytes.Length) { return(FailWithStatusReport("End of stream reading header block length.")); } int headerBlockLength = BitConverter.ToInt32(lengthBytes, 0) - 5; int blockType = _inputStream.ReadByte(); if (blockType > 127 || blockType < 0) { return(FailWithStatusReport($"Unexpected header block type {blockType}")); } if (headerBlockLength < 0) { return(FailWithStatusReport($"Invalid block length {headerBlockLength}.")); } byte[] dataBlock = new byte[headerBlockLength]; if (_inputStream.Read(dataBlock, 0, headerBlockLength) != dataBlock.Length) { return(FailWithStatusReport($"End of stream reading block type {blockType}")); } HeaderBlockType headerBlockType = (HeaderBlockType)blockType; if (headerBlockType == HeaderBlockType.Data && version == AxCryptVersion.Version1) { return(ProcessVersion1DataBlock(dataBlock)); } if (headerBlockType != HeaderBlockType.EncryptedDataPart && dataBlocks > 0) { _statusReport.Add($"{HeaderBlockType.EncryptedDataPart} Ok with {dataBlocks} blocks and the total length {encryptedDataLength}."); dataBlocks = 0; encryptedDataLength = 0; } switch (headerBlockType) { case HeaderBlockType.Version: VersionHeaderBlock versionHeaderBlock = new VersionHeaderBlock(dataBlock); _statusReport.Add($"AxCrypt version {versionHeaderBlock.VersionMajor}.{versionHeaderBlock.VersionMinor}.{versionHeaderBlock.VersionMinuscule}. File format version {versionHeaderBlock.FileVersionMajor}.{versionHeaderBlock.FileVersionMinor}."); version = versionHeaderBlock.VersionMajor >= 2 ? AxCryptVersion.Version2 : AxCryptVersion.Version1; break; case HeaderBlockType.EncryptedDataPart: switch (version) { case AxCryptVersion.Version2: ++dataBlocks; encryptedDataLength += (uint)dataBlock.Length; break; case AxCryptVersion.Unknown: default: return(FailWithStatusReport($"{blockType} found but no {HeaderBlockType.Version} seen.")); } break; default: _statusReport.Add($"{headerBlockType} Ok with length {headerBlockLength}"); break; } if (headerBlockType == HeaderBlockType.V2Hmac) { return(ShowStatusReport()); } } }
public void TestAxCryptVersionIsEmpty() { AxCryptVersion version = new AxCryptVersion(String.Empty, VersionUpdateKind.Empty); Assert.That(version.IsEmpty, Is.True, nameof(AxCryptVersion.IsEmpty)); }