When carrying a signature in the Header, the signature algorithm depends on the transfer method used when uploading the object. In object storage TOS, file upload transfer methods mainly include single-part upload and multipart upload, suitable for different file transfer scenarios.
Single-part upload refers to the method of transferring all valid data in a single part.
When using the TOS V4 basic signature for single-part uploads, two signature calculation methods are supported: signature with checksum and signature without checksum. The details are as follows:
- Using signature with checksum
- You can include the checksum of valid data in the V4 basic signature calculation. If the content or checksum changes during data transfer, the signature verification will fail, ensuring security during the data transfer process.
- However, to obtain the checksum of the valid data in advance, the client usually needs to load all data into memory first to calculate the checksum. Then, it must perform signature calculation based on the checksum. When sending data, the client reads the data into memory a second time for transmission, which may reduce client performance.
- To ensure data integrity while avoiding loading all data into memory for checksum calculation at once, it is recommended to use multipart upload.
- Use signature without checksum
- When calculating the TOS V4 base signature, the checksum of valid data is not included. This method cannot guarantee data integrity in non-HTTPS scenarios and is not recommended.
Multipart upload refers to splitting valid data into multiple fixed or variable length parts, then uploading them separately.
The data structure of a single part is as follows:
- IntHexBase(): a function that converts integers to hexadecimal numbers. For example, if the part size is 65536, the hexadecimal string is 10000.
- ChunkSize: the size of the valid data chunk (excluding signatures and format data). For example, when uploading a 65KB object with a fixed chunk size of 64KB, the data is split into three chunks: the first chunk is 64KB, the second chunk is 1KB, and the last chunk is 0 bytes.
- Signature: the signature data of the chunk, required only when using chained signatures.
- ChunkData: valid data of the chunk.
After the last chunk of valid data, a chunk containing 0 bytes must be written to indicate the end. The basic multi-chunk data format is as follows:
When signing multi-chunk uploads, TOS supports the following signature calculation methods:
- Including only the TOS V4 basic signature
- Similar to single-chunk uploads, when calculating the signature for multi-chunk uploads, it is possible to choose whether to include a checksum in the signature. If the checksum is included in the signature, the client still needs to read all data at once to calculate the checksum, causing additional performance overhead.
- Includes TOS V4 basic signature plus chained signature
- The TOS V4 basic signature does not carry checksum information, but each chunk of data begins with the chunk's signature information, which includes request parameters, the checksum of the current chunk's valid data, and the previous chunk's signature information. By calculating while transmitting, it effectively avoids performance degradation caused by the client reading all data at once to calculate the checksum. It also suits scenarios where the client cannot pre-calculate the checksum for all data due to unknown content length but must ensure data transmission security.
Multipart upload also supports using Trailing Header, which carries a checksum of all valid data after the last chunk, enabling data integrity verification on the server side. Trailing Header and chained signature are two different methods that both effectively ensure security during transmission. Users are advised to choose at least one or use both when uploading.
When using multipart upload, specify x-tos-content-sha256 to indicate the upload format and the signature method used.
tip
Multipart upload can be used together with Transfer-Encoding: chunked. If Transfer-Encoding: chunked is used, the Content-Length header is not required.
Multipart upload request example
- Without using chained signature and Trailing Header
- Using chained signature without Trailing Header
- Use trailing header without chain signature
- Use both chain signature and trailing header