2017-08-05 13:09:50 +00:00
|
|
|
#include <es/ETicketBody_V2.h>
|
2017-07-22 08:59:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
es::ETicketBody_V2::ETicketBody_V2()
|
|
|
|
{
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
es::ETicketBody_V2::ETicketBody_V2(const ETicketBody_V2 & other)
|
|
|
|
{
|
|
|
|
copyFrom(other);
|
|
|
|
}
|
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
es::ETicketBody_V2::ETicketBody_V2(const byte_t * bytes, size_t len)
|
2017-07-22 08:59:06 +00:00
|
|
|
{
|
|
|
|
importBinary(bytes, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool es::ETicketBody_V2::operator==(const ETicketBody_V2 & other) const
|
|
|
|
{
|
|
|
|
return isEqual(other);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool es::ETicketBody_V2::operator!=(const ETicketBody_V2 & other) const
|
|
|
|
{
|
|
|
|
return !isEqual(other);
|
|
|
|
}
|
|
|
|
|
|
|
|
void es::ETicketBody_V2::operator=(const ETicketBody_V2 & other)
|
|
|
|
{
|
|
|
|
copyFrom(other);
|
|
|
|
}
|
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
const byte_t * es::ETicketBody_V2::getBytes() const
|
2017-07-22 08:59:06 +00:00
|
|
|
{
|
|
|
|
return mBinaryBlob.getBytes();
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t es::ETicketBody_V2::getSize() const
|
|
|
|
{
|
|
|
|
return mBinaryBlob.getSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool es::ETicketBody_V2::isEqual(const ETicketBody_V2 & other) const
|
|
|
|
{
|
|
|
|
return (mIssuer == other.mIssuer) \
|
|
|
|
&& (memcmp(mEncTitleKey, other.mEncTitleKey, kEncTitleKeyLen) == 0) \
|
|
|
|
&& (mEncType == other.mEncType) \
|
|
|
|
&& (mTicketVersion == other.mTicketVersion) \
|
|
|
|
&& (mLicenseType == other.mLicenseType) \
|
|
|
|
&& (mPreInstall == other.mPreInstall) \
|
|
|
|
&& (mSharedTitle == other.mSharedTitle) \
|
|
|
|
&& (mAllowAllContent == other.mAllowAllContent) \
|
|
|
|
&& (memcmp(mReservedRegion, other.mReservedRegion, kReservedRegionLen) == 0) \
|
|
|
|
&& (mTicketId == other.mTicketId) \
|
|
|
|
&& (mDeviceId == other.mDeviceId) \
|
|
|
|
&& (memcmp(mRightsId, other.mRightsId, kRightsIdLen) == 0) \
|
|
|
|
&& (mAccountId == other.mAccountId) \
|
|
|
|
&& (mSectTotalSize == other.mSectTotalSize) \
|
|
|
|
&& (mSectHeaderOffset == other.mSectHeaderOffset) \
|
|
|
|
&& (mSectNum == other.mSectNum) \
|
|
|
|
&& (mSectEntrySize == other.mSectEntrySize);
|
|
|
|
}
|
|
|
|
|
|
|
|
void es::ETicketBody_V2::copyFrom(const ETicketBody_V2 & other)
|
|
|
|
{
|
|
|
|
if (other.getSize())
|
|
|
|
{
|
|
|
|
importBinary(other.getBytes(), other.getSize());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
clear();
|
|
|
|
mIssuer = other.mIssuer;
|
|
|
|
memcpy(mEncTitleKey, other.mEncTitleKey, kEncTitleKeyLen);
|
|
|
|
mEncType = other.mEncType;
|
|
|
|
mTicketVersion = other.mTicketVersion;
|
|
|
|
mLicenseType = other.mLicenseType;
|
|
|
|
mPreInstall = other.mPreInstall;
|
|
|
|
mSharedTitle = other.mSharedTitle;
|
|
|
|
mAllowAllContent = other.mAllowAllContent;
|
|
|
|
memcpy(mReservedRegion, other.mReservedRegion, kReservedRegionLen);
|
|
|
|
mTicketId = other.mTicketId;
|
|
|
|
mDeviceId = other.mDeviceId;
|
|
|
|
memcpy(mRightsId, other.mRightsId, kRightsIdLen);
|
|
|
|
mAccountId = other.mAccountId;
|
|
|
|
mSectTotalSize = other.mSectTotalSize;
|
|
|
|
mSectHeaderOffset = other.mSectHeaderOffset;
|
|
|
|
mSectNum = other.mSectNum;
|
|
|
|
mSectEntrySize = other.mSectEntrySize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void es::ETicketBody_V2::exportBinary()
|
|
|
|
{
|
|
|
|
mBinaryBlob.alloc(sizeof(sTicketBody_v2));
|
|
|
|
sTicketBody_v2* body = (sTicketBody_v2*)mBinaryBlob.getBytes();
|
|
|
|
|
|
|
|
body->set_format_version(kFormatVersion);
|
|
|
|
|
|
|
|
body->set_issuer(mIssuer.c_str());
|
|
|
|
body->set_enc_title_key(mEncTitleKey, kEncTitleKeyLen);
|
|
|
|
body->set_title_key_enc_type(mEncType);
|
|
|
|
body->set_ticket_version(mTicketVersion);
|
2018-03-22 05:26:22 +00:00
|
|
|
byte_t property_mask = 0;
|
2017-07-22 08:59:06 +00:00
|
|
|
property_mask |= mPreInstall ? BIT(FLAG_PRE_INSTALL) : 0;
|
|
|
|
property_mask |= mSharedTitle ? BIT(FLAG_SHARED_TITLE) : 0;
|
|
|
|
property_mask |= mAllowAllContent ? BIT(FLAG_ALLOW_ALL_CONTENT) : 0;
|
|
|
|
body->set_property_mask(property_mask);
|
|
|
|
body->set_reserved_region(mReservedRegion, kReservedRegionLen);
|
|
|
|
body->set_ticket_id(mTicketId);
|
|
|
|
body->set_device_id(mDeviceId);
|
|
|
|
body->set_rights_id(mRightsId);
|
|
|
|
body->set_account_id(mAccountId);
|
|
|
|
body->set_sect_total_size(mSectTotalSize);
|
|
|
|
body->set_sect_header_offset(mSectHeaderOffset);
|
|
|
|
body->set_sect_num(mSectNum);
|
|
|
|
body->set_sect_entry_size(mSectEntrySize);
|
|
|
|
}
|
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
void es::ETicketBody_V2::importBinary(const byte_t * bytes, size_t len)
|
2017-07-22 08:59:06 +00:00
|
|
|
{
|
|
|
|
if (len < sizeof(sTicketBody_v2))
|
|
|
|
{
|
|
|
|
throw fnd::Exception(kModuleName, "Header size too small");
|
|
|
|
}
|
|
|
|
|
|
|
|
clear();
|
|
|
|
|
|
|
|
mBinaryBlob.alloc(sizeof(sTicketBody_v2));
|
|
|
|
memcpy(mBinaryBlob.getBytes(), bytes, mBinaryBlob.getSize());
|
|
|
|
sTicketBody_v2* body = (sTicketBody_v2*)mBinaryBlob.getBytes();
|
|
|
|
|
|
|
|
if (body->format_version() != kFormatVersion)
|
|
|
|
{
|
|
|
|
throw fnd::Exception(kModuleName, "Unsupported format version");
|
|
|
|
}
|
|
|
|
|
|
|
|
mIssuer.append(body->issuer(), kIssuerLen);
|
|
|
|
memcpy(mEncTitleKey, body->enc_title_key(), kEncTitleKeyLen);
|
|
|
|
mEncType = (TitleKeyEncType)body->title_key_enc_type();
|
|
|
|
mTicketVersion = body->ticket_version();
|
|
|
|
mLicenseType = (LicenseType)body->license_type();
|
|
|
|
mPreInstall = (body->property_mask() & BIT(FLAG_PRE_INSTALL)) == BIT(FLAG_PRE_INSTALL);
|
|
|
|
mSharedTitle = (body->property_mask() & BIT(FLAG_SHARED_TITLE)) == BIT(FLAG_SHARED_TITLE);
|
|
|
|
mAllowAllContent = (body->property_mask() & BIT(FLAG_ALLOW_ALL_CONTENT)) == BIT(FLAG_ALLOW_ALL_CONTENT);
|
|
|
|
memcpy(mReservedRegion, body->reserved_region(), kReservedRegionLen);
|
|
|
|
mTicketId = body->ticket_id();
|
|
|
|
mDeviceId = body->device_id();
|
|
|
|
memcpy(mRightsId, body->rights_id(), kRightsIdLen);
|
|
|
|
mAccountId = body->account_id();
|
|
|
|
mSectTotalSize = body->sect_total_size();
|
|
|
|
mSectHeaderOffset = body->sect_header_offset();
|
|
|
|
mSectNum = body->sect_num();
|
|
|
|
mSectEntrySize = body->sect_entry_size();
|
|
|
|
}
|
|
|
|
|
|
|
|
void es::ETicketBody_V2::clear()
|
|
|
|
{
|
|
|
|
mBinaryBlob.clear();
|
|
|
|
mIssuer.clear();
|
|
|
|
memset(mEncTitleKey, 0, kEncTitleKeyLen);
|
|
|
|
mEncType = AES128_CBC;
|
|
|
|
mTicketVersion = 0;
|
|
|
|
mLicenseType = ES_LICENSE_PERMANENT;
|
|
|
|
mPreInstall = false;
|
|
|
|
mSharedTitle = false;
|
|
|
|
mAllowAllContent = false;
|
|
|
|
memset(mReservedRegion, 0, kReservedRegionLen);
|
|
|
|
mTicketId = 0;
|
|
|
|
mDeviceId = 0;
|
|
|
|
memset(mRightsId, 0, kRightsIdLen);
|
|
|
|
mAccountId = 0;
|
|
|
|
mSectTotalSize = 0;
|
|
|
|
mSectHeaderOffset = 0;
|
|
|
|
mSectNum = 0;
|
|
|
|
mSectEntrySize = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string & es::ETicketBody_V2::getIssuer() const
|
|
|
|
{
|
|
|
|
return mIssuer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void es::ETicketBody_V2::setIssuer(const std::string & issuer)
|
|
|
|
{
|
|
|
|
if (issuer.length() > kIssuerLen)
|
|
|
|
{
|
|
|
|
throw fnd::Exception(kModuleName, "Issuer is too long");
|
|
|
|
}
|
|
|
|
|
|
|
|
mIssuer = issuer;
|
|
|
|
}
|
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
const byte_t * es::ETicketBody_V2::getEncTitleKey() const
|
2017-07-22 08:59:06 +00:00
|
|
|
{
|
|
|
|
return mEncTitleKey;
|
|
|
|
}
|
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
void es::ETicketBody_V2::setEncTitleKey(const byte_t * data, size_t len)
|
2017-07-22 08:59:06 +00:00
|
|
|
{
|
|
|
|
memset(mEncTitleKey, 0, kEncTitleKeyLen);
|
|
|
|
memcpy(mEncTitleKey, data, MIN(len, kEncTitleKeyLen));
|
|
|
|
}
|
|
|
|
|
|
|
|
es::ETicketBody_V2::TitleKeyEncType es::ETicketBody_V2::getTitleKeyEncType() const
|
|
|
|
{
|
|
|
|
return mEncType;
|
|
|
|
}
|
|
|
|
|
|
|
|
void es::ETicketBody_V2::setTitleKeyEncType(TitleKeyEncType type)
|
|
|
|
{
|
|
|
|
mEncType = type;
|
|
|
|
}
|
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
uint16_t es::ETicketBody_V2::getTicketVersion() const
|
2017-07-22 08:59:06 +00:00
|
|
|
{
|
|
|
|
return mTicketVersion;
|
|
|
|
}
|
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
void es::ETicketBody_V2::setTicketVersion(uint16_t version)
|
2017-07-22 08:59:06 +00:00
|
|
|
{
|
|
|
|
mTicketVersion = version;
|
|
|
|
}
|
|
|
|
|
|
|
|
es::ETicketBody_V2::LicenseType es::ETicketBody_V2::getLicenseType() const
|
|
|
|
{
|
|
|
|
return mLicenseType;
|
|
|
|
}
|
|
|
|
|
|
|
|
void es::ETicketBody_V2::setLicenseType(LicenseType type)
|
|
|
|
{
|
|
|
|
mLicenseType = type;
|
|
|
|
}
|
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
byte_t es::ETicketBody_V2::getCommonKeyId() const
|
2017-08-05 13:09:50 +00:00
|
|
|
{
|
|
|
|
return mCommonKeyId;
|
|
|
|
}
|
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
void es::ETicketBody_V2::setCommonKeyId(byte_t id)
|
2017-08-05 13:09:50 +00:00
|
|
|
{
|
|
|
|
mCommonKeyId = id;
|
|
|
|
}
|
|
|
|
|
2017-07-22 08:59:06 +00:00
|
|
|
bool es::ETicketBody_V2::isPreInstall() const
|
|
|
|
{
|
|
|
|
return mPreInstall;
|
|
|
|
}
|
|
|
|
|
|
|
|
void es::ETicketBody_V2::setIsPreInstall(bool isPreInstall)
|
|
|
|
{
|
|
|
|
mPreInstall = isPreInstall;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool es::ETicketBody_V2::isSharedTitle() const
|
|
|
|
{
|
|
|
|
return mSharedTitle;
|
|
|
|
}
|
|
|
|
|
|
|
|
void es::ETicketBody_V2::setIsSharedTitle(bool isSharedTitle)
|
|
|
|
{
|
|
|
|
mSharedTitle = isSharedTitle;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool es::ETicketBody_V2::allowAllContent() const
|
|
|
|
{
|
|
|
|
return mAllowAllContent;
|
|
|
|
}
|
|
|
|
|
|
|
|
void es::ETicketBody_V2::setAllowAllContent(bool allowAllContent)
|
|
|
|
{
|
|
|
|
mAllowAllContent = allowAllContent;
|
|
|
|
}
|
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
const byte_t * es::ETicketBody_V2::getReservedRegion() const
|
2017-07-22 08:59:06 +00:00
|
|
|
{
|
|
|
|
return mReservedRegion;
|
|
|
|
}
|
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
void es::ETicketBody_V2::setReservedRegion(const byte_t * data, size_t len)
|
2017-07-22 08:59:06 +00:00
|
|
|
{
|
|
|
|
memset(mReservedRegion, 0, kReservedRegionLen);
|
|
|
|
memcpy(mReservedRegion, data, MIN(len, kReservedRegionLen));
|
|
|
|
}
|
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
uint64_t es::ETicketBody_V2::getTicketId() const
|
2017-07-22 08:59:06 +00:00
|
|
|
{
|
|
|
|
return mTicketId;
|
|
|
|
}
|
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
void es::ETicketBody_V2::setTicketId(uint64_t id)
|
2017-07-22 08:59:06 +00:00
|
|
|
{
|
|
|
|
mTicketId = id;
|
|
|
|
}
|
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
uint64_t es::ETicketBody_V2::getDeviceId() const
|
2017-07-22 08:59:06 +00:00
|
|
|
{
|
|
|
|
return mDeviceId;
|
|
|
|
}
|
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
void es::ETicketBody_V2::setDeviceId(uint64_t id)
|
2017-07-22 08:59:06 +00:00
|
|
|
{
|
|
|
|
mDeviceId = id;
|
|
|
|
}
|
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
const byte_t * es::ETicketBody_V2::getRightsId() const
|
2017-07-22 08:59:06 +00:00
|
|
|
{
|
|
|
|
return mRightsId;
|
|
|
|
}
|
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
void es::ETicketBody_V2::setRightsId(const byte_t * id)
|
2017-07-22 08:59:06 +00:00
|
|
|
{
|
|
|
|
memcpy(mRightsId, id, kRightsIdLen);
|
|
|
|
}
|
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
uint32_t es::ETicketBody_V2::getAccountId() const
|
2017-07-22 08:59:06 +00:00
|
|
|
{
|
|
|
|
return mAccountId;
|
|
|
|
}
|
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
void es::ETicketBody_V2::setAccountId(uint32_t id)
|
2017-07-22 08:59:06 +00:00
|
|
|
{
|
|
|
|
mAccountId = id;
|
|
|
|
}
|
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
uint32_t es::ETicketBody_V2::getSectionTotalSize() const
|
2017-07-22 08:59:06 +00:00
|
|
|
{
|
|
|
|
return mSectTotalSize;
|
|
|
|
}
|
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
void es::ETicketBody_V2::setSectionTotalSize(uint32_t size)
|
2017-07-22 08:59:06 +00:00
|
|
|
{
|
|
|
|
mSectTotalSize = size;
|
|
|
|
}
|
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
uint32_t es::ETicketBody_V2::getSectionHeaderOffset() const
|
2017-07-22 08:59:06 +00:00
|
|
|
{
|
|
|
|
return mSectHeaderOffset;
|
|
|
|
}
|
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
void es::ETicketBody_V2::setSectionHeaderOffset(uint32_t offset)
|
2017-07-22 08:59:06 +00:00
|
|
|
{
|
|
|
|
mSectHeaderOffset = offset;
|
|
|
|
}
|
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
uint16_t es::ETicketBody_V2::getSectionNum() const
|
2017-07-22 08:59:06 +00:00
|
|
|
{
|
|
|
|
return mSectNum;
|
|
|
|
}
|
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
void es::ETicketBody_V2::setSectionNum(uint16_t num)
|
2017-07-22 08:59:06 +00:00
|
|
|
{
|
|
|
|
mSectNum = num;
|
|
|
|
}
|
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
uint16_t es::ETicketBody_V2::getSectionEntrySize() const
|
2017-07-22 08:59:06 +00:00
|
|
|
{
|
|
|
|
return mSectEntrySize;
|
|
|
|
}
|
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
void es::ETicketBody_V2::setSectionEntrySize(uint16_t size)
|
2017-07-22 08:59:06 +00:00
|
|
|
{
|
|
|
|
mSectEntrySize = size;
|
|
|
|
}
|