blob: b48b7e95caf0d48b89c45c70fde341a64004e084 [file] [log] [blame]
Tom Joseph8e832ee2016-12-06 17:47:08 +05301#include "open_session.hpp"
2
Tom Joseph8e832ee2016-12-06 17:47:08 +05303#include "comm_module.hpp"
4#include "endian.hpp"
5#include "main.hpp"
6
Vernon Mauery9e801a22018-10-12 13:20:49 -07007#include <iostream>
8
Tom Joseph8e832ee2016-12-06 17:47:08 +05309namespace command
10{
11
Tom Joseph18a45e92017-04-11 11:30:44 +053012std::vector<uint8_t> openSession(const std::vector<uint8_t>& inPayload,
Tom Joseph8e832ee2016-12-06 17:47:08 +053013 const message::Handler& handler)
14{
Tom Joseph8e832ee2016-12-06 17:47:08 +053015
16 std::vector<uint8_t> outPayload(sizeof(OpenSessionResponse));
Vernon Mauery9e801a22018-10-12 13:20:49 -070017 auto request =
18 reinterpret_cast<const OpenSessionRequest*>(inPayload.data());
Tom Joseph8e832ee2016-12-06 17:47:08 +053019 auto response = reinterpret_cast<OpenSessionResponse*>(outPayload.data());
20
21 // Check for valid Authentication Algorithms
Vernon Mauery9b307be2017-11-22 09:28:16 -080022 if (!cipher::rakp_auth::Interface::isAlgorithmSupported(
Vernon Mauery9e801a22018-10-12 13:20:49 -070023 static_cast<cipher::rakp_auth::Algorithms>(request->authAlgo)))
Tom Joseph8e832ee2016-12-06 17:47:08 +053024 {
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 Mauery9b307be2017-11-22 09:28:16 -080031 if (!cipher::integrity::Interface::isAlgorithmSupported(
Vernon Mauery9e801a22018-10-12 13:20:49 -070032 static_cast<cipher::integrity::Algorithms>(request->intAlgo)))
Tom Joseph8e832ee2016-12-06 17:47:08 +053033 {
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 Mauery9e801a22018-10-12 13:20:49 -070040 if (!cipher::crypt::Interface::isAlgorithmSupported(
41 static_cast<cipher::crypt::Algorithms>(request->confAlgo)))
Tom Joseph8e832ee2016-12-06 17:47:08 +053042 {
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 Mauery9e801a22018-10-12 13:20:49 -070052 session =
Vernon Maueryae1fda42018-10-15 12:55:34 -070053 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 Joseph8e832ee2016-12-06 17:47:08 +053062 }
63 catch (std::exception& e)
64 {
65 std::cerr << e.what() << "\n";
Vernon Mauery9e801a22018-10-12 13:20:49 -070066 response->status_code =
67 static_cast<uint8_t>(RAKP_ReturnCode::INSUFFICIENT_RESOURCE);
Tom Joseph8e832ee2016-12-06 17:47:08 +053068 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 Mauery9e801a22018-10-12 13:20:49 -070076 response->managedSystemSessionID =
77 endian::to_ipmi<>(session->getBMCSessionID());
Tom Joseph8e832ee2016-12-06 17:47:08 +053078
Vernon Mauery9e801a22018-10-12 13:20:49 -070079 response->authPayload = request->authPayload;
80 response->authPayloadLen = request->authPayloadLen;
Tom Joseph8e832ee2016-12-06 17:47:08 +053081 response->authAlgo = request->authAlgo;
82
Vernon Mauery9e801a22018-10-12 13:20:49 -070083 response->intPayload = request->intPayload;
84 response->intPayloadLen = request->intPayloadLen;
Tom Joseph8e832ee2016-12-06 17:47:08 +053085 response->intAlgo = request->intAlgo;
86
Vernon Mauery9e801a22018-10-12 13:20:49 -070087 response->confPayload = request->confPayload;
88 response->confPayloadLen = request->confPayloadLen;
Tom Joseph8e832ee2016-12-06 17:47:08 +053089 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 Joseph8e832ee2016-12-06 17:47:08 +053095 return outPayload;
96}
97
98} // namespace command