Compare commits
15 Commits
v1.1.0
...
snyk-fix-5
Author | SHA1 | Date | |
---|---|---|---|
|
6a2466ff2a | ||
|
6d490aec65 | ||
|
41f8f8553c | ||
|
bc1f8d0cfb | ||
|
a8e1bc89f0 | ||
|
5b5a480943 | ||
|
a190a214f1 | ||
|
54b7550e31 | ||
|
e4deeca506 | ||
|
365ad90adc | ||
|
2984880b6e | ||
|
da9c26bc26 | ||
|
bb4e144684 | ||
|
86cf9657ad | ||
|
025152f359 |
3
.github/workflows/ci.yml
vendored
3
.github/workflows/ci.yml
vendored
@@ -41,8 +41,7 @@ jobs:
|
||||
run: cd build && cmake --build . --config Release
|
||||
- name: Build RPC (Debug)
|
||||
run: cd build && cmake --build . --config Debug
|
||||
|
||||
|
||||
|
||||
build-linux:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
|
29
.github/workflows/docker-ci.yml
vendored
Normal file
29
.github/workflows/docker-ci.yml
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
#*********************************************************************
|
||||
# Copyright (c) Intel Corporation 2020
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#*********************************************************************/
|
||||
|
||||
name: Docker Image CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Build the Docker image
|
||||
run: docker build -f "Dockerfile" --tag vprodemo.azurecr.io/rpc:${{ github.sha }} --tag vprodemo.azurecr.io/rpc:latest .
|
||||
- name: Docker Login
|
||||
uses: docker/login-action@v1.6.0
|
||||
with:
|
||||
registry: vprodemo.azurecr.io
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
logout: true
|
||||
- name: Push the Docker image to the registry
|
||||
run: docker push vprodemo.azurecr.io/rpc:${{ github.sha }}
|
||||
- name: Push the Docker image to the registry
|
||||
run: docker push vprodemo.azurecr.io/rpc:latest
|
@@ -1,6 +1,6 @@
|
||||
cmake_minimum_required (VERSION 3.1)
|
||||
|
||||
project (rpc VERSION 1.1.0)
|
||||
project (rpc VERSION 1.2.0)
|
||||
|
||||
set (CMAKE_CXX_STANDARD 11)
|
||||
|
||||
@@ -41,6 +41,46 @@ add_subdirectory(MicroLMS)
|
||||
# CppRestSDK
|
||||
find_package(cpprestsdk CONFIG REQUIRED)
|
||||
|
||||
# GoogleTest
|
||||
# Download and unpack googletest at configure time
|
||||
configure_file(googletest.cmake.in googletest-download/CMakeLists.txt)
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
|
||||
RESULT_VARIABLE result
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
|
||||
if(result)
|
||||
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
|
||||
endif()
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} --build .
|
||||
RESULT_VARIABLE result
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
|
||||
if(result)
|
||||
message(FATAL_ERROR "Build step for googletest failed: ${result}")
|
||||
endif()
|
||||
|
||||
# Prevent overriding the parent project's compiler/linker
|
||||
# settings on Windows
|
||||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
||||
|
||||
# Add googletest directly to our build. This defines
|
||||
# the gtest and gtest_main targets.
|
||||
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src
|
||||
${CMAKE_CURRENT_BINARY_DIR}/googletest-build
|
||||
EXCLUDE_FROM_ALL)
|
||||
|
||||
# add the test executable
|
||||
add_executable(rpctest
|
||||
test.cpp
|
||||
utils.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(rpctest
|
||||
gtest_main
|
||||
cpprestsdk::cpprest
|
||||
cpprestsdk::cpprestsdk_zlib_internal
|
||||
cpprestsdk::cpprestsdk_boost_internal
|
||||
cpprestsdk::cpprestsdk_openssl_internal
|
||||
)
|
||||
|
||||
# ccu-poc
|
||||
add_executable (rpc
|
||||
info.h
|
||||
@@ -58,6 +98,8 @@ add_executable (rpc
|
||||
commands.cpp
|
||||
activation.h
|
||||
activation.cpp
|
||||
heartbeat.h
|
||||
heartbeat.cpp
|
||||
lms.h
|
||||
lms.cpp
|
||||
main.cpp
|
||||
|
37
Dockerfile
Normal file
37
Dockerfile
Normal file
@@ -0,0 +1,37 @@
|
||||
#*********************************************************************
|
||||
# Copyright (c) Intel Corporation 2021
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#*********************************************************************/
|
||||
|
||||
FROM ubuntu:20.10 AS rpc-builder
|
||||
|
||||
WORKDIR /
|
||||
ARG DEBIAN_FRONTEND=noninteractive
|
||||
RUN \
|
||||
apt-get update -y -qq && \
|
||||
apt install -y -qq \
|
||||
git cmake build-essential libssl-dev zlib1g-dev \
|
||||
curl unzip zip pkg-config
|
||||
RUN git clone https://github.com/open-amt-cloud-toolkit/rpc.git
|
||||
WORKDIR /rpc
|
||||
RUN mkdir -p build
|
||||
RUN git clone --branch 2020.11-1 https://github.com/microsoft/vcpkg.git
|
||||
RUN cd vcpkg && ./bootstrap-vcpkg.sh
|
||||
RUN ./vcpkg/vcpkg install cpprestsdk[websockets]
|
||||
|
||||
WORKDIR /rpc/build
|
||||
RUN cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=/rpc/vcpkg/scripts/buildsystems/vcpkg.cmake ..
|
||||
RUN cmake --build .
|
||||
|
||||
FROM ubuntu:20.10
|
||||
|
||||
LABEL license='SPDX-License-Identifier: Apache-2.0' \
|
||||
copyright='Copyright (c) 2021: Intel'
|
||||
|
||||
WORKDIR /root
|
||||
RUN \
|
||||
apt-get update -y -qq && \
|
||||
apt install -y -qq \
|
||||
libssl-dev
|
||||
COPY --from=rpc-builder /rpc/build/rpc .
|
||||
ENTRYPOINT ["/root/rpc"]
|
@@ -77,6 +77,16 @@ web::json::value get_dns()
|
||||
return web::json::value::string(tmp);
|
||||
}
|
||||
|
||||
web::json::value get_hostname()
|
||||
{
|
||||
utility::string_t tmp;
|
||||
|
||||
std::string hostName = net_get_hostname();
|
||||
tmp = utility::conversions::convertstring(hostName);
|
||||
|
||||
return web::json::value::string(tmp);
|
||||
}
|
||||
|
||||
bool getVersion(web::json::value& value)
|
||||
{
|
||||
std::string version;
|
||||
@@ -202,6 +212,9 @@ bool get_activation_payload(web::json::value& payload)
|
||||
// get DNS Info
|
||||
activationParams[U("fqdn")] = get_dns();
|
||||
|
||||
// get hostname
|
||||
activationParams[U("hostname")] = get_hostname();
|
||||
|
||||
// get client string
|
||||
if (!get_client_string(value)) return false;
|
||||
activationParams[U("client")] = value;
|
||||
@@ -223,7 +236,7 @@ bool act_create_request(std::string commands, std::string dns_suffix, std::strin
|
||||
utility::string_t tmp = utility::conversions::convertstring(commands);
|
||||
msg[U("method")] = web::json::value::string(tmp);
|
||||
|
||||
tmp = utility::conversions::convertstring("key");
|
||||
tmp = utility::conversions::convertstring("");
|
||||
msg[U("apiKey")] = web::json::value::string(tmp);
|
||||
|
||||
tmp = utility::conversions::convertstring(PROJECT_VER);
|
||||
@@ -232,10 +245,10 @@ bool act_create_request(std::string commands, std::string dns_suffix, std::strin
|
||||
tmp = utility::conversions::convertstring(PROTOCOL_VERSION);
|
||||
msg[U("protocolVersion")] = web::json::value::string(tmp);
|
||||
|
||||
tmp = utility::conversions::convertstring("ok");
|
||||
tmp = utility::conversions::convertstring("");
|
||||
msg[U("status")] = web::json::value::string(tmp);
|
||||
|
||||
tmp = utility::conversions::convertstring("ok");
|
||||
tmp = utility::conversions::convertstring("");
|
||||
msg[U("message")] = web::json::value::string(tmp);
|
||||
|
||||
// get the activation payload
|
||||
@@ -268,7 +281,7 @@ bool act_create_response(std::string payload, std::string& response)
|
||||
utility::string_t tmp = utility::conversions::convertstring("response");
|
||||
msg[U("method")] = web::json::value::string(tmp);
|
||||
|
||||
tmp = utility::conversions::convertstring("key");
|
||||
tmp = utility::conversions::convertstring("");
|
||||
msg[U("apiKey")] = web::json::value::string(tmp);
|
||||
|
||||
tmp = utility::conversions::convertstring(PROJECT_VER);
|
||||
@@ -277,10 +290,10 @@ bool act_create_response(std::string payload, std::string& response)
|
||||
tmp = utility::conversions::convertstring(PROTOCOL_VERSION);
|
||||
msg[U("protocolVersion")] = web::json::value::string(tmp);
|
||||
|
||||
tmp = utility::conversions::convertstring("ok");
|
||||
tmp = utility::conversions::convertstring("");
|
||||
msg[U("status")] = web::json::value::string(tmp);
|
||||
|
||||
tmp = utility::conversions::convertstring("ok");
|
||||
tmp = utility::conversions::convertstring("");
|
||||
msg[U("message")] = web::json::value::string(tmp);
|
||||
|
||||
tmp = utility::conversions::convertstring(util_encode_base64(payload));
|
||||
@@ -290,3 +303,4 @@ bool act_create_response(std::string payload, std::string& response)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@@ -8,7 +8,7 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#define PROTOCOL_VERSION "3.0.0"
|
||||
#define PROTOCOL_VERSION "4.0.0"
|
||||
|
||||
#ifdef _WIN32
|
||||
#define convertstring to_utf16string
|
||||
|
15
googletest.cmake.in
Normal file
15
googletest.cmake.in
Normal file
@@ -0,0 +1,15 @@
|
||||
cmake_minimum_required(VERSION 2.8.12)
|
||||
|
||||
project(googletest-download NONE)
|
||||
|
||||
include(ExternalProject)
|
||||
ExternalProject_Add(googletest
|
||||
GIT_REPOSITORY https://github.com/google/googletest.git
|
||||
GIT_TAG release-1.10.0
|
||||
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src"
|
||||
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build"
|
||||
CONFIGURE_COMMAND ""
|
||||
BUILD_COMMAND ""
|
||||
INSTALL_COMMAND ""
|
||||
TEST_COMMAND ""
|
||||
)
|
48
heartbeat.cpp
Normal file
48
heartbeat.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
/*********************************************************************
|
||||
* Copyright (c) Intel Corporation 2019 - 2020
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
**********************************************************************/
|
||||
|
||||
#include "heartbeat.h"
|
||||
#include <cpprest/ws_client.h>
|
||||
#include <cpprest/json.h>
|
||||
#include <cpprest/streams.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "activation.h"
|
||||
#include "version.h"
|
||||
#include "commands.h"
|
||||
#include "network.h"
|
||||
#include "utils.h"
|
||||
|
||||
bool heartbeat_create_response(std::string& response)
|
||||
{
|
||||
web::json::value msg;
|
||||
|
||||
utility::string_t tmp = utility::conversions::convertstring("heartbeat_response");
|
||||
msg[U("method")] = web::json::value::string(tmp);
|
||||
|
||||
tmp = utility::conversions::convertstring("");
|
||||
msg[U("apiKey")] = web::json::value::string(tmp);
|
||||
|
||||
tmp = utility::conversions::convertstring(PROJECT_VER);
|
||||
msg[U("appVersion")] = web::json::value::string(tmp);
|
||||
|
||||
tmp = utility::conversions::convertstring(PROTOCOL_VERSION);
|
||||
msg[U("protocolVersion")] = web::json::value::string(tmp);
|
||||
|
||||
tmp = utility::conversions::convertstring("success");
|
||||
msg[U("status")] = web::json::value::string(tmp);
|
||||
|
||||
tmp = utility::conversions::convertstring("");
|
||||
msg[U("message")] = web::json::value::string(tmp);
|
||||
|
||||
// set empty payload
|
||||
tmp = utility::conversions::convertstring("");
|
||||
msg[U("payload")] = web::json::value::string(tmp);
|
||||
|
||||
// serialize the entire message
|
||||
response = utility::conversions::to_utf8string(msg.serialize());
|
||||
|
||||
return true;
|
||||
}
|
13
heartbeat.h
Normal file
13
heartbeat.h
Normal file
@@ -0,0 +1,13 @@
|
||||
/*********************************************************************
|
||||
* Copyright (c) Intel Corporation 2019 - 2020
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
**********************************************************************/
|
||||
|
||||
#ifndef __HEARTBEAT_H__
|
||||
#define __HEARTBEAT_H__
|
||||
|
||||
#include <string>
|
||||
|
||||
bool heartbeat_create_response(std::string& response);
|
||||
|
||||
#endif
|
20
main.cpp
20
main.cpp
@@ -11,6 +11,7 @@
|
||||
#include "lms.h"
|
||||
#include "commands.h"
|
||||
#include "activation.h"
|
||||
#include "heartbeat.h"
|
||||
#include "utils.h"
|
||||
#include "usage.h"
|
||||
#include "args.h"
|
||||
@@ -246,10 +247,25 @@ int main(int argc, char* argv[])
|
||||
return;
|
||||
}
|
||||
|
||||
if (msgMethod.compare("heartbeat_request") == 0)
|
||||
{
|
||||
// create the response
|
||||
std::string response;
|
||||
if (!heartbeat_create_response(response)) return;
|
||||
|
||||
// send it
|
||||
web::websockets::client::websocket_outgoing_message send_websocket_msg;
|
||||
std::string send_websocket_buffer(response);
|
||||
send_websocket_msg.set_utf8_message(send_websocket_buffer);
|
||||
client.send(send_websocket_msg).wait();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// process any messages we can
|
||||
// - if success, done
|
||||
// - if error, get out
|
||||
if (msgMethod.compare("success")==0)
|
||||
if (msgStatus.compare("success")==0)
|
||||
{
|
||||
// cleanup
|
||||
g_timeout_val = 0;
|
||||
@@ -258,7 +274,7 @@ int main(int argc, char* argv[])
|
||||
std::cout << std::endl << msgMessage << std::endl;
|
||||
return;
|
||||
}
|
||||
else if (msgMethod.compare("error")==0)
|
||||
else if (msgStatus.compare("failed")==0)
|
||||
{
|
||||
// cleanup
|
||||
g_timeout_val = 0;
|
||||
|
89
test.cpp
Normal file
89
test.cpp
Normal file
@@ -0,0 +1,89 @@
|
||||
/*********************************************************************
|
||||
* Copyright (c) Intel Corporation 2019 - 2020
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
**********************************************************************/
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <cpprest/ws_client.h>
|
||||
#include <cpprest/json.h>
|
||||
#include "port.h"
|
||||
#include "utils.h"
|
||||
|
||||
const std::string plainText = "Ut aliquet ex id enim accumsan bibendum. Nullam nibh ligula, rhoncus vitae nisl eu, fermentum luctus tellus. Sed non semper augue, vitae congue nibh. Suspendisse sed placerat metus. Nunc a sapien vel nisl semper fringilla. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Aliquam accumsan, nisi vitae efficitur ultricies, velit neque mattis velit, sed sodales tellus est at orci. Duis sed ipsum lorem. In eu enim eu odio fringilla lacinia id id lorem. Vestibulum velit augue, ultricies et neque eget, molestie vehicula urna. Etiam venenatis nibh vel nunc fringilla, vitae feugiat ipsum posuere. Pellentesque ac libero quis nulla pretium iaculis sed at felis. Integer malesuada turpis eget lectus interdum, a commodo nisl tristique. Proin rutrum nisl ut metus aliquam, vel lacinia tortor ullamcorper. Nulla rhoncus ullamcorper accumsan. Fusce eget augue vulputate, porta quam at, laoreet justo.";
|
||||
const std::string encodedText = "VXQgYWxpcXVldCBleCBpZCBlbmltIGFjY3Vtc2FuIGJpYmVuZHVtLiBOdWxsYW0gbmliaCBsaWd1bGEsIHJob25jdXMgdml0YWUgbmlzbCBldSwgZmVybWVudHVtIGx1Y3R1cyB0ZWxsdXMuIFNlZCBub24gc2VtcGVyIGF1Z3VlLCB2aXRhZSBjb25ndWUgbmliaC4gU3VzcGVuZGlzc2Ugc2VkIHBsYWNlcmF0IG1ldHVzLiBOdW5jIGEgc2FwaWVuIHZlbCBuaXNsIHNlbXBlciBmcmluZ2lsbGEuIFBlbGxlbnRlc3F1ZSBoYWJpdGFudCBtb3JiaSB0cmlzdGlxdWUgc2VuZWN0dXMgZXQgbmV0dXMgZXQgbWFsZXN1YWRhIGZhbWVzIGFjIHR1cnBpcyBlZ2VzdGFzLiBBbGlxdWFtIGFjY3Vtc2FuLCBuaXNpIHZpdGFlIGVmZmljaXR1ciB1bHRyaWNpZXMsIHZlbGl0IG5lcXVlIG1hdHRpcyB2ZWxpdCwgc2VkIHNvZGFsZXMgdGVsbHVzIGVzdCBhdCBvcmNpLiBEdWlzIHNlZCBpcHN1bSBsb3JlbS4gSW4gZXUgZW5pbSBldSBvZGlvIGZyaW5naWxsYSBsYWNpbmlhIGlkIGlkIGxvcmVtLiBWZXN0aWJ1bHVtIHZlbGl0IGF1Z3VlLCB1bHRyaWNpZXMgZXQgbmVxdWUgZWdldCwgbW9sZXN0aWUgdmVoaWN1bGEgdXJuYS4gRXRpYW0gdmVuZW5hdGlzIG5pYmggdmVsIG51bmMgZnJpbmdpbGxhLCB2aXRhZSBmZXVnaWF0IGlwc3VtIHBvc3VlcmUuIFBlbGxlbnRlc3F1ZSBhYyBsaWJlcm8gcXVpcyBudWxsYSBwcmV0aXVtIGlhY3VsaXMgc2VkIGF0IGZlbGlzLiBJbnRlZ2VyIG1hbGVzdWFkYSB0dXJwaXMgZWdldCBsZWN0dXMgaW50ZXJkdW0sIGEgY29tbW9kbyBuaXNsIHRyaXN0aXF1ZS4gUHJvaW4gcnV0cnVtIG5pc2wgdXQgbWV0dXMgYWxpcXVhbSwgdmVsIGxhY2luaWEgdG9ydG9yIHVsbGFtY29ycGVyLiBOdWxsYSByaG9uY3VzIHVsbGFtY29ycGVyIGFjY3Vtc2FuLiBGdXNjZSBlZ2V0IGF1Z3VlIHZ1bHB1dGF0ZSwgcG9ydGEgcXVhbSBhdCwgbGFvcmVldCBqdXN0by4=";
|
||||
|
||||
// Test if characters are printable
|
||||
TEST(testUtils, isPrintableTestValid)
|
||||
{
|
||||
std::string s = "The quick brown fox jumps over the lazy dog.";
|
||||
EXPECT_EQ(true, util_is_printable(s));
|
||||
}
|
||||
|
||||
// Test if characters are printable
|
||||
TEST(testUtils, isPrintableTestInvalid)
|
||||
{
|
||||
std::string s = "The quick brown fox jumps over the lazy dog.";
|
||||
s[0] = 10; // non-printable character
|
||||
|
||||
EXPECT_EQ(false, util_is_printable(s));
|
||||
}
|
||||
|
||||
// Test encode of base64 string
|
||||
TEST(testUtils, encodebase64)
|
||||
{
|
||||
EXPECT_EQ(encodedText, util_encode_base64(plainText));
|
||||
}
|
||||
|
||||
// Test decode of base64 sstring
|
||||
TEST(testUtils, decodebase64)
|
||||
{
|
||||
EXPECT_EQ(plainText, util_decode_base64(encodedText));
|
||||
}
|
||||
|
||||
// Test return value of util_format_uuid
|
||||
TEST(testUtils, formatUUIDSuccess)
|
||||
{
|
||||
std::vector<unsigned char> uuid_bytes;
|
||||
for (int i=0; i<16; i++)
|
||||
{
|
||||
uuid_bytes.push_back(i);
|
||||
}
|
||||
|
||||
std::string uuid_string;
|
||||
util_format_uuid(uuid_bytes, uuid_string);
|
||||
|
||||
EXPECT_EQ(true, util_format_uuid(uuid_bytes, uuid_string));
|
||||
}
|
||||
|
||||
// Test return value of util_format_uuid
|
||||
TEST(testUtils, formatUUIDFail)
|
||||
{
|
||||
std::vector<unsigned char> uuid_bytes;
|
||||
for (int i=0; i<5; i++) // invalid length
|
||||
{
|
||||
uuid_bytes.push_back(i);
|
||||
}
|
||||
|
||||
std::string uuid_string;
|
||||
util_format_uuid(uuid_bytes, uuid_string);
|
||||
|
||||
EXPECT_EQ(false, util_format_uuid(uuid_bytes, uuid_string));
|
||||
}
|
||||
|
||||
// Test value of the uuid format to ensure format is correct
|
||||
TEST(testUtils, formatUUIDValue)
|
||||
{
|
||||
std::string uuid_string;
|
||||
std::vector<unsigned char> uuid_bytes;
|
||||
|
||||
for (int i=0; i<16; i++)
|
||||
{
|
||||
uuid_bytes.push_back(i);
|
||||
}
|
||||
|
||||
util_format_uuid(uuid_bytes, uuid_string);
|
||||
|
||||
EXPECT_EQ("03020100-0504-0706-0809-0a0b0c0d0e0f", uuid_string);
|
||||
}
|
Reference in New Issue
Block a user