blob: 6e08d1abace1ad69694d17d6fe751cc2d76d36f6 [file] [log] [blame]
Tom Joseph8e832ee2016-12-06 17:47:08 +05301#include "open_session.hpp"
2
3#include <iostream>
4
5#include "comm_module.hpp"
6#include "endian.hpp"
7#include "main.hpp"
8
9namespace 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));
Tom Joseph18a45e92017-04-11 11:30:44 +053017 auto request = reinterpret_cast<const OpenSessionRequest*>(inPayload.data());
Tom Joseph8e832ee2016-12-06 17:47:08 +053018 auto response = reinterpret_cast<OpenSessionResponse*>(outPayload.data());
19
20 // Check for valid Authentication Algorithms
Vernon Mauery9b307be2017-11-22 09:28:16 -080021 if (!cipher::rakp_auth::Interface::isAlgorithmSupported(
22 static_cast<cipher::rakp_auth::Algorithms>(request->authAlgo)))
Tom Joseph8e832ee2016-12-06 17:47:08 +053023 {
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 Mauery9b307be2017-11-22 09:28:16 -080030 if (!cipher::integrity::Interface::isAlgorithmSupported(
31 static_cast<cipher::integrity::Algorithms>(request->intAlgo)))
Tom Joseph8e832ee2016-12-06 17:47:08 +053032 {
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 Joseph2f0bd0e2017-01-24 18:24:27 +053039 if(!cipher::crypt::Interface::isAlgorithmSupported(static_cast
40 <cipher::crypt::Algorithms>(request->confAlgo)))
Tom Joseph8e832ee2016-12-06 17:47:08 +053041 {
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 Joseph7949afc2017-01-10 16:38:32 +053054 static_cast<cipher::rakp_auth::Algorithms>(request->authAlgo),
Tom Josephba11f792017-01-24 18:21:45 +053055 static_cast<cipher::integrity::Algorithms>(request->intAlgo),
56 static_cast<cipher::crypt::Algorithms>(request->confAlgo)
Tom Joseph8e832ee2016-12-06 17:47:08 +053057 )).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 Joseph8e832ee2016-12-06 17:47:08 +053091 return outPayload;
92}
93
94} // namespace command