blob: 6b9275ae00009202ef59c85bbf6d71637cec8f3a [file] [log] [blame]
Yingdi Yu5ec0ee32014-06-24 16:26:09 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -08003 * Copyright (c) 2013-2017 Regents of the University of California.
Yingdi Yu5ec0ee32014-06-24 16:26:09 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6 *
7 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library 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 Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20 */
21
22#include "security/sec-rule-specific.hpp"
Spyridon Mastorakis1ece2e32015-08-27 18:52:21 -070023#include "security/signing-helpers.hpp"
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070024
25#include "boost-test.hpp"
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -080026#include "identity-management-fixture.hpp"
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070027
28namespace ndn {
Spyridon Mastorakis429634f2015-02-19 17:35:33 -080029namespace security {
30namespace tests {
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070031
Alexander Afanasyeve4f8c3b2016-06-23 16:03:48 -070032using namespace ndn::tests;
33
Davide Pesaventoeee3e822016-11-26 19:19:34 +010034BOOST_AUTO_TEST_SUITE(Security)
Spyridon Mastorakis1ece2e32015-08-27 18:52:21 -070035BOOST_FIXTURE_TEST_SUITE(TestSecRuleSpecific, IdentityManagementFixture)
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070036
Davide Pesaventoeee3e822016-11-26 19:19:34 +010037BOOST_AUTO_TEST_CASE(Basic)
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070038{
Spyridon Mastorakis1ece2e32015-08-27 18:52:21 -070039 auto rsaIdentity = addIdentity("/SecurityTestSecRule/Basic/Rsa", RsaKeyParams());
40 auto ecIdentity = addIdentity("/SecurityTestSecRule/Basic/Ec", EcKeyParams());
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070041
Spyridon Mastorakis1ece2e32015-08-27 18:52:21 -070042 Name dataName("/SecurityTestSecRule/Basic");
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070043 Data rsaData(dataName);
Spyridon Mastorakis1ece2e32015-08-27 18:52:21 -070044 m_keyChain.sign(rsaData, signingByIdentity(rsaIdentity));
45 Data ecData(dataName);
46 m_keyChain.sign(ecData, signingByIdentity(ecIdentity));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070047 Data sha256Data(dataName);
Spyridon Mastorakis1ece2e32015-08-27 18:52:21 -070048 m_keyChain.sign(sha256Data, security::signingWithSha256());
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070049
Spyridon Mastorakis1ece2e32015-08-27 18:52:21 -070050 auto dataRegex = make_shared<Regex>("^<SecurityTestSecRule><Basic>$");
51 auto signerRegex = make_shared<Regex>("^<SecurityTestSecRule><Basic><><KEY><>$");
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070052
53 SecRuleSpecific rule(dataRegex, signerRegex);
54 BOOST_CHECK(rule.satisfy(rsaData));
Spyridon Mastorakis1ece2e32015-08-27 18:52:21 -070055 BOOST_CHECK(rule.satisfy(ecData));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070056 BOOST_CHECK_EQUAL(rule.satisfy(sha256Data), false);
57
58 BOOST_CHECK(rule.matchSignerName(rsaData));
Spyridon Mastorakis1ece2e32015-08-27 18:52:21 -070059 BOOST_CHECK(rule.matchSignerName(ecData));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070060 BOOST_CHECK_EQUAL(rule.matchSignerName(sha256Data), false);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070061}
62
Davide Pesaventoeee3e822016-11-26 19:19:34 +010063BOOST_AUTO_TEST_SUITE_END() // TestSecRuleSpecific
64BOOST_AUTO_TEST_SUITE_END() // Security
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070065
Spyridon Mastorakis429634f2015-02-19 17:35:33 -080066} // namespace tests
67} // namespace security
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070068} // namespace ndn