Code Monkey home page Code Monkey logo

example-cpp-cryptographic-license-files's Introduction

Example C++ Cryptographic License Files

This is an example of how to verify and decrypt cryptographic license files in C++, using OpenSSL, Ed25519 verification and AES-256-GCM decryption.

This example implements the aes-256-gcm+ed25519 algorithm.

Running the example

First up, add an environment variable containing your public key:

# Your Keygen account's Ed25519 public key.
export KEYGEN_PUBLIC_KEY="e8601e48b69383ba520245fd07971e983d06d22c4257cfd82304601479cee788"

# A license key.
export KEYGEN_LICENSE_KEY="E1FBA2-5488D8-8AC81A-53157E-01939A-V3"

You can either run each line above within your terminal session before starting the app, or you can add the above contents to your ~/.bashrc file and then run source ~/.bashrc after saving the file.

Next, on macOS, ensure OpenSSL v1.1.1 is installed. If needed, install using homebrew:

brew install [email protected]

Then compile the source using g++:

g++ main.cpp -o bin.out \
  -std=c++17 \
  -lssl \
  -lcrypto \
  -I /usr/local/opt/openssl/include \
  -L /usr/local/opt/openssl/lib \
  -I include/**/*.c

Then run the script, passing in a path to a license file:

./bin.out /etc/keygen/license.lic

Alternatively, you can prefix the below command with env variables, e.g.:

KEYGEN_PUBLIC_KEY="e8601e48b69383ba520245fd07971e983d06d22c4257cfd82304601479cee788" \
  KEYGEN_LICENSE_KEY="E1FBA2-5488D8-8AC81A-53157E-01939A-V3" \
  ./bin.out examples/license.lic

You should see output indicating that the license file is valid, with its decrypted dataset:

[INFO] Importing...
[OK] License file successfully imported!
[INFO] Verifying...
[OK] License file successfully verified!
[INFO] Decrypting...
[OK] License file successfully decrypted!
[INFO] Parsing...
[OK] License successfully parsed!
name=C++ Example License
key=E1FBA2-5488D8-8AC81A-53157E-01939A-V3
status=ACTIVE
last_validated_at=null
expires_at=2025-01-01T00:00:00.000Z
created_at=2022-08-05T19:27:36.492Z
updated_at=2022-08-05T19:27:36.492Z
entitlements=[FEATURE_ENTITLEMENT_C,FEATURE_ENTITLEMENT_B,FEATURE_ENTITLEMENT_A]
product=3bf34475-dfb4-42d8-a763-a2c89507f16d
policy=5ba80f5e-c3a6-4f38-bc0b-bd12053cef66
user=2068992b-f98f-4efc-95fd-687dbd0c868c

If the license file fails to decrypt, ensure that you're providing the correct license key via KEYGEN_LICENSE_KEY. License files are encrypted with their license's key, so an incorrect license key will fail to decrypt.

Questions?

Reach out at [email protected] if you have any questions or concerns!

example-cpp-cryptographic-license-files's People

Contributors

dizcza avatar ezekg avatar franz-ms-muc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

example-cpp-cryptographic-license-files's Issues

Template function is_empty() is possibly incorrect

is_empty() is defined assuming a struct with std::string(s) will be all zero - which may not be true. I fixed it using template specializations. Also included in PR #9.

diff --git a/main.cpp b/main.cpp
index b1f5146..4362782 100644
--- a/main.cpp
+++ b/main.cpp
@@ -175,6 +175,21 @@ bool is_empty(T data) {
   return (*mm == 0) && memcmp(mm, mm + 1, sizeof(T) - 1) == 0;
 }

+template <>
+bool is_empty(license_file data) {
+  return data.enc.empty();
+}
+
+template <>
+bool is_empty(license data) {
+  return data.id.empty();
+}
+
+template <>
+bool is_empty(machine data) {
+  return data.id.empty();
+}
+

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.