Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 1 | /* -*- 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 | |
| 23 | using namespace ndn; |
| 24 | using namespace std; |
| 25 | using namespace chronos; |
| 26 | |
| 27 | BOOST_AUTO_TEST_SUITE(TestEndorseCertificate) |
| 28 | |
| 29 | const string testCert("Av0DgANRBBdFbmRvcnNlQ2VydGlmaWNhdGVUZXN0cwQMRW5jb2RlRGVjb2RlBANL\ |
| 30 | RVkEEWtzay0xMzkxNzM0NzY0MzE2BAdJRC1DRVJUBAf9AUQJ9fu/EAMUAQIR/QHP\ |
| 31 | MIIByzAiGA8yMDE0MDEwMTAwMDAwMFoYDzIwMTUwMTAxMDAwMDAwWjB/MCwGA1UE\ |
| 32 | KRMlL0VuZG9yc2VDZXJ0aWZpY2F0ZVRlc3RzL0VuY29kZURlY29kZTASBgkqhkiG\ |
| 33 | 9w0BCQETBWFAYi5jMAoGA1UECxMDbmRuMA4GA1UEARMHdWNsYSBjczATBgNVBAMT\ |
| 34 | DGh0dHA6Ly9hLmIuYzAKBgNVBFATA25kbjCCASIwDQYJKoZIhvcNAQEBBQADggEP\ |
| 35 | ADCCAQoCggEBALX3RJhGUUQp+i6nJRMWgCbCxxrpmSOGlUfLNAFQh/zizdFdpG0O\ |
| 36 | +fjI82ilUzOsi4KnCBxpEez+tEMFzRTOFaLYj6bGQhTKhMsDb/d5mtjjKRBE69+R\ |
| 37 | H4IC9rUsD+pD/qh4lEZwoxz74DmsbAL4sCXyNLOTJFAokKpD5GB5/enwkMyC8425\ |
| 38 | seQXCZw/rlhpeIZkh19ULOvq4GXPk6fVPW/HsnReNa2J8toQepoh5nk1KAZjc/ed\ |
| 39 | GdegTAn4rBUH65chfoztBMli7sE9BJMkVf0OHSXTbRGqGSR/u0uOs+F69QisS+du\ |
| 40 | xyEZJFqJGOv7ZROo9C6cRZFpCJH+pjLen00CAwEAARJPFgEBF0oDSAQXRW5kb3Jz\ |
| 41 | ZUNlcnRpZmljYXRlVGVzdHMEDEVuY29kZURlY29kZQQDS0VZBBFrc2stMTM5MTcz\ |
| 42 | NDc2NDMxNgQHSUQtQ0VSVBP9AQBOUc/C6yrGQ9A3FYlwklNz9WrK7FhvkMmynugY\ |
| 43 | Ejasc6rVeMgigCIwgLau+bnIbO0rfMLSGdrvB/XSiWFzZSt1fQj/uJ29he+tIBf+\ |
| 44 | B5tP0MJL5hFNtSxgHgMCXkSRl9cC356GPpEcG+vMCoYMQLILukXfTwhP8qUB/hoy\ |
| 45 | 5/1OxXMUAFnU2EoX90DJYvpVlD6nZt04okLVBUpNJSODEzFJrNbgpapzkb4djGol\ |
| 46 | 6uRDV8iGhMfFtCmf+ZtcXyr49uBF2npqwgz01lTnXAB6jExD+EQ9rxospGkMgKVz\ |
| 47 | camQA/xj3G2PdPylszVO6qfv2clQxr9atW2Vt1BeI1ZtFbd/"); |
| 48 | |
| 49 | KeyChain keyChain; |
| 50 | |
| 51 | BOOST_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 | |
| 92 | BOOST_AUTO_TEST_SUITE_END() |
| 93 | |