blob: 14dda419eacc4968b0fd6c26a59954f77195121a [file] [log] [blame]
Yingdi Yufa4ce792014-02-06 18:09:22 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
3 * Copyright (C) 2013 Regents of the University of California.
4 * @author: Yingdi Yu <yingdi@cs.ucla.edu>
5 * See COPYING for copyright and distribution information.
6 */
7
8#if __clang__
9#pragma clang diagnostic push
10#pragma clang diagnostic ignored "-Wtautological-compare"
11#pragma clang diagnostic ignored "-Wunused-function"
12#elif __GNUC__
13#pragma GCC diagnostic ignored "-Wunused-function"
14#endif
15
16#include <boost/test/unit_test.hpp>
17
18#include <cryptopp/base64.h>
19#include <ndn-cpp-dev/security/key-chain.hpp>
20#include <ndn-cpp-dev/util/time.hpp>
21#include "endorse-certificate.h"
22
23using namespace ndn;
24using namespace std;
25using namespace chronos;
26
27BOOST_AUTO_TEST_SUITE(TestEndorseCertificate)
28
29const string testCert("Av0DgANRBBdFbmRvcnNlQ2VydGlmaWNhdGVUZXN0cwQMRW5jb2RlRGVjb2RlBANL\
30RVkEEWtzay0xMzkxNzM0NzY0MzE2BAdJRC1DRVJUBAf9AUQJ9fu/EAMUAQIR/QHP\
31MIIByzAiGA8yMDE0MDEwMTAwMDAwMFoYDzIwMTUwMTAxMDAwMDAwWjB/MCwGA1UE\
32KRMlL0VuZG9yc2VDZXJ0aWZpY2F0ZVRlc3RzL0VuY29kZURlY29kZTASBgkqhkiG\
339w0BCQETBWFAYi5jMAoGA1UECxMDbmRuMA4GA1UEARMHdWNsYSBjczATBgNVBAMT\
34DGh0dHA6Ly9hLmIuYzAKBgNVBFATA25kbjCCASIwDQYJKoZIhvcNAQEBBQADggEP\
35ADCCAQoCggEBALX3RJhGUUQp+i6nJRMWgCbCxxrpmSOGlUfLNAFQh/zizdFdpG0O\
36+fjI82ilUzOsi4KnCBxpEez+tEMFzRTOFaLYj6bGQhTKhMsDb/d5mtjjKRBE69+R\
37H4IC9rUsD+pD/qh4lEZwoxz74DmsbAL4sCXyNLOTJFAokKpD5GB5/enwkMyC8425\
38seQXCZw/rlhpeIZkh19ULOvq4GXPk6fVPW/HsnReNa2J8toQepoh5nk1KAZjc/ed\
39GdegTAn4rBUH65chfoztBMli7sE9BJMkVf0OHSXTbRGqGSR/u0uOs+F69QisS+du\
40xyEZJFqJGOv7ZROo9C6cRZFpCJH+pjLen00CAwEAARJPFgEBF0oDSAQXRW5kb3Jz\
41ZUNlcnRpZmljYXRlVGVzdHMEDEVuY29kZURlY29kZQQDS0VZBBFrc2stMTM5MTcz\
42NDc2NDMxNgQHSUQtQ0VSVBP9AQBOUc/C6yrGQ9A3FYlwklNz9WrK7FhvkMmynugY\
43Ejasc6rVeMgigCIwgLau+bnIbO0rfMLSGdrvB/XSiWFzZSt1fQj/uJ29he+tIBf+\
44B5tP0MJL5hFNtSxgHgMCXkSRl9cC356GPpEcG+vMCoYMQLILukXfTwhP8qUB/hoy\
455/1OxXMUAFnU2EoX90DJYvpVlD6nZt04okLVBUpNJSODEzFJrNbgpapzkb4djGol\
466uRDV8iGhMfFtCmf+ZtcXyr49uBF2npqwgz01lTnXAB6jExD+EQ9rxospGkMgKVz\
47camQA/xj3G2PdPylszVO6qfv2clQxr9atW2Vt1BeI1ZtFbd/");
48
49KeyChain keyChain;
50
51BOOST_AUTO_TEST_CASE(EncodeDecode)
52{
53 string decoded;
54 CryptoPP::StringSource ss(reinterpret_cast<const uint8_t*>(testCert.c_str()),
55 testCert.size(), true,
56 new CryptoPP::Base64Decoder(new CryptoPP::StringSink(decoded)));
57 Data data;
58 data.wireDecode(Block(decoded.c_str(), decoded.size()));
59 IdentityCertificate identityCertificate(data);
60
61 Profile profile(identityCertificate);
62 vector<string> endorseList;
63 endorseList.push_back("email");
64 endorseList.push_back("homepage");
65
66 EndorseCertificate endorseCertificate(identityCertificate, profile, endorseList);
67
68 KeyChainImpl<SecPublicInfoSqlite3, SecTpmFile> keyChain;
69 Name signingIdentity("/EndorseCertificateTests/EncodeDecode/"+boost::lexical_cast<string>(time::now()));
70 keyChain.createIdentity(signingIdentity);
71
72 keyChain.signByIdentity(endorseCertificate, signingIdentity);
73
74 const Block& endorseDataBlock = endorseCertificate.wireEncode();
75
76 Data decodedEndorseData;
77
78 decodedEndorseData.wireDecode(endorseDataBlock);
79 EndorseCertificate decodedEndorse(decodedEndorseData);
80 BOOST_CHECK_EQUAL(decodedEndorse.getProfile().get("IDENTITY"), "/EndorseCertificateTests/EncodeDecode");
81 BOOST_CHECK_EQUAL(decodedEndorse.getProfile().get("name"), "/EndorseCertificateTests/EncodeDecode");
82 BOOST_CHECK_EQUAL(decodedEndorse.getProfile().get("homepage"), "http://a.b.c");
83 BOOST_CHECK_EQUAL(decodedEndorse.getEndorseList().size(), 2);
84 BOOST_CHECK_EQUAL(decodedEndorse.getEndorseList().at(0), "email");
85 BOOST_CHECK_EQUAL(decodedEndorse.getEndorseList().at(1), "homepage");
86
87 keyChain.deleteIdentity(signingIdentity);
88}
89
90
91
92BOOST_AUTO_TEST_SUITE_END()
93