/// <summary> /// Accepts a DownloadHeader or DownloadFile request with custom metadata. /// </summary> /// <param name="e">The related request with many important information.</param> /// <param name="path">Local path where the file currently exists or will be stored.</param> /// <param name="meta">Only for file sending! The metadata to send especially for E2E server applications.</param> public async Task <bool> AcceptAsync(FTEventArgs e, string path, FileMeta meta) { e.Path = path; e.Assign(parent, this); e.FileMeta = meta; currentItem = e; if (!await parent.Manager.SendPacketAsync(new P06Accepted(true, 7, ProblemCategory.None))) // accept the transfer { return(false); } if (currentItem.Mode == StreamMode.PushHeader || currentItem.Mode == StreamMode.PushFile) // start by sending the FileMeta { if (currentItem.FileMeta == null) { currentItem.FileMeta = await FileMeta.FromFileAsync(path, ContentAlgorithm.None); } if (!await parent.Manager.SendPacketAsync(new P08FileHeader(currentItem.FileMeta.GetBinaryData(parent.ConnectionVersion.Value)))) { return(false); } } else if (meta != null) { throw new ArgumentException("You must not supply a FileMeta for a receive operation.", nameof(meta)); } return(true); }
/// <summary> /// Initalizes a new instance of the <see cref="FTEventArgs"/> that can be used to send the associated file. /// </summary> /// <param name="identifier">A universal identifier to specify the file to process.</param> /// <param name="meta">Meta data of the file and required cryptographic keys.</param> /// <param name="path">The path where file currently exists or will be stored.</param> public FTEventArgs(Identifier identifier, FileMeta meta, string path) : this() { Identifier = identifier; FileMeta = meta; Path = path; }
/// <summary> /// Initializes a new instance of the <see cref="FileMeta"/> class and generates missing keys. /// </summary> /// <param name="path">The local file path to load the meta data from.</param> /// <param name="algorithm">The cryptographic algorith to encrypt this <see cref="FileMeta"/>.</param> /// <param name="hmacKey">256 bit HMAC key to verify integrity of this <see cref="FileMeta"/>.</param> /// <param name="aesKey">256 bit AES key to encrypt this <see cref="FileMeta"/>.</param> /// <param name="fileKey">256 bit AES key to encrypt the associated file.</param> /// <exception cref="ArgumentException"/> /// <exception cref="ArgumentNullException"/> /// <exception cref="ArgumentOutOfRangeException"/> /// <exception cref="FileNotFoundException"/> public static async Task <FileMeta> FromFileAsync(string path, ContentAlgorithm algorithm, byte[] hmacKey, byte[] aesKey, byte[] fileKey) { if (string.IsNullOrWhiteSpace(path)) { throw new ArgumentNullException(nameof(path)); } if (algorithm != ContentAlgorithm.None && algorithm != ContentAlgorithm.Aes256CbcHmacSha256) { throw new ArgumentException("This content algorithm is not supported.", nameof(algorithm)); } FileMeta instance = new FileMeta(algorithm, hmacKey, aesKey, fileKey); await instance.LoadFromFileAsync(path); instance.Available = true; return(instance); }