Yingdi Yu | 3715f8d | 2014-01-30 00:32:20 -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 | |
Alexander Afanasyev | e2dcdfd | 2014-02-07 15:53:28 -0800 | [diff] [blame] | 8 | #include "common.hpp" |
| 9 | |
Yingdi Yu | 3715f8d | 2014-01-30 00:32:20 -0800 | [diff] [blame] | 10 | #include "sec-rule-specific.hpp" |
| 11 | #include "signature-sha256-with-rsa.hpp" |
| 12 | |
Yingdi Yu | 3715f8d | 2014-01-30 00:32:20 -0800 | [diff] [blame] | 13 | using namespace std; |
| 14 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 15 | namespace ndn { |
Yingdi Yu | 3715f8d | 2014-01-30 00:32:20 -0800 | [diff] [blame] | 16 | |
| 17 | SecRuleSpecific::SecRuleSpecific(shared_ptr<Regex> dataRegex, |
| 18 | shared_ptr<Regex> signerRegex) |
| 19 | : SecRule(true) |
| 20 | , m_dataRegex(dataRegex) |
| 21 | , m_signerRegex(signerRegex) |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 22 | { |
| 23 | } |
Yingdi Yu | 3715f8d | 2014-01-30 00:32:20 -0800 | [diff] [blame] | 24 | |
| 25 | SecRuleSpecific::SecRuleSpecific(const SecRuleSpecific& rule) |
| 26 | : SecRule(true) |
| 27 | , m_dataRegex(rule.m_dataRegex) |
| 28 | , m_signerRegex(rule.m_signerRegex) |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 29 | { |
| 30 | } |
Yingdi Yu | 3715f8d | 2014-01-30 00:32:20 -0800 | [diff] [blame] | 31 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 32 | bool |
Yingdi Yu | 3715f8d | 2014-01-30 00:32:20 -0800 | [diff] [blame] | 33 | SecRuleSpecific::matchDataName(const Data& data) |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 34 | { |
| 35 | return m_dataRegex->match(data.getName()); |
| 36 | } |
Yingdi Yu | 3715f8d | 2014-01-30 00:32:20 -0800 | [diff] [blame] | 37 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 38 | bool |
Yingdi Yu | 3715f8d | 2014-01-30 00:32:20 -0800 | [diff] [blame] | 39 | SecRuleSpecific::matchSignerName(const Data& data) |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 40 | { |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 41 | 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 Yu | 3715f8d | 2014-01-30 00:32:20 -0800 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | bool |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 54 | SecRuleSpecific::satisfy(const Data& data) |
| 55 | { |
| 56 | return (matchDataName(data) && matchSignerName(data)) ? true : false; |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 57 | } |
Yingdi Yu | 3715f8d | 2014-01-30 00:32:20 -0800 | [diff] [blame] | 58 | |
| 59 | bool |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 60 | SecRuleSpecific::satisfy(const Name& dataName, const Name& signerName) |
| 61 | { |
| 62 | return (m_dataRegex->match(dataName) && m_signerRegex->match(signerName)); |
Yingdi Yu | 3715f8d | 2014-01-30 00:32:20 -0800 | [diff] [blame] | 63 | } |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 64 | |
| 65 | } // namespace ndn |