blob: b31ae55f2d4cb3f64f6b83e792cdd6edf951d6a4 [file] [log] [blame]
tylerliu182bc532020-09-25 01:54:45 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2017-2020, Regents of the University of California.
4 *
5 * This file is part of ndncert, a certificate management system based on NDN.
6 *
7 * ndncert is free software: you can redistribute it and/or modify it under the terms
8 * of the GNU General Public License as published by the Free Software Foundation, either
9 * version 3 of the License, or (at your option) any later version.
10 *
11 * ndncert is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License along with
16 * ndncert, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * See AUTHORS.md for complete list of ndncert authors and contributors.
19 */
20
21#include "revoke.hpp"
22#include "../logging.hpp"
23#include "../ndncert-common.hpp"
24
25#include <ndn-cxx/security/transform/base64-encode.hpp>
26#include <ndn-cxx/security/transform/buffer-source.hpp>
27#include <ndn-cxx/security/transform/stream-sink.hpp>
28#include <ndn-cxx/util/logger.hpp>
29
30namespace ndn {
31namespace ndncert {
32
33_LOG_INIT(ndncert.client);
34
35Block
36REVOKE::encodeApplicationParameters(const std::string& ecdhPub, const security::v2::Certificate& certToRevoke)
37{
38 Block request = makeEmptyBlock(tlv::ApplicationParameters);
39 std::stringstream ss;
40 try {
41 security::transform::bufferSource(certToRevoke.wireEncode().wire(), certToRevoke.wireEncode().size())
42 >> security::transform::base64Encode(false)
43 >> security::transform::streamSink(ss);
44 }
45 catch (const security::transform::Error& e) {
46 _LOG_ERROR("Cannot convert self-signed cert into BASE64 string " << e.what());
47 return request;
48 }
49
50 request.push_back(makeStringBlock(tlv_ecdh_pub, ecdhPub));
51 request.push_back(makeNestedBlock(tlv_cert_to_revoke, certToRevoke));
52 request.encode();
53 return request;
54}
55
56Block
57REVOKE::encodeDataContent(const std::string& ecdhKey, const std::string& salt,
58 const CertificateRequest& request,
59 const std::list<std::string>& challenges)
60{
61 Block response = makeEmptyBlock(tlv::Content);
62 response.push_back(makeStringBlock(tlv_ecdh_pub, ecdhKey));
63 response.push_back(makeStringBlock(tlv_salt, salt));
64 response.push_back(makeStringBlock(tlv_request_id, request.m_requestId));
Zhiyi Zhang48f23782020-09-28 12:11:24 -070065 response.push_back(makeNonNegativeIntegerBlock(tlv_status, static_cast<size_t>(request.m_status)));
tylerliu182bc532020-09-25 01:54:45 -070066 for (const auto& entry: challenges) {
67 response.push_back(makeStringBlock(tlv_challenge, entry));
68 }
69 response.encode();
70 return response;
71}
72
73} // namespace ndncert
74} // namespace ndn