2019-06-22 14:29:10 +00:00
|
|
|
use endian_trait::Endian;
|
|
|
|
|
2019-06-22 07:12:25 +00:00
|
|
|
// WARNING: PLEASE DO NOT MODIFY THOSE MAGIC VALUES
|
|
|
|
|
2019-11-10 10:34:55 +00:00
|
|
|
// openssl::sha::sha256(b"Proxmox Backup Catalog file v1.0")[0..8]
|
|
|
|
pub const PROXMOX_CATALOG_FILE_MAGIC_1_0: [u8; 8] = [145, 253, 96, 249, 196, 103, 88, 213];
|
|
|
|
|
2019-06-22 07:12:25 +00:00
|
|
|
// openssl::sha::sha256(b"Proxmox Backup uncompressed blob v1.0")[0..8]
|
2019-08-12 09:20:21 +00:00
|
|
|
pub const UNCOMPRESSED_BLOB_MAGIC_1_0: [u8; 8] = [66, 171, 56, 7, 190, 131, 112, 161];
|
2019-06-22 07:12:25 +00:00
|
|
|
|
|
|
|
//openssl::sha::sha256(b"Proxmox Backup zstd compressed blob v1.0")[0..8]
|
2019-08-12 09:20:21 +00:00
|
|
|
pub const COMPRESSED_BLOB_MAGIC_1_0: [u8; 8] = [49, 185, 88, 66, 111, 182, 163, 127];
|
2019-06-22 07:12:25 +00:00
|
|
|
|
|
|
|
// openssl::sha::sha256(b"Proxmox Backup encrypted blob v1.0")[0..8]
|
2019-08-12 09:20:21 +00:00
|
|
|
pub const ENCRYPTED_BLOB_MAGIC_1_0: [u8; 8] = [123, 103, 133, 190, 34, 45, 76, 240];
|
2019-06-22 07:12:25 +00:00
|
|
|
|
|
|
|
// openssl::sha::sha256(b"Proxmox Backup zstd compressed encrypted blob v1.0")[0..8]
|
2019-08-12 09:20:21 +00:00
|
|
|
pub const ENCR_COMPR_BLOB_MAGIC_1_0: [u8; 8] = [230, 89, 27, 191, 11, 191, 216, 11];
|
2019-06-22 07:12:25 +00:00
|
|
|
|
2019-08-02 07:56:01 +00:00
|
|
|
//openssl::sha::sha256(b"Proxmox Backup authenticated blob v1.0")[0..8]
|
2019-08-12 09:20:21 +00:00
|
|
|
pub const AUTHENTICATED_BLOB_MAGIC_1_0: [u8; 8] = [31, 135, 238, 226, 145, 206, 5, 2];
|
2019-08-02 07:56:01 +00:00
|
|
|
|
|
|
|
//openssl::sha::sha256(b"Proxmox Backup zstd compressed authenticated blob v1.0")[0..8]
|
2019-08-12 09:20:21 +00:00
|
|
|
pub const AUTH_COMPR_BLOB_MAGIC_1_0: [u8; 8] = [126, 166, 15, 190, 145, 31, 169, 96];
|
2019-08-02 07:56:01 +00:00
|
|
|
|
2019-06-22 07:12:25 +00:00
|
|
|
// openssl::sha::sha256(b"Proxmox Backup fixed sized chunk index v1.0")[0..8]
|
2019-08-12 09:20:21 +00:00
|
|
|
pub const FIXED_SIZED_CHUNK_INDEX_1_0: [u8; 8] = [47, 127, 65, 237, 145, 253, 15, 205];
|
2019-06-22 07:12:25 +00:00
|
|
|
|
|
|
|
// openssl::sha::sha256(b"Proxmox Backup dynamic sized chunk index v1.0")[0..8]
|
2019-08-12 09:20:21 +00:00
|
|
|
pub const DYNAMIC_SIZED_CHUNK_INDEX_1_0: [u8; 8] = [28, 145, 78, 165, 25, 186, 179, 205];
|
2019-06-22 07:12:25 +00:00
|
|
|
|
2019-06-22 13:45:36 +00:00
|
|
|
/// Data blob binary storage format
|
|
|
|
///
|
|
|
|
/// The format start with a 8 byte magic number to identify the type,
|
|
|
|
/// followed by a 4 byte CRC. This CRC is used on the server side to
|
|
|
|
/// detect file corruption (computed when upload data), so there is
|
|
|
|
/// usually no need to compute it on the client side.
|
|
|
|
///
|
|
|
|
/// Unencrypted blobs simply contain the CRC, followed by the
|
|
|
|
/// (compressed) data.
|
|
|
|
///
|
|
|
|
/// (MAGIC || CRC32 || Data)
|
|
|
|
///
|
|
|
|
/// This is basically the same format we use for chunks, but
|
|
|
|
/// with other magic numbers so that we can distinguish them.
|
2019-06-22 14:29:10 +00:00
|
|
|
#[derive(Endian)]
|
2019-06-22 07:12:25 +00:00
|
|
|
#[repr(C,packed)]
|
|
|
|
pub struct DataBlobHeader {
|
|
|
|
pub magic: [u8; 8],
|
|
|
|
pub crc: [u8; 4],
|
|
|
|
}
|
|
|
|
|
2019-08-02 07:56:01 +00:00
|
|
|
/// Authenticated data blob binary storage format
|
|
|
|
///
|
|
|
|
/// The ``DataBlobHeader`` for authenticated blobs additionally contains
|
|
|
|
/// a 16 byte HMAC tag, followed by the data:
|
|
|
|
///
|
|
|
|
/// (MAGIC || CRC32 || TAG || Data).
|
|
|
|
#[derive(Endian)]
|
|
|
|
#[repr(C,packed)]
|
|
|
|
pub struct AuthenticatedDataBlobHeader {
|
|
|
|
pub head: DataBlobHeader,
|
|
|
|
pub tag: [u8; 32],
|
|
|
|
}
|
|
|
|
|
2019-06-22 13:45:36 +00:00
|
|
|
/// Encrypted data blob binary storage format
|
|
|
|
///
|
|
|
|
/// The ``DataBlobHeader`` for encrypted blobs additionally contains
|
|
|
|
/// a 16 byte IV, followed by a 16 byte Authenticated Encyrypten (AE)
|
|
|
|
/// tag, followed by the encrypted data:
|
|
|
|
///
|
|
|
|
/// (MAGIC || CRC32 || IV || TAG || EncryptedData).
|
2019-06-22 14:29:10 +00:00
|
|
|
#[derive(Endian)]
|
2019-06-22 07:12:25 +00:00
|
|
|
#[repr(C,packed)]
|
|
|
|
pub struct EncryptedDataBlobHeader {
|
|
|
|
pub head: DataBlobHeader,
|
|
|
|
pub iv: [u8; 16],
|
|
|
|
pub tag: [u8; 16],
|
|
|
|
}
|
|
|
|
|
2019-08-14 10:35:53 +00:00
|
|
|
/// Header size for different file types
|
|
|
|
///
|
|
|
|
/// Panics on unknown magic numbers.
|
|
|
|
pub fn header_size(magic: &[u8; 8]) -> usize {
|
|
|
|
match magic {
|
|
|
|
&UNCOMPRESSED_BLOB_MAGIC_1_0 => std::mem::size_of::<DataBlobHeader>(),
|
|
|
|
&COMPRESSED_BLOB_MAGIC_1_0 => std::mem::size_of::<DataBlobHeader>(),
|
|
|
|
&ENCRYPTED_BLOB_MAGIC_1_0 => std::mem::size_of::<EncryptedDataBlobHeader>(),
|
|
|
|
&ENCR_COMPR_BLOB_MAGIC_1_0 => std::mem::size_of::<EncryptedDataBlobHeader>(),
|
|
|
|
&AUTHENTICATED_BLOB_MAGIC_1_0 => std::mem::size_of::<AuthenticatedDataBlobHeader>(),
|
|
|
|
&AUTH_COMPR_BLOB_MAGIC_1_0 => std::mem::size_of::<AuthenticatedDataBlobHeader>(),
|
|
|
|
_ => panic!("unknown blob magic"),
|
|
|
|
}
|
|
|
|
}
|