Validate Integrity Algorithm in Open Session Request command
Change-Id: I54106099fbbe50156529644eaadd65dc1db7e141
Signed-off-by: Tom Joseph <tomjoseph@in.ibm.com>
diff --git a/command/open_session.cpp b/command/open_session.cpp
index 5b0800f..96507f6 100644
--- a/command/open_session.cpp
+++ b/command/open_session.cpp
@@ -28,10 +28,8 @@
}
// Check for valid Integrity Algorithms
- if ((request->intAlgo !=
- static_cast<uint8_t>(cipher::integrity::Algorithms::NONE)) &&
- (request->intAlgo !=
- static_cast<uint8_t>(cipher::integrity::Algorithms::HMAC_SHA1_96)))
+ if(!cipher::integrity::Interface::isAlgorithmSupported(static_cast
+ <cipher::integrity::Algorithms>(request->intAlgo)))
{
response->status_code =
static_cast<uint8_t>(RAKP_ReturnCode::INVALID_INTEGRITY_ALGO);
diff --git a/integrity_algo.hpp b/integrity_algo.hpp
index ac06e06..7b895c5 100644
--- a/integrity_algo.hpp
+++ b/integrity_algo.hpp
@@ -102,6 +102,26 @@
*/
Buffer virtual generateIntegrityData(const Buffer& input) const = 0;
+ /**
+ * @brief Check if the Integrity algorithm is supported
+ *
+ * @param[in] algo - integrity algorithm
+ *
+ * @return true if algorithm is supported else false
+ *
+ */
+ static bool isAlgorithmSupported(Algorithms algo)
+ {
+ if (algo == Algorithms::NONE || algo == Algorithms::HMAC_SHA1_96)
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
/*
* AuthCode field length varies based on the integrity algorithm, for
* HMAC-SHA1-96 the authcode field is 12 bytes. For HMAC-SHA256-128 and