Skip to content

Commit df5ddc8

Browse files
authored
Merge pull request #33 from tianyuan129/master
add token checking before processing DKEY request
2 parents 30a93b6 + 7e098e1 commit df5ddc8

File tree

2 files changed

+45
-12
lines changed

2 files changed

+45
-12
lines changed

src/attribute-authority.cpp

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,19 @@ AttributeAuthority::AttributeAuthority(const security::Certificate& identityCert
5252
NDN_THROW(std::runtime_error("Unsupported ABE type: " + m_abeType));
5353
}
5454

55-
// prefix registrationexport NDN_LOG="nacabe.*=TRACE:ndn.security.Validator=DEBUG"
55+
// prefix registration
5656
m_registeredPrefix = m_face.registerPrefix(m_cert.getIdentity(),
5757
[this] (const Name& name) {
5858
NDN_LOG_TRACE("Prefix " << name << " registered successfully");
5959

6060
// public parameters filter
6161
auto hdl1 = m_face.setInterestFilter(Name(name).append(PUBLIC_PARAMS),
62-
std::bind(&CpAttributeAuthority::onPublicParamsRequest, this, _2));
62+
std::bind(&AttributeAuthority::onPublicParamsRequest, this, _2));
6363
m_interestFilters.emplace_back(hdl1);
6464
NDN_LOG_TRACE("InterestFilter " << Name(name).append(PUBLIC_PARAMS) << " set");
6565

6666
// decryption key filter
67-
auto hdl2 = m_face.setInterestFilter(Name(name).append(DECRYPT_KEY),
68-
std::bind(&CpAttributeAuthority::onDecryptionKeyRequest, this, _2));
69-
m_interestFilters.emplace_back(hdl2);
70-
NDN_LOG_TRACE("InterestFilter " << Name(name).append(DECRYPT_KEY) << " set");
67+
// this filter registration has been moved to the children constructors.
7168
},
7269
[] (const Name&, const auto& reason) {
7370
NDN_LOG_ERROR("Failed to register prefix: " << reason);
@@ -82,8 +79,6 @@ AttributeAuthority::onDecryptionKeyRequest(const Interest& request)
8279
// naming1: /AA-prefix/DKEY/<key name block>
8380
// naming2: /AA-prefix/DKEY/<key name block>/<version>/<segment>
8481
Name requestName = request.getName();
85-
NDN_LOG_INFO("Got DKEY request: " << requestName);
86-
8782
Name supposedKeyName(request.getName().at(m_cert.getIdentity().size() + 1).blockFromValue());
8883
if (requestName.at(-1).isSegment() && requestName.at(-2).isVersion()) {
8984
NDN_LOG_DEBUG("For DKEY segment --------> " << requestName);
@@ -99,7 +94,7 @@ AttributeAuthority::onDecryptionKeyRequest(const Interest& request)
9994
else if (security::isValidKeyName(supposedKeyName)) {
10095
NDN_LOG_DEBUG("KeyName --------> " << supposedKeyName);
10196
Name identityName = security::extractIdentityFromKeyName(supposedKeyName);
102-
// verify request and generate token
97+
// fetch corresponding certificate
10398
auto optionalCert = m_trustConfig.findCertificateFromLocal(supposedKeyName);
10499
if (optionalCert) {
105100
NDN_LOG_INFO("Found local certificate for " << supposedKeyName << ", bypass certificate fetching...");
@@ -168,6 +163,9 @@ CpAttributeAuthority::CpAttributeAuthority(const security::Certificate& identity
168163
security::Validator& validator, KeyChain& keyChain)
169164
: AttributeAuthority(identityCert, face, validator, keyChain, ABE_TYPE_CP_ABE)
170165
{
166+
// decryption key filter
167+
m_face.setInterestFilter(Name(m_cert.getIdentity()).append(DECRYPT_KEY),
168+
std::bind(&CpAttributeAuthority::onDecryptionKeyRequest, this, _2));
171169
}
172170

173171
void
@@ -195,11 +193,27 @@ CpAttributeAuthority::getPrivateKey(Name identityName)
195193
return algo::ABESupport::getInstance().cpPrvKeyGen(m_pubParams, m_masterKey, attrs);
196194
}
197195

196+
void
197+
CpAttributeAuthority::onDecryptionKeyRequest(const Interest& request)
198+
{
199+
Name requestName = request.getName();
200+
NDN_LOG_INFO("CpAA Got DKEY request: " << requestName);
201+
202+
Name supposedKeyName(request.getName().at(m_cert.getIdentity().size() + 1).blockFromValue());
203+
Name identityName = security::extractIdentityFromKeyName(supposedKeyName);
204+
if (m_tokens.find(identityName) != m_tokens.end()) {
205+
AttributeAuthority::onDecryptionKeyRequest(request);
206+
}
207+
}
208+
198209
KpAttributeAuthority::KpAttributeAuthority(const security::Certificate& identityCert, Face& face,
199210
security::Validator& validator, KeyChain& keyChain,
200211
size_t maxSegmentSize)
201212
: AttributeAuthority(identityCert, face, validator, keyChain, ABE_TYPE_KP_ABE, maxSegmentSize)
202213
{
214+
// decryption key filter
215+
m_face.setInterestFilter(Name(m_cert.getIdentity()).append(DECRYPT_KEY),
216+
std::bind(&KpAttributeAuthority::onDecryptionKeyRequest, this, _2));
203217
}
204218

205219
void
@@ -224,5 +238,18 @@ KpAttributeAuthority::getPrivateKey(Name identityName)
224238
return algo::ABESupport::getInstance().kpPrvKeyGen(m_pubParams, m_masterKey, policy);
225239
}
226240

241+
void
242+
KpAttributeAuthority::onDecryptionKeyRequest(const Interest& request)
243+
{
244+
Name requestName = request.getName();
245+
NDN_LOG_INFO("KpAA Got DKEY request: " << requestName);
246+
247+
Name supposedKeyName(request.getName().at(m_cert.getIdentity().size() + 1).blockFromValue());
248+
Name identityName = security::extractIdentityFromKeyName(supposedKeyName);
249+
if (m_tokens.find(identityName) != m_tokens.end()) {
250+
AttributeAuthority::onDecryptionKeyRequest(request);
251+
}
252+
}
253+
227254
} // namespace nacabe
228255
} // namespace ndn

src/attribute-authority.hpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ class AttributeAuthority : noncopyable
5252
SPtrVector<Data>
5353
generateDecryptionKeySegments(const Name& objName, const security::Certificate& cert);
5454

55-
void
56-
onDecryptionKeyRequest(const Interest& interest);
57-
5855
void
5956
onPublicParamsRequest(const Interest& interest);
6057

6158
protected:
59+
void
60+
onDecryptionKeyRequest(const Interest& interest);
61+
6262
security::Certificate m_cert;
6363
Face& m_face;
6464
KeyChain& m_keyChain;
@@ -110,6 +110,9 @@ class CpAttributeAuthority: public AttributeAuthority
110110
getPrivateKey(Name identityName) override;
111111

112112
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
113+
void
114+
onDecryptionKeyRequest(const Interest& interest);
115+
113116
std::map<Name/* Consumer Identity */, std::list<std::string>/* Attr */> m_tokens;
114117
};
115118

@@ -146,6 +149,9 @@ class KpAttributeAuthority: public AttributeAuthority
146149
getPrivateKey(Name identityName) override;
147150

148151
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
152+
void
153+
onDecryptionKeyRequest(const Interest& interest);
154+
149155
std::map<Name/* Consumer Identity */, Policy> m_tokens;
150156
};
151157

0 commit comments

Comments
 (0)