Skip to content

Commit

Permalink
Populate subject descriptor (in session handle) (#13003)
Browse files Browse the repository at this point in the history
* Populate subject descriptor

* Clean up draft

* Clarify TODO

* Add utility function to convert GroupId to NodeId

* Fix include
  • Loading branch information
mlepage-google authored and pull[bot] committed Jan 7, 2022
1 parent a3ffb9d commit 3350586
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/lib/core/NodeId.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

#pragma once

#include <lib/core/GroupId.h>

#include <cstdint>

namespace chip {
Expand Down Expand Up @@ -71,4 +73,9 @@ constexpr bool IsPAKEKeyId(NodeId aNodeId)
return (aNodeId >= kMinPAKEKeyId) && (aNodeId <= kMaxPAKEKeyId);
}

constexpr NodeId NodeIdFromGroupId(GroupId aGroupId)
{
return kMinGroupNodeId | aGroupId;
}

} // namespace chip
25 changes: 23 additions & 2 deletions src/transport/SessionHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,33 @@ namespace chip {

using namespace Transport;

using AuthMode = Access::AuthMode;
using SubjectDescriptor = Access::SubjectDescriptor;

SubjectDescriptor SessionHandle::GetSubjectDescriptor() const
{
SubjectDescriptor subjectDescriptor = { .fabricIndex = mFabric };
// TODO: fill subject descriptor with proper fields
SubjectDescriptor subjectDescriptor;
if (IsSecure())
{
if (IsOperationalNodeId(mPeerNodeId))
{
subjectDescriptor.authMode = AuthMode::kCase;
subjectDescriptor.subject = mPeerNodeId;
subjectDescriptor.fabricIndex = mFabric;
// TODO(#10243): add CATs
}
else if (IsPAKEKeyId(mPeerNodeId))
{
subjectDescriptor.authMode = AuthMode::kPase;
subjectDescriptor.subject = mPeerNodeId;
// TODO(#10242): PASE *can* have fabric in some situations
}
else if (mGroupId.HasValue())
{
subjectDescriptor.authMode = AuthMode::kGroup;
subjectDescriptor.subject = NodeIdFromGroupId(mGroupId.Value());
}
}
return subjectDescriptor;
}

Expand Down

0 comments on commit 3350586

Please sign in to comment.