Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 1 | #include "rakp12.hpp" |
| 2 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 3 | #include "comm_module.hpp" |
| 4 | #include "endian.hpp" |
| 5 | #include "guid.hpp" |
Vernon Mauery | 2085ae0 | 2021-06-10 11:51:00 -0700 | [diff] [blame] | 6 | #include "sessions_manager.hpp" |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 7 | |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 8 | #include <openssl/rand.h> |
| 9 | |
| 10 | #include <algorithm> |
Tom Joseph | 56527b9 | 2018-03-21 19:31:58 +0530 | [diff] [blame] | 11 | #include <cstring> |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 12 | #include <iomanip> |
Jayaprakash Mutyala | 05c1447 | 2020-10-19 10:26:24 +0000 | [diff] [blame^] | 13 | #include <ipmid/types.hpp> |
Vernon Mauery | fc37e59 | 2018-12-19 14:55:15 -0800 | [diff] [blame] | 14 | #include <phosphor-logging/log.hpp> |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 15 | |
Vernon Mauery | fc37e59 | 2018-12-19 14:55:15 -0800 | [diff] [blame] | 16 | using namespace phosphor::logging; |
| 17 | |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 18 | namespace command |
| 19 | { |
| 20 | |
AppaRao Puli | ecb32fb | 2020-07-01 22:55:38 +0530 | [diff] [blame] | 21 | bool isChannelAccessModeEnabled(const uint8_t accessMode) |
| 22 | { |
| 23 | return accessMode != |
| 24 | static_cast<uint8_t>(ipmi::EChannelAccessMode::disabled); |
| 25 | } |
| 26 | |
sunitakx | 0e0546f | 2021-06-15 08:57:10 +0000 | [diff] [blame] | 27 | void logInvalidLoginRedfishEvent(const std::string& journalMsg, |
| 28 | const std::optional<std::string>& messageArgs) |
| 29 | { |
| 30 | static constexpr std::string_view openBMCMessageRegistryVersion = "0.1."; |
| 31 | std::string messageID = "OpenBMC." + |
| 32 | std::string(openBMCMessageRegistryVersion) + |
| 33 | "InvalidLoginAttempted"; |
| 34 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 35 | journalMsg.c_str(), |
| 36 | phosphor::logging::entry("REDFISH_MESSAGE_ID=%s", messageID.c_str()), |
| 37 | phosphor::logging::entry("REDFISH_MESSAGE_ARGS=%s", |
| 38 | messageArgs.value().c_str())); |
| 39 | } |
Tom Joseph | 18a45e9 | 2017-04-11 11:30:44 +0530 | [diff] [blame] | 40 | std::vector<uint8_t> RAKP12(const std::vector<uint8_t>& inPayload, |
Vernon Mauery | 41ff9b5 | 2021-06-11 11:37:40 -0700 | [diff] [blame] | 41 | std::shared_ptr<message::Handler>& handler) |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 42 | { |
Tom Joseph | 18a45e9 | 2017-04-11 11:30:44 +0530 | [diff] [blame] | 43 | auto request = reinterpret_cast<const RAKP1request*>(inPayload.data()); |
Zhikui Ren | 2b1edef | 2020-07-24 14:32:13 -0700 | [diff] [blame] | 44 | // verify inPayload minimum size |
| 45 | if (inPayload.size() < (sizeof(*request) - userNameMaxLen)) |
| 46 | { |
| 47 | std::vector<uint8_t> errorPayload{IPMI_CC_REQ_DATA_LEN_INVALID}; |
| 48 | return errorPayload; |
| 49 | } |
| 50 | |
| 51 | std::vector<uint8_t> outPayload(sizeof(RAKP2response)); |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 52 | auto response = reinterpret_cast<RAKP2response*>(outPayload.data()); |
| 53 | |
| 54 | // Session ID zero is reserved for Session Setup |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 55 | if (endian::from_ipmi(request->managedSystemSessionID) == |
Suryakanth Sekar | f8a34fc | 2019-06-12 20:59:18 +0530 | [diff] [blame] | 56 | session::sessionZero) |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 57 | { |
Vernon Mauery | fc37e59 | 2018-12-19 14:55:15 -0800 | [diff] [blame] | 58 | log<level::INFO>("RAKP12: BMC invalid Session ID"); |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 59 | response->rmcpStatusCode = |
| 60 | static_cast<uint8_t>(RAKP_ReturnCode::INVALID_SESSION_ID); |
| 61 | return outPayload; |
| 62 | } |
| 63 | |
| 64 | std::shared_ptr<session::Session> session; |
| 65 | try |
| 66 | { |
Vernon Mauery | 2085ae0 | 2021-06-10 11:51:00 -0700 | [diff] [blame] | 67 | session = session::Manager::get().getSession( |
| 68 | endian::from_ipmi(request->managedSystemSessionID)); |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 69 | } |
| 70 | catch (std::exception& e) |
| 71 | { |
Vernon Mauery | fc37e59 | 2018-12-19 14:55:15 -0800 | [diff] [blame] | 72 | log<level::ERR>("RAKP12 : session not found", |
| 73 | entry("EXCEPTION=%s", e.what())); |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 74 | response->rmcpStatusCode = |
| 75 | static_cast<uint8_t>(RAKP_ReturnCode::INVALID_SESSION_ID); |
| 76 | return outPayload; |
| 77 | } |
| 78 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 79 | auto rakp1Size = |
| 80 | sizeof(RAKP1request) - (userNameMaxLen - request->user_name_len); |
Tom Joseph | 56527b9 | 2018-03-21 19:31:58 +0530 | [diff] [blame] | 81 | |
sunitakx | 0e0546f | 2021-06-15 08:57:10 +0000 | [diff] [blame] | 82 | std::string message = "Invalid login attempted via RCMPP interface "; |
Tom Joseph | 56527b9 | 2018-03-21 19:31:58 +0530 | [diff] [blame] | 83 | // Validate user name length in the message |
| 84 | if (request->user_name_len > userNameMaxLen || |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 85 | inPayload.size() != rakp1Size) |
Tom Joseph | 56527b9 | 2018-03-21 19:31:58 +0530 | [diff] [blame] | 86 | { |
| 87 | response->rmcpStatusCode = |
| 88 | static_cast<uint8_t>(RAKP_ReturnCode::INVALID_NAME_LENGTH); |
sunitakx | 0e0546f | 2021-06-15 08:57:10 +0000 | [diff] [blame] | 89 | logInvalidLoginRedfishEvent(message); |
Tom Joseph | 56527b9 | 2018-03-21 19:31:58 +0530 | [diff] [blame] | 90 | return outPayload; |
| 91 | } |
| 92 | |
| 93 | session->userName.assign(request->user_name, request->user_name_len); |
| 94 | |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 95 | // Update transaction time |
| 96 | session->updateLastTransactionTime(); |
| 97 | |
| 98 | auto rcSessionID = endian::to_ipmi(session->getRCSessionID()); |
| 99 | auto bmcSessionID = endian::to_ipmi(session->getBMCSessionID()); |
| 100 | auto authAlgo = session->getAuthAlgo(); |
| 101 | |
| 102 | /* |
| 103 | * Generate Key Authentication Code - RAKP 2 |
| 104 | * |
| 105 | * 1) Remote Console Session ID - 4 bytes |
| 106 | * 2) Managed System Session ID - 4 bytes |
| 107 | * 3) Remote Console Random Number - 16 bytes |
| 108 | * 4) Managed System Random Number - 16 bytes |
| 109 | * 5) Managed System GUID - 16 bytes |
| 110 | * 6) Requested Privilege Level - 1 byte |
| 111 | * 7) User Name Length Byte - 1 byte (0 for 'null' username) |
| 112 | * 8) User Name - variable (absent for 'null' username) |
| 113 | */ |
| 114 | |
| 115 | std::vector<uint8_t> input; |
| 116 | input.resize(sizeof(rcSessionID) + sizeof(bmcSessionID) + |
| 117 | cipher::rakp_auth::REMOTE_CONSOLE_RANDOM_NUMBER_LEN + |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 118 | cipher::rakp_auth::BMC_RANDOM_NUMBER_LEN + BMC_GUID_LEN + |
| 119 | sizeof(request->req_max_privilege_level) + |
| 120 | sizeof(request->user_name_len) + session->userName.size()); |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 121 | |
| 122 | auto iter = input.begin(); |
| 123 | |
| 124 | // Remote Console Session ID |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 125 | std::copy_n(reinterpret_cast<uint8_t*>(&rcSessionID), sizeof(rcSessionID), |
| 126 | iter); |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 127 | std::advance(iter, sizeof(rcSessionID)); |
| 128 | |
| 129 | // Managed System Session ID |
| 130 | std::copy_n(reinterpret_cast<uint8_t*>(&bmcSessionID), sizeof(bmcSessionID), |
| 131 | iter); |
| 132 | std::advance(iter, sizeof(bmcSessionID)); |
| 133 | |
| 134 | // Copy the Remote Console Random Number from the RAKP1 request to the |
| 135 | // Authentication Algorithm |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 136 | std::copy_n( |
| 137 | reinterpret_cast<const uint8_t*>(request->remote_console_random_number), |
| 138 | cipher::rakp_auth::REMOTE_CONSOLE_RANDOM_NUMBER_LEN, |
| 139 | authAlgo->rcRandomNum.begin()); |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 140 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 141 | std::copy(authAlgo->rcRandomNum.begin(), authAlgo->rcRandomNum.end(), iter); |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 142 | std::advance(iter, cipher::rakp_auth::REMOTE_CONSOLE_RANDOM_NUMBER_LEN); |
| 143 | |
| 144 | // Generate the Managed System Random Number |
| 145 | if (!RAND_bytes(input.data() + sizeof(rcSessionID) + sizeof(bmcSessionID) + |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 146 | cipher::rakp_auth::REMOTE_CONSOLE_RANDOM_NUMBER_LEN, |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 147 | cipher::rakp_auth::BMC_RANDOM_NUMBER_LEN)) |
| 148 | { |
| 149 | response->rmcpStatusCode = |
| 150 | static_cast<uint8_t>(RAKP_ReturnCode::INSUFFICIENT_RESOURCE); |
| 151 | return outPayload; |
| 152 | } |
Richard Marian Thomaiyar | d5a4f45 | 2019-01-16 12:15:44 +0530 | [diff] [blame] | 153 | // As stated in Set Session Privilege Level command in IPMI Spec, when |
jayaprakash Mutyala | 2555e2e | 2019-12-24 22:51:46 +0000 | [diff] [blame] | 154 | // creating a session through Activate command / RAKP 1 message, it must |
| 155 | // be established with USER privilege as well as all other sessions are |
| 156 | // initially set to USER privilege, regardless of the requested maximum |
| 157 | // privilege. |
| 158 | if (!(static_cast<session::Privilege>(request->req_max_privilege_level & |
| 159 | session::reqMaxPrivMask) > |
| 160 | session::Privilege::CALLBACK)) |
Richard Marian Thomaiyar | d5a4f45 | 2019-01-16 12:15:44 +0530 | [diff] [blame] | 161 | { |
jayaprakash Mutyala | 2555e2e | 2019-12-24 22:51:46 +0000 | [diff] [blame] | 162 | response->rmcpStatusCode = |
| 163 | static_cast<uint8_t>(RAKP_ReturnCode::UNAUTH_ROLE_PRIV); |
| 164 | return outPayload; |
Richard Marian Thomaiyar | d5a4f45 | 2019-01-16 12:15:44 +0530 | [diff] [blame] | 165 | } |
jayaprakash Mutyala | 2555e2e | 2019-12-24 22:51:46 +0000 | [diff] [blame] | 166 | session->currentPrivilege(static_cast<uint8_t>(session::Privilege::USER)); |
| 167 | |
Tom Joseph | 4021b1f | 2019-02-12 10:10:12 +0530 | [diff] [blame] | 168 | session->reqMaxPrivLevel = |
| 169 | static_cast<session::Privilege>(request->req_max_privilege_level); |
Richard Marian Thomaiyar | d91fd9d | 2018-12-06 12:03:50 +0530 | [diff] [blame] | 170 | if (request->user_name_len == 0) |
Richard Marian Thomaiyar | 127748a | 2018-09-06 07:08:51 +0530 | [diff] [blame] | 171 | { |
Richard Marian Thomaiyar | d91fd9d | 2018-12-06 12:03:50 +0530 | [diff] [blame] | 172 | // Bail out, if user name is not specified. |
| 173 | // Yes, NULL user name is not supported for security reasons. |
Richard Marian Thomaiyar | 99b8784 | 2018-12-06 21:35:43 +0530 | [diff] [blame] | 174 | response->rmcpStatusCode = |
| 175 | static_cast<uint8_t>(RAKP_ReturnCode::UNAUTH_NAME); |
sunitakx | 0e0546f | 2021-06-15 08:57:10 +0000 | [diff] [blame] | 176 | logInvalidLoginRedfishEvent(message); |
Richard Marian Thomaiyar | 99b8784 | 2018-12-06 21:35:43 +0530 | [diff] [blame] | 177 | return outPayload; |
Richard Marian Thomaiyar | d2563c5 | 2018-11-29 11:49:10 +0530 | [diff] [blame] | 178 | } |
Richard Marian Thomaiyar | 99b8784 | 2018-12-06 21:35:43 +0530 | [diff] [blame] | 179 | |
| 180 | // Perform user name based lookup |
| 181 | std::string userName(request->user_name, request->user_name_len); |
Jayaprakash Mutyala | 05c1447 | 2020-10-19 10:26:24 +0000 | [diff] [blame^] | 182 | ipmi::SecureString passwd; |
Richard Marian Thomaiyar | 99b8784 | 2018-12-06 21:35:43 +0530 | [diff] [blame] | 183 | uint8_t userId = ipmi::ipmiUserGetUserId(userName); |
| 184 | if (userId == ipmi::invalidUserId) |
| 185 | { |
| 186 | response->rmcpStatusCode = |
| 187 | static_cast<uint8_t>(RAKP_ReturnCode::UNAUTH_NAME); |
sunitakx | 0e0546f | 2021-06-15 08:57:10 +0000 | [diff] [blame] | 188 | logInvalidLoginRedfishEvent(message); |
Richard Marian Thomaiyar | 99b8784 | 2018-12-06 21:35:43 +0530 | [diff] [blame] | 189 | return outPayload; |
| 190 | } |
| 191 | // check user is enabled before proceeding. |
| 192 | bool userEnabled = false; |
| 193 | ipmi::ipmiUserCheckEnabled(userId, userEnabled); |
| 194 | if (!userEnabled) |
| 195 | { |
| 196 | response->rmcpStatusCode = |
| 197 | static_cast<uint8_t>(RAKP_ReturnCode::INACTIVE_ROLE); |
sunitakx | 0e0546f | 2021-06-15 08:57:10 +0000 | [diff] [blame] | 198 | logInvalidLoginRedfishEvent(message); |
Richard Marian Thomaiyar | 99b8784 | 2018-12-06 21:35:43 +0530 | [diff] [blame] | 199 | return outPayload; |
| 200 | } |
Richard Marian Thomaiyar | 4c4694e | 2019-06-20 16:36:49 +0530 | [diff] [blame] | 201 | // Get the user password for RAKP message authenticate |
| 202 | passwd = ipmi::ipmiUserGetPassword(userName); |
| 203 | if (passwd.empty()) |
| 204 | { |
| 205 | response->rmcpStatusCode = |
| 206 | static_cast<uint8_t>(RAKP_ReturnCode::UNAUTH_NAME); |
sunitakx | 0e0546f | 2021-06-15 08:57:10 +0000 | [diff] [blame] | 207 | logInvalidLoginRedfishEvent(message); |
Richard Marian Thomaiyar | 4c4694e | 2019-06-20 16:36:49 +0530 | [diff] [blame] | 208 | return outPayload; |
| 209 | } |
Ayushi Smriti | b31e969 | 2019-05-15 12:06:51 +0000 | [diff] [blame] | 210 | // Check whether user is already locked for failed attempts |
| 211 | if (!ipmi::ipmiUserPamAuthenticate(userName, passwd)) |
| 212 | { |
| 213 | log<level::ERR>("Authentication failed - user already locked out", |
| 214 | entry("USER-ID=%d", static_cast<uint8_t>(userId))); |
| 215 | |
| 216 | response->rmcpStatusCode = |
| 217 | static_cast<uint8_t>(RAKP_ReturnCode::UNAUTH_NAME); |
sunitakx | 0e0546f | 2021-06-15 08:57:10 +0000 | [diff] [blame] | 218 | logInvalidLoginRedfishEvent(message); |
Ayushi Smriti | b31e969 | 2019-05-15 12:06:51 +0000 | [diff] [blame] | 219 | return outPayload; |
| 220 | } |
Saravanan Palanisamy | d9c86bb | 2019-08-07 17:57:37 +0000 | [diff] [blame] | 221 | |
| 222 | uint8_t chNum = static_cast<uint8_t>(getInterfaceIndex()); |
Richard Marian Thomaiyar | 99b8784 | 2018-12-06 21:35:43 +0530 | [diff] [blame] | 223 | // Get channel based access information |
Richard Marian Thomaiyar | 992e53c | 2019-03-03 13:30:46 +0530 | [diff] [blame] | 224 | if ((ipmi::ipmiUserGetPrivilegeAccess( |
| 225 | userId, chNum, session->sessionUserPrivAccess) != IPMI_CC_OK) || |
| 226 | (ipmi::getChannelAccessData(chNum, session->sessionChannelAccess) != |
| 227 | IPMI_CC_OK)) |
Richard Marian Thomaiyar | 99b8784 | 2018-12-06 21:35:43 +0530 | [diff] [blame] | 228 | { |
| 229 | response->rmcpStatusCode = |
| 230 | static_cast<uint8_t>(RAKP_ReturnCode::INACTIVE_ROLE); |
sunitakx | 0e0546f | 2021-06-15 08:57:10 +0000 | [diff] [blame] | 231 | logInvalidLoginRedfishEvent(message); |
Richard Marian Thomaiyar | 99b8784 | 2018-12-06 21:35:43 +0530 | [diff] [blame] | 232 | return outPayload; |
| 233 | } |
AppaRao Puli | ecb32fb | 2020-07-01 22:55:38 +0530 | [diff] [blame] | 234 | if (!isChannelAccessModeEnabled(session->sessionChannelAccess.accessMode)) |
| 235 | { |
| 236 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 237 | "Channel access mode disabled."); |
| 238 | response->rmcpStatusCode = |
| 239 | static_cast<uint8_t>(RAKP_ReturnCode::INACTIVE_ROLE); |
sunitakx | 0e0546f | 2021-06-15 08:57:10 +0000 | [diff] [blame] | 240 | logInvalidLoginRedfishEvent(message); |
AppaRao Puli | ecb32fb | 2020-07-01 22:55:38 +0530 | [diff] [blame] | 241 | return outPayload; |
| 242 | } |
Richard Marian Thomaiyar | 992e53c | 2019-03-03 13:30:46 +0530 | [diff] [blame] | 243 | if (session->sessionUserPrivAccess.privilege > |
| 244 | static_cast<uint8_t>(session::Privilege::OEM)) |
Richard Marian Thomaiyar | 7e5d38d | 2019-03-02 22:11:41 +0530 | [diff] [blame] | 245 | { |
| 246 | response->rmcpStatusCode = |
| 247 | static_cast<uint8_t>(RAKP_ReturnCode::INACTIVE_ROLE); |
sunitakx | 0e0546f | 2021-06-15 08:57:10 +0000 | [diff] [blame] | 248 | logInvalidLoginRedfishEvent(message); |
Richard Marian Thomaiyar | 7e5d38d | 2019-03-02 22:11:41 +0530 | [diff] [blame] | 249 | return outPayload; |
| 250 | } |
Suryakanth Sekar | f8a34fc | 2019-06-12 20:59:18 +0530 | [diff] [blame] | 251 | session->channelNum(chNum); |
| 252 | session->userID(userId); |
jayaprakash Mutyala | 2555e2e | 2019-12-24 22:51:46 +0000 | [diff] [blame] | 253 | // minimum privilege of Channel / User / session::privilege::USER |
Richard Marian Thomaiyar | d5a4f45 | 2019-01-16 12:15:44 +0530 | [diff] [blame] | 254 | // has to be used as session current privilege level |
Richard Marian Thomaiyar | 99b8784 | 2018-12-06 21:35:43 +0530 | [diff] [blame] | 255 | uint8_t minPriv = 0; |
Richard Marian Thomaiyar | 992e53c | 2019-03-03 13:30:46 +0530 | [diff] [blame] | 256 | if (session->sessionChannelAccess.privLimit < |
| 257 | session->sessionUserPrivAccess.privilege) |
Richard Marian Thomaiyar | 99b8784 | 2018-12-06 21:35:43 +0530 | [diff] [blame] | 258 | { |
Richard Marian Thomaiyar | 992e53c | 2019-03-03 13:30:46 +0530 | [diff] [blame] | 259 | minPriv = session->sessionChannelAccess.privLimit; |
Richard Marian Thomaiyar | 99b8784 | 2018-12-06 21:35:43 +0530 | [diff] [blame] | 260 | } |
| 261 | else |
| 262 | { |
Richard Marian Thomaiyar | 992e53c | 2019-03-03 13:30:46 +0530 | [diff] [blame] | 263 | minPriv = session->sessionUserPrivAccess.privilege; |
Richard Marian Thomaiyar | 99b8784 | 2018-12-06 21:35:43 +0530 | [diff] [blame] | 264 | } |
Suryakanth Sekar | f8a34fc | 2019-06-12 20:59:18 +0530 | [diff] [blame] | 265 | if (session->currentPrivilege() > minPriv) |
Richard Marian Thomaiyar | 99b8784 | 2018-12-06 21:35:43 +0530 | [diff] [blame] | 266 | { |
Suryakanth Sekar | f8a34fc | 2019-06-12 20:59:18 +0530 | [diff] [blame] | 267 | session->currentPrivilege(static_cast<uint8_t>(minPriv)); |
Richard Marian Thomaiyar | 99b8784 | 2018-12-06 21:35:43 +0530 | [diff] [blame] | 268 | } |
Richard Marian Thomaiyar | d91fd9d | 2018-12-06 12:03:50 +0530 | [diff] [blame] | 269 | // For username / privilege lookup, fail with UNAUTH_NAME, if requested |
Richard Marian Thomaiyar | d8e92fe | 2019-01-16 11:56:23 +0530 | [diff] [blame] | 270 | // max privilege does not match user privilege |
Richard Marian Thomaiyar | d91fd9d | 2018-12-06 12:03:50 +0530 | [diff] [blame] | 271 | if (((request->req_max_privilege_level & userNameOnlyLookupMask) == |
| 272 | userNamePrivLookup) && |
Richard Marian Thomaiyar | d8e92fe | 2019-01-16 11:56:23 +0530 | [diff] [blame] | 273 | ((request->req_max_privilege_level & session::reqMaxPrivMask) != |
Richard Marian Thomaiyar | 992e53c | 2019-03-03 13:30:46 +0530 | [diff] [blame] | 274 | session->sessionUserPrivAccess.privilege)) |
Richard Marian Thomaiyar | d91fd9d | 2018-12-06 12:03:50 +0530 | [diff] [blame] | 275 | { |
Vernon Mauery | fc37e59 | 2018-12-19 14:55:15 -0800 | [diff] [blame] | 276 | log<level::INFO>( |
| 277 | "Username/Privilege lookup failed for requested privilege"); |
Richard Marian Thomaiyar | d91fd9d | 2018-12-06 12:03:50 +0530 | [diff] [blame] | 278 | response->rmcpStatusCode = |
| 279 | static_cast<uint8_t>(RAKP_ReturnCode::UNAUTH_NAME); |
sunitakx | 0e0546f | 2021-06-15 08:57:10 +0000 | [diff] [blame] | 280 | |
| 281 | logInvalidLoginRedfishEvent(message); |
Richard Marian Thomaiyar | d91fd9d | 2018-12-06 12:03:50 +0530 | [diff] [blame] | 282 | return outPayload; |
| 283 | } |
Richard Marian Thomaiyar | 99b8784 | 2018-12-06 21:35:43 +0530 | [diff] [blame] | 284 | |
| 285 | std::fill(authAlgo->userKey.data(), |
| 286 | authAlgo->userKey.data() + authAlgo->userKey.size(), 0); |
| 287 | std::copy_n(passwd.c_str(), passwd.size(), authAlgo->userKey.data()); |
| 288 | |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 289 | // Copy the Managed System Random Number to the Authentication Algorithm |
| 290 | std::copy_n(iter, cipher::rakp_auth::BMC_RANDOM_NUMBER_LEN, |
| 291 | authAlgo->bmcRandomNum.begin()); |
| 292 | std::advance(iter, cipher::rakp_auth::BMC_RANDOM_NUMBER_LEN); |
| 293 | |
| 294 | // Managed System GUID |
Tom Joseph | 83029cb | 2017-09-01 16:37:31 +0530 | [diff] [blame] | 295 | std::copy_n(cache::guid.data(), cache::guid.size(), iter); |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 296 | std::advance(iter, BMC_GUID_LEN); |
| 297 | |
| 298 | // Requested Privilege Level |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 299 | std::copy_n(&(request->req_max_privilege_level), |
| 300 | sizeof(request->req_max_privilege_level), iter); |
| 301 | std::advance(iter, sizeof(request->req_max_privilege_level)); |
| 302 | |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 303 | // User Name Length Byte |
| 304 | std::copy_n(&(request->user_name_len), sizeof(request->user_name_len), |
| 305 | iter); |
Tom Joseph | 56527b9 | 2018-03-21 19:31:58 +0530 | [diff] [blame] | 306 | std::advance(iter, sizeof(request->user_name_len)); |
| 307 | |
| 308 | std::copy_n(session->userName.data(), session->userName.size(), iter); |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 309 | |
| 310 | // Generate Key Exchange Authentication Code - RAKP2 |
| 311 | auto output = authAlgo->generateHMAC(input); |
| 312 | |
| 313 | response->messageTag = request->messageTag; |
| 314 | response->rmcpStatusCode = static_cast<uint8_t>(RAKP_ReturnCode::NO_ERROR); |
| 315 | response->reserved = 0; |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 316 | response->remoteConsoleSessionID = rcSessionID; |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 317 | |
| 318 | // Copy Managed System Random Number to the Response |
| 319 | std::copy(authAlgo->bmcRandomNum.begin(), authAlgo->bmcRandomNum.end(), |
| 320 | response->managed_system_random_number); |
| 321 | |
| 322 | // Copy System GUID to the Response |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 323 | std::copy_n(cache::guid.data(), cache::guid.size(), |
Tom Joseph | 83029cb | 2017-09-01 16:37:31 +0530 | [diff] [blame] | 324 | response->managed_system_guid); |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 325 | |
| 326 | // Insert the HMAC output into the payload |
| 327 | outPayload.insert(outPayload.end(), output.begin(), output.end()); |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 328 | return outPayload; |
| 329 | } |
| 330 | |
| 331 | } // namespace command |