Prashanth Swaminathan | b210590 | 2015-08-20 14:28:54 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame^] | 3 | * Copyright (c) 2014-2018, Regents of the University of California |
Prashanth Swaminathan | b210590 | 2015-08-20 14:28:54 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-group-encrypt (Group-based Encryption Protocol for NDN). |
| 6 | * See AUTHORS.md for complete list of ndn-group-encrypt authors and contributors. |
| 7 | * |
| 8 | * ndn-group-encrypt is free software: you can redistribute it and/or modify it under the terms |
| 9 | * of the GNU General Public License as published by the Free Software Foundation, |
| 10 | * either version 3 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * ndn-group-encrypt is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 | * PURPOSE. See the GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * ndn-group-encrypt, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * @author Prashanth Swaminathan <prashanthsw@gmail.com> |
Yingdi Yu | 79ce239 | 2016-03-10 10:21:55 -0800 | [diff] [blame] | 20 | * @author Yingdi Yu <yuyingdi@gmail.com> |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame^] | 21 | * @author Zhiyi Zhang <zhiyi@cs.ucla.edu> |
Prashanth Swaminathan | b210590 | 2015-08-20 14:28:54 -0700 | [diff] [blame] | 22 | */ |
| 23 | |
| 24 | #include "producer.hpp" |
Prashanth Swaminathan | b210590 | 2015-08-20 14:28:54 -0700 | [diff] [blame] | 25 | #include "algo/aes.hpp" |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame^] | 26 | #include "algo/encryptor.hpp" |
Yingdi Yu | 79ce239 | 2016-03-10 10:21:55 -0800 | [diff] [blame] | 27 | #include "algo/error.hpp" |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame^] | 28 | #include <iostream> |
Prashanth Swaminathan | b210590 | 2015-08-20 14:28:54 -0700 | [diff] [blame] | 29 | |
| 30 | namespace ndn { |
| 31 | namespace gep { |
| 32 | |
| 33 | using time::system_clock; |
| 34 | |
Yingdi Yu | 79ce239 | 2016-03-10 10:21:55 -0800 | [diff] [blame] | 35 | static const int START_TS_INDEX = -2; |
| 36 | static const int END_TS_INDEX = -1; |
Prashanth Swaminathan | b210590 | 2015-08-20 14:28:54 -0700 | [diff] [blame] | 37 | |
Yingdi Yu | 48967a6 | 2016-03-11 22:04:14 -0800 | [diff] [blame] | 38 | const Link Producer::NO_LINK = Link(); |
| 39 | |
Prashanth Swaminathan | b210590 | 2015-08-20 14:28:54 -0700 | [diff] [blame] | 40 | /** |
| 41 | @brief Method to round the provided @p timeslot to the nearest whole |
| 42 | hour, so that we can store content keys uniformly (by start of the hour). |
| 43 | */ |
| 44 | static const system_clock::TimePoint |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame^] | 45 | getRoundedTimeslot(const system_clock::TimePoint& timeslot) |
| 46 | { |
| 47 | return time::fromUnixTimestamp((time::toUnixTimestamp(timeslot) / 3600000) * 3600000); |
Prashanth Swaminathan | b210590 | 2015-08-20 14:28:54 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame^] | 50 | Producer::Producer(const Name& prefix, |
| 51 | const Name& dataType, |
| 52 | Face& face, |
| 53 | const std::string& dbPath, |
Yingdi Yu | 48967a6 | 2016-03-11 22:04:14 -0800 | [diff] [blame] | 54 | uint8_t repeatAttempts, |
| 55 | const Link& keyRetrievalLink) |
| 56 | : m_face(face) |
| 57 | , m_db(dbPath) |
| 58 | , m_maxRepeatAttempts(repeatAttempts) |
| 59 | , m_keyRetrievalLink(keyRetrievalLink) |
Prashanth Swaminathan | b210590 | 2015-08-20 14:28:54 -0700 | [diff] [blame] | 60 | { |
| 61 | Name fixedPrefix = prefix; |
| 62 | Name fixedDataType = dataType; |
| 63 | KeyInfo keyInfo; |
| 64 | /** |
| 65 | Fill m_ekeyInfo vector with all permutations of dataType, including the 'E-KEY' |
| 66 | component of the name. This will be used in DataProducer::createContentKey to |
| 67 | send interests without reconstructing names every time. |
| 68 | */ |
| 69 | fixedPrefix.append(NAME_COMPONENT_READ); |
| 70 | while (!fixedDataType.empty()) { |
| 71 | Name nodeName = fixedPrefix; |
| 72 | nodeName.append(fixedDataType); |
| 73 | nodeName.append(NAME_COMPONENT_E_KEY); |
| 74 | |
| 75 | m_ekeyInfo[nodeName] = keyInfo; |
| 76 | fixedDataType = fixedDataType.getPrefix(-1); |
| 77 | } |
| 78 | fixedPrefix.append(dataType); |
| 79 | m_namespace = prefix; |
| 80 | m_namespace.append(NAME_COMPONENT_SAMPLE); |
| 81 | m_namespace.append(dataType); |
| 82 | } |
| 83 | |
| 84 | Name |
| 85 | Producer::createContentKey(const system_clock::TimePoint& timeslot, |
Yingdi Yu | 79ce239 | 2016-03-10 10:21:55 -0800 | [diff] [blame] | 86 | const ProducerEKeyCallback& callback, |
| 87 | const ErrorCallBack& errorCallback) |
Prashanth Swaminathan | b210590 | 2015-08-20 14:28:54 -0700 | [diff] [blame] | 88 | { |
| 89 | const system_clock::TimePoint hourSlot = getRoundedTimeslot(timeslot); |
| 90 | |
| 91 | // Create content key name. |
| 92 | Name contentKeyName = m_namespace; |
| 93 | contentKeyName.append(NAME_COMPONENT_C_KEY); |
| 94 | contentKeyName.append(time::toIsoString(hourSlot)); |
| 95 | |
| 96 | Buffer contentKeyBits; |
Yingdi Yu | 79ce239 | 2016-03-10 10:21:55 -0800 | [diff] [blame] | 97 | |
| 98 | // Check if we have created the content key before. |
Prashanth Swaminathan | b210590 | 2015-08-20 14:28:54 -0700 | [diff] [blame] | 99 | if (m_db.hasContentKey(timeslot)) { |
Yingdi Yu | 79ce239 | 2016-03-10 10:21:55 -0800 | [diff] [blame] | 100 | // We have created the content key, return its name directly. |
Prashanth Swaminathan | b210590 | 2015-08-20 14:28:54 -0700 | [diff] [blame] | 101 | return contentKeyName; |
| 102 | } |
| 103 | |
Yingdi Yu | 79ce239 | 2016-03-10 10:21:55 -0800 | [diff] [blame] | 104 | // We haven't created the content key, create one and add it into the database. |
Prashanth Swaminathan | b210590 | 2015-08-20 14:28:54 -0700 | [diff] [blame] | 105 | AesKeyParams aesParams(128); |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame^] | 106 | contentKeyBits = algo::Aes::generateKey(aesParams).getKeyBits(); |
Prashanth Swaminathan | b210590 | 2015-08-20 14:28:54 -0700 | [diff] [blame] | 107 | m_db.addContentKey(timeslot, contentKeyBits); |
| 108 | |
Yingdi Yu | 79ce239 | 2016-03-10 10:21:55 -0800 | [diff] [blame] | 109 | // Now we need to retrieve the E-KEYs for content key encryption. |
Prashanth Swaminathan | b210590 | 2015-08-20 14:28:54 -0700 | [diff] [blame] | 110 | uint64_t timeCount = toUnixTimestamp(timeslot).count(); |
| 111 | m_keyRequests.insert({timeCount, KeyRequest(m_ekeyInfo.size())}); |
| 112 | KeyRequest& keyRequest = m_keyRequests.at(timeCount); |
| 113 | |
Yingdi Yu | 79ce239 | 2016-03-10 10:21:55 -0800 | [diff] [blame] | 114 | // Check if current E-KEYs can cover the content key. |
Prashanth Swaminathan | b210590 | 2015-08-20 14:28:54 -0700 | [diff] [blame] | 115 | Exclude timeRange; |
| 116 | timeRange.excludeAfter(name::Component(time::toIsoString(timeslot))); |
Prashanth Swaminathan | b210590 | 2015-08-20 14:28:54 -0700 | [diff] [blame] | 117 | std::unordered_map<Name, KeyInfo>::iterator it; |
| 118 | for (it = m_ekeyInfo.begin(); it != m_ekeyInfo.end(); ++it) { |
Yingdi Yu | 79ce239 | 2016-03-10 10:21:55 -0800 | [diff] [blame] | 119 | // for each current E-KEY |
| 120 | if (timeslot < it->second.beginTimeslot || timeslot >= it->second.endTimeslot) { |
| 121 | // current E-KEY cannot cover the content key, retrieve one. |
| 122 | keyRequest.repeatAttempts[it->first] = 0; |
| 123 | sendKeyInterest(Interest(it->first).setExclude(timeRange).setChildSelector(1), |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame^] | 124 | timeslot, |
| 125 | callback, |
| 126 | errorCallback); |
Prashanth Swaminathan | b210590 | 2015-08-20 14:28:54 -0700 | [diff] [blame] | 127 | } |
| 128 | else { |
Yingdi Yu | 79ce239 | 2016-03-10 10:21:55 -0800 | [diff] [blame] | 129 | // current E-KEY can cover the content key, encrypt the content key directly. |
Prashanth Swaminathan | b210590 | 2015-08-20 14:28:54 -0700 | [diff] [blame] | 130 | Name eKeyName(it->first); |
Yingdi Yu | 79ce239 | 2016-03-10 10:21:55 -0800 | [diff] [blame] | 131 | eKeyName.append(time::toIsoString(it->second.beginTimeslot)); |
| 132 | eKeyName.append(time::toIsoString(it->second.endTimeslot)); |
| 133 | encryptContentKey(it->second.keyBits, eKeyName, timeslot, callback, errorCallback); |
Prashanth Swaminathan | b210590 | 2015-08-20 14:28:54 -0700 | [diff] [blame] | 134 | } |
| 135 | } |
| 136 | |
| 137 | return contentKeyName; |
| 138 | } |
| 139 | |
| 140 | void |
Yingdi Yu | 79ce239 | 2016-03-10 10:21:55 -0800 | [diff] [blame] | 141 | Producer::defaultErrorCallBack(const ErrorCode& code, const std::string& msg) |
Prashanth Swaminathan | b210590 | 2015-08-20 14:28:54 -0700 | [diff] [blame] | 142 | { |
Yingdi Yu | 79ce239 | 2016-03-10 10:21:55 -0800 | [diff] [blame] | 143 | // do nothing. |
| 144 | } |
Prashanth Swaminathan | b210590 | 2015-08-20 14:28:54 -0700 | [diff] [blame] | 145 | |
Yingdi Yu | 79ce239 | 2016-03-10 10:21:55 -0800 | [diff] [blame] | 146 | void |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame^] | 147 | Producer::produce(Data& data, |
| 148 | const system_clock::TimePoint& timeslot, |
| 149 | const uint8_t* content, |
| 150 | size_t contentLen, |
Yingdi Yu | 79ce239 | 2016-03-10 10:21:55 -0800 | [diff] [blame] | 151 | const ErrorCallBack& errorCallBack) |
| 152 | { |
| 153 | // Get a content key |
| 154 | Name contentKeyName = createContentKey(timeslot, nullptr, errorCallBack); |
| 155 | Buffer contentKey = m_db.getContentKey(timeslot); |
Prashanth Swaminathan | b210590 | 2015-08-20 14:28:54 -0700 | [diff] [blame] | 156 | |
Yingdi Yu | 79ce239 | 2016-03-10 10:21:55 -0800 | [diff] [blame] | 157 | // Produce data |
Prashanth Swaminathan | b210590 | 2015-08-20 14:28:54 -0700 | [diff] [blame] | 158 | Name dataName = m_namespace; |
Yingdi Yu | 0c530b7 | 2016-03-20 18:19:14 -0700 | [diff] [blame] | 159 | dataName.append(time::toIsoString(timeslot)); |
Prashanth Swaminathan | b210590 | 2015-08-20 14:28:54 -0700 | [diff] [blame] | 160 | data.setName(dataName); |
| 161 | algo::EncryptParams params(tlv::AlgorithmAesCbc, 16); |
| 162 | algo::encryptData(data, content, contentLen, contentKeyName, |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame^] | 163 | contentKey.data(), contentKey.size(), params); |
Prashanth Swaminathan | b210590 | 2015-08-20 14:28:54 -0700 | [diff] [blame] | 164 | m_keychain.sign(data); |
| 165 | } |
| 166 | |
| 167 | void |
Yingdi Yu | 79ce239 | 2016-03-10 10:21:55 -0800 | [diff] [blame] | 168 | Producer::sendKeyInterest(const Interest& interest, |
| 169 | const system_clock::TimePoint& timeslot, |
Prashanth Swaminathan | b210590 | 2015-08-20 14:28:54 -0700 | [diff] [blame] | 170 | const ProducerEKeyCallback& callback, |
Yingdi Yu | 79ce239 | 2016-03-10 10:21:55 -0800 | [diff] [blame] | 171 | const ErrorCallBack& errorCallback) |
Prashanth Swaminathan | b210590 | 2015-08-20 14:28:54 -0700 | [diff] [blame] | 172 | { |
Yingdi Yu | 48967a6 | 2016-03-11 22:04:14 -0800 | [diff] [blame] | 173 | Interest request(interest); |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame^] | 174 | if (m_keyRetrievalLink.getDelegationList().size() > 0) { |
| 175 | request.setForwardingHint(m_keyRetrievalLink.getDelegationList()); |
Yingdi Yu | 48967a6 | 2016-03-11 22:04:14 -0800 | [diff] [blame] | 176 | } |
| 177 | m_face.expressInterest(request, |
Yingdi Yu | 79ce239 | 2016-03-10 10:21:55 -0800 | [diff] [blame] | 178 | std::bind(&Producer::handleCoveringKey, this, _1, _2, |
| 179 | timeslot, callback, errorCallback), |
| 180 | std::bind(&Producer::handleNack, this, _1, _2, |
Yingdi Yu | 48967a6 | 2016-03-11 22:04:14 -0800 | [diff] [blame] | 181 | timeslot, callback, errorCallback), |
Yingdi Yu | 79ce239 | 2016-03-10 10:21:55 -0800 | [diff] [blame] | 182 | std::bind(&Producer::handleTimeout, this, _1, |
| 183 | timeslot, callback, errorCallback)); |
Prashanth Swaminathan | b210590 | 2015-08-20 14:28:54 -0700 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | void |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame^] | 187 | Producer::handleCoveringKey(const Interest& interest, |
| 188 | const Data& data, |
Prashanth Swaminathan | b210590 | 2015-08-20 14:28:54 -0700 | [diff] [blame] | 189 | const system_clock::TimePoint& timeslot, |
Yingdi Yu | 79ce239 | 2016-03-10 10:21:55 -0800 | [diff] [blame] | 190 | const ProducerEKeyCallback& callback, |
| 191 | const ErrorCallBack& errorCallback) |
Prashanth Swaminathan | b210590 | 2015-08-20 14:28:54 -0700 | [diff] [blame] | 192 | { |
Yingdi Yu | 79ce239 | 2016-03-10 10:21:55 -0800 | [diff] [blame] | 193 | uint64_t timeCount = toUnixTimestamp(timeslot).count(); |
| 194 | KeyRequest& keyRequest = m_keyRequests.at(timeCount); |
| 195 | |
| 196 | Name interestName = interest.getName(); |
| 197 | Name keyName = data.getName(); |
| 198 | |
| 199 | system_clock::TimePoint begin = time::fromIsoString(keyName.get(START_TS_INDEX).toUri()); |
| 200 | system_clock::TimePoint end = time::fromIsoString(keyName.get(END_TS_INDEX).toUri()); |
| 201 | |
| 202 | if (timeslot >= end) { |
| 203 | // if received E-KEY covers some earlier period, try to retrieve an E-KEY covering later one. |
| 204 | keyRequest.repeatAttempts[interestName] = 0; |
| 205 | |
| 206 | Exclude timeRange = interest.getSelectors().getExclude(); |
| 207 | timeRange.excludeBefore(keyName.get(START_TS_INDEX)); |
| 208 | |
| 209 | sendKeyInterest(Interest(interestName).setExclude(timeRange).setChildSelector(1), |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame^] | 210 | timeslot, |
| 211 | callback, |
| 212 | errorCallback); |
Yingdi Yu | 79ce239 | 2016-03-10 10:21:55 -0800 | [diff] [blame] | 213 | } |
| 214 | else { |
| 215 | // if received E-KEY covers the content key, encrypt the content |
| 216 | Buffer encryptionKey(data.getContent().value(), data.getContent().value_size()); |
| 217 | // if everything is correct, save the E-KEY as the current key |
| 218 | if (encryptContentKey(encryptionKey, keyName, timeslot, callback, errorCallback)) { |
| 219 | m_ekeyInfo[interestName].beginTimeslot = begin; |
| 220 | m_ekeyInfo[interestName].endTimeslot = end; |
| 221 | m_ekeyInfo[interestName].keyBits = encryptionKey; |
| 222 | } |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | void |
| 227 | Producer::handleTimeout(const Interest& interest, |
| 228 | const system_clock::TimePoint& timeslot, |
| 229 | const ProducerEKeyCallback& callback, |
| 230 | const ErrorCallBack& errorCallback) |
| 231 | { |
| 232 | uint64_t timeCount = toUnixTimestamp(timeslot).count(); |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame^] | 233 | if (m_keyRequests.find(timeCount) == m_keyRequests.end()) { |
| 234 | return; |
| 235 | } |
Yingdi Yu | 79ce239 | 2016-03-10 10:21:55 -0800 | [diff] [blame] | 236 | KeyRequest& keyRequest = m_keyRequests.at(timeCount); |
| 237 | |
| 238 | Name interestName = interest.getName(); |
| 239 | if (keyRequest.repeatAttempts[interestName] < m_maxRepeatAttempts) { |
| 240 | // increase retrial count |
| 241 | keyRequest.repeatAttempts[interestName]++; |
| 242 | sendKeyInterest(interest, timeslot, callback, errorCallback); |
| 243 | } |
| 244 | else { |
Yingdi Yu | 48967a6 | 2016-03-11 22:04:14 -0800 | [diff] [blame] | 245 | // treat eventual timeout as a NACK |
| 246 | handleNack(interest, lp::Nack(), timeslot, callback, errorCallback); |
Yingdi Yu | 79ce239 | 2016-03-10 10:21:55 -0800 | [diff] [blame] | 247 | } |
| 248 | } |
| 249 | |
| 250 | void |
| 251 | Producer::handleNack(const Interest& interest, |
| 252 | const lp::Nack& nack, |
| 253 | const system_clock::TimePoint& timeslot, |
Yingdi Yu | 48967a6 | 2016-03-11 22:04:14 -0800 | [diff] [blame] | 254 | const ProducerEKeyCallback& callback, |
| 255 | const ErrorCallBack& errorCallback) |
Yingdi Yu | 79ce239 | 2016-03-10 10:21:55 -0800 | [diff] [blame] | 256 | { |
Yingdi Yu | 48967a6 | 2016-03-11 22:04:14 -0800 | [diff] [blame] | 257 | // we run out of options... |
Yingdi Yu | 79ce239 | 2016-03-10 10:21:55 -0800 | [diff] [blame] | 258 | uint64_t timeCount = toUnixTimestamp(timeslot).count(); |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame^] | 259 | |
| 260 | if (m_keyRequests.find(timeCount) != m_keyRequests.end()) { |
| 261 | updateKeyRequest(m_keyRequests.at(timeCount), timeCount, callback); |
| 262 | } |
Yingdi Yu | 79ce239 | 2016-03-10 10:21:55 -0800 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | void |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame^] | 266 | Producer::updateKeyRequest(KeyRequest& keyRequest, |
| 267 | uint64_t timeCount, |
Yingdi Yu | 79ce239 | 2016-03-10 10:21:55 -0800 | [diff] [blame] | 268 | const ProducerEKeyCallback& callback) |
| 269 | { |
| 270 | keyRequest.interestCount--; |
| 271 | if (keyRequest.interestCount == 0 && callback) { |
| 272 | callback(keyRequest.encryptedKeys); |
| 273 | m_keyRequests.erase(timeCount); |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | bool |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame^] | 278 | Producer::encryptContentKey(const Buffer& encryptionKey, |
| 279 | const Name& eKeyName, |
Yingdi Yu | 79ce239 | 2016-03-10 10:21:55 -0800 | [diff] [blame] | 280 | const system_clock::TimePoint& timeslot, |
| 281 | const ProducerEKeyCallback& callback, |
| 282 | const ErrorCallBack& errorCallBack) |
| 283 | { |
| 284 | uint64_t timeCount = toUnixTimestamp(timeslot).count(); |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame^] | 285 | if (m_keyRequests.find(timeCount) == m_keyRequests.end()) { |
| 286 | return false; |
| 287 | } |
Yingdi Yu | 79ce239 | 2016-03-10 10:21:55 -0800 | [diff] [blame] | 288 | KeyRequest& keyRequest = m_keyRequests.at(timeCount); |
| 289 | |
Prashanth Swaminathan | b210590 | 2015-08-20 14:28:54 -0700 | [diff] [blame] | 290 | Name keyName = m_namespace; |
| 291 | keyName.append(NAME_COMPONENT_C_KEY); |
| 292 | keyName.append(time::toIsoString(getRoundedTimeslot(timeslot))); |
| 293 | |
| 294 | Buffer contentKey = m_db.getContentKey(timeslot); |
Prashanth Swaminathan | b210590 | 2015-08-20 14:28:54 -0700 | [diff] [blame] | 295 | Data cKeyData; |
| 296 | cKeyData.setName(keyName); |
| 297 | algo::EncryptParams params(tlv::AlgorithmRsaOaep); |
Yingdi Yu | 79ce239 | 2016-03-10 10:21:55 -0800 | [diff] [blame] | 298 | try { |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame^] | 299 | algo::encryptData(cKeyData, |
| 300 | contentKey.data(), |
| 301 | contentKey.size(), |
| 302 | eKeyName, |
| 303 | encryptionKey.data(), |
| 304 | encryptionKey.size(), |
| 305 | params); |
Yingdi Yu | 79ce239 | 2016-03-10 10:21:55 -0800 | [diff] [blame] | 306 | } |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame^] | 307 | catch (const algo::Error& e) { |
Yingdi Yu | 79ce239 | 2016-03-10 10:21:55 -0800 | [diff] [blame] | 308 | errorCallBack(ErrorCode::EncryptionFailure, e.what()); |
| 309 | return false; |
| 310 | } |
Prashanth Swaminathan | b210590 | 2015-08-20 14:28:54 -0700 | [diff] [blame] | 311 | m_keychain.sign(cKeyData); |
| 312 | keyRequest.encryptedKeys.push_back(cKeyData); |
Yingdi Yu | 79ce239 | 2016-03-10 10:21:55 -0800 | [diff] [blame] | 313 | updateKeyRequest(keyRequest, timeCount, callback); |
| 314 | return true; |
Prashanth Swaminathan | b210590 | 2015-08-20 14:28:54 -0700 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | } // namespace gep |
Yingdi Yu | 266badb | 2016-03-09 18:58:27 -0800 | [diff] [blame] | 318 | } // namespace ndn |