Yingdi Yu | 06202d3 | 2013-10-26 15:08:37 -0700 | [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 | * Yingdi Yu |
| 5 | * |
| 6 | * BSD license, See the LICENSE file for more information |
| 7 | * |
| 8 | * Author: Yingdi Yu <yingdi@cs.ucla.edu> |
| 9 | */ |
| 10 | |
Yingdi Yu | 93adb1a | 2014-01-16 10:30:26 -0800 | [diff] [blame^] | 11 | #include "sec-rule-chrono-chat.h" |
| 12 | #include <ndn-cpp/security/signature-sha256-with-rsa.hpp> |
Yingdi Yu | 06202d3 | 2013-10-26 15:08:37 -0700 | [diff] [blame] | 13 | |
| 14 | using namespace ndn; |
| 15 | using namespace std; |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 16 | using namespace ndn::ptr_lib; |
Yingdi Yu | 06202d3 | 2013-10-26 15:08:37 -0700 | [diff] [blame] | 17 | |
| 18 | |
Yingdi Yu | 93adb1a | 2014-01-16 10:30:26 -0800 | [diff] [blame^] | 19 | SecRuleChronoChat::SecRuleChronoChat(shared_ptr<Regex> dataRegex, |
| 20 | shared_ptr<Regex> signerRegex) |
| 21 | : SecRule(SecRule::IDENTITY_RULE, true) |
Yingdi Yu | 06202d3 | 2013-10-26 15:08:37 -0700 | [diff] [blame] | 22 | , m_dataRegex(dataRegex) |
| 23 | , m_signerRegex(signerRegex) |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 24 | {} |
| 25 | |
Yingdi Yu | 93adb1a | 2014-01-16 10:30:26 -0800 | [diff] [blame^] | 26 | SecRuleChronoChat::SecRuleChronoChat(const SecRuleChronoChat& rule) |
| 27 | : SecRule(SecRule::IDENTITY_RULE, true) |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 28 | , m_dataRegex(rule.m_dataRegex) |
| 29 | , m_signerRegex(rule.m_signerRegex) |
Yingdi Yu | 06202d3 | 2013-10-26 15:08:37 -0700 | [diff] [blame] | 30 | {} |
| 31 | |
| 32 | bool |
Yingdi Yu | 93adb1a | 2014-01-16 10:30:26 -0800 | [diff] [blame^] | 33 | SecRuleChronoChat::matchDataName(const Data & data) |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 34 | { return m_dataRegex->match(data.getName()); } |
Yingdi Yu | 06202d3 | 2013-10-26 15:08:37 -0700 | [diff] [blame] | 35 | |
| 36 | bool |
Yingdi Yu | 93adb1a | 2014-01-16 10:30:26 -0800 | [diff] [blame^] | 37 | SecRuleChronoChat::matchSignerName(const Data & data) |
Yingdi Yu | 06202d3 | 2013-10-26 15:08:37 -0700 | [diff] [blame] | 38 | { |
Yingdi Yu | f8f572d | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 39 | try{ |
| 40 | SignatureSha256WithRsa sig(data.getSignature()); |
| 41 | Name signerName = sig.getKeyLocator().getName (); |
| 42 | return m_signerRegex->match(signerName); |
| 43 | }catch(SignatureSha256WithRsa::Error &e){ |
Yingdi Yu | e35bdb8 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 44 | return false; |
Yingdi Yu | f8f572d | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 45 | }catch(KeyLocator::Error &e){ |
Yingdi Yu | e35bdb8 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 46 | return false; |
Yingdi Yu | f8f572d | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 47 | } |
Yingdi Yu | 06202d3 | 2013-10-26 15:08:37 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | bool |
Yingdi Yu | 93adb1a | 2014-01-16 10:30:26 -0800 | [diff] [blame^] | 51 | SecRuleChronoChat::satisfy(const Data & data) |
Yingdi Yu | 06202d3 | 2013-10-26 15:08:37 -0700 | [diff] [blame] | 52 | { return (matchDataName(data) && matchSignerName(data)) ? true : false ; } |
| 53 | |
| 54 | bool |
Yingdi Yu | 93adb1a | 2014-01-16 10:30:26 -0800 | [diff] [blame^] | 55 | SecRuleChronoChat::satisfy(const Name & dataName, const Name & signerName) |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 56 | { return (m_dataRegex->match(dataName) && m_signerRegex->match(signerName)); } |