rublon-ssh/PAM/ssh/include/rublon/sign.hpp
rublon-bwi c3127e8b58
Bwi/bugfix (#7)
* generate user enrolement message
* Fix bugs found during testing
2024-01-25 16:30:12 +01:00

26 lines
647 B
C++

#pragma once
#include <array>
#include <string_view>
#include <openssl/evp.h>
#include <openssl/hmac.h>
namespace rublon {
// +1 for \0
inline std::array< char, 64 + 1 > signData(std::string_view data, std::string_view secretKey) {
std::array< char, 64 + 1 > xRublon;
std::array< unsigned char, EVP_MAX_MD_SIZE > md;
unsigned int md_len{};
HMAC(EVP_sha256(), secretKey.data(), secretKey.size(), ( unsigned const char * ) data.data(), data.size(), md.data(), &md_len);
for(unsigned int i = 0; i < md_len; i++)
sprintf(&xRublon[i * 2], "%02x", ( unsigned int ) md[i]);
return xRublon;
}
} // namespace rublon