Tom Joseph | 8e832ee | 2016-12-06 17:47:08 +0530 | [diff] [blame] | 1 | #include "open_session.hpp" |
| 2 | |
Tom Joseph | 8e832ee | 2016-12-06 17:47:08 +0530 | [diff] [blame] | 3 | #include "comm_module.hpp" |
| 4 | #include "endian.hpp" |
| 5 | #include "main.hpp" |
| 6 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 7 | #include <iostream> |
| 8 | |
Tom Joseph | 8e832ee | 2016-12-06 17:47:08 +0530 | [diff] [blame] | 9 | namespace command |
| 10 | { |
| 11 | |
Tom Joseph | 18a45e9 | 2017-04-11 11:30:44 +0530 | [diff] [blame] | 12 | std::vector<uint8_t> openSession(const std::vector<uint8_t>& inPayload, |
Tom Joseph | 8e832ee | 2016-12-06 17:47:08 +0530 | [diff] [blame] | 13 | const message::Handler& handler) |
| 14 | { |
Tom Joseph | 8e832ee | 2016-12-06 17:47:08 +0530 | [diff] [blame] | 15 | |
| 16 | std::vector<uint8_t> outPayload(sizeof(OpenSessionResponse)); |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 17 | auto request = |
| 18 | reinterpret_cast<const OpenSessionRequest*>(inPayload.data()); |
Tom Joseph | 8e832ee | 2016-12-06 17:47:08 +0530 | [diff] [blame] | 19 | auto response = reinterpret_cast<OpenSessionResponse*>(outPayload.data()); |
| 20 | |
| 21 | // Check for valid Authentication Algorithms |
Vernon Mauery | 9b307be | 2017-11-22 09:28:16 -0800 | [diff] [blame] | 22 | if (!cipher::rakp_auth::Interface::isAlgorithmSupported( |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 23 | static_cast<cipher::rakp_auth::Algorithms>(request->authAlgo))) |
Tom Joseph | 8e832ee | 2016-12-06 17:47:08 +0530 | [diff] [blame] | 24 | { |
| 25 | response->status_code = |
| 26 | static_cast<uint8_t>(RAKP_ReturnCode::INVALID_AUTH_ALGO); |
| 27 | return outPayload; |
| 28 | } |
| 29 | |
| 30 | // Check for valid Integrity Algorithms |
Vernon Mauery | 9b307be | 2017-11-22 09:28:16 -0800 | [diff] [blame] | 31 | if (!cipher::integrity::Interface::isAlgorithmSupported( |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 32 | static_cast<cipher::integrity::Algorithms>(request->intAlgo))) |
Tom Joseph | 8e832ee | 2016-12-06 17:47:08 +0530 | [diff] [blame] | 33 | { |
| 34 | response->status_code = |
| 35 | static_cast<uint8_t>(RAKP_ReturnCode::INVALID_INTEGRITY_ALGO); |
| 36 | return outPayload; |
| 37 | } |
| 38 | |
| 39 | // Check for valid Confidentiality Algorithms |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 40 | if (!cipher::crypt::Interface::isAlgorithmSupported( |
| 41 | static_cast<cipher::crypt::Algorithms>(request->confAlgo))) |
Tom Joseph | 8e832ee | 2016-12-06 17:47:08 +0530 | [diff] [blame] | 42 | { |
| 43 | response->status_code = |
| 44 | static_cast<uint8_t>(RAKP_ReturnCode::INVALID_CONF_ALGO); |
| 45 | return outPayload; |
| 46 | } |
| 47 | |
| 48 | std::shared_ptr<session::Session> session; |
| 49 | try |
| 50 | { |
| 51 | // Start an IPMI session |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 52 | session = |
Vernon Mauery | ae1fda4 | 2018-10-15 12:55:34 -0700 | [diff] [blame] | 53 | std::get<session::Manager&>(singletonPool) |
| 54 | .startSession( |
| 55 | endian::from_ipmi<>(request->remoteConsoleSessionID), |
| 56 | static_cast<session::Privilege>(request->maxPrivLevel), |
| 57 | static_cast<cipher::rakp_auth::Algorithms>( |
| 58 | request->authAlgo), |
| 59 | static_cast<cipher::integrity::Algorithms>( |
| 60 | request->intAlgo), |
| 61 | static_cast<cipher::crypt::Algorithms>(request->confAlgo)); |
Tom Joseph | 8e832ee | 2016-12-06 17:47:08 +0530 | [diff] [blame] | 62 | } |
| 63 | catch (std::exception& e) |
| 64 | { |
| 65 | std::cerr << e.what() << "\n"; |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 66 | response->status_code = |
| 67 | static_cast<uint8_t>(RAKP_ReturnCode::INSUFFICIENT_RESOURCE); |
Tom Joseph | 8e832ee | 2016-12-06 17:47:08 +0530 | [diff] [blame] | 68 | std::cerr << "openSession : Problem opening a session\n"; |
| 69 | return outPayload; |
| 70 | } |
| 71 | |
| 72 | response->messageTag = request->messageTag; |
| 73 | response->status_code = static_cast<uint8_t>(RAKP_ReturnCode::NO_ERROR); |
| 74 | response->maxPrivLevel = static_cast<uint8_t>(session->curPrivLevel); |
| 75 | response->remoteConsoleSessionID = request->remoteConsoleSessionID; |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 76 | response->managedSystemSessionID = |
| 77 | endian::to_ipmi<>(session->getBMCSessionID()); |
Tom Joseph | 8e832ee | 2016-12-06 17:47:08 +0530 | [diff] [blame] | 78 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 79 | response->authPayload = request->authPayload; |
| 80 | response->authPayloadLen = request->authPayloadLen; |
Tom Joseph | 8e832ee | 2016-12-06 17:47:08 +0530 | [diff] [blame] | 81 | response->authAlgo = request->authAlgo; |
| 82 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 83 | response->intPayload = request->intPayload; |
| 84 | response->intPayloadLen = request->intPayloadLen; |
Tom Joseph | 8e832ee | 2016-12-06 17:47:08 +0530 | [diff] [blame] | 85 | response->intAlgo = request->intAlgo; |
| 86 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 87 | response->confPayload = request->confPayload; |
| 88 | response->confPayloadLen = request->confPayloadLen; |
Tom Joseph | 8e832ee | 2016-12-06 17:47:08 +0530 | [diff] [blame] | 89 | response->confAlgo = request->confAlgo; |
| 90 | |
| 91 | session->updateLastTransactionTime(); |
| 92 | |
| 93 | // Session state is Setup in progress |
| 94 | session->state = session::State::SETUP_IN_PROGRESS; |
Tom Joseph | 8e832ee | 2016-12-06 17:47:08 +0530 | [diff] [blame] | 95 | return outPayload; |
| 96 | } |
| 97 | |
| 98 | } // namespace command |