Jeff Thompson | 3f3cfd3 | 2013-09-27 11:46:52 -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 | * @author: Yingdi Yu <yingdi@cs.ucla.edu> |
| 5 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
| 6 | * See COPYING for copyright and distribution information. |
| 7 | */ |
| 8 | |
Yingdi Yu | 4f32463 | 2014-01-15 18:10:03 -0800 | [diff] [blame] | 9 | #ifndef NDN_SEC_POLICY_HPP |
| 10 | #define NDN_SEC_POLICY_HPP |
Jeff Thompson | 3f3cfd3 | 2013-09-27 11:46:52 -0700 | [diff] [blame] | 11 | |
Yingdi Yu | 4f32463 | 2014-01-15 18:10:03 -0800 | [diff] [blame] | 12 | #include "../data.hpp" |
Yingdi Yu | e07e339 | 2014-01-28 10:29:27 -0800 | [diff] [blame] | 13 | #include "verifier.hpp" |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 14 | #include "validation-request.hpp" |
Jeff Thompson | 3f3cfd3 | 2013-09-27 11:46:52 -0700 | [diff] [blame] | 15 | |
| 16 | namespace ndn { |
Jeff Thompson | 3f3cfd3 | 2013-09-27 11:46:52 -0700 | [diff] [blame] | 17 | |
| 18 | /** |
Yingdi Yu | 4f32463 | 2014-01-15 18:10:03 -0800 | [diff] [blame] | 19 | * A SecPolicy is an abstract base class to represent the policy for verifying data packets. |
Jeff Thompson | 3f3cfd3 | 2013-09-27 11:46:52 -0700 | [diff] [blame] | 20 | * You must create an object of a subclass. |
| 21 | */ |
Yingdi Yu | 4f32463 | 2014-01-15 18:10:03 -0800 | [diff] [blame] | 22 | class SecPolicy { |
Jeff Thompson | 3f3cfd3 | 2013-09-27 11:46:52 -0700 | [diff] [blame] | 23 | public: |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 24 | struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} }; |
| 25 | |
Jeff Thompson | 3f3cfd3 | 2013-09-27 11:46:52 -0700 | [diff] [blame] | 26 | /** |
| 27 | * The virtual destructor. |
| 28 | */ |
| 29 | virtual |
Yingdi Yu | 4f32463 | 2014-01-15 18:10:03 -0800 | [diff] [blame] | 30 | ~SecPolicy() {} |
Jeff Thompson | 3f3cfd3 | 2013-09-27 11:46:52 -0700 | [diff] [blame] | 31 | |
| 32 | /** |
Jeff Thompson | 3f3cfd3 | 2013-09-27 11:46:52 -0700 | [diff] [blame] | 33 | * Check whether the received data packet complies with the verification policy, and get the indication of the next verification step. |
Yingdi Yu | e07e339 | 2014-01-28 10:29:27 -0800 | [diff] [blame] | 34 | * If there is no next verification step, that imlies policy MUST have already made the verification decision. |
| 35 | * i.e., either onVerified or onVerifyFailed callback is invoked. |
Jeff Thompson | 3f3cfd3 | 2013-09-27 11:46:52 -0700 | [diff] [blame] | 36 | * @param data The Data object with the signature to check. |
| 37 | * @param stepCount The number of verification steps that have been done, used to track the verification progress. |
| 38 | * @param onVerified If the signature is verified, this calls onVerified(data). |
| 39 | * @param onVerifyFailed If the signature check fails, this calls onVerifyFailed(data). |
| 40 | * @return the indication of next verification step, null if there is no further step. |
| 41 | */ |
| 42 | virtual ptr_lib::shared_ptr<ValidationRequest> |
| 43 | checkVerificationPolicy |
Yingdi Yu | 4270f20 | 2014-01-28 14:19:16 -0800 | [diff] [blame] | 44 | (const ptr_lib::shared_ptr<const Data>& data, int stepCount, const OnVerified& onVerified, const OnVerifyFailed& onVerifyFailed) |
Yingdi Yu | e07e339 | 2014-01-28 10:29:27 -0800 | [diff] [blame] | 45 | { |
| 46 | onVerifyFailed(); |
| 47 | return ptr_lib::shared_ptr<ValidationRequest>(); |
| 48 | } |
| 49 | |
Jeff Thompson | 3f3cfd3 | 2013-09-27 11:46:52 -0700 | [diff] [blame] | 50 | /** |
Yingdi Yu | e07e339 | 2014-01-28 10:29:27 -0800 | [diff] [blame] | 51 | * Check whether the received interest packet complies with the verification policy, and get the indication of the next verification step. |
| 52 | * If there is no next verification step, that implies policy MUST have already made the verification decision. |
| 53 | * i.e., either onVerified or onVerifyFailed callback is invoked. |
| 54 | * @param data The Data object with the signature to check. |
| 55 | * @param stepCount The number of verification steps that have been done, used to track the verification progress. |
| 56 | * @param onVerified If the signature is verified, this calls onVerified(data). |
| 57 | * @param onVerifyFailed If the signature check fails, this calls onVerifyFailed(data). |
| 58 | * @return the indication of next verification step, null if there is no further step. |
Jeff Thompson | 3f3cfd3 | 2013-09-27 11:46:52 -0700 | [diff] [blame] | 59 | */ |
Yingdi Yu | e07e339 | 2014-01-28 10:29:27 -0800 | [diff] [blame] | 60 | virtual ptr_lib::shared_ptr<ValidationRequest> |
| 61 | checkVerificationPolicy |
Yingdi Yu | 4270f20 | 2014-01-28 14:19:16 -0800 | [diff] [blame] | 62 | (const ptr_lib::shared_ptr<const Interest>& interest, int stepCount, const OnVerified& onVerified, const OnVerifyFailed& onVerifyFailed) |
Yingdi Yu | e07e339 | 2014-01-28 10:29:27 -0800 | [diff] [blame] | 63 | { |
| 64 | onVerifyFailed(); |
| 65 | return ptr_lib::shared_ptr<ValidationRequest>(); |
| 66 | } |
Jeff Thompson | 3f3cfd3 | 2013-09-27 11:46:52 -0700 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | } |
| 70 | |
| 71 | #endif |