nstool/lib/libes/include/es/ETicketBody_V2.h

172 lines
4.1 KiB
C
Raw Normal View History

2017-07-22 08:59:06 +00:00
#pragma once
#include <string>
#include <fnd/MemoryBlob.h>
2017-07-22 08:59:06 +00:00
#include <fnd/ISerialiseableBinary.h>
#include <crypto/rsa.h>
namespace es
{
class ETicketBody_V2 :
public fnd::ISerialiseableBinary
{
public:
enum TitleKeyEncType
{
AES128_CBC,
RSA2048
};
enum LicenseType
{
ES_LICENSE_PERMANENT = 0,
ES_LICENSE_DEMO = 1,
ES_LICENSE_TRIAL = 2,
ES_LICENSE_RENTAL = 3,
ES_LICENSE_SUBSCRIPTION = 4,
ES_LICENSE_SERVICE = 5,
};
ETicketBody_V2();
ETicketBody_V2(const ETicketBody_V2& other);
2018-03-22 05:26:22 +00:00
ETicketBody_V2(const byte_t* bytes, size_t len);
2017-07-22 08:59:06 +00:00
bool operator==(const ETicketBody_V2& other) const;
bool operator!=(const ETicketBody_V2& other) const;
void operator=(const ETicketBody_V2& other);
// to be used after export
2018-03-22 05:26:22 +00:00
const byte_t* getBytes() const;
2017-07-22 08:59:06 +00:00
size_t getSize() const;
// export/import binary
virtual void exportBinary();
2018-03-22 05:26:22 +00:00
virtual void importBinary(const byte_t* bytes, size_t len);
2017-07-22 08:59:06 +00:00
// variables
virtual void clear();
const std::string& getIssuer() const;
void setIssuer(const std::string& issuer);
2018-03-22 05:26:22 +00:00
const byte_t* getEncTitleKey() const;
void setEncTitleKey(const byte_t* data, size_t len);
2017-07-22 08:59:06 +00:00
TitleKeyEncType getTitleKeyEncType() const;
void setTitleKeyEncType(TitleKeyEncType type);
2018-03-22 05:26:22 +00:00
uint16_t getTicketVersion() const;
void setTicketVersion(uint16_t version);
2017-07-22 08:59:06 +00:00
LicenseType getLicenseType() const;
void setLicenseType(LicenseType type);
2018-03-22 05:26:22 +00:00
byte_t getCommonKeyId() const;
void setCommonKeyId(byte_t id);
2017-07-22 08:59:06 +00:00
bool isPreInstall() const;
void setIsPreInstall(bool isPreInstall);
bool isSharedTitle() const;
void setIsSharedTitle(bool isSharedTitle);
bool allowAllContent() const;
void setAllowAllContent(bool allowAllContent);
2018-03-22 05:26:22 +00:00
const byte_t* getReservedRegion() const;
void setReservedRegion(const byte_t* data, size_t len);
2017-07-22 08:59:06 +00:00
2018-03-22 05:26:22 +00:00
uint64_t getTicketId() const;
void setTicketId(uint64_t id);
2017-07-22 08:59:06 +00:00
2018-03-22 05:26:22 +00:00
uint64_t getDeviceId() const;
void setDeviceId(uint64_t id);
2017-07-22 08:59:06 +00:00
2018-03-22 05:26:22 +00:00
const byte_t* getRightsId() const;
void setRightsId(const byte_t* id);
2017-07-22 08:59:06 +00:00
2018-03-22 05:26:22 +00:00
uint32_t getAccountId() const;
void setAccountId(uint32_t id);
2017-07-22 08:59:06 +00:00
2018-03-22 05:26:22 +00:00
uint32_t getSectionTotalSize() const;
void setSectionTotalSize(uint32_t size);
2017-07-22 08:59:06 +00:00
2018-03-22 05:26:22 +00:00
uint32_t getSectionHeaderOffset() const;
void setSectionHeaderOffset(uint32_t offset);
2017-07-22 08:59:06 +00:00
2018-03-22 05:26:22 +00:00
uint16_t getSectionNum() const;
void setSectionNum(uint16_t num);
2017-07-22 08:59:06 +00:00
2018-03-22 05:26:22 +00:00
uint16_t getSectionEntrySize() const;
void setSectionEntrySize(uint16_t size);
2017-07-22 08:59:06 +00:00
private:
const std::string kModuleName = "ES_ETICKET_BODY_V2";
static const size_t kIssuerLen = 0x40;
2018-03-22 05:26:22 +00:00
static const byte_t kFormatVersion = 2;
2017-07-22 08:59:06 +00:00
static const size_t kEncTitleKeyLen = crypto::rsa::kRsa2048Size;
static const size_t kReservedRegionLen = 8;
static const size_t kRightsIdLen = 16;
enum PropertyMaskFlags
{
FLAG_PRE_INSTALL,
FLAG_SHARED_TITLE,
FLAG_ALLOW_ALL_CONTENT
};
#pragma pack (push, 1)
struct sTicketBody_v2
{
char issuer[kIssuerLen];
byte_t enc_title_key[kEncTitleKeyLen];
byte_t format_version;
byte_t title_key_enc_type;
le_uint16_t ticket_version;
byte_t license_type;
byte_t common_key_id;
byte_t property_mask;
byte_t reserved_0;
byte_t reserved_region[kReservedRegionLen]; // explicitly reserved
le_uint64_t ticket_id;
le_uint64_t device_id;
byte_t rights_id[kRightsIdLen];
le_uint32_t account_id;
le_uint32_t sect_total_size;
le_uint32_t sect_header_offset;
le_uint16_t sect_num;
le_uint16_t sect_entry_size;
2017-07-22 08:59:06 +00:00
};
#pragma pack (pop)
// raw binary
fnd::MemoryBlob mBinaryBlob;
// variables
std::string mIssuer;
2018-03-22 05:26:22 +00:00
byte_t mEncTitleKey[kEncTitleKeyLen];
2017-07-22 08:59:06 +00:00
TitleKeyEncType mEncType; // 0 = aes-cbc, 1 = rsa2048
2018-03-22 05:26:22 +00:00
uint16_t mTicketVersion;
2017-07-22 08:59:06 +00:00
LicenseType mLicenseType;
2018-03-22 05:26:22 +00:00
byte_t mCommonKeyId;
2017-07-22 08:59:06 +00:00
bool mPreInstall;
bool mSharedTitle;
bool mAllowAllContent;
2018-03-22 05:26:22 +00:00
byte_t mReservedRegion[kReservedRegionLen]; // explicitly reserved
uint64_t mTicketId;
uint64_t mDeviceId;
byte_t mRightsId[kRightsIdLen];
uint32_t mAccountId;
uint32_t mSectTotalSize;
uint32_t mSectHeaderOffset;
uint16_t mSectNum;
uint16_t mSectEntrySize;
2017-07-22 08:59:06 +00:00
// helpers
bool isEqual(const ETicketBody_V2& other) const;
void copyFrom(const ETicketBody_V2& other);
};
}