54 Commits

Author SHA1 Message Date
Mike
c9a2ab44dd fix(spelling): lan inteface -> lan interface in amtinfo 2021-08-24 16:03:21 -07:00
Mike
fb29227f9d Merge pull request #61 from open-amt-cloud-toolkit/feat_message_formatting
feat: format json status messages
2021-08-18 08:51:44 -07:00
Mudit Vats
26629a1a68 feat: format json status messages 2021-08-17 13:41:07 -07:00
Mike
db924a9b2e build: bump version to v1.3.0 2021-08-02 10:13:39 -07:00
Mike
f0682c4588 Merge pull request #60 from open-amt-cloud-toolkit/fix_klockwork_opens
fix: klockwork reported success / failure check fix
2021-07-21 10:39:29 -07:00
Mudit Vats
913fa41b17 fix: klockwork reported success / failure check fix 2021-07-19 13:25:33 -07:00
Mike
f6666d857b Merge pull request #55 from open-amt-cloud-toolkit/feature_wireless
feat: add AMT wireless adapter info to amtinfo LAN settings.
2021-07-07 10:46:44 -07:00
Mike
e51dc9f1f7 Merge branch 'master' into feature_wireless 2021-07-07 10:20:14 -07:00
Mike
a4929a2d08 Merge pull request #53 from open-amt-cloud-toolkit/update-readme
docs(readme): update readme
2021-07-07 10:20:01 -07:00
Mike
615e9156dc Merge branch 'master' into feature_wireless 2021-07-07 10:19:14 -07:00
Matt Primrose
373a560b1a Merge branch 'master' into update-readme 2021-07-06 17:17:08 -07:00
Matt Primrose
0f8050b6bf Merge pull request #56 from open-amt-cloud-toolkit/changelog_automation
ci(changelog): add automation for changelog generation
2021-07-06 17:16:43 -07:00
Matt Primrose
c70335ae2e Merge branch 'master' into update-readme 2021-07-06 16:21:30 -07:00
Matt Primrose
d94302543b Merge branch 'master' into changelog_automation 2021-07-06 16:20:35 -07:00
Matt Primrose
dea97dec64 Merge pull request #59 from bill-mahoney/master
ci: update scanning
2021-07-06 16:18:24 -07:00
mpvats-intel
cd2887a992 Merge branch 'master' into feature_wireless 2021-07-01 06:16:05 -07:00
Bill Mahoney
33abb9d2d2 ci: update scanning
Signed-off-by: Bill Mahoney <bill.mahoney@intel.com>
2021-06-30 11:18:27 -07:00
bwendlandt-intel
34981ad2c7 docs(readme): wording 2021-06-28 11:42:37 -07:00
Mike
17efe70b4e Merge pull request #57 from open-amt-cloud-toolkit/matt-primrose-patch-1
docs(security): added security.md file
2021-06-24 17:10:00 -07:00
Matt Primrose
c2be90c8a7 docs(security): added SECURITY.md file 2021-06-24 14:44:31 -07:00
Matt Primrose
b4c12d63b5 docs(security): added security.md file 2021-06-24 14:30:37 -07:00
Mike
bea1eb22ef Merge branch 'master' into changelog_automation 2021-06-23 11:01:46 -07:00
Mike
ec1374280b ci(changelog): add automation for changelog generation 2021-06-22 16:43:53 -07:00
Mudit Vats
f7dc3f4faa feat: add AMT wireless adapter info to amtinfo LAN settings. 2021-06-22 15:37:11 -07:00
bwendlandt-intel
491f5087de docs(readme): update readme 2021-06-18 15:37:41 -07:00
mpvats-intel
a968777550 Merge pull request #52 from open-amt-cloud-toolkit/examples_update
fix: update examples text and version
2021-06-03 09:03:18 -07:00
mpvats-intel
db9605ab82 Merge branch 'master' into examples_update 2021-06-03 08:38:43 -07:00
Mike
91d7481264 Merge pull request #50 from bill-mahoney/daily-cleanup
ci: remove Jenkins chron
2021-06-03 08:25:17 -07:00
Mudit Vats
cb24fae43a fix: update examples text and version 2021-06-01 15:32:57 -07:00
Bill Mahoney
4d551ef09d ci: remove Jenkins chron 2021-05-10 11:15:18 -07:00
Mike
39ddea389a Merge pull request #48 from open-amt-cloud-toolkit/docker
build(docker): revert to ubuntu 20.04
2021-05-06 12:07:01 -07:00
Mike
9aa745e5a2 build(docker): revert to ubuntu 20.04 2021-05-06 11:45:56 -07:00
Mike
38c8bc2384 Merge pull request #47 from open-amt-cloud-toolkit/add_missing_ca
fix(docker): add missing ca-certs
2021-05-05 22:34:30 -07:00
Mike
584ca67799 build(docker): bump to ubuntu-20.10 2021-05-05 16:31:58 -07:00
Mike
cf7fac325f fix(docker): add missing ca-certs 2021-05-05 16:04:58 -07:00
Mike
8569684593 Merge pull request #40 from bill-mahoney/jenkins-feedback
ci: update build for scanning
2021-04-08 11:46:51 -07:00
Mike
1e72b281a5 Merge branch 'master' into jenkins-feedback 2021-04-06 09:56:45 -07:00
Mike
75673aa373 Merge pull request #43 from open-amt-cloud-toolkit/v1.2.0
docs: add changelog.md
2021-04-05 10:31:36 -07:00
Mike
5772e831ad docs: add changelog.md 2021-04-02 21:16:43 -07:00
Bill Mahoney
67202dc5d3 ci: update build for scanning
Signed-off-by: Bill Mahoney <bill.mahoney@intel.com>
2021-03-31 18:11:41 -07:00
mpvats-intel
6d490aec65 Merge pull request #39 from open-amt-cloud-toolkit/feature_update_version
feat: update RPC version to 1.2.0.
2021-03-29 14:58:30 -07:00
Mudit Vats
41f8f8553c feat: update RPC version to 1.2.0. 2021-03-29 14:35:21 -07:00
mpvats-intel
bc1f8d0cfb Merge pull request #38 from open-amt-cloud-toolkit/feature_heatbeat
feat: add heartbeat capability
2021-03-23 16:25:05 -07:00
Mudit Vats
a8e1bc89f0 feat: add heartbeat capability 2021-03-23 14:00:49 -07:00
Mike
5b5a480943 Merge pull request #36 from open-amt-cloud-toolkit/test
ci: breakout docker build for merge only
2021-03-16 16:00:42 -07:00
Mike
a190a214f1 ci: breakout docker build for merge only 2021-03-16 15:29:52 -07:00
Mike
54b7550e31 Merge pull request #35 from rsdmike/dockersupport
feat(docker): add dockerfile support for RPC
2021-03-16 14:48:11 -07:00
Mike
e4deeca506 feat(docker): add dockerfile support for RPC 2021-03-16 14:44:28 -07:00
trleasher-intel
365ad90adc Merge pull request #31 from open-amt-cloud-toolkit/fix_msg_cleanup
fix: use message status instead, cleanup message fields.
2021-02-23 09:27:01 -07:00
Mudit Vats
2984880b6e fix: use message status instead, cleanup message fields. 2021-02-23 08:25:46 -07:00
trleasher-intel
da9c26bc26 Merge pull request #30 from open-amt-cloud-toolkit/feature_test_framework
feat: add unit test framework
2021-02-16 08:37:47 -07:00
Mudit Vats
bb4e144684 feat: add unit test framework 2021-02-12 16:49:02 -07:00
trleasher-intel
86cf9657ad Merge pull request #29 from open-amt-cloud-toolkit/feature_hostname
feat: add hostname to activation info
2021-02-12 15:54:23 -07:00
Mudit Vats
025152f359 feat: add hostname to activation info 2021-02-12 14:42:43 -07:00
23 changed files with 678 additions and 85 deletions

20
.github/workflows/changelog.yml vendored Normal file
View File

@@ -0,0 +1,20 @@
name: Changelog Generator
on:
pull_request:
branches: [ master ]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- run: docker run -v $PWD:/workdir quay.io/git-chglog/git-chglog --next-tag vNext --output CHANGELOG-new.md vNext..
- name: GitHub Upload Release Artifacts
uses: actions/upload-artifact@v2
with:
name: CHANGELOG-new.md
path: |
./CHANGELOG-new.md

View File

@@ -42,7 +42,6 @@ jobs:
- 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
View 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

View File

@@ -1,3 +1,35 @@
<a name="v1.2.2"></a>
## [v1.2.2] - 2021-06-22
### Ci
- remove Jenkins chron
- **changelog:** add automation for changelog generation
### Fix
- update examples text and version
<a name="v1.2.1"></a>
## [v1.2.1] - 2021-05-06
### Fix
**docker:** add missing ca-certs
<a name="v1.2.0"></a>
## v1.2.0
### Ci
- breakout docker build for merge only
### Feat
- update RPC version to 1.2.0.
- BREAKING CHANGE: add heartbeat capability, bump RPC Protocol version to 4.0.0
- add unit test framework
- add hostname to activation info
- **docker:** add dockerfile support for RPC
### Fix
- use message status instead, cleanup message fields.
<a name="v1.1.0"></a>
## [v1.1.0] - 2021-02-09

View File

@@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.1)
project (rpc VERSION 1.1.0)
project (rpc VERSION 1.3.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
View File

@@ -0,0 +1,37 @@
#*********************************************************************
# Copyright (c) Intel Corporation 2021
# SPDX-License-Identifier: Apache-2.0
#*********************************************************************/
FROM ubuntu:20.04 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 ca-certificates
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.04
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"]

154
Jenkinsfile vendored Normal file
View File

@@ -0,0 +1,154 @@
pipeline {
agent {
label 'docker-amt'
}
options {
buildDiscarder(logRotator(numToKeepStr: '5', daysToKeepStr: '30'))
timestamps()
timeout(unit: 'HOURS', time: 2)
}
stages {
stage ('Cloning Repository') {
steps {
script {
scmCheckout {
clean = true
}
}
}
}
stage('Static Code Scan - Protex') {
environment{
PROJECT_NAME = 'OpenAMT - RPC'
SCANNERS = 'protex'
}
steps {
rbheStaticCodeScan()
}
}
stage ('Parallel Builds') {
parallel {
stage ('Linux') {
agent { label 'docker-amt' }
stages {
stage('Build') {
agent {
docker {
image 'ubuntu:18.04'
reuseNode true
}
}
steps {
sh './scripts/jenkins-pre-build.sh'
sh './scripts/jenkins-build.sh'
stash includes: 'build/rpc', name: 'linux-rpc-app'
}
}
stage ('Archive') {
steps {
archiveArtifacts allowEmptyArchive: true, artifacts: 'build/rpc', caseSensitive: false, onlyIfSuccessful: true
}
}
}
}
stage ('Windows') {
agent { label 'openamt-win' }
stages{
stage ('Build') {
steps {
bat 'scripts\\jenkins-pre-build.cmd'
bat 'scripts\\jenkins-build.cmd'
// prepare stash for the binary scan
stash includes: '**/*.exe', name: 'win-rpc-app'
}
}
stage ('Archive') {
steps {
archiveArtifacts allowEmptyArchive: true, artifacts: 'build\\Release\\rpc.exe', caseSensitive: false, onlyIfSuccessful: true
}
}
}
}
}
}
stage('Prep Binary') {
steps {
sh 'mkdir -p ./bin'
dir('./bin') {
unstash 'linux-rpc-app'
unstash 'win-rpc-app'
}
}
}
stage('Linux Scans') {
environment{
PROJECT_NAME = 'OpenAMT - RPC - Linux'
SCANNERS = 'bdba,klocwork'
// protecode details
PROTECODE_BIN_DIR = './bin'
PROTECODE_INCLUDE_SUB_DIRS = true
// klocwork details
KLOCWORK_SCAN_TYPE = 'c++'
KLOCWORK_PRE_BUILD_SCRIPT = './scripts/jenkins-pre-build.sh'
KLOCWORK_BUILD_COMMAND = './scripts/jenkins-build.sh'
KLOCWORK_IGNORE_COMPILE_ERRORS = true
// publishArtifacts details
PUBLISH_TO_ARTIFACTORY = true
}
steps {
rbheStaticCodeScan()
dir('artifacts/Klockwork'){
sh 'cp kw_report.html kw_report_linux.html'
sh 'cp kw_report.csv kw_report_linux.csv'
archiveArtifacts allowEmptyArchive: true, artifacts: 'kw_report_linux.html'
archiveArtifacts allowEmptyArchive: true, artifacts: 'kw_report_linux.csv'
}
}
}
stage('Windows Scans'){
agent { label 'openamt-win' }
stages{
stage ('Windows Scans - klocwork') {
environment {
PROJECT_NAME = 'OpenAMT - RPC - Windows'
SCANNERS = 'klocwork'
// klocwork details
KLOCWORK_SCAN_TYPE = 'c++'
KLOCWORK_PRE_BUILD_SCRIPT = 'scripts\\jenkins-pre-build.cmd'
KLOCWORK_BUILD_COMMAND = 'scripts\\jenkins-build.cmd'
KLOCWORK_IGNORE_COMPILE_ERRORS = true
// publishArtifacts details
PUBLISH_TO_ARTIFACTORY = true
}
steps {
rbheStaticCodeScan()
dir('artifacts\\Klockwork'){
bat 'copy kw_report.html kw_report_windows.html'
bat 'copy kw_report.csv kw_report_windows.csv'
stash includes: 'kw_report_windows.*', name: 'win-kwreports'
archiveArtifacts allowEmptyArchive: true, artifacts: 'kw_report_windows.html'
archiveArtifacts allowEmptyArchive: true, artifacts: 'kw_report_windows.csv'
}
}
}
}
}
stage('Publish Artifacts'){
steps{
dir('artifacts/Klockwork'){
unstash 'win-kwreports'
}
publishArtifacts()
}
}
}
}

View File

@@ -4,26 +4,43 @@
The Remote Provisioning Client (RPC) is an application that enables remote capabilities for Intel® AMT, such as as device activation and configuration. To accomplish this, RPC communicates with the Remote Provisioning Server (RPS) to activate and connect the edge device.
<br><br>
**For detailed documentation** about RPC or other features of the Open AMT Cloud Toolkit, see the [docs](https://open-amt-cloud-toolkit.github.io/docs/).
<br>
## Prerequisites
We leverage GitHub Actions as a means to build RPC automatically leveraging Github's CI/CD Infrastructure. This avoids having to deal with the challenges of getting your build environment just right on your local machine and allows you to get up and running much faster. Read more about GitHub Actions [here](https://github.blog/2019-08-08-github-actions-now-supports-ci-cd/#:~:text=GitHub%20Actions%20is%20an%20API,every%20step%20along%20the%20way.)
## Build the Remote Provisioning Client (RPC)
<p align="center">
<img src="assets/animations/forkandbuild.gif" width="650" />
</p>
1. Create a fork of the rpc repository [here](https://github.com/open-amt-cloud-toolkit/rpc/fork) or via the Fork button in the top-right corner of the rpc repository.
## Build the Remote Provisioning Client (RPC)
2. Click on "Actions" and Select "Build RPC (Native)" Workflow.
1. <a href="https://github.com/open-amt-cloud-toolkit/rpc/fork" target="_blank">Create a fork of rpc on GitHub.</a>
3. Click "Run Workflow", select branch "master", and click "Run Workflow".
2. Click on the **Actions** tab at the top and select **Build RPC (Native) Debug/Release**.
4. Grab a coffee. The build for Windows will take approximately 30 minutes and the build for Linux will take approximately 5 minutes.
3. Click the **Run Workflow** dropdown.
5. Once complete, click the completed job, and download the appropriate RPC for your OS under the "Artifacts" section.
4. Select the **Branch: master**, or a preferred version, from the **Use workflow from** dropdown.
5. By default, the Build Type should be **release**.
6. Click the **Run Workflow** button. Grab a coffee and take a break! The build time ranges from 15 to 20 minutes.
8. Once the download is complete, click the completed job which will feature a green checkmark.
9. Download the appropriate RPC for your managed device's OS under the **Artifacts** section.
### To Delete your workflow run
1. Click the ellipsis ( **...** ) menu for the workflow.
2. Choose the **Delete workflow run** option.
For detailed documentation about RPC and using it to activate a device, see the [docs](https://open-amt-cloud-toolkit.github.io/docs/)

5
SECURITY.md Normal file
View File

@@ -0,0 +1,5 @@
# Security Policy
Intel is committed to rapidly addressing security vulnerabilities affecting our customers and providing clear guidance on the solution, impact, severity and mitigation.
## Reporting a Vulnerability
Please report any security vulnerabilities in this project utilizing the guidelines [here](https://www.intel.com/content/www/us/en/security-center/vulnerability-handling-guidelines.html).

View File

@@ -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;
}

View File

@@ -8,7 +8,7 @@
#include <string>
#define PROTOCOL_VERSION "3.0.0"
#define PROTOCOL_VERSION "4.0.0"
#ifdef _WIN32
#define convertstring to_utf16string

View File

@@ -282,8 +282,10 @@ bool cmd_get_certificate_hashes(std::vector<cert_hash_entry>& hash_entries)
for (int i = 0; i < (int) amt_hash_handles.Length; i++)
{
// get each entry
AMT_STATUS status = pthi_GetCertificateHashEntry(amt_hash_handles.Handles[i], &certhash_entry);
AMT_STATUS amt_status = pthi_GetCertificateHashEntry(amt_hash_handles.Handles[i], &certhash_entry);
if (amt_status == 0)
{
int hashSize;
cert_hash_entry tmp;
switch (certhash_entry.HashAlgorithm) {
@@ -329,6 +331,7 @@ bool cmd_get_certificate_hashes(std::vector<cert_hash_entry>& hash_entries)
hash_entries.push_back(tmp);
}
}
}
return true;
}
@@ -377,14 +380,14 @@ bool cmd_get_remote_access_connection_status(int& network_status, int& remote_st
return false;
}
bool cmd_get_lan_interface_settings(lan_interface_settings& lan_interface_settings)
bool cmd_get_lan_interface_settings(lan_interface_settings& lan_interface_settings, bool wired_interface)
{
// initialize HECI interface
if (heci_Init(NULL, PTHI_CLIENT) == 0) return false;
// get wired interface
LAN_SETTINGS lan_settings;
UINT32 interface_settings = 0; // wired=0, wireless=1
UINT32 interface_settings = (wired_interface) ? 0 : 1; // wired=0, wireless=1
AMT_STATUS amt_status = pthi_GetLanInterfaceSettings(interface_settings, &lan_settings);
if (amt_status == 0)
{
@@ -393,11 +396,13 @@ bool cmd_get_lan_interface_settings(lan_interface_settings& lan_interface_settin
lan_interface_settings.dhcp_enabled = lan_settings.DhcpEnabled;
lan_interface_settings.link_status = lan_settings.LinkStatus;
lan_interface_settings.ip_address.clear();
lan_interface_settings.ip_address.push_back((lan_settings.Ipv4Address >> 24) & 0xff);
lan_interface_settings.ip_address.push_back((lan_settings.Ipv4Address >> 16) & 0xff);
lan_interface_settings.ip_address.push_back((lan_settings.Ipv4Address >> 8) & 0xff);
lan_interface_settings.ip_address.push_back((lan_settings.Ipv4Address) & 0xff);
lan_interface_settings.mac_address.clear();
lan_interface_settings.mac_address.push_back(lan_settings.MacAddress[0]);
lan_interface_settings.mac_address.push_back(lan_settings.MacAddress[1]);
lan_interface_settings.mac_address.push_back(lan_settings.MacAddress[2]);

View File

@@ -49,6 +49,6 @@ bool cmd_get_dns_suffix(std::string& suffix);
bool cmd_get_wired_mac_address(std::vector<unsigned char>& address);
bool cmd_get_certificate_hashes(std::vector<cert_hash_entry>& hash_entries);
bool cmd_get_remote_access_connection_status(int& network_status, int& remote_status, int& remote_trigger, std::string& mps_hostname);
bool cmd_get_lan_interface_settings(lan_interface_settings& lan_interface_settings);
bool cmd_get_lan_interface_settings(lan_interface_settings& lan_interface_settings, bool wired_interface = true);
#endif

15
googletest.cmake.in Normal file
View 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
View 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
View 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

View File

@@ -20,7 +20,7 @@ void out_text(const std::string name, const std::vector<unsigned char> value, co
for (unsigned char tmp : value)
{
(hex) ? std::cout << std::setfill('0') << std::setw(2) << std::hex << (unsigned int)tmp
: std::cout << (unsigned int)tmp;
: std::cout << std::dec << (unsigned int)tmp;
if (char_count++ < value.size())
{
@@ -270,15 +270,41 @@ bool info_get_lan_interface_settings()
tmp.ip_address.clear();
tmp.mac_address.clear();
if (!cmd_get_lan_interface_settings(tmp)) return false;
bool hasWired = cmd_get_lan_interface_settings(tmp);
if (hasWired)
{
out_text("LAN Interface", "wired");
out_text("DHCP Enabled", (tmp.dhcp_enabled) ? "true" : "false");
out_text("DHCP Mode", (tmp.dhcp_mode == 1) ? "active" : "passive");
out_text("Link Status", (tmp.link_status) ? "up" : "down");
out_text("IP Address", tmp.ip_address, '.', false);
out_text("MAC Address", tmp.mac_address, ':');
}
tmp.is_enabled = false;
tmp.link_status = false;
tmp.dhcp_enabled = false;
tmp.dhcp_mode = 0;
tmp.ip_address.clear();
tmp.mac_address.clear();
bool hasWireless = cmd_get_lan_interface_settings(tmp, false);
if (hasWireless)
{
out_text("LAN Interface", "wireless");
out_text("DHCP Enabled", (tmp.dhcp_enabled) ? "true" : "false");
out_text("DHCP Mode", (tmp.dhcp_mode == 1) ? "active" : "passive");
out_text("Link Status", (tmp.link_status) ? "up" : "down");
out_text("IP Address", tmp.ip_address, '.', false);
out_text("MAC Address", tmp.mac_address, ':');
}
if (hasWired || hasWireless)
{
return true;
}
return false;
}
bool info_get(const std::string info)

View File

@@ -7,10 +7,12 @@
#include <thread>
#include <cpprest/ws_client.h>
#include <cpprest/json.h>
#include <algorithm>
#include "port.h"
#include "lms.h"
#include "commands.h"
#include "activation.h"
#include "heartbeat.h"
#include "utils.h"
#include "usage.h"
#include "args.h"
@@ -246,25 +248,70 @@ 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;
// exit
try {
std::cout << std::endl;
utility::string_t tmp = utility::conversions::convertstring(msgMessage);
web::json::value parsed = web::json::value::parse(tmp);
for (const auto& obj : parsed.as_object()) {
std::string key = utility::conversions::to_utf8string(obj.first);
std::string value = utility::conversions::to_utf8string(obj.second.serialize());
value.erase(std::remove(value.begin(), value.end(), '"'), value.end());
std::cout << key << ": " << value << std::endl;
}
}
catch (...)
{
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;
// exit
try {
std::cout << std::endl;
utility::string_t tmp = utility::conversions::convertstring(msgMessage);
web::json::value parsed = web::json::value::parse(tmp);
for (const auto& obj : parsed.as_object()) {
std::string key = utility::conversions::to_utf8string(obj.first);
std::string value = utility::conversions::to_utf8string(obj.second.serialize());
value.erase(std::remove(value.begin(), value.end(), '"'), value.end());
std::cout << key << ": " << value << std::endl;
}
}
catch (...)
{
std::cout << std::endl << msgMessage << std::endl;
}
return;
}

View File

@@ -14,7 +14,7 @@ set BASE_DIR=%cd%
set VCPKG_DIR=C:\opt\vcpkg-source
REM build RPC
cd %BASE_DIR%/rpc
if exist "build" rd /q /s "build"
@@ -23,4 +23,4 @@ cd build
echo %VCPKG_DIR%\vcpkg\scripts\buildsystems\vcpkg.cmake
cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static -DCMAKE_TOOLCHAIN_FILE=%VCPKG_DIR%\vcpkg\scripts\buildsystems\vcpkg.cmake ..
cmake --build . --config Release
dir %BASE_DIR%\rpc\build
dir %BASE_DIR%\build

View File

@@ -5,9 +5,9 @@ set -x
# Jenkins Build script
# - Ubuntu 18.04
#
export BASE_DIR="$PWD"
export CMAKE_CXX_FLAGS="-isystem /usr/lib/gcc/x86_64-linux-gnu/7/include"
cd "$BASE_DIR"/rpc
if [ -d "build" ]; then
rm -rf build
@@ -15,5 +15,5 @@ fi
mkdir build
cd build
cmake -DCMAKE_TOOLCHAIN_FILE="$BASE_DIR"/rpc/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_BUILD_TYPE=Release ..
cmake -DCMAKE_TOOLCHAIN_FILE="$BASE_DIR"/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_BUILD_TYPE=Release ..
cmake --build .

View File

@@ -4,14 +4,15 @@
# - Ubuntu 18.04
#
sudo apt install git cmake build-essential curl zip unzip tar pkg-config
apt update
apt install git cmake build-essential curl zip unzip tar pkg-config -y
## current dir - RPC source directory
export BASE_DIR="$PWD"
#export BASE_DIR="$PWD"
cd "$BASE_DIR"/rpc
#cd "$BASE_DIR"/rpc
## build vcpkg
git clone --branch 2020.11-1 https://github.com/microsoft/vcpkg.git
git -C vcpkg pull || git clone --branch 2020.11-1 https://github.com/microsoft/vcpkg.git vcpkg
cd vcpkg
./bootstrap-vcpkg.sh

89
test.cpp Normal file
View 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);
}

View File

@@ -49,15 +49,15 @@ void usage_show_help()
std::cout << "Examples:" << std::endl;
std::cout << " # Activate platform using profile1" << std::endl;
std::cout << " " << PROJECT_NAME << \
" --url wss://localhost:8080 --cmd \"-t activate --profile profile1\"" << std::endl;
" --url wss://192.168.86.100/activate --cmd \"-t activate --profile profile1\"" << std::endl;
std::cout << std::endl;
std::cout << " # Activate platform using profile1 and override DNS detection" << std::endl;
std::cout << " " << PROJECT_NAME << \
" --url wss://localhost:8080 --cmd \"-t activate --profile profile1\" --dns corp.com" << std::endl;
" --url wss://mycloud.com/activate --cmd \"-t activate --profile profile1\" --dns corp.com" << std::endl;
std::cout << std::endl;
std::cout << " # Deactivate platform and connect through a proxy" << std::endl;
std::cout << " " << PROJECT_NAME << \
" -u wss://localhost:8080 -c \"-t deactivate --password P@ssw0rd\" -p http://proxy.com:1000" << std::endl;
" -u wss://mycloud.com/activate -c \"-t deactivate --password P@ssw0rd\" -p http://proxy.com:1000" << std::endl;
std::cout << std::endl;
std::cout << " # Show all informational items" << std::endl;
std::cout << " " << PROJECT_NAME << " --amtinfo all" << std::endl;