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