blob: 96507f6e87d0a401f28ed70a9cb8e3afd0c9a030 [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
12std::vector<uint8_t> openSession(std::vector<uint8_t>& inPayload,
13 const message::Handler& handler)
14{
15 std::cout << ">> openSession\n";
16
17 std::vector<uint8_t> outPayload(sizeof(OpenSessionResponse));
18 auto request = reinterpret_cast<OpenSessionRequest*>(inPayload.data());
19 auto response = reinterpret_cast<OpenSessionResponse*>(outPayload.data());
20
21 // Check for valid Authentication Algorithms
22 if (request->authAlgo != static_cast<uint8_t>
23 (cipher::rakp_auth::Algorithms::RAKP_HMAC_SHA1))
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
Tom Joseph1e7aa192017-02-24 17:16:49 +053031 if(!cipher::integrity::Interface::isAlgorithmSupported(static_cast
32 <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
Tom Joseph2f0bd0e2017-01-24 18:24:27 +053040 if(!cipher::crypt::Interface::isAlgorithmSupported(static_cast
41 <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
52 session = (std::get<session::Manager&>(singletonPool).startSession(
53 endian::from_ipmi<>(request->remoteConsoleSessionID),
54 static_cast<session::Privilege>(request->maxPrivLevel),
Tom Joseph7949afc2017-01-10 16:38:32 +053055 static_cast<cipher::rakp_auth::Algorithms>(request->authAlgo),
Tom Josephba11f792017-01-24 18:21:45 +053056 static_cast<cipher::integrity::Algorithms>(request->intAlgo),
57 static_cast<cipher::crypt::Algorithms>(request->confAlgo)
Tom Joseph8e832ee2016-12-06 17:47:08 +053058 )).lock();
59 }
60 catch (std::exception& e)
61 {
62 std::cerr << e.what() << "\n";
63 response->status_code = static_cast<uint8_t>
64 (RAKP_ReturnCode::INSUFFICIENT_RESOURCE);
65 std::cerr << "openSession : Problem opening a session\n";
66 return outPayload;
67 }
68
69 response->messageTag = request->messageTag;
70 response->status_code = static_cast<uint8_t>(RAKP_ReturnCode::NO_ERROR);
71 response->maxPrivLevel = static_cast<uint8_t>(session->curPrivLevel);
72 response->remoteConsoleSessionID = request->remoteConsoleSessionID;
73 response->managedSystemSessionID = endian::to_ipmi<>
74 (session->getBMCSessionID());
75
76 response->authPayload = request->authPayload ;
77 response->authPayloadLen = request->authPayloadLen ;
78 response->authAlgo = request->authAlgo;
79
80 response->intPayload = request->intPayload ;
81 response->intPayloadLen = request->intPayloadLen ;
82 response->intAlgo = request->intAlgo;
83
84 response->confPayload = request->confPayload ;
85 response->confPayloadLen = request->confPayloadLen ;
86 response->confAlgo = request->confAlgo;
87
88 session->updateLastTransactionTime();
89
90 // Session state is Setup in progress
91 session->state = session::State::SETUP_IN_PROGRESS;
92
93 std::cout << "<< openSession\n";
94 return outPayload;
95}
96
97} // namespace command