//////////////////////////////////////////////////////////////////////////////// // Copyright 2016 Google LLC. // // This software is licensed under the terms defined in the Widevine Master // License Agreement. For a copy of this agreement, please contact // widevine-licensing@google.com. //////////////////////////////////////////////////////////////////////////////// #include "provisioning_sdk/internal/provisioning_session_impl.h" #include #include "glog/logging.h" #include "common/rsa_key.h" DEFINE_int32(prov_sdk_log_every_n, 1, "parameter for LOG_EVERY_N to help abate log spamming."); namespace widevine { ProvisioningSessionImpl::ProvisioningSessionImpl( const ProvisioningEngineImpl& engine) : engine_(engine), rsa_key_factory_(new RsaKeyFactory) {} ProvisioningSessionImpl::~ProvisioningSessionImpl() {} ProvisioningStatus ProvisioningSessionImpl::Initialize( const std::string& device_drm_public_key, const std::string& device_drm_private_key) { auto rsa_public_key = rsa_key_factory_->CreateFromPkcs1PublicKey(device_drm_public_key); if (!rsa_public_key) return INVALID_DRM_DEVICE_PUBLIC_KEY; // Use empty std::string to indicate the private key is not encrypted. const std::string kClearPkcs8PrivateKeyPassphrase; auto rsa_private_key = rsa_key_factory_->CreateFromPkcs8PrivateKey( device_drm_private_key, kClearPkcs8PrivateKeyPassphrase); if (!rsa_private_key) return INVALID_DRM_DEVICE_PRIVATE_KEY; if (!rsa_public_key->MatchesPrivateKey(*rsa_private_key)) { LOG(WARNING) << "Device public key and private key do not match."; return INVALID_DRM_DEVICE_PRIVATE_KEY; } device_drm_public_key_ = device_drm_public_key; device_drm_private_key_ = device_drm_private_key; return OK; } ProvisioningStatus ProvisioningSessionImpl::Initialize( const std::string& keybox_device_key) { if (keybox_device_key.empty()) { LOG(WARNING) << "Keybox device key is empty."; return INVALID_KEYBOX_DEVICE_KEY; } keybox_device_key_ = keybox_device_key; return OK; } const ProvisionedDeviceInfo* ProvisioningSessionImpl::GetDeviceInfo() const { LOG(FATAL) << "Not implemented."; } } // namespace widevine