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 | |
| 13 | using namespace ndn; |
| 14 | using namespace std; |
| 15 | |
| 16 | namespace ndn{ |
| 17 | |
| 18 | SecRuleSpecific::SecRuleSpecific(shared_ptr<Regex> dataRegex, |
| 19 | shared_ptr<Regex> signerRegex) |
| 20 | : SecRule(true) |
| 21 | , m_dataRegex(dataRegex) |
| 22 | , m_signerRegex(signerRegex) |
| 23 | {} |
| 24 | |
| 25 | SecRuleSpecific::SecRuleSpecific(const SecRuleSpecific& rule) |
| 26 | : SecRule(true) |
| 27 | , m_dataRegex(rule.m_dataRegex) |
| 28 | , m_signerRegex(rule.m_signerRegex) |
| 29 | {} |
| 30 | |
| 31 | bool |
| 32 | SecRuleSpecific::matchDataName(const Data& data) |
| 33 | { return m_dataRegex->match(data.getName()); } |
| 34 | |
| 35 | bool |
| 36 | SecRuleSpecific::matchSignerName(const Data& data) |
| 37 | { |
| 38 | try{ |
| 39 | SignatureSha256WithRsa sig(data.getSignature()); |
| 40 | Name signerName = sig.getKeyLocator().getName (); |
| 41 | return m_signerRegex->match(signerName); |
| 42 | }catch(SignatureSha256WithRsa::Error &e){ |
| 43 | return false; |
| 44 | }catch(KeyLocator::Error &e){ |
| 45 | return false; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | bool |
| 50 | SecRuleSpecific::satisfy(const Data & data) |
| 51 | { return (matchDataName(data) && matchSignerName(data)) ? true : false ; } |
| 52 | |
| 53 | bool |
| 54 | SecRuleSpecific::satisfy(const Name & dataName, const Name & signerName) |
| 55 | { return (m_dataRegex->match(dataName) && m_signerRegex->match(signerName)); } |
| 56 | |
| 57 | } |