143 lines
6.2 KiB
C
143 lines
6.2 KiB
C
/* Copyright 2020 Google LLC. All Rights Reserved. This file and proprietary
|
|
source code may only be used and distributed under the Widevine Master
|
|
License Agreement. */
|
|
|
|
#ifndef OEMCRYPTO_TA_OEMCRYPTO_USAGE_TABLE_H_
|
|
#define OEMCRYPTO_TA_OEMCRYPTO_USAGE_TABLE_H_
|
|
|
|
#include "stdbool.h"
|
|
#include "stdint.h"
|
|
|
|
#include "OEMCryptoCENC.h"
|
|
#include "oemcrypto_config_macros.h"
|
|
#include "oemcrypto_key_types.h"
|
|
#include "oemcrypto_session.h"
|
|
|
|
/**
|
|
* Clear out memory for the usage table. No other usage table functions may be
|
|
* called before this. */
|
|
OEMCryptoResult InitializeUsageTable(void);
|
|
|
|
/**
|
|
* Erase data from usage table. No other usage table functions may be called
|
|
* without calling InitializeUsageTable. */
|
|
OEMCryptoResult TerminateUsageTable(void);
|
|
|
|
/** Create a new empty usage table header. */
|
|
OEMCryptoResult CreateUsageTableHeader(uint8_t* header_buffer,
|
|
size_t* header_buffer_length);
|
|
|
|
/** Load a usage table header. */
|
|
OEMCryptoResult LoadUsageTableHeader(const uint8_t* buffer,
|
|
size_t buffer_length);
|
|
|
|
/**
|
|
* Create a new usage table entry and attach it to the |session|. This may
|
|
* return an error if the usage table is full, or if too many open sessions have
|
|
* active usage entries. |session| must be open and not already have an entry
|
|
* associated with it.
|
|
* Pointers must be non-null and are owned by the caller. */
|
|
OEMCryptoResult CreateNewUsageEntry(OEMCryptoSession* session,
|
|
uint32_t* usage_entry_number);
|
|
|
|
/**
|
|
* Load a usage table entry and attach it to the |session|. This may return an
|
|
* error if too many open sessions have active usage entries. |session| must be
|
|
* open and not already have an entry associated with it. The usage_entry_number
|
|
* must match that in the loaded entry.
|
|
* Pointers must be non-null and are owned by the caller. */
|
|
OEMCryptoResult LoadUsageEntry(OEMCryptoSession* session,
|
|
uint32_t usage_entry_number,
|
|
const uint8_t* buffer, size_t buffer_length);
|
|
|
|
/**
|
|
* Release the active usage entry associated with |session|.
|
|
* Pointers must be non-null and are owned by the caller. */
|
|
OEMCryptoResult ReleaseEntry(OEMCryptoSession* session,
|
|
uint32_t usage_entry_number);
|
|
|
|
/**
|
|
* Update all values in the usage entry associated with |session|. After
|
|
* updating values, the generation numbers are all updated and the master
|
|
* generation number is saved to persistent storage. Then the entry and the
|
|
* usage table header are saved to the specified buffer. If the buffer lengths
|
|
* are not large enough, none of the work above is completed -- instead the
|
|
* lengths are updated and OEMCrypto_ERROR_SHORT_BUFFER is returned.
|
|
* Pointers must be non-null and are owned by the caller. */
|
|
OEMCryptoResult UpdateUsageEntry(OEMCryptoSession* session,
|
|
uint8_t* header_buffer,
|
|
size_t* header_buffer_length,
|
|
uint8_t* entry_buffer,
|
|
size_t* entry_buffer_length);
|
|
|
|
/**
|
|
* Update the playback times in the usage entry attached to |session|.
|
|
* Pointers must be non-null and are owned by the caller. */
|
|
OEMCryptoResult UpdateLastPlaybackTime(const OEMCryptoSession* session);
|
|
|
|
/**
|
|
* Set the provider session token in the usage entry associated with |session|.
|
|
* This is done when a license is first loaded.
|
|
* Pointers must be non-null and are owned by the caller. */
|
|
OEMCryptoResult SetUsageEntryPST(OEMCryptoSession* session, const uint8_t* pst,
|
|
size_t pst_length);
|
|
|
|
/**
|
|
* Verify the provider session token in the usage entry associated with
|
|
* |session|. This is done when a license is reloaded to verify the license
|
|
* matches the usage entry.
|
|
* Pointers must be non-null and are owned by the caller. */
|
|
OEMCryptoResult VerfiyUsageEntryPST(OEMCryptoSession* session,
|
|
const uint8_t* pst, size_t pst_length);
|
|
|
|
/**
|
|
* Set the mac keys in the usage entry associated with |session|.
|
|
* This is done when a license is first loaded.
|
|
* Pointers must be non-null and are owned by the caller. */
|
|
OEMCryptoResult SetUsageEntryMacKeys(const OEMCryptoSession* session);
|
|
|
|
/**
|
|
* Verify the mac keys in the usage entry associated with
|
|
* |session|. This is done when a license is reloaded to verify the license
|
|
* matches the usage entry.
|
|
* Pointers must be non-null and are owned by the caller. */
|
|
OEMCryptoResult VerifysageEntryMacKeys(const OEMCryptoSession* session);
|
|
|
|
/**
|
|
* Mark the usage entry associated with |session| as deactivated. After this,
|
|
* the license may not be used to decrypt content.
|
|
* Pointers must be non-null and are owned by the caller. */
|
|
OEMCryptoResult DeactivateUsageEntry(OEMCryptoSession* session,
|
|
const uint8_t* pst, size_t pst_length);
|
|
|
|
/**
|
|
* Generate a usage report from the entry associated with |session|.
|
|
* Pointers must be non-null and are owned by the caller. */
|
|
OEMCryptoResult ReportUsage(OEMCryptoSession* session, const uint8_t* pst,
|
|
size_t pst_length, uint8_t* buffer,
|
|
size_t* buffer_length);
|
|
|
|
/**
|
|
* Sign |buffer| with the client mac key in the entry associated with |session|.
|
|
* Pointers must be non-null and are owned by the caller. */
|
|
OEMCryptoResult SignReleaseRequest(OEMCryptoSession* session,
|
|
const uint8_t* message,
|
|
size_t message_length, uint8_t* signature,
|
|
size_t* signature_length);
|
|
|
|
/**
|
|
* Move the usage entry associated with |session| to the new index in the usage
|
|
* table header. The generation numbers are updated as specified in the
|
|
* OEMCrypto spec.
|
|
* Pointers must be non-null and are owned by the caller. */
|
|
OEMCryptoResult MoveEntry(OEMCryptoSession* session, uint32_t new_index);
|
|
|
|
/**
|
|
* Shrink the usage table to the size specified.
|
|
* Pointers must be non-null and are owned by the caller. */
|
|
OEMCryptoResult ShrinkUsageTableHeader(uint32_t new_entry_count,
|
|
uint8_t* header_buffer,
|
|
size_t* header_buffer_length);
|
|
|
|
#endif /* OEMCRYPTO_TA_OEMCRYPTO_USAGE_TABLE_H_ */
|