blob: 0682927167ba4673100ed958b5bbeb619fff4c61 [file] [log] [blame]
Yingdi Yu2abd73f2014-01-08 23:34:11 -08001/* -*- 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
9#ifndef NDN_VERIFIER_HPP
10#define NDN_VERIFIER_HPP
11
12#include "../data.hpp"
13#include "../face.hpp"
14#include "policy/validation-request.hpp"
15#include "certificate/public-key.hpp"
16#include "signature/signature-sha256-with-rsa.hpp"
17
18namespace ndn {
19
20class PolicyManager;
21
22/**
23 * Verifier is one of the main classes of the security librar .
24 *
25 * The Verifier class provides the interfaces for packet verification.
26 */
27class Verifier {
28public:
29 struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} };
30
31 Verifier(const ptr_lib::shared_ptr<PolicyManager> &policyManager = DefaultPolicyManager);
32
33 /**
34 * @brief Set the Face which will be used to fetch required certificates.
35 * @param face A pointer to the Face object.
36 *
37 * Setting face is necessary for verifier operation that involve fetching data.
38 */
39 void
40 setFace(const ptr_lib::shared_ptr<Face> &face) { face_ = face; }
41
42 /**
43 * @brief Get the policyManager.
44 * @return The PolicyManager.
45 */
46 inline PolicyManager&
47 policies()
48 {
49 if (!policyManager_)
50 throw Error("PolicyManager is not assigned to the KeyChain");
51
52 return *policyManager_;
53 }
54
55
56 /**
57 * Check the signature on the Data object and call either onVerify or onVerifyFailed.
58 * We use callback functions because verify may fetch information to check the signature.
59 * @param data The Data object with the signature to check. It is an error if data does not have a wireEncoding.
60 * To set the wireEncoding, you can call data.wireDecode.
61 * @param onVerified If the signature is verified, this calls onVerified(data).
62 * @param onVerifyFailed If the signature check fails, this calls onVerifyFailed(data).
63 */
64 void
65 verifyData
66 (const ptr_lib::shared_ptr<Data>& data, const OnVerified& onVerified, const OnVerifyFailed& onVerifyFailed, int stepCount = 0);
67
68 /*****************************************
69 * verifySignature method set *
70 *****************************************/
71 static bool
72 verifySignature(const Data& data, const SignatureSha256WithRsa& sig, const PublicKey& publicKey);
73
74
75public:
76 static const ptr_lib::shared_ptr<PolicyManager> DefaultPolicyManager;
77
78private:
79 void
80 onCertificateData
81 (const ptr_lib::shared_ptr<const Interest> &interest, const ptr_lib::shared_ptr<Data> &data, ptr_lib::shared_ptr<ValidationRequest> nextStep);
82
83 void
84 onCertificateInterestTimeout
85 (const ptr_lib::shared_ptr<const Interest> &interest, int retry, const OnVerifyFailed& onVerifyFailed,
86 const ptr_lib::shared_ptr<Data> &data, ptr_lib::shared_ptr<ValidationRequest> nextStep);
87
88private:
89 ptr_lib::shared_ptr<PolicyManager> policyManager_;
90 ptr_lib::shared_ptr<Face> face_;
91};
92
93}
94
95#endif