blob: 23075e3692beac14db5dd48a73334bde1889edff [file] [log] [blame]
Yingdi Yu6df61252014-01-21 11:05:11 -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 "-Wreorder"
11#pragma clang diagnostic ignored "-Wtautological-compare"
12#pragma clang diagnostic ignored "-Wunused-variable"
13#pragma clang diagnostic ignored "-Wunused-function"
14#elif __GNUC__
15#pragma GCC diagnostic ignored "-Wreorder"
16#pragma GCC diagnostic ignored "-Wunused-variable"
17#pragma GCC diagnostic ignored "-Wunused-function"
18#endif
19
20#include <boost/test/unit_test.hpp>
21
22#include <iostream>
23#include <iomanip>
24#include <cryptopp/base64.h>
25#include <ndn-cpp/security/key-chain.hpp>
26#include "endorse-certificate.h"
27
28using namespace ndn;
29using namespace ndn::ptr_lib;
30using namespace std;
31
32BOOST_AUTO_TEST_SUITE(EndorseCertificateTests)
33
34const string aliceCert("BIICqgOyEIUBbIk+NUYUb6QYOBmPyWrhj9WiEKgoAzXAjQ+gz6iAmeX4srvcH3dQ\
35a/Y1H4Vf/LmNrXUsqbEJn1tmGoxGoQlkMtuKZ9K9X40R2SbH8d01IOIHILodRdG3\
36KXlsXS13vBkuGB8RwhMCh3RCBc6K10LQ87TkkpLdYpIjS8n2stQn2HgiHPsIUGyE\
37yLXqJ8ght2ZLVUYzHcpW4D0asckiQGXJuFmkGnbQVNHEBuirY8R1Zak6uDopoZi1\
38xvFCH6UkUXBzh3FhXrk/GA5Y6sZTKTDqo1fwz6GRubyhPq1+nHOM7ud5k4DoC6zI\
39Xstlhi5LSrCInSBItBaSNd2RPO3dbp0QAADy+p1uZG4A+sV1Y2xhLmVkdQD6nUtF\
40WQD6rWFsaWNlAPr1a3NrLTEzODI5MzQyMDEA+r1JRC1DRVJUAPrN/f/////ea6GX\
41AAABogPiAoX4UXq6YdztiNp79l71bcPBOBnRKOJBPKxDZTeC3YrfSgACurUFJt5r\
42oZgAAeIB6vL6nW5kbgD6xXVjbGEuZWR1APqdS0VZAPr1ZHNrLTEzODI5MzQyMDAA\
43+r1JRC1DRVJUAAAAAAABmhfdMIIBdzAiGA8yMDEzMTAyODAwMDAwMFoYDzIwMzMx\
44MDI4MDAwMDAwWjArMCkGA1UEKRMiL25kbi91Y2xhLmVkdS9hbGljZS9rc2stMTM4\
45MjkzNDIwMTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAJ9b5S6MJIDz\
46EyYDYL6/1PeeM1ZIr9lyDJojyLBa/nxvCkTykdeUEIEsQb0+B5UDcyS9iGZRlBUf\
47CXOjRlnbo5BtD0IWw2aR048RT3pDh2U+dsOsJQMdPwTAaegwv+BEBvWVX+A93xya\
48qoYQcJF56q6ktvxfFj5c4G6vuuuf8ZSGbIeesXy1P5wYdSu1ceTL8mnawR0+Nj2D\
49VG71gn1A9NiIBKKQcT0rUgxo3NOaPHBUdQP67qLdfBOj0HrktGndVDxD5pWbnxKU\
50V3zd/aD1DJuP826RJ8b/7eftdIF7/8gVRN5fz3wbjFtNzAE5RLmXP+ik8MhnHMx+\
51B2QkdwR+8gcCAwEAAQAA");
52
53KeyChain keyChain;
54
55BOOST_AUTO_TEST_CASE(ProfileDataEncodeDecode)
56{
57 string decoded;
58 CryptoPP::StringSource ss(reinterpret_cast<const unsigned char *>(aliceCert.c_str()),
59 aliceCert.size(),
60 true,
61 new CryptoPP::Base64Decoder(new CryptoPP::StringSink(decoded)));
62 Data data;
63 data.wireDecode(Block(decoded.c_str(), decoded.size()));
64 IdentityCertificate identityCertificate(data);
65
66 Profile profile(identityCertificate);
67 ProfileData profileData(profile);
68
69 Name certificateName = keyChain.getDefaultCertificateName();
70 keyChain.sign(profileData, certificateName);
71
72 const Block& profileDataBlock = profileData.wireEncode();
73 Data decodedProfileData;
74
75 decodedProfileData.wireDecode(profileDataBlock);
76 ProfileData decodedProfile(decodedProfileData);
77 BOOST_CHECK_EQUAL(decodedProfile.getProfile().getProfileEntry("IDENTITY"), string("/ndn/ucla.edu/alice"));
78 BOOST_CHECK_EQUAL(decodedProfile.getProfile().getProfileEntry("name"), string("/ndn/ucla.edu/alice/ksk-1382934201"));
79}
80
81BOOST_AUTO_TEST_CASE(EndorseCertifiicateEncodeDecode)
82{
83 string decoded;
84 CryptoPP::StringSource ss(reinterpret_cast<const unsigned char *>(aliceCert.c_str()),
85 aliceCert.size(),
86 true,
87 new CryptoPP::Base64Decoder(new CryptoPP::StringSink(decoded)));
88 Data data;
89 data.wireDecode(Block(decoded.c_str(), decoded.size()));
90 IdentityCertificate identityCertificate(data);
91
92 Profile profile(identityCertificate);
93 ProfileData profileData(profile);
94
95 Name certificateName = keyChain.getDefaultCertificateName();
96 keyChain.sign(profileData, certificateName);
97
98 EndorseCertificate endorseCertificate(identityCertificate, profileData);
99
100 keyChain.sign(endorseCertificate, certificateName);
101
102 const Block& endorseDataBlock = endorseCertificate.wireEncode();
103
104 Data decodedEndorseData;
105
106 decodedEndorseData.wireDecode(endorseDataBlock);
107 EndorseCertificate decodedEndorse(decodedEndorseData);
108 BOOST_CHECK_EQUAL(decodedEndorse.getProfileData().getProfile().getProfileEntry("IDENTITY"), string("/ndn/ucla.edu/alice"));
109 BOOST_CHECK_EQUAL(decodedEndorse.getProfileData().getProfile().getProfileEntry("name"), string("/ndn/ucla.edu/alice/ksk-1382934201"));
110}
111
112
113
114BOOST_AUTO_TEST_SUITE_END()
115