blob: a9fee4e92889c55c9fedadf0e424e02f30980bad [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)
22{}
23
24SecRuleSpecific::SecRuleSpecific(const SecRuleSpecific& rule)
25 : SecRule(true)
26 , m_dataRegex(rule.m_dataRegex)
27 , m_signerRegex(rule.m_signerRegex)
28{}
29
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070030bool
Yingdi Yu3715f8d2014-01-30 00:32:20 -080031SecRuleSpecific::matchDataName(const Data& data)
32{ return m_dataRegex->match(data.getName()); }
33
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070034bool
Yingdi Yu3715f8d2014-01-30 00:32:20 -080035SecRuleSpecific::matchSignerName(const Data& data)
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070036{
37 try {
Yingdi Yu3715f8d2014-01-30 00:32:20 -080038 SignatureSha256WithRsa sig(data.getSignature());
39 Name signerName = sig.getKeyLocator().getName ();
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070040 return m_signerRegex->match(signerName);
41 }
42 catch (SignatureSha256WithRsa::Error& e) {
Yingdi Yu3715f8d2014-01-30 00:32:20 -080043 return false;
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070044 }
45 catch (KeyLocator::Error& e) {
Yingdi Yu3715f8d2014-01-30 00:32:20 -080046 return false;
47 }
48}
49
50bool
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070051SecRuleSpecific::satisfy(const Data& data)
52{
53 return (matchDataName(data) && matchSignerName(data)) ? true : false;
Yingdi Yufc40d872014-02-18 12:56:04 -080054}
Yingdi Yu3715f8d2014-01-30 00:32:20 -080055
56bool
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070057SecRuleSpecific::satisfy(const Name& dataName, const Name& signerName)
58{
59 return (m_dataRegex->match(dataName) && m_signerRegex->match(signerName));
Yingdi Yu3715f8d2014-01-30 00:32:20 -080060}
Yingdi Yufc40d872014-02-18 12:56:04 -080061
62} // namespace ndn