2022-08-26 15:44:59 +00:00
|
|
|
// Copyright 2014 Google LLC. All rights reserved.
|
2014-02-14 23:21:05 +00:00
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
2014-01-14 04:52:05 +00:00
|
|
|
|
2017-12-20 00:56:36 +00:00
|
|
|
#ifndef PACKAGER_MEDIA_BASE_REQUEST_SIGNER_H_
|
|
|
|
#define PACKAGER_MEDIA_BASE_REQUEST_SIGNER_H_
|
2014-01-14 04:52:05 +00:00
|
|
|
|
2016-08-17 17:41:40 +00:00
|
|
|
#include <memory>
|
2014-01-14 04:52:05 +00:00
|
|
|
#include <string>
|
2017-06-14 23:18:16 +00:00
|
|
|
#include <vector>
|
2014-01-14 04:52:05 +00:00
|
|
|
|
2022-11-04 22:46:41 +00:00
|
|
|
#include "packager/macros.h"
|
2014-01-14 04:52:05 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2014-01-14 04:52:05 +00:00
|
|
|
namespace media {
|
|
|
|
|
2016-03-25 18:02:43 +00:00
|
|
|
class AesCbcEncryptor;
|
2014-01-14 04:52:05 +00:00
|
|
|
class RsaPrivateKey;
|
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Abstract class used for signature generation.
|
2014-01-14 04:52:05 +00:00
|
|
|
class RequestSigner {
|
|
|
|
public:
|
|
|
|
virtual ~RequestSigner();
|
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Generate signature for the input message.
|
|
|
|
/// @param signature should not be NULL.
|
|
|
|
/// @return true on success, false otherwise.
|
2014-01-14 04:52:05 +00:00
|
|
|
virtual bool GenerateSignature(const std::string& message,
|
|
|
|
std::string* signature) = 0;
|
|
|
|
|
|
|
|
const std::string& signer_name() const { return signer_name_; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
explicit RequestSigner(const std::string& signer_name);
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string signer_name_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(RequestSigner);
|
|
|
|
};
|
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// AesRequestSigner uses AES-CBC signing.
|
2014-01-14 04:52:05 +00:00
|
|
|
class AesRequestSigner : public RequestSigner {
|
|
|
|
public:
|
2015-07-22 23:40:45 +00:00
|
|
|
~AesRequestSigner() override;
|
2014-01-14 04:52:05 +00:00
|
|
|
|
2017-06-14 23:18:16 +00:00
|
|
|
/// Create an AesSigner object from key and iv.
|
2014-01-24 18:46:46 +00:00
|
|
|
/// @return The created AesRequestSigner object on success, NULL otherwise.
|
2014-01-14 04:52:05 +00:00
|
|
|
static AesRequestSigner* CreateSigner(const std::string& signer_name,
|
2017-06-14 23:18:16 +00:00
|
|
|
const std::vector<uint8_t>& aes_key,
|
|
|
|
const std::vector<uint8_t>& iv);
|
2014-01-14 04:52:05 +00:00
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// RequestSigner implementation override.
|
2015-07-22 23:40:45 +00:00
|
|
|
bool GenerateSignature(const std::string& message,
|
|
|
|
std::string* signature) override;
|
2014-01-14 04:52:05 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
AesRequestSigner(const std::string& signer_name,
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<AesCbcEncryptor> encryptor);
|
2014-01-14 04:52:05 +00:00
|
|
|
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<AesCbcEncryptor> aes_cbc_encryptor_;
|
2014-01-14 04:52:05 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(AesRequestSigner);
|
|
|
|
};
|
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// RsaRequestSigner uses RSA-PSS signing.
|
2014-01-14 04:52:05 +00:00
|
|
|
class RsaRequestSigner : public RequestSigner {
|
|
|
|
public:
|
2015-07-22 23:40:45 +00:00
|
|
|
~RsaRequestSigner() override;
|
2014-01-14 04:52:05 +00:00
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Create an RsaSigner object using a DER encoded PKCS#1 RSAPrivateKey.
|
|
|
|
/// @return The created RsaRequestSigner object on success, NULL otherwise.
|
2014-01-14 04:52:05 +00:00
|
|
|
static RsaRequestSigner* CreateSigner(const std::string& signer_name,
|
|
|
|
const std::string& pkcs1_rsa_key);
|
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// RequestSigner implementation override.
|
2015-07-22 23:40:45 +00:00
|
|
|
bool GenerateSignature(const std::string& message,
|
|
|
|
std::string* signature) override;
|
2014-01-14 04:52:05 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
RsaRequestSigner(const std::string& signer_name,
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<RsaPrivateKey> rsa_private_key);
|
2014-01-14 04:52:05 +00:00
|
|
|
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<RsaPrivateKey> rsa_private_key_;
|
2014-01-14 04:52:05 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(RsaRequestSigner);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace media
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|
2014-01-14 04:52:05 +00:00
|
|
|
|
2017-12-20 00:56:36 +00:00
|
|
|
#endif // PACKAGER_MEDIA_BASE_REQUEST_SIGNER_H_
|