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