blob: 14da3c1a6250fa6296260729cff0f174499c4ebd [file] [log] [blame]
Jeff Thompson3a2eb2f2013-12-11 11:00:27 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
3 * Copyright (C) 2013 Regents of the University of California.
4 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
5 * See COPYING for copyright and distribution information.
6 */
7
8#ifndef NDN_SELF_VERIFY_POLICY_MANAGER_HPP
9#define NDN_SELF_VERIFY_POLICY_MANAGER_HPP
10
11#include "policy-manager.hpp"
12
13namespace ndn {
14
15class IdentityManager;
16
17/**
18 * A SelfVerifyPolicyManager implements a PolicyManager to use the public key DER in the data packet's KeyLocator (if available)
19 * or look in the IdentityStorage for the public key with the name in the KeyLocator (if available) and use
20 * it to verify the data packet, without searching a certificate chain. If the public key can't be found, the
21 * verification fails.
22 */
23class SelfVerifyPolicyManager : public PolicyManager {
24public:
25 /**
26 * Create a new SelfVerifyPolicyManager which will look up the public key in the given identityManager.
27 * @param identityManager (optional) The IdentityManager for looking up the public key. This points to an object must which remain
28 * valid during the life of this SelfVerifyPolicyManager. If omitted, then don't look for a public key with the name
29 * in the KeyLocator and rely on the KeyLocator having the full public key DER.
30 */
31 SelfVerifyPolicyManager(IdentityStorage* identityStorage = 0)
32 : identityStorage_(identityStorage)
33 {
34 }
35
36 /**
37 * The virtual destructor.
38 */
39 virtual
40 ~SelfVerifyPolicyManager();
41
42 /**
43 * Never skip verification.
44 * @param data The received data packet.
45 * @return false.
46 */
47 virtual bool
48 skipVerifyAndTrust(const Data& data);
49
50 /**
51 * Always return true to use the self-verification rule for the received data.
52 * @param data The received data packet.
53 * @return true.
54 */
55 virtual bool
56 requireVerify(const Data& data);
57
58 /**
59 * Use the public key DER in the data packet's KeyLocator (if available) or look in the IdentityStorage for the
60 * public key with the name in the KeyLocator (if available) and use it to verify the data packet. If the public key can't
61 * be found, call onVerifyFailed.
62 * @param data The Data object with the signature to check.
63 * @param stepCount The number of verification steps that have been done, used to track the verification progress.
64 * (stepCount is ignored.)
65 * @param onVerified If the signature is verified, this calls onVerified(data).
66 * @param onVerifyFailed If the signature check fails or can't find the public key, this calls onVerifyFailed(data).
67 * @return null for no further step for looking up a certificate chain.
68 */
69 virtual ptr_lib::shared_ptr<ValidationRequest>
70 checkVerificationPolicy
71 (const ptr_lib::shared_ptr<Data>& data, int stepCount, const OnVerified& onVerified, const OnVerifyFailed& onVerifyFailed);
72
73 /**
74 * Override to always indicate that the signing certificate name and data name satisfy the signing policy.
75 * @param dataName The name of data to be signed.
76 * @param certificateName The name of signing certificate.
77 * @return true to indicate that the signing certificate can be used to sign the data.
78 */
79 virtual bool
80 checkSigningPolicy(const Name& dataName, const Name& certificateName);
81
82 /**
83 * Override to indicate that the signing identity cannot be inferred.
84 * @param dataName The name of data to be signed.
85 * @return An empty name because cannot infer.
86 */
87 virtual Name
88 inferSigningIdentity(const Name& dataName);
89
90private:
91 IdentityStorage* identityStorage_;
92};
93
94}
95
96#endif