blob: b62b6a830962411b318640f6f63d128a6fa48c81 [file] [log] [blame]
Yingdi Yu06202d32013-10-26 15:08:37 -07001/* -*- 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 Yu93adb1a2014-01-16 10:30:26 -080011#include "sec-rule-chrono-chat.h"
12#include <ndn-cpp/security/signature-sha256-with-rsa.hpp>
Yingdi Yu06202d32013-10-26 15:08:37 -070013
14using namespace ndn;
15using namespace std;
Yingdi Yu76dd8002013-12-24 11:16:32 +080016using namespace ndn::ptr_lib;
Yingdi Yu06202d32013-10-26 15:08:37 -070017
18
Yingdi Yu93adb1a2014-01-16 10:30:26 -080019SecRuleChronoChat::SecRuleChronoChat(shared_ptr<Regex> dataRegex,
20 shared_ptr<Regex> signerRegex)
21 : SecRule(SecRule::IDENTITY_RULE, true)
Yingdi Yu06202d32013-10-26 15:08:37 -070022 , m_dataRegex(dataRegex)
23 , m_signerRegex(signerRegex)
Yingdi Yu7989eb22013-10-31 17:38:22 -070024{}
25
Yingdi Yu93adb1a2014-01-16 10:30:26 -080026SecRuleChronoChat::SecRuleChronoChat(const SecRuleChronoChat& rule)
27 : SecRule(SecRule::IDENTITY_RULE, true)
Yingdi Yu7989eb22013-10-31 17:38:22 -070028 , m_dataRegex(rule.m_dataRegex)
29 , m_signerRegex(rule.m_signerRegex)
Yingdi Yu06202d32013-10-26 15:08:37 -070030{}
31
32bool
Yingdi Yu93adb1a2014-01-16 10:30:26 -080033SecRuleChronoChat::matchDataName(const Data & data)
Yingdi Yu7989eb22013-10-31 17:38:22 -070034{ return m_dataRegex->match(data.getName()); }
Yingdi Yu06202d32013-10-26 15:08:37 -070035
36bool
Yingdi Yu93adb1a2014-01-16 10:30:26 -080037SecRuleChronoChat::matchSignerName(const Data & data)
Yingdi Yu06202d32013-10-26 15:08:37 -070038{
Yingdi Yuf8f572d2014-01-13 11:19:47 -080039 try{
40 SignatureSha256WithRsa sig(data.getSignature());
41 Name signerName = sig.getKeyLocator().getName ();
42 return m_signerRegex->match(signerName);
43 }catch(SignatureSha256WithRsa::Error &e){
Yingdi Yue35bdb82013-11-07 11:32:40 -080044 return false;
Yingdi Yuf8f572d2014-01-13 11:19:47 -080045 }catch(KeyLocator::Error &e){
Yingdi Yue35bdb82013-11-07 11:32:40 -080046 return false;
Yingdi Yuf8f572d2014-01-13 11:19:47 -080047 }
Yingdi Yu06202d32013-10-26 15:08:37 -070048}
49
50bool
Yingdi Yu93adb1a2014-01-16 10:30:26 -080051SecRuleChronoChat::satisfy(const Data & data)
Yingdi Yu06202d32013-10-26 15:08:37 -070052{ return (matchDataName(data) && matchSignerName(data)) ? true : false ; }
53
54bool
Yingdi Yu93adb1a2014-01-16 10:30:26 -080055SecRuleChronoChat::satisfy(const Name & dataName, const Name & signerName)
Yingdi Yu7989eb22013-10-31 17:38:22 -070056{ return (m_dataRegex->match(dataName) && m_signerRegex->match(signerName)); }