From b939d1a0b6b375ea5bae54d83a1cb89eb888c75a Mon Sep 17 00:00:00 2001 From: gcontini <1121667+gcontini@users.noreply.github.com> Date: 周六, 21 3月 2020 20:57:47 +0800 Subject: [PATCH] update docs --- src/library/hw_identifier/hw_identifier_facade.hpp | 2 src/library/hw_identifier/default_strategy.hpp | 4 src/library/hw_identifier/hw_identifier_facade.cpp | 10 src/library/hw_identifier/identification_strategy.cpp | 4 doc/analysis/features.md | 36 +- test/library/hw_identifier/hw_identifier_facade_test.cpp | 4 doc/analysis/Development-And-Usage-Workflow.md | 2 doc/api/extend.rst | 26 ++ src/inspector/inspector.cpp | 2 doc/_static/lock_32.png | 0 doc/_templates/breadcrumbs.html | 21 + src/library/hw_identifier/hw_identifier.hpp | 4 src/library/hw_identifier/identification_strategy.hpp | 13 test/library/hw_identifier/hw_identifier_test.cpp | 4 doc/analysis/Backoffice.md | 6 CMakeLists.txt | 4 doc/development/Build-the-library-windows.md | 15 src/library/hw_identifier/hw_identifier.cpp | 6 doc/index.rst | 135 ++++++++++ doc/conf.py | 21 + doc/development/Dependencies.md | 2 doc/api/hardware_identifiers.rst | 11 doc/api/public_api.rst | 24 + doc/other/QA.md | 16 doc/development/Build-the-library.md | 2 doc/development/Development-Environment-Setup.md | 29 +- doc/_static/css/custom.css | 1 test/functional/hw_identifier_it_test.cpp | 10 doc/_static/lock_32.ico | 0 src/templates/licensecc_properties.h.in | 108 ++++++-- CONTRIBUTING.md | 16 doc/usage/License-retrieval.md | 7 src/library/hw_identifier/ethernet.hpp | 2 /dev/null | 29 -- src/library/hw_identifier/disk_strategy.cpp | 2 src/library/licensecc.cpp | 2 doc/other/CREDITS.md | 37 +- src/library/hw_identifier/ethernet.cpp | 2 doc/usage/Hardware-identifiers.rst | 59 ++++ src/library/hw_identifier/default_strategy.cpp | 18 include/licensecc/datatypes.h | 8 include/licensecc/licensecc.h | 33 + src/library/hw_identifier/disk_strategy.hpp | 2 43 files changed, 530 insertions(+), 209 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c32f44..d401573 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -165,10 +165,10 @@ message(STATUS "Doxygen found, generating docs.") SET(DOXYGEN_EXCLUDE_PATTERNS "*/library/ini/*;*/doc/resources/*") SET(DOXYGEN_DISABLE_INDEX YES) - SET(DOXYGEN_GENERATE_TREEVIEW YES) + #SET(DOXYGEN_GENERATE_TREEVIEW YES) SET(DOXYGEN_GENERATE_XML YES) SET(DOXYGEN_LAYOUT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/doc/DoxygenLayout.xml") - doxygen_add_docs(docs doc src include/licensecc COMMENT "doxygen docs") + doxygen_add_docs(docs doc src include/licensecc ${LCC_INCLUDE_DIR} COMMENT "doxygen docs") #file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/doc/resources/" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/html") #file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/doc/sphinx/" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}") diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 636c98e..8161e88 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,23 +2,19 @@ ========== :+1::tada: First off, if you landed here means you want to contribute! :tada::+1: -The following is a set of guidelines for contributing to Open License Manager and its packages, which are hosted in the [Open License Manager organization](https://github.com/open-license-manager) on GitHub. These are mostly guidelines, not rules. +The following is a set of guidelines for contributing to Open License Manager and its packages, which are hosted in the [Open License Manager organization](https://github.com/open-license-manager) on GitHub. ## How to contribute ### Interacting with the team -This section will help you understand how to interact with the development team and seek help. This is also a way of contributing because the answers given to you may help others. - -If you're experinecing issues with the project, due to lack/unclear documentation and you're unsure if opening or not a bug you can first contact us on the [project forum](https://groups.google.com/forum/#!forum/licensecc). Please try to be very specific about your problem. Use the guidelines in ["How to Submit A (Good) Bug Report"](#how-do-i-submit-a-good-bug-report) to structure your question. +If you're experinecing issues with the project, due to lack/unclear documentation and you're unsure if opening or not a bug you can first contact us on the [project forum](https://groups.google.com/forum/#!forum/licensecc). Please try to be very specific about your problem. Use the guidelines in ["How to Submit A (Good) Bug Report"](#how-to-submit-a-good-bug-report) to structure your question. ### Reporting Bugs -This section guides you through submitting a bug report for Open License Manager. Following these guidelines helps maintainers and the community understand your report :pencil:, reproduce the behavior :computer: :computer:, and find related reports :mag_right:. +Before creating bug reports, please [check the repository](https://github.com/open-license-manager/open-license-manager/issues) to see if the problem has already been reported. If it has **and the issue is still open**, add a comment to the existing issue instead of opening a new one. When you are creating a bug report, please [include as many details as possible](#how-to-submit-a-good-bug-report). -Before creating bug reports, please [check the repository](https://github.com/open-license-manager/open-license-manager/issues) to see if the problem has already been reported. If it has **and the issue is still open**, add a comment to the existing issue instead of opening a new one. When you are creating a bug report, please [include as many details as possible](#how-do-i-submit-a-good-bug-report). - -#### How to Submit A (Good) Bug Report +#### How to submit a good Bug Report Bugs are tracked as [GitHub issues](https://guides.github.com/features/issues/). Explain the problem and include additional details to help maintainers reproduce the problem: @@ -48,11 +44,11 @@ This section guides you through submitting an enhancement suggestion for Open License Manager, including completely new features and minor improvements to existing functionality. Following these guidelines helps maintainers and the community understand your suggestion :pencil: and find related suggestions :mag_right:. -Before creating enhancement suggestions, please check [existing enhancement request](https://github.com/open-license-manager/open-license-manager/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3Aenhancement) to see if the enhancement has already been suggested, as you might find out that you don't need to create one. When you are creating an enhancement suggestion, please [include as many details as possible](#how-do-i-submit-a-good-enhancement-suggestion). +Before creating enhancement suggestions, please check [existing enhancement request](https://github.com/open-license-manager/open-license-manager/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3Aenhancement) to see if the enhancement has already been suggested, as you might find out that you don't need to create one. When you are creating an enhancement suggestion, please [include as many details as possible](#how-to-submit-a-good-enhancement-suggestion). Please also check for the [current and planned features](https://github.com/open-license-manager/open-license-manager/wiki/features) in the wiki to see where the project is heading to. -#### How to submit a (Good) enhancement suggestion +#### How to submit a (good) enhancement suggestion Enhancement suggestions are tracked as [GitHub issues](https://guides.github.com/features/issues/). diff --git a/doc/_static/css/custom.css b/doc/_static/css/custom.css new file mode 100644 index 0000000..e8a2f8d --- /dev/null +++ b/doc/_static/css/custom.css @@ -0,0 +1 @@ +.icon-home::before { content: url("../lock_32.png"); } \ No newline at end of file diff --git a/doc/_static/lock_32.ico b/doc/_static/lock_32.ico new file mode 100644 index 0000000..0658e23 --- /dev/null +++ b/doc/_static/lock_32.ico Binary files differ diff --git a/doc/_static/lock_32.png b/doc/_static/lock_32.png new file mode 100644 index 0000000..7b2542d --- /dev/null +++ b/doc/_static/lock_32.png Binary files differ diff --git a/doc/_templates/breadcrumbs.html b/doc/_templates/breadcrumbs.html new file mode 100644 index 0000000..059aeaf --- /dev/null +++ b/doc/_templates/breadcrumbs.html @@ -0,0 +1,21 @@ +{%- extends "sphinx_rtd_theme/breadcrumbs.html" %} + +{% block breadcrumbs_aside %} +<li class="breadcrumbs-aside wy-breadcrumbs-aside"> + <a class="github-button" + href="https://github.com/open-license-manager/open-license-manager" + data-color-scheme="no-preference: light; light: light; dark: dark;" + data-icon="octicon-star" data-size="large" data-show-count="true" + aria-label="Star open-license-manager/open-license-manager on GitHub">Star</a> + <a class="github-button" + href="https://github.com/open-license-manager/open-license-manager/fork" + data-icon="octicon-repo-forked" data-size="large" + data-show-count="true" + aria-label="Fork open-license-manager/open-license-manager on GitHub">Fork</a> + <a class="github-button" + href="https://github.com/open-license-manager/open-license-manager/issues" + data-icon="octicon-issue-opened" data-size="large" + data-show-count="true" + aria-label="Issue open-license-manager/open-license-manager on GitHub">Issue</a> +</li> +{% endblock %} diff --git a/doc/analysis/Backoffice.md b/doc/analysis/Backoffice.md index 4e5d9de..1f05fb5 100644 --- a/doc/analysis/Backoffice.md +++ b/doc/analysis/Backoffice.md @@ -1,6 +1,8 @@ # Backoffice (Draft) (Use Cases) -Not implemented yet. +This is a very old sketch of a backoffice domain model (this documentation should be removed since it's not in the +current plans) + ## Domain **Software Provider** @@ -25,7 +27,7 @@ * HostId (NULL) -## Use Cases +## Use Cases ... **Software Provider Sign Up** \<\<inlcude\>\> diff --git a/doc/analysis/Development-And-Usage-Workflow.md b/doc/analysis/Development-And-Usage-Workflow.md index 6cd5528..bb90ab7 100644 --- a/doc/analysis/Development-And-Usage-Workflow.md +++ b/doc/analysis/Development-And-Usage-Workflow.md @@ -10,7 +10,7 @@ ### Binary release contents Binary release contains: - * open-license-manager executable (`lcc`). + * open-license-manager executable (`lcc-gen`). * source code of the unconfigured library. * source code of (part of) the tests. diff --git a/doc/analysis/features.md b/doc/analysis/features.md index 1872ce5..741566d 100644 --- a/doc/analysis/features.md +++ b/doc/analysis/features.md @@ -1,6 +1,7 @@ -# Features: +# Features ## features and their status + | Feature | Implementation status | |--------------------------------------|:---------------------:| | Trial license with expiry date | :heavy_check_mark: | @@ -17,7 +18,7 @@ See [execution limits](Implemented/Planned execution limits) section. ### Licenses linked to "physical" hardware id -Link the software to a physical hardware (a pc). In this scenario the software editor wants his software to be executed on a specific piece of hardware. We suppose the operating system is installed "bare to metal" and we're able to calculate an identifier of that hardware. This isn't always true for virtualized environments for which alternative strategies must be planned [eg. floating licenses (not yet implemented)]. See the section on [hardware identifiers](hardware-identifiers) for a detailed discussion of the use cases. +Link the software to a physical hardware (a pc). In this scenario the software editor wants his software to be executed on a specific piece of hardware. We suppose the operating system is installed "bare to metal" and we're able to calculate an identifier of that hardware. This isn't always true for virtualized environments for which alternative strategies must be planned [eg. floating licenses (not yet implemented)]. See the section on [hardware identifiers](../usage/Hardware-identifiers) for a detailed discussion of the use cases. Depending on the situation there are are different kinds of hardware id that can be used. See [execution limits](Implemented/Planned execution limits) section. @@ -25,9 +26,9 @@ Detect if the software is running in a virtualized environment and (optionally) forbid the execution. This is useful if software editors want to prevent the execution in virtual machines (lxc/dockers...) and be able to compute a meaningful hardware id. Another use case is the software is to be used only in a specific class of virtualized environments. For instance it was initially packaged as a docker image, the software editor don't want it to be "extracted" and placed elsewhere. -### License retrieval +### Licenses retrieval Open License Manager, when integrated into a licensed software will find its license file based on many different strategies. -It can handle multiple licenses at the same time. See the wiki page about [license retrieval](license-retrieval) for details. +It can handle multiple licenses at the same time. See the wiki page about [license retrieval](../usage/License-retrieval) for details. ### Licensed software features (partially implemented) A licensed software may be composed by many features (functions) each one activable independently. Licensing system tells the licensed software which features are enabled, and which features are disabled. @@ -56,7 +57,7 @@ Open License Manager can limit execution of licensed software based on some criteria, called "execution limits". Depending on the execution environment some criteria may not be applicable: -| | Windows BareToMetal | Linux BareToMetal | Linux container (lxc/docker) |Virtual Machine | +| |Windows BareToMetal | Linux BareToMetal | Linux container (lxc/docker) |Virtual Machine | |----------------|:------------------:|:------------------:|:------------------:|:------------------:| | date | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | disk label | :heavy_check_mark: | :heavy_check_mark: | :x:<sup>1</sup> | :heavy_check_mark: | @@ -66,24 +67,33 @@ | cpu number | Planned | Planned | Planned | Planned | | process memory | Planned | Planned | Planned | Planned | | machine memory | Planned | Planned | Planned | Planned | -| virtualization type | Planned | Planned | Planned | Planned | -| concurrent execution | Planned | Planned | Planned | Planned | -| licensed sw version | Planned | Planned | Planned | Planned | +| virtualization type | Planned | Planned | Planned | Planned | +| concurrent execution | Planned | Planned | Planned | Planned | +| licensed sw version | Planned | Planned | Planned | Planned | ### Date This is the most common limit set on a license, allow the software to expire after the defined date. ### Disk label/Disk id -It is possible to limit the execution to a computer that has a certain disk connected. -This kind of limitation doesn't make sense in linux containerized environments. +It is possible to limit the execution to a computer that has a certain disk connected. +This feature has been implemented in the `hardware identifier`. + +N.B. This kind of limitation doesn't make sense in containerized environments. + +### Ip address/Mac address +It is possible to limit the execution to a computer that has a network card with a spefified MAC address +(or even we can force to have a specific ip address). +This feature has been implemented in the `hardware identifier`. ### Cpu Number/Machine memory -Allow to restrict the execution only to a machine with the specified amount of cpu or memory or less. This is useful in virtualized environments, to create a licensed software demo version with limited performaces or with limited scalability. - +Allow to restrict the execution only to a machine with the specified amount of cpu or memory or less. +This is useful in virtualized environments, to create a licensed software demo version with limited performaces or with limited scalability. Status of this implementation is tracked in [issue #4](https://github.com/open-license-manager/open-license-manager/issues/4) ### Virtualization type -Allow the execution of the licensed software only on some type of hardware or virtualized environment eg. only bare to metal, only in virtual machine, only in docker. +Allow the execution of the licensed software only on some type of hardware or virtualized environment +eg. only bare to metal, only in virtual machine, only in docker. +This feature is being implemented. ### Licensed software version A licensed software may declare a version (eg 1.0.0). A license may span multiple releases of the software e.g. allow version 1.1.1 but not 2.0.0. diff --git a/doc/api/extend.rst b/doc/api/extend.rst new file mode 100644 index 0000000..8deda9a --- /dev/null +++ b/doc/api/extend.rst @@ -0,0 +1,26 @@ +####################################### +Customizations +####################################### + +The version 2.0 of the library comes with clear API extension and customization points. + +Custom hardware signature generator +*************************************** + +You've found the provided hardware signatures don't behave well for your customers (we can test on a limited set of +hardware we've receiving reports of usage on environments we never imagined before). +You can either change the way the default strategy behaves (choose for instance cpu type over disk label as default) or +invent your own identification method. + +.. toctree:: + + hardware_identifiers + +Custom license locator +*************************************** +Your software struggle to find the license file ? you can implement your own way to find it. For instance if you want +to download the license from a remote server, you could implement the logic here. + +.. TODO:: + + this section need to be completed \ No newline at end of file diff --git a/doc/api/hardware_identifiers.rst b/doc/api/hardware_identifiers.rst new file mode 100644 index 0000000..b4c491e --- /dev/null +++ b/doc/api/hardware_identifiers.rst @@ -0,0 +1,11 @@ +############################################### +Implement your own hardware signature generator +############################################### + +Customize how default strategy behaves +***************************************** + +Implement your own hardware signature generator +************************************************* + +.. doxygenclass:: license::hw_identifier::IdentificationStrategy \ No newline at end of file diff --git a/doc/api/public_api.rst b/doc/api/public_api.rst index 051e84f..803c1fb 100644 --- a/doc/api/public_api.rst +++ b/doc/api/public_api.rst @@ -1,8 +1,22 @@ +####################################### +Public api +####################################### + +The public api of the library can be found in ``include/licensecc/licensecc.h`` that is the only file you should +include when you want to use the library. + +Print hardware identifier +************************** + +.. doxygenfunction:: identify_pc + +.. doxygenenum:: LCC_API_HW_IDENTIFICATION_STRATEGY + +.. doxygengroup:: strategies + :content-only: +Verify a license +*********************** -Documentation -================== -.. doxygennamespace:: license - :project: licensecc - :members: \ No newline at end of file +.. doxygenfunction:: acquire_license diff --git a/doc/conf.py b/doc/conf.py index 13f61aa..4a4bf1e 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -32,7 +32,10 @@ # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = ['sphinx.ext.todo', - 'sphinx.ext.githubpages', 'breathe', 'recommonmark', 'sphinx_markdown_tables', 'sphinx_rtd_theme' ] + 'sphinx.ext.githubpages', 'breathe', 'recommonmark', 'sphinx_markdown_tables', 'sphinx_rtd_theme', + 'sphinx_sitemap','sphinx.ext.autosectionlabel' ] + +autosectionlabel_prefix_document = True # Breathe Configuration breathe_default_project = "licensecc" @@ -50,7 +53,7 @@ master_doc = 'index' # General information about the project. -project = 'licensecc' +project = 'Licensecc' copyright = '2020, Open License Manager' author = 'Open License Manager' @@ -94,6 +97,8 @@ # documentation. # html_theme_options = { + 'canonical_url': 'http://open-license-manager.github.io/open-license-manager/', + 'analytics_id': 'UA-61067325-2', # Provided by Google in your dashboard 'titles_only': False } @@ -114,6 +119,13 @@ # ] #} +html_js_files = [ + 'https://buttons.github.io/buttons.js' +] + +html_css_files = [ + 'css/custom.css' +] # -- Options for HTMLHelp output ------------------------------------------ @@ -171,5 +183,8 @@ 'Miscellaneous'), ] +# Sitemap plugin +html_baseurl = 'http://open-license-manager.github.io/open-license-manager' - +#html_logo = "_static/lock_32.png" +html_favicon="_static/lock_32.ico" \ No newline at end of file diff --git a/doc/development/Build-the-library-windows.md b/doc/development/Build-the-library-windows.md index e3e015f..e9a8719 100644 --- a/doc/development/Build-the-library-windows.md +++ b/doc/development/Build-the-library-windows.md @@ -1,15 +1,14 @@ -# Windows +# Build - Windows -This page describes how to build the library. It's a good starting point if you just downloaded it and you want to start explore. - -Under windows both MSVC compiler and MinGW are supported +This page describes how to build the library. Under windows both MSVC compiler and MinGW are supported ## MSVC (2015~2019) - prerequisites Pre-compiled [versions of boost](https://sourceforge.net/projects/boost/files/boost-binaries/) for windows are available at SourceForge. -For MSVC 2019: recommended cmake => 3.15.2 (the version 3.14 embedded in visual studio is not working with boost 1.71), [boost 1.71 msvc-14.2](https://dl.bintray.com/boostorg/release/1.71.0/binaries/boost_1_71_0-msvc-14.2-64.exe) +For MSVC 2019: recommended cmake => 3.15.2 (the version 3.14 embedded in visual studio is not working with boost 1.71), +[boost 1.71 msvc-14.2](https://dl.bintray.com/boostorg/release/1.71.0/binaries/boost_1_71_0-msvc-14.2-64.exe) -### Download: +### Checkout the code This project has a submodule (the license generator). Remember to add the option `--recursive` to clone it. ```console @@ -29,7 +28,7 @@ ``` ### Supported cmake definitions/options -Below a list of some useful cmake configurations +Below a list of some useful cmake configurations: |Definition name|Description| |---------------|-----------| @@ -44,4 +43,4 @@ cmake --build . --target install --config Release ctest -C Release -``` \ No newline at end of file +``` diff --git a/doc/development/Build-the-library.md b/doc/development/Build-the-library.md index 974a1d6..00f8854 100644 --- a/doc/development/Build-the-library.md +++ b/doc/development/Build-the-library.md @@ -1,4 +1,4 @@ -# Linux +# Build - Linux ## Install prerequisites Below the prerequisites for compiling open-license-manager. For developing it we use Eclipse. Recent CDT works smoothly with CMake. Remember to install the Ninja package as build system and Cmake Gui for a good eclipse integration. diff --git a/doc/development/Dependencies.md b/doc/development/Dependencies.md index 3fd54e6..aa81f4e 100644 --- a/doc/development/Dependencies.md +++ b/doc/development/Dependencies.md @@ -20,7 +20,7 @@ | Windows MinGW | optional<sup>1</sup> | | optional(test) 1.71 | -## License generator executable `lcc` dependencies +## License generator executable `lccgen` dependencies | Operating System | Openssl | Zlib | Boost<sup>3</sup> | |--------------------------------|:------------:|:--------------------------:|:-----------------------:| diff --git a/doc/development/Development-Environment-Setup.md b/doc/development/Development-Environment-Setup.md index 9a71cd5..3939aa2 100644 --- a/doc/development/Development-Environment-Setup.md +++ b/doc/development/Development-Environment-Setup.md @@ -2,11 +2,19 @@ This guide is just an help in case you haven't decided your development environment or your development environment match ours. We don't have any specific dependency on development tools, you can choose the one you prefer. Though if you want to contribute you're required to format the code using `clang-format` before you submit the pull request. -We use Eclipse CDT to develop the software under Linux (Ubuntu) and Visual Studio under windows. +We use Eclipse CDT to develop the software under Linux (Ubuntu) and Visual Studio under Windows. -First of all download the source code and compile it from command line as described in [build the library](build-the-library) +## Linux setup -## Eclipse +First of all download the source code and compile it from command line as described in [build the library](Build-the-library) +Download prerequisites: + +``` +sudo curl -L "https://github.com/google/styleguide/blob/gh-pages/cpplint/cpplint.py" -o /usr/bin/cpplint.py +sudo chmod a+x /usr/local/bin/cpplint.py +sudo apt-get install clang-format ninja-build +``` +### Eclipse Eclipse CDT has recently improved the support for Cmake projects, be sure to install the latest CDT version from the marketplace, with cmake support. Remember to install `ninja` build system for integration with cmake. @@ -18,19 +26,8 @@ It is also necessary to install clang-format and cpplint.py (from google). -### Ubuntu setup - -``` -sudo curl -L "https://github.com/google/styleguide/blob/gh-pages/cpplint/cpplint.py" -o /usr/bin/cpplint.py -sudo chmod a+x /usr/local/bin/cpplint.py -sudo apt-get install clang-format ninja-build -``` - Go to Window > Preferences > C++ > CppStyle and configure the path for `cpplint.py` you just downloaded. Go to Project > Properties > C++ General > Formatter and select CppStyle as code formatter. -We also suggest to install a pre-commit hook that helps keeping the code well formatted. - -``` -./scripts/git-pre-commit-hook install -``` \ No newline at end of file +## Windows setup +(To be done ...) \ No newline at end of file diff --git a/doc/index.rst b/doc/index.rst index e26f190..63b3e13 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -1,6 +1,135 @@ +####################################### +C++ software protection with Licensecc +####################################### +Copy protect, restrict the usage of your C++ software with a license file using this library. -Welcome to licensecc's documentation. +|c11|_ |License|_ |unstable|_ |BuildStatus|_ |CodacyBadge|_ |codecov|_ |forum|_ + +.. |c11| image:: https://img.shields.io/badge/c%2B%2B-11-blue.svg +.. _c11: https://en.wikipedia.org/wiki/C%2B%2B#Standardization +.. |unstable| image:: http://badges.github.io/stability-badges/dist/unstable.svg +.. _unstable: http://github.com/badges/stability-badges +.. |License| image:: https://img.shields.io/badge/License-BSD%203--Clause-blue.svg +.. _License: ttps://opensource.org/licenses/BSD-3-Clause +.. |BuildStatus| image:: https://travis-ci.org/open-license-manager/open-license-manager.svg?branch=develop +.. _BuildStatus: https://travis-ci.org/open-license-manager/open-license-manager +.. |CodacyBadge| image:: https://api.codacy.com/project/badge/Grade/62d6e1bb22d648bd85b6f3bc344a545a +.. _CodacyBadge: https://www.codacy.com/manual/gcontini/open-license-manager?utm_source=github.com&utm_medium=referral&utm_content=open-license-manager/open-license-manager&utm_campaign=Badge_Grade +.. |codecov| image:: https://codecov.io/gh/open-license-manager/open-license-manager/branch/develop/graph/badge.svg +.. _codecov: https://codecov.io/gh/open-license-manager/open-license-manager +.. |issues| image:: https://img.shields.io/github/issues/open-license-manager/open-license-manager +.. _issues: http://github.com/open-license-manager/open-license-manager/issues +.. |forum| image:: https://img.shields.io/badge/forum-licensecc-blue.svg?style=flat +.. _forum: https://groups.google.com/d/forum/licensecc + +Protect the software you develop from unauthorized copies, limit the usage in time, to a specific set of +machines, or prevent the usage in virtualized environments. It is an open source license management system that helps to keep your +software closed :smirk: . Among the other features the most notable one is: if it runs on a "real hardware" +it can generate a signature of that hardware and report if the signature doesn't match, because for instance +the software has been copied to another pc. + +A comprehensive :ref:`list of features <analysis/features:Features>`, and their status is available in the project wiki. + +License (BSD) +************** +The project is donated to the community. It comes with a very large freedom of use for everyone, and it will always be. +It uses a `BSD 3 clauses`_ licensing schema, that allows modification and inclusion in GPL and commercial software. + +.. _BSD 3 clauses: https://opensource.org/licenses/BSD-3-Clause + +Project Structure +******************* +The software is made by 3 main sub-components: + +* ``licensecc`` : the C++ library with a C api (the part you have to integrate in your software) with minimal (or no) external dependencies. This is the project you're currently looking at. +* ``lccinspector`` : a license debugger to be sent to the final customer to diagnose licensing problems or for calculating the pc hash before issuing the license. +* ``lccgen`` : a license generator (github project `lcc-license-generator`_ ) to initialize the library and generate the licenses. + +.. _lcc-license-generator: https://github.com/open-license-manager/lcc-license-generator + +How to build +**************** +Below an overview of the basic build procedure, provided as an example but if you really want to try we suggest you to refer to the detailed section +for your operating system: :ref:`Linux <development/Build-the-library:Build - Linux>` or :ref:`Windows <development/Build-the-library-windows:Build - Windows>`. + +Prerequisites +=================== + +* Operating system : Linux(Ubuntu, CentOS), Windows +* compilers : GCC (Linux) MINGW (Linux cross compile for Windows), MINGW or MSVC (Windows) +* tools : Cmake(>3.6), git, make/ninja(linux) +* libraries : If target is Linux Openssl is required. Windows depends only on system libraries. Boost is necessary to build license generator and to run the tests but it's NOT a dependency of the final `licensecc` library. + +For a complete list of dependencies and supported environments see the :ref:`development/Dependencies:Dependencies` section. +Clone the project. It has submodules, don't forget the `--recursive` option. + +.. code-block:: console + + git clone --recursive https://github.com/open-license-manager/open-license-manager.git + cd open-license-manager/ + cd build + +Build on Linux +=================== + +.. code-block:: console + + cmake .. -DCMAKE_INSTALL_PREFIX=../install + make + make install + +Build on Windows (with MSVC 2015) +================================== + +.. code-block:: console + + cmake .. -G "Visual Studio 14 2015 Win64" -DBOOST_ROOT="{Folder where boost is}" -DCMAKE_INSTALL_PREFIX=../install + cmake --build . --target install --config Release + +Cross compile with MINGW on Linux ===================================== + +.. code-block:: console + + x86_64-w64-mingw32.static-cmake .. -DCMAKE_INSTALL_PREFIX=../install + make + make install + +How to test +**************** + +On Linux: + +.. code-block:: console + + make test + +On Windows (MSVC): + +.. code-block:: console + + ctest -C Release + +How to use +************** +The `examples`_ repository shows various ways to integrate `licensecc` into your project. + +.. _examples: https://github.com/open-license-manager/examples + +How to contribute +******************** + +.. TIP:: + The easiest way you can solve your problems or ask help is through the `forums`_ (hosted on Google) + +Otherwise you can open an issue in the `issue system`_. Have a look to the `contribution guidelines`_ before reporting. + +We use `GitFlow`_ (or at least a subset of it). Remember to install the gitflow git plugin and use ``develop`` as default branch for your pull requests. + +.. _forums: https://groups.google.com/forum/#!forum/licensecc +.. _issue system: https://github.com/open-license-manager/open-license-manager/issues +.. _contribution guidelines: https://github.com/open-license-manager/open-license-manager/blob/develop/CONTRIBUTING.md +.. _GitFlow: https://datasift.github.io/gitflow/IntroducingGitFlow.html * :ref:`genindex` * :ref:`modindex` @@ -25,12 +154,12 @@ .. toctree:: - :glob: :maxdepth: 2 :hidden: :caption: API: - api/* + api/public_api + api/extend .. toctree:: :glob: diff --git a/doc/other/CREDITS.md b/doc/other/CREDITS.md index 221ff1d..7ee3c93 100644 --- a/doc/other/CREDITS.md +++ b/doc/other/CREDITS.md @@ -1,33 +1,24 @@ # Credits The following open source code has been used in OpenLicenseManager. -Thanks to every one of the authors of such projects. Without you open license manager would never have been completed. +Thanks to every one of the authors of such projects. Without you open license manager would never have been released. + +## [inja](https://github.com/pantor/inja) +A very nice template rendering library used to customize the code. + +MIT License +Copyright (c) 2013-2017 Niels Lohmann -## isVM +## [isVM](https://github.com/0of/isvm) Thanks for the great smbios parsing code. It saved me days. -isvm : https://github.com/0of/isvm - -The MIT License (MIT) - +MIT License Copyright (c) 2015 Magnus -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. +## [SimpleIni](https://github.com/brofield/simpleini) +INI parsing library (used to parse the licenses) -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - - +MIT license +Copyright (c) 2006-2012, Brodie Thiesfield + \ No newline at end of file diff --git a/doc/other/QA.md b/doc/other/QA.md index d3093dd..98643e9 100644 --- a/doc/other/QA.md +++ b/doc/other/QA.md @@ -5,7 +5,9 @@ ### Why do i have to build from source? Can you release a pre-compiled version of the library? No we can't release pre-compiled binaries of the library. -In the early phases of the build the library is customized: among other things a private and public key pair is generated and the public key is included into the compiled code, in a way that every project gets its own signature keys. See [Development and Usage](development-and-usage-workflow) +In the early phases of the build the library is customized: among other things a private and public key pair is +generated and the public key is included into the compiled code, in a way that every project gets its own signature keys. +See [Development and Usage](../analysis/Development-And-Usage-Workflow) ## Project status @@ -13,10 +15,16 @@ This project started as a week-end project in 2014, donated and almost forgotten. This doesn't necessarily meant bad. It was "functional". Thanks to the effort of some people that are using it, and to the help of many of you it has been kept up to date (2019). Recently there has been a long waited enhancement regarding license management procedures. ### Is it production ready? -Let's be honest. It's still in a very alhpa  stage. This means it's usable with some effort. Some companies are actively using it in production to issue demo licenses and few production licenses. If you plan to use it in a scenario where you need to issue hundreds of licenses plan some maintaining effort. +Let's be honest. It's still in a very alhpa  +stage. This means it's usable with some effort. Some companies are actively using it in production to issue demo licenses and few production licenses. +If you plan to use it in a scenario where you need to issue hundreds of licenses plan some maintaining effort. ### Challenges ? -The most challenging aspect is the number of environment/libraries we must work with. We've recently set up automated tests on Travis CI to help contributors to verify their code automatically in conditions they've not thought about. +The most challenging aspect is the number of environment/libraries we must work with. +We've recently set up automated tests on Travis CI to help contributors to verify their code automatically in conditions they've not thought about. ### Open License Manager and "the community" -Open License Manager has a very strange relationship with "the community", its aim is to protect proprietary software from copy and unintended usage. But out there, there are people that think that all the software should be licensed as AGPL... Thus StackOverflow and its fellow sites turned out to be not a collaborative place to talk about software protection. Remember to choose your questions carefully. :speak_no_evil: \ No newline at end of file +Open License Manager has a very strange relationship with "the community", its aim is to protect proprietary software +from copy and unintended usage. But out there, there are people that think that all the software should be licensed as AGPL... +StackOverflow and its fellow sites turned out to be not such a collaborative place to talk about software protection. +Remember to choose your questions carefully. :speak_no_evil: \ No newline at end of file diff --git a/doc/usage/Hardware-identifiers.md b/doc/usage/Hardware-identifiers.md deleted file mode 100644 index 1767c07..0000000 --- a/doc/usage/Hardware-identifiers.md +++ /dev/null @@ -1,29 +0,0 @@ -# Hardware Identifiers - -## Use cases -Linking the execution of a software to a physical hardware (a pc). With the recent coming of virtualized environments -the installation of software directly on the machine has been less and less. - -OpenLicenseManager guess the environment where the user is trying to launch the software, and reports it to the software publisher when he is generating a license in a way that he can decide how to limit the usage on per license basis. - -### Executing in a physical hardware -This is straightforward case. If the software is executing on a physical hardware it is possible to identify the hardware by various parameters (cpu type/memory/disk label/mac address) - -### Execution in a virtual machine -Generating a hardware identifier on a virtual machine doesn't make much sense, since the vm can be copied as a whole elsewhere -and there are few ways to detect this without using an external license server. - -* Usually when the machine is copied the MAC address is changed. But sometimes it changes on its own. Software publishers may want to use this as a last resort to prevent the vm for being cloned. It has to be verified case by case. -* Software editors may want to prevent people from extracting the software from the VM. They can use an hidden registry key or a specific file in a location outside the installation directory to verify the software is distributed in the original VM. Or they can link the execution to a specific kind of virtualization (this is supported by OpenLicenseManager). - -### Executing in a container -Depending on how containers are used having hardware identifiers may make sense or no sense at all. For instance if containers are used -to avoid to pollute the external distribution it makes perfect sense to have an hardware identifier, if users are running dockers in a kubernetes cluster it makes no sense at all. - -## Identifier Generation -Below the identifier generation workflow. - - -If the licensed software specify the parameter -If the licensed software uses `STRATEGY_DEFAULT` and the strategy generates an unstable identifier it is possible to ask the user to -set the environemnt variable. diff --git a/doc/usage/Hardware-identifiers.rst b/doc/usage/Hardware-identifiers.rst new file mode 100644 index 0000000..414ef00 --- /dev/null +++ b/doc/usage/Hardware-identifiers.rst @@ -0,0 +1,59 @@ +####################### +Hardware Identifiers +####################### + +Hardware identifiers are used to link the execution of the software to a physical hardware (a pc). +The software executing on client's hardware, when it finds the license is missing, calls the api +:ref:`identify_pc <api/public_api:Public api>` +and generates an hardware identifier. The client has to communicate the hardware id back to the software publisher that +will issue a license for him (for details see: :ref:`issue licenses <usage/issue-licenses:Issue Licenses>`). + +.. NOTE:: + + Licensecc will guess the environment where the user is trying to launch the software (eg. a Virtual Machine), + embed the information into the hardware id and report it to the software publisher before he is issuing the license. + +***************** +Usage scenarios +***************** +With the recent coming of virtualized environments the installation of software directly on the machine has been less and less. + + +Execution in a physical hardware +================================= +If the client executes the software on a physical hardware it is possible to identify the +hardware by various parameters (cpu type/memory/disk label/mac address) see :ref:`features <analysis/features:Features>` +for detail of supported identification strageties. + +Execution in a virtual machine +============================== +If you're allowing software users to generate pc identifiers in a virtual machine +you should ask yourself what's the real use of it, since the vm can be copied as a whole elsewhere +and there are few ways to detect this (without using an external license server that's not yet supported by this library). + +* Usually when the machine is copied the MAC address is changed. But sometimes it changes on its own. Software publishers may want to use this as a last resort to prevent the vm for being cloned. It has to be verified case by case. +* Software editors may want to prevent people from extracting the software from the VM. They can use an hidden registry key or a specific file in a location outside the installation directory to verify the software is distributed in the original VM. Or they can link the execution to a specific kind of virtualization (this is supported by OpenLicenseManager). + +.. TIP:: + + In this case issuing a `demo` license with just a date limitation is advised. + +Execution in a container +======================== +Depending on how containers are used having hardware identifiers may make sense or no sense at all. +For instance if containers are used to avoid to pollute the external distribution it makes perfect sense to have an +hardware identifier, if users are running dockers in a kubernetes cluster in the cloud it makes no sense at all. + +************************ +Identifier Generation +************************ +`Licensecc` is able to identify which virtual environment the user is running in and select the appropriate generation +strategy. Below the identifier generation workflow used by the :ref:`identify_pc <api/public_api:Public api>` method. + +.. figure:: ../_static/pc-id-selection.png + + +First of all it takes in account the application specified parameter +If the licensed software uses `STRATEGY_DEFAULT` and the strategy generates an unstable identifier it is possible to ask the user to +set the environemnt variable. + diff --git a/doc/usage/License-retrieval.md b/doc/usage/License-retrieval.md index 08110bb..1b5340e 100644 --- a/doc/usage/License-retrieval.md +++ b/doc/usage/License-retrieval.md @@ -1,7 +1,8 @@ -# Place the license file +# License retrieval -Open License Manager, when integrated into a licensed software can automatically find its license file (or multiple license files) based on: - +## how `licensecc` find the license file + +Open License Manager, when integrated into a licensed software can automatically find its license file (or multiple license files) based on: * An environment variable: * Placing the full path of the license file in the environment variable `LICENSE_LOCATION` the library will look for it. Multiple license files can be separated by ';' * Placing the full license content in the environment `LICENSE_DATA` will let the library load it. diff --git a/include/licensecc/datatypes.h b/include/licensecc/datatypes.h index f9da78a..5e80ee6 100644 --- a/include/licensecc/datatypes.h +++ b/include/licensecc/datatypes.h @@ -1,8 +1,8 @@ -/** \addtogroup api - * @{ - */ #ifndef DATATYPES_H_ #define DATATYPES_H_ +/** \addtogroup apistruct + * @{ + */ #ifdef __cplusplus extern "C" { @@ -130,7 +130,7 @@ } #endif -#endif /** * @} */ +#endif diff --git a/include/licensecc/licensecc.h b/include/licensecc/licensecc.h index 0b0391c..dc273bd 100644 --- a/include/licensecc/licensecc.h +++ b/include/licensecc/licensecc.h @@ -22,36 +22,51 @@ void print_error(char out_buffer[LCC_API_ERROR_BUFFER_SIZE], LicenseInfo* licenseInfo); /** - * This method calculates the hardware identifier. The string need to be shown to the user and given back to the software - * editor when issuing a license. - * pc_id_method = STRATEGY_DEFAULT usually works. + * \brief Calculates the hardware identifier associated with a specific pc. + * \details + * The software, when it doesn't find a valid license should show to the user the calculated identifier. + * The user should report the pc_identifier to the software editor that will in turn use it to issue a license. + * + * pc_id_method = ::STRATEGY_DEFAULT is usually the best choice. + * + * First call this method with `identifier_out` = nullptr and `buf_size` = 0 , it will return the requested buffer size + * in `buf_size` parameter. + * + * Then allocate the necessary memory, and call the method again. + * + * @return true if successful, false if failure (because it is not possible to identify or buffer too small). + * @param hw_id_method[in] specifies a preferred identification method. Usually #STRATEGY_DEFAULT works well. See the + * wiki for more informations. + * @param identifier_out[out] buffer where the identification string will be placed. + * @param identifier_out[in-out] size of the buffer where the identification string will be placed. */ -bool identify_pc(LCC_API_IDENTIFICATION_STRATEGY pc_id_method, char* identifier_out, size_t* bufSize); +bool identify_pc(LCC_API_HW_IDENTIFICATION_STRATEGY hw_id_method, char* identifier_out, size_t* buf_size); /** * This method is used to request the use of one license for a product. * In case of local license it's used to check if the product is licensed. * - * @return LICENSE_OK(0) if successful. Other values if there are errors. - * @param productName[in] + * @return ::LICENSE_OK(0) if successful. Other values if there are errors. + * + * @param callerInformation[in] * a vendor defined string containing the name of the product we want to request. * @param licenseLocation[in] otpional, can be NULL. * licenseLocation, either the name of the file * or the name of the environment variable should be !='\0' - * @param license[out] optional, can be NULL, if set it will return extra informations about the license. + * @param license_out[out] optional, can be NULL, if set it will return extra informations about the license. */ LCC_EVENT_TYPE acquire_license(const CallerInformations* callerInformation, const LicenseLocation* licenseLocation, LicenseInfo* license_out); /** - * Do nothing for now, useful for network licenses. + * Not implemented yet, useful (later) for network licenses. * Should be called from time to time to confirm we're still using the * license. */ LCC_EVENT_TYPE confirm_license(char* featureName, LicenseLocation* licenseLocation); /** - * Do nothing for now, useful for network licenses. + * Not implemented yet, useful (later) for network licenses. */ LCC_EVENT_TYPE release_license(char* featureName, LicenseLocation licenseLocation); diff --git a/src/inspector/inspector.cpp b/src/inspector/inspector.cpp index 5608ebb..af9e61c 100644 --- a/src/inspector/inspector.cpp +++ b/src/inspector/inspector.cpp @@ -72,7 +72,7 @@ char hw_identifier[LCC_API_PC_IDENTIFIER_SIZE + 1]; size_t bufSize = LCC_API_PC_IDENTIFIER_SIZE + 1; for (const auto& x : stringByStrategyId) { - if (identify_pc(static_cast<LCC_API_IDENTIFICATION_STRATEGY>(x.first), hw_identifier, &bufSize)) { + if (identify_pc(static_cast<LCC_API_HW_IDENTIFICATION_STRATEGY>(x.first), hw_identifier, &bufSize)) { std::cout << x.second << ':' << hw_identifier << std::endl; } else { std::cout << x.second << ": NA" << endl; diff --git a/src/library/hw_identifier/default_strategy.cpp b/src/library/hw_identifier/default_strategy.cpp index da21f20..b4ab755 100644 --- a/src/library/hw_identifier/default_strategy.cpp +++ b/src/library/hw_identifier/default_strategy.cpp @@ -13,10 +13,10 @@ namespace license { namespace hw_identifier { -static vector<LCC_API_IDENTIFICATION_STRATEGY> available_strategies() { +static vector<LCC_API_HW_IDENTIFICATION_STRATEGY> available_strategies() { os::ExecutionEnvironment exec; os::VIRTUALIZATION virtualization = exec.getVirtualization(); - vector<LCC_API_IDENTIFICATION_STRATEGY> strategy_to_try; + vector<LCC_API_HW_IDENTIFICATION_STRATEGY> strategy_to_try; if (virtualization == os::CONTAINER) { if (exec.is_docker()) { strategy_to_try = LCC_DOCKER_STRATEGIES; @@ -39,15 +39,15 @@ DefaultStrategy::~DefaultStrategy() {} -LCC_API_IDENTIFICATION_STRATEGY DefaultStrategy::identification_strategy() const { return STRATEGY_DEFAULT; } +LCC_API_HW_IDENTIFICATION_STRATEGY DefaultStrategy::identification_strategy() const { return STRATEGY_DEFAULT; } -FUNCTION_RETURN DefaultStrategy::identify_pc(HwIdentifier& pc_id) const { - vector<LCC_API_IDENTIFICATION_STRATEGY> strategy_to_try = available_strategies(); +FUNCTION_RETURN DefaultStrategy::generate_pc_id(HwIdentifier& pc_id) const { + vector<LCC_API_HW_IDENTIFICATION_STRATEGY> strategy_to_try = available_strategies(); FUNCTION_RETURN ret = FUNC_RET_NOT_AVAIL; for (auto it : strategy_to_try) { - LCC_API_IDENTIFICATION_STRATEGY strat_to_try = it; + LCC_API_HW_IDENTIFICATION_STRATEGY strat_to_try = it; unique_ptr<IdentificationStrategy> strategy_ptr = IdentificationStrategy::get_strategy(strat_to_try); - ret = strategy_ptr->identify_pc(pc_id); + ret = strategy_ptr->generate_pc_id(pc_id); if (ret == FUNC_RET_OK) { break; } @@ -56,11 +56,11 @@ } std::vector<HwIdentifier> DefaultStrategy::alternative_ids() const { - vector<LCC_API_IDENTIFICATION_STRATEGY> strategy_to_try = available_strategies(); + vector<LCC_API_HW_IDENTIFICATION_STRATEGY> strategy_to_try = available_strategies(); vector<HwIdentifier> identifiers; FUNCTION_RETURN ret = FUNC_RET_NOT_AVAIL; for (auto it : strategy_to_try) { - LCC_API_IDENTIFICATION_STRATEGY strat_to_try = it; + LCC_API_HW_IDENTIFICATION_STRATEGY strat_to_try = it; unique_ptr<IdentificationStrategy> strategy_ptr = IdentificationStrategy::get_strategy(strat_to_try); vector<HwIdentifier> alt_ids = strategy_ptr->alternative_ids(); identifiers.insert(alt_ids.begin(), alt_ids.end(), identifiers.end()); diff --git a/src/library/hw_identifier/default_strategy.hpp b/src/library/hw_identifier/default_strategy.hpp index 8f43827..ab10a6b 100644 --- a/src/library/hw_identifier/default_strategy.hpp +++ b/src/library/hw_identifier/default_strategy.hpp @@ -16,8 +16,8 @@ public: DefaultStrategy(); virtual ~DefaultStrategy(); - virtual LCC_API_IDENTIFICATION_STRATEGY identification_strategy() const; - virtual FUNCTION_RETURN identify_pc(HwIdentifier &pc_id) const; + virtual LCC_API_HW_IDENTIFICATION_STRATEGY identification_strategy() const; + virtual FUNCTION_RETURN generate_pc_id(HwIdentifier &pc_id) const; virtual std::vector<HwIdentifier> alternative_ids() const; virtual LCC_EVENT_TYPE validate_identifier(const HwIdentifier &identifier) const; }; diff --git a/src/library/hw_identifier/disk_strategy.cpp b/src/library/hw_identifier/disk_strategy.cpp index d9f6831..64142f7 100644 --- a/src/library/hw_identifier/disk_strategy.cpp +++ b/src/library/hw_identifier/disk_strategy.cpp @@ -73,7 +73,7 @@ DiskStrategy::~DiskStrategy() {} -LCC_API_IDENTIFICATION_STRATEGY DiskStrategy::identification_strategy() const { +LCC_API_HW_IDENTIFICATION_STRATEGY DiskStrategy::identification_strategy() const { return m_use_id ? STRATEGY_DISK_NUM : STRATEGY_DISK_LABEL; } diff --git a/src/library/hw_identifier/disk_strategy.hpp b/src/library/hw_identifier/disk_strategy.hpp index 67f5998..33e3909 100644 --- a/src/library/hw_identifier/disk_strategy.hpp +++ b/src/library/hw_identifier/disk_strategy.hpp @@ -19,7 +19,7 @@ public: DiskStrategy(bool use_id); virtual ~DiskStrategy(); - virtual LCC_API_IDENTIFICATION_STRATEGY identification_strategy() const; + virtual LCC_API_HW_IDENTIFICATION_STRATEGY identification_strategy() const; virtual std::vector<HwIdentifier> alternative_ids() const; }; diff --git a/src/library/hw_identifier/ethernet.cpp b/src/library/hw_identifier/ethernet.cpp index bd21bc9..55b5197 100644 --- a/src/library/hw_identifier/ethernet.cpp +++ b/src/library/hw_identifier/ethernet.cpp @@ -54,7 +54,7 @@ Ethernet::~Ethernet() {} -LCC_API_IDENTIFICATION_STRATEGY Ethernet::identification_strategy() const { +LCC_API_HW_IDENTIFICATION_STRATEGY Ethernet::identification_strategy() const { return use_ip ? STRATEGY_IP_ADDRESS : STRATEGY_ETHERNET; } diff --git a/src/library/hw_identifier/ethernet.hpp b/src/library/hw_identifier/ethernet.hpp index e02d2c1..4cc96ad 100644 --- a/src/library/hw_identifier/ethernet.hpp +++ b/src/library/hw_identifier/ethernet.hpp @@ -19,7 +19,7 @@ public: Ethernet(bool use_ip); virtual ~Ethernet(); - virtual LCC_API_IDENTIFICATION_STRATEGY identification_strategy() const; + virtual LCC_API_HW_IDENTIFICATION_STRATEGY identification_strategy() const; virtual std::vector<HwIdentifier> alternative_ids() const; }; diff --git a/src/library/hw_identifier/hw_identifier.cpp b/src/library/hw_identifier/hw_identifier.cpp index 5c163e7..405310e 100644 --- a/src/library/hw_identifier/hw_identifier.cpp +++ b/src/library/hw_identifier/hw_identifier.cpp @@ -31,7 +31,7 @@ HwIdentifier::HwIdentifier(const HwIdentifier& other) : m_data(other.m_data) {} -void HwIdentifier::set_identification_strategy(LCC_API_IDENTIFICATION_STRATEGY strategy) { +void HwIdentifier::set_identification_strategy(LCC_API_HW_IDENTIFICATION_STRATEGY strategy) { if (strategy == STRATEGY_NONE || strategy == STRATEGY_DEFAULT) { throw logic_error("Only known strategies are permitted"); } @@ -73,9 +73,9 @@ return result.substr(0, result.size() - 1); } -LCC_API_IDENTIFICATION_STRATEGY HwIdentifier::get_identification_strategy() const { +LCC_API_HW_IDENTIFICATION_STRATEGY HwIdentifier::get_identification_strategy() const { uint8_t stratMov = m_data[1] >> 5; - return static_cast<LCC_API_IDENTIFICATION_STRATEGY>(stratMov); + return static_cast<LCC_API_HW_IDENTIFICATION_STRATEGY>(stratMov); } bool HwIdentifier::data_match(const std::array<uint8_t, HW_IDENTIFIER_PROPRIETARY_DATA>& data) const { diff --git a/src/library/hw_identifier/hw_identifier.hpp b/src/library/hw_identifier/hw_identifier.hpp index 56d3716..c2738b9 100644 --- a/src/library/hw_identifier/hw_identifier.hpp +++ b/src/library/hw_identifier/hw_identifier.hpp @@ -50,8 +50,8 @@ HwIdentifier(const std::string ¶m); virtual ~HwIdentifier(); HwIdentifier(const HwIdentifier &other); - void set_identification_strategy(LCC_API_IDENTIFICATION_STRATEGY strategy); - LCC_API_IDENTIFICATION_STRATEGY get_identification_strategy() const; + void set_identification_strategy(LCC_API_HW_IDENTIFICATION_STRATEGY strategy); + LCC_API_HW_IDENTIFICATION_STRATEGY get_identification_strategy() const; void set_use_environment_var(bool use_env_var); void set_virtual_environment(os::VIRTUALIZATION virtualization); void set_virtualization(os::VIRTUALIZATION_DETAIL virtualization_detail); diff --git a/src/library/hw_identifier/hw_identifier_facade.cpp b/src/library/hw_identifier/hw_identifier_facade.cpp index 07808f6..0b834db 100644 --- a/src/library/hw_identifier/hw_identifier_facade.cpp +++ b/src/library/hw_identifier/hw_identifier_facade.cpp @@ -24,7 +24,7 @@ LCC_EVENT_TYPE HwIdentifierFacade::validate_pc_signature(const std::string& str_code) { HwIdentifier pc_id(str_code); - LCC_API_IDENTIFICATION_STRATEGY id_strategy = pc_id.get_identification_strategy(); + LCC_API_HW_IDENTIFICATION_STRATEGY id_strategy = pc_id.get_identification_strategy(); LCC_EVENT_TYPE result = IDENTIFIERS_MISMATCH; try { unique_ptr<IdentificationStrategy> strategy = IdentificationStrategy::get_strategy(id_strategy); @@ -35,9 +35,9 @@ return result; } -std::string HwIdentifierFacade::generate_user_pc_signature(LCC_API_IDENTIFICATION_STRATEGY strategy) { +std::string HwIdentifierFacade::generate_user_pc_signature(LCC_API_HW_IDENTIFICATION_STRATEGY strategy) { bool use_env_var = false; - vector<LCC_API_IDENTIFICATION_STRATEGY> strategies_to_try; + vector<LCC_API_HW_IDENTIFICATION_STRATEGY> strategies_to_try; if (strategy == STRATEGY_DEFAULT) { char* env_var_value = getenv(LCC_IDENTIFICATION_STRATEGY_ENV_VAR); if (env_var_value != nullptr && env_var_value[0] != '\0') { @@ -45,7 +45,7 @@ if (strategy_int < 0 || strategy_int > 3) { LOG_WARN("unknown " LCC_IDENTIFICATION_STRATEGY_ENV_VAR " %s", env_var_value); } else { - strategy = (LCC_API_IDENTIFICATION_STRATEGY)strategy_int; + strategy = (LCC_API_HW_IDENTIFICATION_STRATEGY)strategy_int; use_env_var = true; } } @@ -53,7 +53,7 @@ unique_ptr<IdentificationStrategy> strategy_ptr = IdentificationStrategy::get_strategy(strategy); HwIdentifier pc_id; - FUNCTION_RETURN result = strategy_ptr->identify_pc(pc_id); + FUNCTION_RETURN result = strategy_ptr->generate_pc_id(pc_id); if (result != FUNC_RET_OK) { throw logic_error("strategy " + to_string(strategy_ptr->identification_strategy()) + " failed"); } diff --git a/src/library/hw_identifier/hw_identifier_facade.hpp b/src/library/hw_identifier/hw_identifier_facade.hpp index c587c53..aced4a2 100644 --- a/src/library/hw_identifier/hw_identifier_facade.hpp +++ b/src/library/hw_identifier/hw_identifier_facade.hpp @@ -29,7 +29,7 @@ * @param strategy * @return */ - static std::string generate_user_pc_signature(LCC_API_IDENTIFICATION_STRATEGY strategy); + static std::string generate_user_pc_signature(LCC_API_HW_IDENTIFICATION_STRATEGY strategy); }; } // namespace hw_identifier diff --git a/src/library/hw_identifier/identification_strategy.cpp b/src/library/hw_identifier/identification_strategy.cpp index 273c670..794b97b 100644 --- a/src/library/hw_identifier/identification_strategy.cpp +++ b/src/library/hw_identifier/identification_strategy.cpp @@ -22,7 +22,7 @@ return result; } -FUNCTION_RETURN IdentificationStrategy::identify_pc(HwIdentifier& pc_id) const { +FUNCTION_RETURN IdentificationStrategy::generate_pc_id(HwIdentifier& pc_id) const { vector<array<uint8_t, HW_IDENTIFIER_PROPRIETARY_DATA>> data; const vector<HwIdentifier> available_ids = alternative_ids(); FUNCTION_RETURN result = FUNC_RET_NOT_AVAIL; @@ -33,7 +33,7 @@ return result; } -std::unique_ptr<IdentificationStrategy> IdentificationStrategy::get_strategy(LCC_API_IDENTIFICATION_STRATEGY strategy) { +std::unique_ptr<IdentificationStrategy> IdentificationStrategy::get_strategy(LCC_API_HW_IDENTIFICATION_STRATEGY strategy) { unique_ptr<IdentificationStrategy> result; switch (strategy) { case STRATEGY_DEFAULT: diff --git a/src/library/hw_identifier/identification_strategy.hpp b/src/library/hw_identifier/identification_strategy.hpp index 22ded81..1f0d1bc 100644 --- a/src/library/hw_identifier/identification_strategy.hpp +++ b/src/library/hw_identifier/identification_strategy.hpp @@ -1,5 +1,5 @@ -/* - * identification_strategy.hpp +/** + * \file identification_strategy.hpp * * Created on: Jan 1, 2020 * Author: devel @@ -18,14 +18,17 @@ namespace license { namespace hw_identifier { +/** + * Abstract class that represent a way to calculate hardware identifiers. + */ class IdentificationStrategy { protected: IdentificationStrategy(){}; public: virtual ~IdentificationStrategy(){}; - virtual LCC_API_IDENTIFICATION_STRATEGY identification_strategy() const = 0; - virtual FUNCTION_RETURN identify_pc(HwIdentifier& identifier_out) const; + virtual LCC_API_HW_IDENTIFICATION_STRATEGY identification_strategy() const = 0; + virtual FUNCTION_RETURN generate_pc_id(HwIdentifier& identifier_out) const; virtual std::vector<HwIdentifier> alternative_ids() const = 0; virtual LCC_EVENT_TYPE validate_identifier(const HwIdentifier& identifier_in) const; @@ -34,7 +37,7 @@ * @param strategy * @return */ - static std::unique_ptr<IdentificationStrategy> get_strategy(LCC_API_IDENTIFICATION_STRATEGY strategy); + static std::unique_ptr<IdentificationStrategy> get_strategy(LCC_API_HW_IDENTIFICATION_STRATEGY strategy); }; } // namespace hw_identifier diff --git a/src/library/licensecc.cpp b/src/library/licensecc.cpp index 5378638..7736df2 100644 --- a/src/library/licensecc.cpp +++ b/src/library/licensecc.cpp @@ -28,7 +28,7 @@ void print_error(char out_buffer[LCC_API_ERROR_BUFFER_SIZE], LicenseInfo* licenseInfo) {} -bool identify_pc(LCC_API_IDENTIFICATION_STRATEGY pc_id_method, char* chbuffer, size_t* bufSize) { +bool identify_pc(LCC_API_HW_IDENTIFICATION_STRATEGY pc_id_method, char* chbuffer, size_t* bufSize) { bool result = false; if (*bufSize > LCC_API_PC_IDENTIFIER_SIZE && chbuffer != nullptr) { try { diff --git a/src/templates/licensecc_properties.h.in b/src/templates/licensecc_properties.h.in index b8026f9..55c22a2 100644 --- a/src/templates/licensecc_properties.h.in +++ b/src/templates/licensecc_properties.h.in @@ -1,6 +1,22 @@ +/** + * \file + * This file contains all the properties that are customizable on on a per-project basis eg: + * 1) api parameter sizes + * 2) + * + * It is safe to place the values that your project need to customize here, since each project get its own copy of this + * file. + */ + +/** + * \addtogroup api + * @{ + */ + #ifndef BUILD_PROPERTIES_H_ #define BUILD_PROPERTIES_H_ + /** * This file contains all the properties that are customizable on on a per-project basis eg: * 1) api parameter sizes @@ -22,35 +38,8 @@ #define LCC_LICENSE_FILE_EXTENSION ".lic" #define LCC_LICENSE_LOCATION_ENV_VAR "LICENSE_LOCATION" #define LCC_LICENSE_DATA_ENV_VAR "LICENSE_DATA" -/** - * Environment variable that if defined will change the identification strategy used to generate the hardware identifier. - * If a client has an unstable pc-identifier use this variable to generate one. - * Valid values are integers defined in `LCC_IDENTIFICATION_STRATEGY` enum. - */ -#define LCC_IDENTIFICATION_STRATEGY_ENV_VAR "IDENTIFICATION_STRATEGY" -/** - * Enum to select a specific pc identification_strategy. DEFAULT Should be used in most cases. - */ -typedef enum { - STRATEGY_DEFAULT = -1, - STRATEGY_ETHERNET = 0, - STRATEGY_IP_ADDRESS = 1, - STRATEGY_DISK_NUM = 2, - STRATEGY_DISK_LABEL = 3, - STRATEGY_MEMORY_CPU_SIZE = 4, - STRATEGY_HOST_NAME = 5, - STRATEGY_NONE = -2 -} LCC_API_IDENTIFICATION_STRATEGY; - -//strategies used for each virtual environment. -#define LCC_BARE_TO_METAL_STRATEGIES { STRATEGY_ETHERNET, STRATEGY_DISK_LABEL, STRATEGY_NONE } -#define LCC_VM_STRATEGIES { STRATEGY_ETHERNET, STRATEGY_NONE } -#define LCC_LXC_STRATEGIES { STRATEGY_ETHERNET, STRATEGY_NONE } -#define LCC_DOCKER_STRATEGIES { STRATEGY_NONE } -#define LCC_CLOUD_STRATEGIES { STRATEGY_NONE } - -//Api structure limits +// Api structure limits /** * Maximum size of a license file or base64 data */ @@ -71,4 +60,67 @@ */ #define LCC_VERIFY_MAGIC (lic_info.m_magic == @LCC_PROJECT_MAGIC_NUM@) +/** + * + * Environment variable name that if defined will change the identification strategy used to generate the hardware + * identifier. If a client has an unstable pc-identifier use this variable to generate one. Valid values are integers + * defined in `LCC_IDENTIFICATION_STRATEGY` enum. + */ +#define LCC_IDENTIFICATION_STRATEGY_ENV_VAR "IDENTIFICATION_STRATEGY" + +/** + * \enum LCC_API_HW_IDENTIFICATION_STRATEGY + * + * This enum list all the possible pc identification strategy. It is to be used as a parameter of ::identify_pc + * + * ::STRATEGY_DEFAULT Should be used in most cases. + */ +enum LCC_API_HW_IDENTIFICATION_STRATEGY { + /** + * \brief Default strategy. + * + * This strategy try to detect which virtual environment the software is running in. + * - If no virtual environment is detected it will try the strategies defined in ::LCC_BARE_TO_METAL_STRATEGIES + * - If it detects the software is running in a virtual machine it will use ::LCC_VM_STRATEGIES + * - If it detects the software is running in a docker or in an LXC it will use ::LCC_DOCKER_STRATEGIES or + * ::LCC_DOCKER_STRATEGIES + * - If it detects the software is running in a virtual machine in the cloud it will use ::LCC_CLOUD_STRATEGIES + */ + STRATEGY_DEFAULT = -1, + STRATEGY_ETHERNET = 0, + STRATEGY_IP_ADDRESS = 1, + STRATEGY_DISK_NUM = 2, + STRATEGY_DISK_LABEL = 3, + STRATEGY_MEMORY_CPU_SIZE = 4, + STRATEGY_HOST_NAME = 5, + STRATEGY_NONE = -2 +}; + +/** + * @addtogroup strategies + * @{ + */ +/** + * List the strategies used when no virtual envrionment is detected + */ +#define LCC_BARE_TO_METAL_STRATEGIES { STRATEGY_ETHERNET, STRATEGY_DISK_LABEL, STRATEGY_NONE } +/** + * List the strategies used when the software is executing in a virtual machine + */ +#define LCC_VM_STRATEGIES { STRATEGY_ETHERNET, STRATEGY_NONE } +#define LCC_LXC_STRATEGIES { STRATEGY_ETHERNET, STRATEGY_NONE } +#define LCC_DOCKER_STRATEGIES { STRATEGY_NONE } +/** + * List the strategies used when it's detected an execution in the cloud + */ +#define LCC_CLOUD_STRATEGIES { STRATEGY_NONE } + +/** + * @} + */ + + #endif +/** + * @} + */ diff --git a/test/functional/hw_identifier_it_test.cpp b/test/functional/hw_identifier_it_test.cpp index e1ae99a..7f200ee 100644 --- a/test/functional/hw_identifier_it_test.cpp +++ b/test/functional/hw_identifier_it_test.cpp @@ -28,7 +28,7 @@ * is OK */ -static void generate_and_verify_license(LCC_API_IDENTIFICATION_STRATEGY strategy, const string& lic_fname) { +static void generate_and_verify_license(LCC_API_HW_IDENTIFICATION_STRATEGY strategy, const string& lic_fname) { BOOST_TEST_CHECKPOINT("Before generate"); const string identifier_out = HwIdentifierFacade::generate_user_pc_signature(strategy); BOOST_TEST_CHECKPOINT("After generate signature"); @@ -52,7 +52,7 @@ size_t disk_num; FUNCTION_RETURN result_diskinfos = getDiskInfos(nullptr, &disk_num); if ((result_diskinfos == FUNC_RET_BUFFER_TOO_SMALL || result_diskinfos == FUNC_RET_OK) && disk_num > 0) { - generate_and_verify_license(LCC_API_IDENTIFICATION_STRATEGY::STRATEGY_DISK_NUM, "volid_lic_file"); + generate_and_verify_license(LCC_API_HW_IDENTIFICATION_STRATEGY::STRATEGY_DISK_NUM, "volid_lic_file"); } else { BOOST_TEST_MESSAGE("No disk found skipping testing disk hardware identifier"); } @@ -63,7 +63,7 @@ size_t disk_num; FUNCTION_RETURN result_diskinfos = getDiskInfos(nullptr, &disk_num); if ((result_diskinfos == FUNC_RET_BUFFER_TOO_SMALL || result_diskinfos == FUNC_RET_OK) && disk_num > 0) { - generate_and_verify_license(LCC_API_IDENTIFICATION_STRATEGY::STRATEGY_DISK_LABEL, "volume_name_lic_file"); + generate_and_verify_license(LCC_API_HW_IDENTIFICATION_STRATEGY::STRATEGY_DISK_LABEL, "volume_name_lic_file"); } else { BOOST_TEST_MESSAGE("No disk found skipping testing volume name disk hardware identifier"); } @@ -74,7 +74,7 @@ FUNCTION_RETURN result_adapterInfos = os::getAdapterInfos(adapters); if ((result_adapterInfos == FUNC_RET_BUFFER_TOO_SMALL || result_adapterInfos == FUNC_RET_OK) && adapters.size() > 0) { - generate_and_verify_license(LCC_API_IDENTIFICATION_STRATEGY::STRATEGY_ETHERNET, "strategy_mac_address"); + generate_and_verify_license(LCC_API_HW_IDENTIFICATION_STRATEGY::STRATEGY_ETHERNET, "strategy_mac_address"); } else { BOOST_TEST_MESSAGE("No ethernet adapter found skipping testing mac address hardware identifier"); } @@ -85,7 +85,7 @@ FUNCTION_RETURN result_adapterInfos = os::getAdapterInfos(adapters); if ((result_adapterInfos == FUNC_RET_BUFFER_TOO_SMALL || result_adapterInfos == FUNC_RET_OK) && adapters.size() > 0) { - generate_and_verify_license(LCC_API_IDENTIFICATION_STRATEGY::STRATEGY_IP_ADDRESS, "strategy_ip_address"); + generate_and_verify_license(LCC_API_HW_IDENTIFICATION_STRATEGY::STRATEGY_IP_ADDRESS, "strategy_ip_address"); } else { BOOST_TEST_MESSAGE("No ethernet adapter found skipping testing ip hardware identifier"); } diff --git a/test/library/hw_identifier/hw_identifier_facade_test.cpp b/test/library/hw_identifier/hw_identifier_facade_test.cpp index 1a47b38..f0df625 100644 --- a/test/library/hw_identifier/hw_identifier_facade_test.cpp +++ b/test/library/hw_identifier/hw_identifier_facade_test.cpp @@ -14,7 +14,7 @@ * 2) save it to disk * 3) every time check that the identifier can still be verified. */ -static void generate_reference_file(const string &idfileLocation, LCC_API_IDENTIFICATION_STRATEGY strategies[], +static void generate_reference_file(const string &idfileLocation, LCC_API_HW_IDENTIFICATION_STRATEGY strategies[], int num_strategies) { ofstream idfile(idfileLocation); PcSignature identifier_out; @@ -32,7 +32,7 @@ BOOST_AUTO_TEST_CASE(generated_identifiers_stability) { const string idfileLocation(PROJECT_TEST_TEMP_DIR "/identifiers_file"); - std::vector<LCC_API_IDENTIFICATION_STRATEGY> strategies; + std::vector<LCC_API_HW_IDENTIFICATION_STRATEGY> strategies; size_t disk_num; getDiskInfos(NULL, &disk_num); if (disk_num > 0) { diff --git a/test/library/hw_identifier/hw_identifier_test.cpp b/test/library/hw_identifier/hw_identifier_test.cpp index 1e0062c..28db0c1 100644 --- a/test/library/hw_identifier/hw_identifier_test.cpp +++ b/test/library/hw_identifier/hw_identifier_test.cpp @@ -52,11 +52,11 @@ array<uint8_t, HW_IDENTIFIER_PROPRIETARY_DATA> data = {0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42}; HwIdentifier pc_id; pc_id.set_data(data); - pc_id.set_identification_strategy(LCC_API_IDENTIFICATION_STRATEGY::STRATEGY_ETHERNET); + pc_id.set_identification_strategy(LCC_API_HW_IDENTIFICATION_STRATEGY::STRATEGY_ETHERNET); string pc_id_str = pc_id.print(); cout << pc_id_str << endl; const HwIdentifier id2(pc_id_str); - BOOST_CHECK_MESSAGE(id2.get_identification_strategy() == LCC_API_IDENTIFICATION_STRATEGY::STRATEGY_ETHERNET, + BOOST_CHECK_MESSAGE(id2.get_identification_strategy() == LCC_API_HW_IDENTIFICATION_STRATEGY::STRATEGY_ETHERNET, "Strategy decoded correctly"); BOOST_CHECK_MESSAGE(id2.data_match(data), "Data deserialized correctly"); } -- Gitblit v1.9.1