Yingdi Yu | 3715f8d | 2014-01-30 00:32:20 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /** |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame^] | 3 | * Copyright (c) 2013-2014, Regents of the University of California. |
| 4 | * All rights reserved. |
| 5 | * |
| 6 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 7 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 8 | * |
| 9 | * This file licensed under New BSD License. See COPYING for detailed information about |
| 10 | * ndn-cxx library copyright, permissions, and redistribution restrictions. |
| 11 | * |
| 12 | * @author Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/> |
Yingdi Yu | 3715f8d | 2014-01-30 00:32:20 -0800 | [diff] [blame] | 13 | */ |
| 14 | |
Alexander Afanasyev | e2dcdfd | 2014-02-07 15:53:28 -0800 | [diff] [blame] | 15 | #include "common.hpp" |
| 16 | |
Yingdi Yu | 3715f8d | 2014-01-30 00:32:20 -0800 | [diff] [blame] | 17 | #include "sec-rule-specific.hpp" |
| 18 | #include "signature-sha256-with-rsa.hpp" |
| 19 | |
Yingdi Yu | 3715f8d | 2014-01-30 00:32:20 -0800 | [diff] [blame] | 20 | using namespace std; |
| 21 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 22 | namespace ndn { |
Yingdi Yu | 3715f8d | 2014-01-30 00:32:20 -0800 | [diff] [blame] | 23 | |
| 24 | SecRuleSpecific::SecRuleSpecific(shared_ptr<Regex> dataRegex, |
| 25 | shared_ptr<Regex> signerRegex) |
| 26 | : SecRule(true) |
| 27 | , m_dataRegex(dataRegex) |
| 28 | , m_signerRegex(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 | |
| 32 | SecRuleSpecific::SecRuleSpecific(const SecRuleSpecific& rule) |
| 33 | : SecRule(true) |
| 34 | , m_dataRegex(rule.m_dataRegex) |
| 35 | , m_signerRegex(rule.m_signerRegex) |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 36 | { |
| 37 | } |
Yingdi Yu | 3715f8d | 2014-01-30 00:32:20 -0800 | [diff] [blame] | 38 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 39 | bool |
Yingdi Yu | 3715f8d | 2014-01-30 00:32:20 -0800 | [diff] [blame] | 40 | SecRuleSpecific::matchDataName(const Data& data) |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 41 | { |
| 42 | return m_dataRegex->match(data.getName()); |
| 43 | } |
Yingdi Yu | 3715f8d | 2014-01-30 00:32:20 -0800 | [diff] [blame] | 44 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 45 | bool |
Yingdi Yu | 3715f8d | 2014-01-30 00:32:20 -0800 | [diff] [blame] | 46 | SecRuleSpecific::matchSignerName(const Data& data) |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 47 | { |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 48 | try |
| 49 | { |
| 50 | SignatureSha256WithRsa sig(data.getSignature()); |
| 51 | Name signerName = sig.getKeyLocator().getName(); |
| 52 | return m_signerRegex->match(signerName); |
| 53 | } |
| 54 | catch (std::runtime_error& e) |
| 55 | { |
| 56 | return false; |
| 57 | } |
Yingdi Yu | 3715f8d | 2014-01-30 00:32:20 -0800 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | bool |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 61 | SecRuleSpecific::satisfy(const Data& data) |
| 62 | { |
| 63 | return (matchDataName(data) && matchSignerName(data)) ? true : false; |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 64 | } |
Yingdi Yu | 3715f8d | 2014-01-30 00:32:20 -0800 | [diff] [blame] | 65 | |
| 66 | bool |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 67 | SecRuleSpecific::satisfy(const Name& dataName, const Name& signerName) |
| 68 | { |
| 69 | return (m_dataRegex->match(dataName) && m_signerRegex->match(signerName)); |
Yingdi Yu | 3715f8d | 2014-01-30 00:32:20 -0800 | [diff] [blame] | 70 | } |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 71 | |
| 72 | } // namespace ndn |