Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
96f4c68ecc | ||
|
87ca74fdf3 | ||
|
185cdceadb | ||
|
706a512bc7 | ||
|
e0fe219646 |
16
.github/PULL_REQUEST_TEMPLATE.md
vendored
16
.github/PULL_REQUEST_TEMPLATE.md
vendored
@@ -1,16 +0,0 @@
|
||||
## PR Checklist
|
||||
<!-- Please check if your PR fulfills the following requirements: -->
|
||||
|
||||
- [ ] Unit Tests have been added for new changes
|
||||
- [ ] API tests have been updated if applicable
|
||||
- [ ] All commented code has been removed
|
||||
- [ ] If you've added a dependency, you've ensured license is compatible with Apache 2.0 and clearly outlined the added dependency.
|
||||
|
||||
|
||||
## What are you changing?
|
||||
<!-- Please provide a short description of the updates that are in the PR -->
|
||||
|
||||
|
||||
## Anything the reviewer should know when reviewing this PR?
|
||||
|
||||
### If the there are associated PRs in other repositories, please link them here (i.e. open-amt-cloud-toolkit/repo#365 )
|
4
.github/workflows/build_all.yml
vendored
4
.github/workflows/build_all.yml
vendored
@@ -24,7 +24,7 @@ jobs:
|
||||
- name: Create Build Dir
|
||||
run: mkdir build
|
||||
- name: Clone
|
||||
run: git clone https://github.com/microsoft/vcpkg.git && cd vcpkg && git checkout 772d435ba18bf2f342458e0187ab7b48b84fe3f0
|
||||
run: git clone --branch 2020.11-1 https://github.com/microsoft/vcpkg.git
|
||||
- name: Build VCPKG
|
||||
run: cd vcpkg && bootstrap-vcpkg.bat
|
||||
shell: cmd
|
||||
@@ -71,7 +71,7 @@ jobs:
|
||||
- name: Create Build Dir
|
||||
run: mkdir build
|
||||
- name: Clone
|
||||
run: git clone https://github.com/microsoft/vcpkg.git && cd vcpkg && git checkout 772d435ba18bf2f342458e0187ab7b48b84fe3f0
|
||||
run: git clone --branch 2020.11-1 https://github.com/microsoft/vcpkg.git
|
||||
- name: Build VCPKG
|
||||
run: cd vcpkg && ./bootstrap-vcpkg.sh
|
||||
shell: bash
|
||||
|
2
.github/workflows/changelog.yml
vendored
2
.github/workflows/changelog.yml
vendored
@@ -2,7 +2,7 @@ name: Changelog Generator
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches: [ main ]
|
||||
branches: [ master ]
|
||||
workflow_dispatch:
|
||||
jobs:
|
||||
build:
|
||||
|
6
.github/workflows/ci.yml
vendored
6
.github/workflows/ci.yml
vendored
@@ -7,7 +7,7 @@ name: Build RPC (Native)
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches: [ main ]
|
||||
branches: [ master ]
|
||||
|
||||
env:
|
||||
BUILD_TYPE: Release
|
||||
@@ -21,7 +21,7 @@ jobs:
|
||||
- name: Create Build Dir
|
||||
run: mkdir build
|
||||
- name: Clone
|
||||
run: git clone https://github.com/microsoft/vcpkg.git && cd vcpkg && git checkout 772d435ba18bf2f342458e0187ab7b48b84fe3f0
|
||||
run: git clone --branch 2020.11-1 https://github.com/microsoft/vcpkg.git
|
||||
- name: Build VCPKG
|
||||
run: cd vcpkg && bootstrap-vcpkg.bat
|
||||
shell: cmd
|
||||
@@ -54,7 +54,7 @@ jobs:
|
||||
- name: Create Build Dir
|
||||
run: mkdir build
|
||||
- name: Clone
|
||||
run: git clone https://github.com/microsoft/vcpkg.git && cd vcpkg && git checkout 772d435ba18bf2f342458e0187ab7b48b84fe3f0
|
||||
run: git clone --branch 2020.11-1 https://github.com/microsoft/vcpkg.git
|
||||
- name: Build VCPKG
|
||||
run: cd vcpkg && ./bootstrap-vcpkg.sh
|
||||
shell: bash
|
||||
|
2
.github/workflows/docker-ci.yml
vendored
2
.github/workflows/docker-ci.yml
vendored
@@ -7,7 +7,7 @@ name: Docker Image CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
branches: [ master ]
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
6
Build.md
6
Build.md
@@ -25,9 +25,8 @@ sudo apt install git cmake build-essential curl zip unzip tar pkg-config
|
||||
Open a Terminal window.
|
||||
|
||||
```
|
||||
git clone https://github.com/microsoft/vcpkg.git
|
||||
git clone -b 2020.11-1 https://github.com/microsoft/vcpkg.git
|
||||
cd vcpkg
|
||||
git checkout 772d435ba18bf2f342458e0187ab7b48b84fe3f0
|
||||
./bootstrap-vcpkg.sh
|
||||
./vcpkg install cpprestsdk[websockets]
|
||||
```
|
||||
@@ -69,9 +68,8 @@ Steps below are for Windows 10 and Visual Studio 2019 Professional.
|
||||
Open an x64 Native Tools Command Prompt for Visual Studio 2019.
|
||||
|
||||
```
|
||||
git clone https://github.com/microsoft/vcpkg.git
|
||||
git clone -b 2020.11-1 https://github.com/microsoft/vcpkg.git
|
||||
cd vcpkg
|
||||
git checkout 772d435ba18bf2f342458e0187ab7b48b84fe3f0
|
||||
bootstrap-vcpkg.bat
|
||||
vcpkg install cpprestsdk[websockets]:x64-windows-static
|
||||
```
|
||||
|
27
CHANGELOG.md
27
CHANGELOG.md
@@ -1,30 +1,3 @@
|
||||
<a name="v2.0.0"></a>
|
||||
## v2.0.0
|
||||
|
||||
### Build
|
||||
- bump version to v1.3.0
|
||||
- bump version to v2.0.0
|
||||
|
||||
### Ci
|
||||
- update scanning
|
||||
|
||||
### Docs
|
||||
- **readme:** wording
|
||||
- **readme:** update readme
|
||||
- **security:** added SECURITY.md file
|
||||
|
||||
### Feat
|
||||
- update to OpenSSL 1.1.1l
|
||||
- update workflows and Docker build.
|
||||
- Update to latest vcpkg
|
||||
- Update docs and scripts for Windows and Ubuntu.
|
||||
- format json status messages
|
||||
- add AMT wireless adapter info to amtinfo LAN settings.
|
||||
|
||||
### Fix
|
||||
- klockwork reported success / failure check fix
|
||||
- **spelling:** lan inteface -> lan interface in amtinfo
|
||||
|
||||
<a name="v1.2.2"></a>
|
||||
## [v1.2.2] - 2021-06-22
|
||||
### Ci
|
||||
|
@@ -1,6 +1,6 @@
|
||||
cmake_minimum_required (VERSION 3.1)
|
||||
|
||||
project (rpc VERSION 2.0.0)
|
||||
project (rpc VERSION 1.2.1)
|
||||
|
||||
set (CMAKE_CXX_STANDARD 11)
|
||||
|
||||
@@ -98,6 +98,8 @@ add_executable (rpc
|
||||
commands.cpp
|
||||
activation.h
|
||||
activation.cpp
|
||||
shbc.h
|
||||
shbc.cpp
|
||||
heartbeat.h
|
||||
heartbeat.cpp
|
||||
lms.h
|
||||
|
101
CONTRIBUTING.MD
101
CONTRIBUTING.MD
@@ -1,101 +0,0 @@
|
||||
## <a name="commit"></a> Commit Message Guidelines
|
||||
|
||||
We have precise rules over how our git commit messages should be formatted. This leads to more readable messages that are easy to follow when looking through the project history.
|
||||
|
||||
### Commit Message Format
|
||||
Each commit message consists of a **header**, a **body** and a **footer**. The header has a special format that includes a **type**, a **scope** and a **subject**:
|
||||
|
||||
```
|
||||
<type>(<scope>): <subject>
|
||||
<BLANK LINE>
|
||||
<body>
|
||||
<BLANK LINE>
|
||||
<footer>
|
||||
```
|
||||
|
||||
The **header** with **type** is mandatory. The **scope** of the header is optional as far as the automated PR checks are concerned, but be advised that PR reviewers **may request** you provide an applicable scope.
|
||||
|
||||
Any line of the commit message should no be longer 72 characters! This allows the message to be easier to read on GitHub as well as in various git tools.
|
||||
|
||||
The footer should contain a reference to an Azure Boards ticket (e.g. AB#[number]).
|
||||
|
||||
Example 1:
|
||||
```
|
||||
feat(telemetry): Add new MQTT events
|
||||
|
||||
Events are now emitted over various /mps topics on MQTT for success/failures
|
||||
as they occur throughout the service.
|
||||
|
||||
Resolves: AB#2222
|
||||
```
|
||||
|
||||
|
||||
### Revert
|
||||
If the commit reverts a previous commit, it should begin with `revert: `, followed by the header of the reverted commit. In the body it should say: `This reverts commit <hash>.`, where the hash is the SHA of the commit being reverted.
|
||||
|
||||
### Type
|
||||
|
||||
Must be one of the following:
|
||||
|
||||
* **feat**: A new feature
|
||||
* **fix**: A bug fix
|
||||
* **docs**: Documentation only changes
|
||||
* **style**: Changes that do not affect the meaning of the code (white-space, formatting, etc)
|
||||
* **refactor**: A code change that neither fixes a bug nor adds a feature
|
||||
* **perf**: A code change that improves performance
|
||||
* **test**: Adding missing tests or correcting existing tests
|
||||
* **build**: Changes that affect the CI/CD pipeline or build system or external dependencies (example scopes: travis, jenkins, makefile)
|
||||
* **ci**: Changes provided by DevOps for CI purposes.
|
||||
* **revert**: Reverts a previous commit.
|
||||
|
||||
### Scope
|
||||
|
||||
Should be one of the following:
|
||||
Modules:
|
||||
* **common**: A change or addition to the common module
|
||||
* **tracker**: A change or addition to the tracker module
|
||||
* **server**: A change or addition to the server module
|
||||
* **msgs**: A change or addition to msgs module
|
||||
* **eval**: Any change to benchmark tools
|
||||
* **deps**: A change to any dependency or 3rd-party library
|
||||
* **all**: A change that affects all modules
|
||||
* *no scope*: If no scope is provided, it is assumed the PR does not apply to the above scopes
|
||||
|
||||
### Body
|
||||
Just as in the **subject**, use the imperative, present tense: "change" not "changed" nor "changes".
|
||||
Here is detailed guideline on how to write the body of the commit message ([Reference](https://chris.beams.io/posts/git-commit/)):
|
||||
```
|
||||
More detailed explanatory text, if necessary. Wrap it to about 72
|
||||
characters or so. In some contexts, the first line is treated as the
|
||||
subject of the commit and the rest of the text as the body. The
|
||||
blank line separating the summary from the body is critical (unless
|
||||
you omit the body entirely); various tools like `log`, `shortlog`
|
||||
and `rebase` can get confused if you run the two together.
|
||||
|
||||
Explain the problem that this commit is solving. Focus on why you
|
||||
are making this change as opposed to how (the code explains that).
|
||||
Are there side effects or other unintuitive consequences of this
|
||||
change? Here's the place to explain them.
|
||||
|
||||
Further paragraphs come after blank lines.
|
||||
|
||||
- Bullet points are okay, too
|
||||
|
||||
- Typically a hyphen or asterisk is used for the bullet, preceded
|
||||
by a single space, with blank lines in between, but conventions
|
||||
vary here
|
||||
```
|
||||
|
||||
### Footer
|
||||
|
||||
The footer should contain a reference to JIRA ticket (e.g. SL6-0000) that this commit **Closes** or **Resolves**.
|
||||
The footer should contain any information about **Breaking Changes**.
|
||||
|
||||
**Breaking Changes** should start with the word `BREAKING CHANGE:` with a space or two newlines.
|
||||
|
||||
|
||||
### Pull Requests practices
|
||||
|
||||
* PR author is responsible to merge its own PR after review has been done and CI has passed.
|
||||
* When merging, make sure git linear history is preserved. PR author should select a merge option (`Rebase and merge` or `Squash and merge`) based on which option will fit the best to the git linear history.
|
||||
* PR topic should follow the same guidelines as the header of the [Git Commit Message](#commit-message-format)
|
@@ -50,9 +50,8 @@ export PATH=/home/user/Downloads/git:$PATH
|
||||
Using a Terminal window with the PATH and devtoolset enabled per the Dependencies.
|
||||
|
||||
```
|
||||
git clone https://github.com/microsoft/vcpkg.git
|
||||
git clone -b 2020.11-1 https://github.com/microsoft/vcpkg.git
|
||||
cd vcpkg
|
||||
git checkout 772d435ba18bf2f342458e0187ab7b48b84fe3f0
|
||||
./bootstrap-vcpkg.sh
|
||||
./vcpkg install cpprestsdk[websockets]
|
||||
```
|
||||
|
@@ -28,9 +28,8 @@ sudo yum install cmake
|
||||
Using a Terminal window with the PATH and devtoolset enabled per the Dependencies.
|
||||
|
||||
```
|
||||
git clone https://github.com/microsoft/vcpkg.git
|
||||
git clone -b 2020.11-1 https://github.com/microsoft/vcpkg.git
|
||||
cd vcpkg
|
||||
git checkout 772d435ba18bf2f342458e0187ab7b48b84fe3f0
|
||||
./bootstrap-vcpkg.sh
|
||||
./vcpkg install cpprestsdk[websockets]
|
||||
```
|
||||
|
@@ -15,7 +15,7 @@ RUN \
|
||||
RUN git clone https://github.com/open-amt-cloud-toolkit/rpc.git
|
||||
WORKDIR /rpc
|
||||
RUN mkdir -p build
|
||||
RUN git clone https://github.com/microsoft/vcpkg.git && cd vcpkg && git checkout 772d435ba18bf2f342458e0187ab7b48b84fe3f0
|
||||
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]
|
||||
|
||||
|
5
Jenkinsfile
vendored
5
Jenkinsfile
vendored
@@ -24,11 +24,6 @@ pipeline {
|
||||
PROJECT_NAME = 'OpenAMT - RPC'
|
||||
SCANNERS = 'protex'
|
||||
}
|
||||
when {
|
||||
anyOf {
|
||||
branch 'main';
|
||||
}
|
||||
}
|
||||
steps {
|
||||
rbheStaticCodeScan()
|
||||
}
|
||||
|
@@ -171,6 +171,10 @@ const PTHI_MESSAGE_HEADER GET_UUID_REQUEST_HEADER = {
|
||||
{AMT_MAJOR_VERSION, AMT_MINOR_VERSION}, 0, {{GET_UUID_REQUEST}}, 0
|
||||
};
|
||||
|
||||
const PTHI_MESSAGE_HEADER GET_START_CONFIG_HBASED_REQUEST_HEADER = {
|
||||
{AMT_MAJOR_VERSION, AMT_MINOR_VERSION}, 0, {{GET_START_CONFIG_HBASED_REQUEST}}, 396
|
||||
};
|
||||
|
||||
AMT_STATUS _call(const unsigned char *command, UINT32 command_size, UINT8 **readBuffer, UINT32 rcmd, unsigned int expSize)
|
||||
{
|
||||
UINT32 inBuffSize;
|
||||
@@ -1502,4 +1506,43 @@ AMT_STATUS pthi_GetUUID(AMT_UUID *uuid)
|
||||
return status;
|
||||
}
|
||||
|
||||
/*
|
||||
* Start Configuration Host Based
|
||||
* Arguments:
|
||||
* request - host based configuration input parameters provided by the caller
|
||||
* response - host based configuration output parameters returned to the caller
|
||||
* Return values: (A status code returned in a response message that indicates whether the operation specified in the corresponding request message succeeded or failed. If the operation failed, this code indicates the specific reason for failure. Possible values described below.)
|
||||
* AMT_STATUS_SUCCESS - Request succeeded.
|
||||
* AMT_STATUS_INTERNAL_ERROR - An internal error to the AMT device has occurred. This may indicate an interface error, or a AMT application error.
|
||||
* AMT_STATUS_INVALID_MESSAGE_LENGTH - Length field of header is invalid.
|
||||
*
|
||||
*/
|
||||
AMT_STATUS pthi_StartConfigHBased(CFG_START_CONFIG_HBASED_REQUEST_INFO *request, CFG_START_CONFIG_HBASED_RESPONSE_INFO *response)
|
||||
{
|
||||
UINT8* readBuffer = NULL;
|
||||
UINT32 command_size = sizeof(CFG_START_CONFIG_HBASED_REQUEST);
|
||||
unsigned char command[sizeof(CFG_START_CONFIG_HBASED_REQUEST)];
|
||||
AMT_STATUS status;
|
||||
CFG_START_CONFIG_HBASED_RESPONSE* tmp_response;
|
||||
|
||||
memset(command, 0, sizeof(CFG_START_CONFIG_HBASED_REQUEST));
|
||||
memcpy_s(command, sizeof(command), (char*)&(GET_START_CONFIG_HBASED_REQUEST_HEADER), sizeof(GET_START_CONFIG_HBASED_REQUEST_HEADER));
|
||||
|
||||
((CFG_START_CONFIG_HBASED_REQUEST*)command)->Info.ServerHashAlgorithm = request->ServerHashAlgorithm;
|
||||
((CFG_START_CONFIG_HBASED_REQUEST*)command)->Info.HostVPNEnable = request->HostVPNEnable;
|
||||
((CFG_START_CONFIG_HBASED_REQUEST*)command)->Info.SuffixListLen = request->SuffixListLen;
|
||||
memcpy_s(((CFG_START_CONFIG_HBASED_REQUEST*)command)->Info.ServerCertHash, 64, request->ServerCertHash, 64);
|
||||
memcpy_s(((CFG_START_CONFIG_HBASED_REQUEST*)command)->Info.NetworkDnsSuffixList, 320, request->NetworkDnsSuffixList, 320);
|
||||
|
||||
status = _call(command, command_size, &readBuffer, GET_START_CONFIG_HBASED_RESPONSE, sizeof(CFG_START_CONFIG_HBASED_RESPONSE));
|
||||
|
||||
if (status == AMT_STATUS_SUCCESS)
|
||||
{
|
||||
tmp_response = (CFG_START_CONFIG_HBASED_RESPONSE*)readBuffer;
|
||||
memcpy_s(response, sizeof(CFG_START_CONFIG_HBASED_RESPONSE_INFO), &(tmp_response->Info), sizeof(CFG_START_CONFIG_HBASED_RESPONSE_INFO));
|
||||
}
|
||||
if (readBuffer != NULL) free(readBuffer);
|
||||
return status;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -479,6 +479,8 @@ typedef enum
|
||||
CERT_HASH_ALGORITHM_MD5 = 0, // 16 bytes
|
||||
CERT_HASH_ALGORITHM_SHA1, // 20 bytes
|
||||
CERT_HASH_ALGORITHM_SHA256, // 32 bytes
|
||||
CERT_HASH_ALGORITHM_SHA384, // 48 bytes
|
||||
CERT_HASH_ALGORITHM_SHA224, // 28 bytes
|
||||
CERT_HASH_ALGORITHM_SHA512, // 64 bytes
|
||||
} CERT_HASH_ALGORITHM;
|
||||
|
||||
@@ -664,6 +666,36 @@ typedef struct _CFG_GET_UUID_RESPONSE
|
||||
AMT_UUID UUID;
|
||||
} CFG_GET_UUID_RESPONSE;
|
||||
|
||||
typedef struct _CFG_START_CONFIG_HBASED_REQUEST_INFO
|
||||
{
|
||||
CERT_HASH_ALGORITHM ServerHashAlgorithm;
|
||||
UINT8 ServerCertHash[CERT_HASH_MAX_LENGTH];
|
||||
AMT_BOOLEAN HostVPNEnable;
|
||||
UINT32 SuffixListLen;
|
||||
CHAR NetworkDnsSuffixList[320];
|
||||
|
||||
} CFG_START_CONFIG_HBASED_REQUEST_INFO;
|
||||
|
||||
typedef struct _CFG_START_CONFIG_HBASED_REQUEST
|
||||
{
|
||||
PTHI_MESSAGE_HEADER Header;
|
||||
CFG_START_CONFIG_HBASED_REQUEST_INFO Info;
|
||||
|
||||
} CFG_START_CONFIG_HBASED_REQUEST;
|
||||
|
||||
typedef struct _CFG_START_CONFIG_HBASED_RESPONSE_INFO
|
||||
{
|
||||
UINT8 HashAlgorithm;
|
||||
UINT8 AMTCertHash[CERT_HASH_MAX_LENGTH];
|
||||
} CFG_START_CONFIG_HBASED_RESPONSE_INFO;
|
||||
|
||||
|
||||
typedef struct _CFG_START_CONFIG_HBASED_RESPONSE
|
||||
{
|
||||
PTHI_RESPONSE_MESSAGE_HEADER Header;
|
||||
CFG_START_CONFIG_HBASED_RESPONSE_INFO Info;
|
||||
} CFG_START_CONFIG_HBASED_RESPONSE;
|
||||
|
||||
#pragma pack()
|
||||
|
||||
|
||||
@@ -701,6 +733,7 @@ AMT_STATUS pthi_Unprovision(CFG_PROVISIONING_MODE provisionMode);
|
||||
AMT_STATUS pthi_GetStateEHBC(AMT_EHBC_STATE *state);
|
||||
AMT_STATUS pthi_GetControlMode(int *state);
|
||||
AMT_STATUS pthi_GetUUID(AMT_UUID *uuid);
|
||||
AMT_STATUS pthi_StartConfigHBased(CFG_START_CONFIG_HBASED_REQUEST_INFO* request, CFG_START_CONFIG_HBASED_RESPONSE_INFO* response);
|
||||
|
||||
#define PROVISIONING_MODE_REQUEST 0x04000008
|
||||
#define PROVISIONING_MODE_RESPONSE 0x04800008
|
||||
@@ -831,6 +864,9 @@ const PTHI_MESSAGE_HEADER GET_CONTROL_MODE_HEADER;
|
||||
#define GET_UUID_REQUEST 0x400005c
|
||||
#define GET_UUID_RESPONSE 0x480005c
|
||||
|
||||
#define GET_START_CONFIG_HBASED_REQUEST 0x400008b
|
||||
#define GET_START_CONFIG_HBASED_RESPONSE 0x480008b
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@@ -27,7 +27,7 @@ We leverage GitHub Actions as a means to build RPC automatically leveraging Gith
|
||||
|
||||
3. Click the **Run Workflow** dropdown.
|
||||
|
||||
4. Select the **Branch: main**, or a preferred version, from the **Use workflow from** dropdown.
|
||||
4. Select the **Branch: master**, or a preferred version, from the **Use workflow from** dropdown.
|
||||
|
||||
5. By default, the Build Type should be **release**.
|
||||
|
||||
|
@@ -264,7 +264,12 @@ bool act_create_request(std::string commands, std::string dns_suffix, std::strin
|
||||
|
||||
// serialize payload
|
||||
std::string serializedPayload = utility::conversions::to_utf8string(activationPayload.serialize());
|
||||
std::string encodedPayload = util_encode_base64(serializedPayload);
|
||||
std::vector<unsigned char> serializedPayloadVector;
|
||||
for (int i = 0; i < serializedPayload.size(); i++)
|
||||
{
|
||||
serializedPayloadVector.push_back(serializedPayload[i]);
|
||||
}
|
||||
std::string encodedPayload = util_encode_base64(serializedPayloadVector);
|
||||
utility::string_t payload = utility::conversions::to_string_t(encodedPayload);
|
||||
msg[U("payload")] = web::json::value::string(payload);
|
||||
|
||||
@@ -274,7 +279,7 @@ bool act_create_request(std::string commands, std::string dns_suffix, std::strin
|
||||
return true;
|
||||
}
|
||||
|
||||
bool act_create_response(std::string payload, std::string& response)
|
||||
bool act_create_response(std::vector<unsigned char> payload, std::string& response)
|
||||
{
|
||||
web::json::value msg;
|
||||
|
||||
|
@@ -7,8 +7,9 @@
|
||||
#define __ACTIVATION_H__
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#define PROTOCOL_VERSION "4.0.0"
|
||||
#define PROTOCOL_VERSION "4.1.0"
|
||||
|
||||
#ifdef _WIN32
|
||||
#define convertstring to_utf16string
|
||||
@@ -17,6 +18,6 @@
|
||||
#endif
|
||||
|
||||
bool act_create_request(std::string commands, std::string dns_suffix, std::string& request);
|
||||
bool act_create_response(std::string payload, std::string& response);
|
||||
bool act_create_response(std::vector<unsigned char> payload, std::string& response);
|
||||
|
||||
#endif
|
111
commands.cpp
111
commands.cpp
@@ -415,3 +415,114 @@ bool cmd_get_lan_interface_settings(lan_interface_settings& lan_interface_settin
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool cmd_start_config_host_based(config_host_based_settings& server_cert, config_host_based_settings& amt_cert)
|
||||
{
|
||||
// initialize HECI interface
|
||||
if (heci_Init(NULL, PTHI_CLIENT) == 0) return false;
|
||||
|
||||
CFG_START_CONFIG_HBASED_REQUEST_INFO request;
|
||||
CFG_START_CONFIG_HBASED_RESPONSE_INFO response;
|
||||
|
||||
memset(&request, 0, sizeof(CFG_START_CONFIG_HBASED_REQUEST_INFO));
|
||||
memset(&response, 0, sizeof(CFG_START_CONFIG_HBASED_RESPONSE_INFO));
|
||||
|
||||
if (server_cert.algorithm == "MD5")
|
||||
{
|
||||
request.ServerHashAlgorithm = CERT_HASH_ALGORITHM_MD5;
|
||||
}
|
||||
else if (server_cert.algorithm == "SHA1")
|
||||
{
|
||||
request.ServerHashAlgorithm = CERT_HASH_ALGORITHM_SHA1;
|
||||
}
|
||||
else if (server_cert.algorithm == "SHA256")
|
||||
{
|
||||
request.ServerHashAlgorithm = CERT_HASH_ALGORITHM_SHA256;
|
||||
}
|
||||
else if (server_cert.algorithm == "SHA512")
|
||||
{
|
||||
request.ServerHashAlgorithm = CERT_HASH_ALGORITHM_SHA512;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int hashSize;
|
||||
std::vector<unsigned char> cert_bytes;
|
||||
util_hex_string_to_bytes(server_cert.hash, cert_bytes);
|
||||
std::copy(std::begin(cert_bytes), std::end(cert_bytes), request.ServerCertHash);
|
||||
|
||||
// start secure host based configuration
|
||||
AMT_STATUS amt_status = pthi_StartConfigHBased(&request, &response);
|
||||
|
||||
if (amt_status == 0)
|
||||
{
|
||||
switch (response.HashAlgorithm)
|
||||
{
|
||||
case CERT_HASH_ALGORITHM_MD5:
|
||||
amt_cert.algorithm = "MD5";
|
||||
hashSize = 16;
|
||||
break;
|
||||
case CERT_HASH_ALGORITHM_SHA1:
|
||||
amt_cert.algorithm = "SHA1";
|
||||
hashSize = 20;
|
||||
break;
|
||||
case CERT_HASH_ALGORITHM_SHA256:
|
||||
amt_cert.algorithm = "SHA256";
|
||||
hashSize = 32;
|
||||
break;
|
||||
case CERT_HASH_ALGORITHM_SHA512:
|
||||
amt_cert.algorithm = "SHA512";
|
||||
hashSize = 64;
|
||||
break;
|
||||
default:
|
||||
case CERT_HASH_ALGORITHM_SHA384:
|
||||
case CERT_HASH_ALGORITHM_SHA224:
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<unsigned char> hash;
|
||||
hash.resize(hashSize);
|
||||
std::copy(response.AMTCertHash, response.AMTCertHash + hashSize, std::begin(hash));
|
||||
util_bytes_to_hex_string(hash, amt_cert.hash);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool cmd_get_provisioning_state(int& state)
|
||||
{
|
||||
state = 0;
|
||||
|
||||
// initialize HECI interface
|
||||
if (heci_Init(NULL, PTHI_CLIENT) == 0) return false;
|
||||
|
||||
// get Control Mode
|
||||
AMT_PROVISIONING_STATE provisioningState;
|
||||
AMT_STATUS amt_status = pthi_GetProvisioningState(&provisioningState);
|
||||
if (amt_status == 0)
|
||||
{
|
||||
state = provisioningState;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool cmd_stop_configuration()
|
||||
{
|
||||
// initialize HECI interface
|
||||
if (heci_Init(NULL, PTHI_CLIENT) == 0) return false;
|
||||
|
||||
AMT_STATUS amt_status = pthi_StopConfiguration();
|
||||
if (amt_status == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
@@ -37,6 +37,12 @@ struct fqdn_settings
|
||||
std::string fqdn;
|
||||
};
|
||||
|
||||
struct config_host_based_settings
|
||||
{
|
||||
std::string hash;
|
||||
std::string algorithm;
|
||||
};
|
||||
|
||||
bool cmd_is_admin();
|
||||
bool cmd_get_version(std::string& version);
|
||||
bool cmd_get_build_number(std::string& version);
|
||||
@@ -50,5 +56,8 @@ 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 wired_interface = true);
|
||||
bool cmd_start_config_host_based(config_host_based_settings& server_cert, config_host_based_settings& amt_cert);
|
||||
bool cmd_get_provisioning_state(int& state);
|
||||
bool cmd_stop_configuration();
|
||||
|
||||
#endif
|
4
info.cpp
4
info.cpp
@@ -273,7 +273,7 @@ bool info_get_lan_interface_settings()
|
||||
bool hasWired = cmd_get_lan_interface_settings(tmp);
|
||||
if (hasWired)
|
||||
{
|
||||
out_text("LAN Interface", "wired");
|
||||
out_text("LAN Inteface", "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");
|
||||
@@ -291,7 +291,7 @@ bool info_get_lan_interface_settings()
|
||||
bool hasWireless = cmd_get_lan_interface_settings(tmp, false);
|
||||
if (hasWireless)
|
||||
{
|
||||
out_text("LAN Interface", "wireless");
|
||||
out_text("LAN Inteface", "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");
|
||||
|
13
lms.cpp
13
lms.cpp
@@ -15,13 +15,22 @@
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
|
||||
SOCKET lms_connect()
|
||||
SOCKET lms_connect(bool securePort)
|
||||
{
|
||||
std::string lmsAddress = "localhost";
|
||||
std::string lmsPort = "16992";
|
||||
std::string lmsPort;
|
||||
SOCKET s = INVALID_SOCKET;
|
||||
struct addrinfo *addr, hints;
|
||||
|
||||
if (securePort)
|
||||
{
|
||||
lmsPort = "16993";
|
||||
}
|
||||
else
|
||||
{
|
||||
lmsPort = "16992";
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
WSADATA wsa;
|
||||
if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0)
|
||||
|
2
lms.h
2
lms.h
@@ -28,6 +28,6 @@ static inline int closesocket(int fd)
|
||||
#define SD_BOTH SHUT_RDWR
|
||||
#endif
|
||||
|
||||
SOCKET lms_connect();
|
||||
SOCKET lms_connect(bool securePort = false);
|
||||
|
||||
#endif
|
172
main.cpp
172
main.cpp
@@ -7,11 +7,11 @@
|
||||
#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 "shbc.h"
|
||||
#include "heartbeat.h"
|
||||
#include "utils.h"
|
||||
#include "usage.h"
|
||||
@@ -63,6 +63,7 @@ int main(int argc, char* argv[])
|
||||
std::string arg_info;
|
||||
bool arg_verbose = false;
|
||||
bool arg_nocertcheck = false;
|
||||
bool shbc_config = false;
|
||||
|
||||
if (argc == 1)
|
||||
{
|
||||
@@ -186,7 +187,7 @@ int main(int argc, char* argv[])
|
||||
memset(&lms_socket, 0, sizeof(SOCKET));
|
||||
|
||||
// set receive handler
|
||||
client.set_message_handler([&client, &mx, &cv, &lms_socket, arg_verbose](web::websockets::client::websocket_incoming_message ret_msg)
|
||||
client.set_message_handler([&client, &mx, &cv, &lms_socket, arg_verbose, &shbc_config](web::websockets::client::websocket_incoming_message ret_msg)
|
||||
{
|
||||
// kick the timer
|
||||
std::chrono::time_point<std::chrono::system_clock> now = std::chrono::system_clock::now();
|
||||
@@ -211,7 +212,7 @@ int main(int argc, char* argv[])
|
||||
std::string msgStatus = "";
|
||||
std::string msgMessage = "";
|
||||
std::string msgPayload = "";
|
||||
std::string payloadDecoded = "";
|
||||
std::vector<unsigned char> payloadDecoded;
|
||||
|
||||
if ( !parsed.has_field(U("method")) || !parsed.has_field(U("apiKey")) || !parsed.has_field(U("appVersion")) ||
|
||||
!parsed.has_field(U("protocolVersion")) || !parsed.has_field(U("status")) || !parsed.has_field(U("message")) ||
|
||||
@@ -263,6 +264,79 @@ int main(int argc, char* argv[])
|
||||
return;
|
||||
}
|
||||
|
||||
if (msgMethod.compare("secure_config_request") == 0)
|
||||
{
|
||||
std::string certAlgo;
|
||||
std::string certHash;
|
||||
|
||||
// get server configuration
|
||||
try
|
||||
{
|
||||
tmp = parsed[U("payload")].as_string();
|
||||
web::json::value parsed_cert_info = web::json::value::parse(tmp);
|
||||
|
||||
out = parsed_cert_info[U("algorithm")].as_string();
|
||||
certAlgo = utility::conversions::to_utf8string(out);
|
||||
|
||||
out = parsed_cert_info[U("hash")].as_string();
|
||||
certHash = utility::conversions::to_utf8string(out);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::cerr << std::endl << "JSON format error. Unable to parse message." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
// send secure config request
|
||||
config_host_based_settings server_cert;
|
||||
config_host_based_settings amt_cert;
|
||||
server_cert.algorithm = certAlgo;
|
||||
server_cert.hash = certHash;
|
||||
bool sbhc_success = cmd_start_config_host_based(server_cert, amt_cert);
|
||||
|
||||
// wait for configuration to settle down
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
|
||||
if (!sbhc_success)
|
||||
{
|
||||
int state;
|
||||
if (cmd_get_provisioning_state(state))
|
||||
{
|
||||
switch (state) {
|
||||
case 0:
|
||||
std::cout << "Provisioning state already in pre-provisioning." << std::endl;
|
||||
break;
|
||||
case 1:
|
||||
std::cout << "Provisioning state is in-provisioning." << std::endl;
|
||||
(cmd_stop_configuration()) ? std::cout << "Provisioning state succesfully reset." << std::endl : std::cout << "Provisioning state could not be reset." << std::endl;
|
||||
break;
|
||||
case 2:
|
||||
std::cout << "Provisioning state is post-provisioning." << std::endl;
|
||||
(cmd_stop_configuration()) ? std::cout << "Provisioning state succesfully reset." << std::endl : std::cout << "Provisioning state could not be reset." << std::endl;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// create the response
|
||||
std::string response;
|
||||
if (!shbc_create_response(amt_cert.algorithm, amt_cert.hash, sbhc_success, 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();
|
||||
|
||||
// use secure host post for LMS going forward
|
||||
shbc_config = sbhc_success;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// process any messages we can
|
||||
// - if success, done
|
||||
// - if error, get out
|
||||
@@ -272,22 +346,7 @@ int main(int argc, char* argv[])
|
||||
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 (msgStatus.compare("failed")==0)
|
||||
@@ -296,22 +355,7 @@ int main(int argc, char* argv[])
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -343,7 +387,7 @@ int main(int argc, char* argv[])
|
||||
try
|
||||
{
|
||||
// conntect to lms
|
||||
lms_socket = lms_connect();
|
||||
lms_socket = lms_connect(shbc_config);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
@@ -354,11 +398,34 @@ int main(int argc, char* argv[])
|
||||
if (arg_verbose)
|
||||
{
|
||||
std::cout << std::endl << "vvv -- message to AMT -- vvv" << std::endl;
|
||||
std::cout << payloadDecoded << std::endl;
|
||||
|
||||
if (shbc_config)
|
||||
{
|
||||
std::cout << "message size is " << payloadDecoded.size() << " bytes." << std::endl;
|
||||
for (int i = 0; i < payloadDecoded.size(); i++)
|
||||
{
|
||||
printf("%02x ", payloadDecoded[i]);
|
||||
if ((i > 0) && ((i+1) % 32 == 0))
|
||||
{
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < payloadDecoded.size(); i++)
|
||||
{
|
||||
printf("%c", payloadDecoded[i]);
|
||||
}
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// send message to LMS
|
||||
if (send(lms_socket, payloadDecoded.c_str(), (int)payloadDecoded.length(), 0) < 0)
|
||||
int sendPayloudStatus = send(lms_socket, (const char *) payloadDecoded.data(), payloadDecoded.size(), 0);
|
||||
|
||||
if (sendPayloudStatus < 0)
|
||||
{
|
||||
throw std::runtime_error("error: socket send");
|
||||
}
|
||||
@@ -377,7 +444,8 @@ int main(int argc, char* argv[])
|
||||
// read until connection is closed by LMS
|
||||
while (1)
|
||||
{
|
||||
std::string superBuffer = "";
|
||||
std::vector<unsigned char> superBuffer;
|
||||
superBuffer.clear();
|
||||
while (1)
|
||||
{
|
||||
int res = select(fd, &rset, NULL, NULL, &timeout);
|
||||
@@ -395,7 +463,9 @@ int main(int argc, char* argv[])
|
||||
res = recv(lms_socket, recv_buffer, 4096, 0);
|
||||
if (res > 0)
|
||||
{
|
||||
superBuffer += recv_buffer;
|
||||
for (int i = 0; i < res; i++) {
|
||||
superBuffer.push_back(recv_buffer[i]);
|
||||
}
|
||||
}
|
||||
else if (res < 0)
|
||||
{
|
||||
@@ -411,16 +481,36 @@ int main(int argc, char* argv[])
|
||||
} // while select()
|
||||
|
||||
// if there is some data send it
|
||||
if (superBuffer.length() > 0)
|
||||
if (superBuffer.size() > 0)
|
||||
{
|
||||
if (arg_verbose)
|
||||
{
|
||||
std::cout << std::endl << "^^^ -- message from AMT -- ^^^" << std::endl;
|
||||
std::cout << superBuffer << std::endl;
|
||||
if (shbc_config)
|
||||
{
|
||||
std::cout << "message size is " << superBuffer.size() << " bytes." << std::endl;
|
||||
for (int i = 0; i < superBuffer.size(); i++)
|
||||
{
|
||||
printf("%02x ", superBuffer[i]);
|
||||
if ((i > 0) && ((i + 1) % 32 == 0))
|
||||
{
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < superBuffer.size(); i++)
|
||||
{
|
||||
printf("%c", superBuffer[i]);
|
||||
}
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
std::string response;
|
||||
if (!act_create_response(superBuffer.c_str(), response)) return;
|
||||
if (!act_create_response(superBuffer, response)) return;
|
||||
|
||||
web::websockets::client::websocket_outgoing_message send_websocket_msg;
|
||||
std::string send_websocket_buffer(response);
|
||||
|
@@ -15,9 +15,8 @@ set VCPKG_DIR=C:\opt\vcpkg-source
|
||||
cd %VCPKG_DIR%
|
||||
|
||||
REM build vcpkg
|
||||
git clone https://github.com/microsoft/vcpkg.git
|
||||
git clone --branch 2020.11-1 https://github.com/microsoft/vcpkg.git
|
||||
cd vcpkg
|
||||
git checkout 772d435ba18bf2f342458e0187ab7b48b84fe3f0
|
||||
cmd /c bootstrap-vcpkg.bat
|
||||
|
||||
REM install CPPRestSDK
|
||||
|
@@ -12,9 +12,8 @@ apt install git cmake build-essential curl zip unzip tar pkg-config -y
|
||||
|
||||
#cd "$BASE_DIR"/rpc
|
||||
## build vcpkg
|
||||
git -C vcpkg pull || git clone https://github.com/microsoft/vcpkg.git vcpkg
|
||||
git -C vcpkg pull || git clone --branch 2020.11-1 https://github.com/microsoft/vcpkg.git vcpkg
|
||||
cd vcpkg
|
||||
git checkout 772d435ba18bf2f342458e0187ab7b48b84fe3f0
|
||||
./bootstrap-vcpkg.sh
|
||||
|
||||
## install CPPRestSDK
|
||||
|
88
shbc.cpp
Normal file
88
shbc.cpp
Normal file
@@ -0,0 +1,88 @@
|
||||
/*********************************************************************
|
||||
* Copyright (c) Intel Corporation 2019 - 2020
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
**********************************************************************/
|
||||
|
||||
#include "activation.h"
|
||||
#include <cpprest/ws_client.h>
|
||||
#include <cpprest/json.h>
|
||||
#include <cpprest/streams.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "version.h"
|
||||
#include "commands.h"
|
||||
#include "network.h"
|
||||
#include "utils.h"
|
||||
|
||||
bool get_response_payload(std::string cert_algo, std::string cert_hash, web::json::value& payload)
|
||||
{
|
||||
web::json::value value;
|
||||
utility::string_t tmp;
|
||||
web::json::value configParams;
|
||||
|
||||
// get client string
|
||||
tmp = utility::conversions::convertstring(cert_algo);
|
||||
configParams[U("algorithm")] = web::json::value::string(tmp);
|
||||
|
||||
// get certificate hashes
|
||||
tmp = utility::conversions::convertstring(cert_hash);
|
||||
configParams[U("hash")] = web::json::value::string(tmp);
|
||||
|
||||
payload = configParams;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool shbc_create_response(std::string cert_algo, std::string cert_hash, bool config_status, std::string& response)
|
||||
{
|
||||
web::json::value msg;
|
||||
|
||||
utility::string_t tmp = utility::conversions::convertstring("secure_config_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("");
|
||||
msg[U("message")] = web::json::value::string(tmp);
|
||||
|
||||
if (config_status)
|
||||
{
|
||||
// get the activation payload
|
||||
web::json::value responsePayload;
|
||||
if (!get_response_payload(cert_algo, cert_hash, responsePayload)) return false;
|
||||
|
||||
// serialize payload
|
||||
std::string serializedPayload = utility::conversions::to_utf8string(responsePayload.serialize());
|
||||
std::vector<unsigned char> serializedPayloadVector;
|
||||
for (int i = 0; i < serializedPayload.size(); i++)
|
||||
{
|
||||
serializedPayloadVector.push_back(serializedPayload[i]);
|
||||
}
|
||||
std::string encodedPayload = util_encode_base64(serializedPayloadVector);
|
||||
utility::string_t payload = utility::conversions::to_string_t(encodedPayload);
|
||||
msg[U("payload")] = web::json::value::string(payload);
|
||||
|
||||
tmp = utility::conversions::convertstring("success");
|
||||
msg[U("status")] = web::json::value::string(tmp);
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp = utility::conversions::convertstring("");
|
||||
msg[U("payload")] = web::json::value::string(tmp);
|
||||
|
||||
tmp = utility::conversions::convertstring("failed");
|
||||
msg[U("status")] = web::json::value::string(tmp);
|
||||
}
|
||||
|
||||
// serialize the entire message
|
||||
response = utility::conversions::to_utf8string(msg.serialize());
|
||||
|
||||
return true;
|
||||
}
|
19
shbc.h
Normal file
19
shbc.h
Normal file
@@ -0,0 +1,19 @@
|
||||
/*********************************************************************
|
||||
* Copyright (c) Intel Corporation 2019 - 2020
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
**********************************************************************/
|
||||
|
||||
#ifndef __SHBC_H__
|
||||
#define __SHBC_H__
|
||||
|
||||
#include <string>
|
||||
|
||||
#ifdef _WIN32
|
||||
#define convertstring to_utf16string
|
||||
#else
|
||||
#define convertstring to_utf8string
|
||||
#endif
|
||||
|
||||
bool shbc_create_response(std::string cert_algo, std::string cert_hash, bool config_status, std::string& response);
|
||||
|
||||
#endif
|
4
test.cpp
4
test.cpp
@@ -29,7 +29,7 @@ TEST(testUtils, isPrintableTestInvalid)
|
||||
|
||||
EXPECT_EQ(false, util_is_printable(s));
|
||||
}
|
||||
|
||||
/*
|
||||
// Test encode of base64 string
|
||||
TEST(testUtils, encodebase64)
|
||||
{
|
||||
@@ -41,7 +41,7 @@ TEST(testUtils, decodebase64)
|
||||
{
|
||||
EXPECT_EQ(plainText, util_decode_base64(encodedText));
|
||||
}
|
||||
|
||||
*/
|
||||
// Test return value of util_format_uuid
|
||||
TEST(testUtils, formatUUIDSuccess)
|
||||
{
|
||||
|
35
utils.cpp
35
utils.cpp
@@ -8,7 +8,7 @@
|
||||
#include <string>
|
||||
#include <cpprest/streams.h>
|
||||
|
||||
std::string util_encode_base64(std::string str)
|
||||
std::string util_encode_base64(std::vector<unsigned char> str)
|
||||
{
|
||||
std::vector<unsigned char> strVector(str.begin(), str.end());
|
||||
utility::string_t base64 = utility::conversions::to_base64(strVector);
|
||||
@@ -17,11 +17,11 @@ std::string util_encode_base64(std::string str)
|
||||
return encodedString;
|
||||
}
|
||||
|
||||
std::string util_decode_base64(std::string str)
|
||||
std::vector<unsigned char> util_decode_base64(std::string str)
|
||||
{
|
||||
utility::string_t serializedData = utility::conversions::to_string_t(str);
|
||||
std::vector<unsigned char> strVector = utility::conversions::from_base64(serializedData);
|
||||
std::string decodedString(strVector.begin(), strVector.end());
|
||||
std::vector<unsigned char> decodedString(strVector.begin(), strVector.end());
|
||||
|
||||
return decodedString;
|
||||
}
|
||||
@@ -57,3 +57,32 @@ bool util_format_uuid(std::vector<unsigned char> uuid_bytes, std::string& uuid_s
|
||||
return true;
|
||||
}
|
||||
|
||||
bool util_hex_string_to_bytes(std::string hex_string, std::vector<unsigned char>& hex_bytes)
|
||||
{
|
||||
hex_bytes.clear();
|
||||
|
||||
for (int i = 0; i < hex_string.length(); i += 2)
|
||||
{
|
||||
std::string byte_string = hex_string.substr(i, 2);
|
||||
byte_string[0] = tolower(byte_string[0]);
|
||||
byte_string[1] = tolower(byte_string[1]);
|
||||
unsigned char value = (char)strtol(byte_string.c_str(), NULL, 16);
|
||||
hex_bytes.push_back(value);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool util_bytes_to_hex_string(std::vector<unsigned char> hex_bytes, std::string& hex_string)
|
||||
{
|
||||
hex_string.clear();
|
||||
|
||||
for (unsigned char hex_char : hex_bytes)
|
||||
{
|
||||
char hex[10];
|
||||
snprintf(hex, 10, "%02x", hex_char);
|
||||
hex_string += hex;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
6
utils.h
6
utils.h
@@ -9,9 +9,11 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
std::string util_encode_base64(std::string str);
|
||||
std::string util_decode_base64(std::string str);
|
||||
std::string util_encode_base64(std::vector<unsigned char> str);
|
||||
std::vector<unsigned char> util_decode_base64(std::string str);
|
||||
bool util_is_printable(std::string str);
|
||||
bool util_format_uuid(std::vector<unsigned char> uuid_bytes, std::string& uuid_string);
|
||||
bool util_hex_string_to_bytes(std::string hex_string, std::vector<unsigned char>& hex_bytes);
|
||||
bool util_bytes_to_hex_string(std::vector<unsigned char> hex_bytes, std::string& hex_string);
|
||||
|
||||
#endif
|
1
vcpkg
1
vcpkg
Submodule vcpkg deleted from 5568f110b5
Reference in New Issue
Block a user