2014-02-14 23:21:05 +00:00
|
|
|
// Copyright 2014 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
|
|
|
#ifndef MEDIA_BASE_REQUEST_SIGNER_H_
|
|
|
|
#define MEDIA_BASE_REQUEST_SIGNER_H_
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/base/memory/scoped_ptr.h"
|
2014-01-14 04:52:05 +00:00
|
|
|
|
2014-09-19 20:41:13 +00:00
|
|
|
namespace edash_packager {
|
2014-01-14 04:52:05 +00:00
|
|
|
namespace media {
|
|
|
|
|
2014-09-09 22:56:02 +00:00
|
|
|
class AesCbcPkcs5Encryptor;
|
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
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Create an AesSigner object from key and iv in hex.
|
|
|
|
/// @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,
|
|
|
|
const std::string& aes_key_hex,
|
|
|
|
const std::string& iv_hex);
|
|
|
|
|
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,
|
2014-09-09 22:56:02 +00:00
|
|
|
scoped_ptr<AesCbcPkcs5Encryptor> encryptor);
|
2014-01-14 04:52:05 +00:00
|
|
|
|
2014-09-09 22:56:02 +00:00
|
|
|
scoped_ptr<AesCbcPkcs5Encryptor> 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,
|
|
|
|
scoped_ptr<RsaPrivateKey> rsa_private_key);
|
|
|
|
|
|
|
|
scoped_ptr<RsaPrivateKey> rsa_private_key_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(RsaRequestSigner);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace media
|
2014-09-19 20:41:13 +00:00
|
|
|
} // namespace edash_packager
|
2014-01-14 04:52:05 +00:00
|
|
|
|
|
|
|
#endif // MEDIA_BASE_REQUEST_SIGNER_H_
|