blob: f9b266235973ddd125a326768e66a61fd893e434 [file] [log] [blame]
Yingdi Yu3715f8d2014-01-30 00:32:20 -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
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -08008#include "common.hpp"
9
Yingdi Yu3715f8d2014-01-30 00:32:20 -080010#include "sec-rule-specific.hpp"
11#include "signature-sha256-with-rsa.hpp"
12
Yingdi Yu3715f8d2014-01-30 00:32:20 -080013using namespace std;
14
Yingdi Yufc40d872014-02-18 12:56:04 -080015namespace ndn {
Yingdi Yu3715f8d2014-01-30 00:32:20 -080016
17SecRuleSpecific::SecRuleSpecific(shared_ptr<Regex> dataRegex,
18 shared_ptr<Regex> signerRegex)
19 : SecRule(true)
20 , m_dataRegex(dataRegex)
21 , m_signerRegex(signerRegex)
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070022{
23}
Yingdi Yu3715f8d2014-01-30 00:32:20 -080024
25SecRuleSpecific::SecRuleSpecific(const SecRuleSpecific& rule)
26 : SecRule(true)
27 , m_dataRegex(rule.m_dataRegex)
28 , m_signerRegex(rule.m_signerRegex)
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070029{
30}
Yingdi Yu3715f8d2014-01-30 00:32:20 -080031
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070032bool
Yingdi Yu3715f8d2014-01-30 00:32:20 -080033SecRuleSpecific::matchDataName(const Data& data)
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070034{
35 return m_dataRegex->match(data.getName());
36}
Yingdi Yu3715f8d2014-01-30 00:32:20 -080037
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070038bool
Yingdi Yu3715f8d2014-01-30 00:32:20 -080039SecRuleSpecific::matchSignerName(const Data& data)
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070040{
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070041 try
42 {
43 SignatureSha256WithRsa sig(data.getSignature());
44 Name signerName = sig.getKeyLocator().getName();
45 return m_signerRegex->match(signerName);
46 }
47 catch (std::runtime_error& e)
48 {
49 return false;
50 }
Yingdi Yu3715f8d2014-01-30 00:32:20 -080051}
52
53bool
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070054SecRuleSpecific::satisfy(const Data& data)
55{
56 return (matchDataName(data) && matchSignerName(data)) ? true : false;
Yingdi Yufc40d872014-02-18 12:56:04 -080057}
Yingdi Yu3715f8d2014-01-30 00:32:20 -080058
59bool
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070060SecRuleSpecific::satisfy(const Name& dataName, const Name& signerName)
61{
62 return (m_dataRegex->match(dataName) && m_signerRegex->match(signerName));
Yingdi Yu3715f8d2014-01-30 00:32:20 -080063}
Yingdi Yufc40d872014-02-18 12:56:04 -080064
65} // namespace ndn