AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
ContentDecrypter.h
Go to the documentation of this file.
1 /*
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0/
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
16 #ifndef ALEXA_CLIENT_SDK_PLAYLISTPARSER_INCLUDE_PLAYLISTPARSER_CONTENTDECRYPTER_H_
17 #define ALEXA_CLIENT_SDK_PLAYLISTPARSER_INCLUDE_PLAYLISTPARSER_CONTENTDECRYPTER_H_
18 
19 #include <atomic>
20 #include <chrono>
21 #include <memory>
22 #include <string>
23 #include <vector>
24 
27 
30 
31 namespace alexaClientSDK {
32 namespace playlistParser {
33 
35 typedef std::vector<unsigned char> ByteVector;
36 
41 public:
47 
54  void setMediaInitToDecryptedContent(const ByteVector& mediaInitSection, std::chrono::milliseconds totalDuration);
55 
66  bool decryptAndWrite(
67  const ByteVector& encryptedContent,
68  const ByteVector& key,
70  const std::shared_ptr<avsCommon::avs::attachment::AttachmentWriter>& streamWriter,
71  const std::shared_ptr<Id3TagsRemover>& id3TagRemover);
72 
80  static bool convertIVToByteArray(const std::string& hexIV, ByteVector* ivByteArray);
81 
84  void doShutdown() override;
86 
87 private:
93  ByteVector prependMediaInitSection(const ByteVector& bytes) const;
94 
105  int decryptAES(
106  const ByteVector& encryptedContent,
107  const ByteVector& key,
108  const ByteVector& iv,
109  ByteVector* decryptedContent,
110  bool usePadding = true);
111 
121  bool decryptSampleAES(
122  const ByteVector& encryptedContent,
123  const ByteVector& key,
124  const ByteVector& iv,
125  const std::shared_ptr<avsCommon::avs::attachment::AttachmentWriter>& streamWriter);
126 
135  bool writeToStream(
136  const std::shared_ptr<avsCommon::avs::attachment::AttachmentWriter>& streamWriter,
137  const unsigned char* buffer,
138  size_t size);
139 
147  bool writeToStream(
148  const ByteVector& content,
149  std::shared_ptr<avsCommon::avs::attachment::AttachmentWriter> streamWriter);
150 
158  static void logAVError(const char* event, const char* reason, int averror);
159 
161  struct ByteBuffer {
163  uint8_t* data;
164 
166  int len;
167 
169  int pos;
170  };
171 
179  static int bytesRemaining(uint8_t* pos, uint8_t* end);
180 
182  ByteVector m_mediaInitSection;
183 
185  bool m_needWavHeader;
186 
188  std::chrono::milliseconds m_totalDuration;
189 
191  std::atomic<bool> m_shuttingDown;
192 };
193 
194 } // namespace playlistParser
195 } // namespace alexaClientSDK
196 
197 #endif // ALEXA_CLIENT_SDK_PLAYLISTPARSER_INCLUDE_PLAYLISTPARSER_CONTENTDECRYPTER_H_
::std::string string
Definition: gtest-port.h:1097
static bool convertIVToByteArray(const std::string &hexIV, ByteVector *ivByteArray)
Definition: ContentDecrypter.h:40
void setMediaInitToDecryptedContent(const ByteVector &mediaInitSection, std::chrono::milliseconds totalDuration)
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
bool decryptAndWrite(const ByteVector &encryptedContent, const ByteVector &key, const avsCommon::utils::playlistParser::EncryptionInfo &encryptionInfo, const std::shared_ptr< avsCommon::avs::attachment::AttachmentWriter > &streamWriter, const std::shared_ptr< Id3TagsRemover > &id3TagRemover)
static const std::string key
The database key to be used by the protocol given the METADATA object.
Definition: SharedAVSSettingProtocolTest.cpp:58
std::vector< unsigned char > ByteVector
Alias for bytes.
Definition: ContentDecrypter.h:35

AlexaClientSDK 3.0.0 - Copyright 2016-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0