1#ifndef SECURITY_ACCESS_H
2#define SECURITY_ACCESS_H
4#include "./reentrancy.h"
5#include "./routing/delay_timer.h"
6#include "./routing/routable_uds_service.h"
40 static const uint8_t cSid{0x27};
41 static const uint16_t cInitialSeed{1};
43 const size_t cSidIndex{0};
44 const size_t cSubFunctionIndex{1};
45 const size_t cDataRecordOffset{2};
46 const size_t cKeyLength{2};
48 const uint8_t cSuppressPosRspMask{0x80};
49 const uint8_t cGeneralReject{0x10};
50 const uint8_t cInvalidKey{0x35};
51 const uint8_t cExceededNumberOfAttempts{0x36};
53 const uint8_t cIsoReservedSubFunction{0x00};
54 const uint8_t cIsoReservedLBound{0x43};
55 const uint8_t cIsoReservedHBound{0x5e};
56 const uint8_t cSupplierReservedLBound{0x61};
57 const uint8_t cSupplierReservedHBound{0x7f};
59 const std::string cEncryptorKey{
"Encryptor"};
60 const std::string cAttemptThresholdKey{
"AttemptThreshold"};
61 const std::string cExceededAttemptDelayKey{
"ExceededAttemptDelay"};
65 std::map<uint8_t, SecurityLevel> mSecurityLevels;
67 uint8_t mFailedUnlockAttempt;
70 const std::vector<uint8_t> &requestData, uint8_t &nrc)
const;
72 bool tryFetchSeed(uint8_t level, uint16_t &seed)
const;
73 uint16_t addLevel(uint8_t level);
74 void handleRequestSeed(
77 const std::vector<uint8_t> &securityAccessDataRecord,
80 bool suppressPositiveResponse);
82 void handlePassedAttempt(
83 std::map<uint8_t, SecurityLevel>::iterator securityLevelItr);
84 void handleFailedAttempt(
MetaInfo &metaInfo);
88 const std::vector<uint8_t> &key,
91 bool suppressPositiveResponse);
104 const std::vector<uint8_t> &requestData,
114 std::future<std::vector<uint8_t>>
GetSeed(
116 std::vector<uint8_t> securityAccessDataRecord,
128 std::vector<uint8_t> key,
AUTOSAR shortname-path wrapper.
Definition: instance_specifier.h:14
A wrapper class around a conversation cancellation handler callback.
Definition: cancellation_handler.h:12
A class to evaluate the security access to the data among diagnostic services.
Definition: security_access.h:38
SecurityAccess(const core::InstanceSpecifier &specifier, ReentrancyType reentrancyType) noexcept
Constructor.
Definition: security_access.cpp:10
std::future< std::vector< uint8_t > > GetSeed(uint8_t subFunction, std::vector< uint8_t > securityAccessDataRecord, MetaInfo &metaInfo, CancellationHandler &&cancellationHandler)
Request a seed from the client side to provide a security key.
Definition: security_access.cpp:188
std::future< KeyCompareResultType > CompareKey(uint8_t subFunction, std::vector< uint8_t > key, MetaInfo &metaInfo, CancellationHandler &&cancellationHandler)
Evaluate the key provided by a client.
Definition: security_access.cpp:316
std::future< OperationOutput > HandleMessage(const std::vector< uint8_t > &requestData, MetaInfo &metaInfo, CancellationHandler &&cancellationHandler) override
Handle an UDS request message.
Definition: security_access.cpp:57
A thread-safe countdown timer running on a different thread.
Definition: delay_timer.h:15
An UDS service to handle a diagnostic request by offering itself to a router.
Definition: routable_uds_service.h:28
KeyCompareResultType
Security key comparison result.
Definition: security_access.h:30
@ kKeyValid
Valid security key.
@ kKeyInvalid
Invalid security key.
ReentrancyType
Reentrancy type of an instance.
Definition: reentrancy.h:12
Positive response of a handled UDS request.
Definition: routable_uds_service.h:17
A data model that contains the status of a security level.
Definition: security_access.h:15
bool Unlocked
Indicate whether the security level has been unlocked or not.
Definition: security_access.h:17
SecurityLevel(uint16_t seed=0) noexcept
Constructor.
Definition: security_access.h:23
uint16_t Seed
Seed that corresponds to the security level for key comparison.
Definition: security_access.h:19