Git Product home page Git Product logo

softsec's Introduction

Licensed software protection


Project Softsec provides a user-friendly interface for working with license generation, message encryption and decryption, key generation and other functions to ensure the security of the application usage RSA and ED25519.

Installation

go get github.com/singl3focus/softsec
go mod tidy

Usage

Global Usage

Global example of licensing via flags.

package main

import (
	"os"
	"log"
	"flag"
	"time"
	"math/rand"
	"path/filepath"

	"github.com/joho/godotenv"
	"github.com/singl3focus/softsec"
)

var (
	defaultValueGenFlag = ""
	genFlag = flag.String("g", defaultValueGenFlag, "Generated keys with specifed name")
	
	defaultValueGenLicRespFlag = ""
	licRespFlag = flag.String("resp", defaultValueGenLicRespFlag, "Reading request file and generate response, flag must be contain name of device")

	defaultValueGenLicReqFlag = ""
	licReqFlag = flag.String("l", defaultValueGenLicReqFlag, "Generate request license file, flag must be contain name of device")
)


func main() {
	// Env load
	err := godotenv.Load()
  	if err != nil {
    	log.Fatal("Error loading .env file")
  	}

	// Log setup _____________________________________
	err = os.MkdirAll("logs", os.ModePerm)
	if err != nil {
		log.Fatalf("failed to create log directory: %v", err)
	}

	today := time.Now().Format("2006-01-02")
	filePath := filepath.Join("logs", "license_app_"+today+".log")

	file, err := os.OpenFile(filePath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
	if err != nil { log.Fatalf("failed to open the log file: %v", err) }
	defer file.Close()

	log.SetOutput(file)
	
	// App setup _____________________________________
    log.Println("Start license app....")
	flag.Parse()

	salt1 := os.Getenv("SALT1")
	salt2 := os.Getenv("SALT2")

	// Generated keys ________________________________ 
	if *genFlag != defaultValueGenFlag {
		pubKeyPathTXT := softsec.CreateFilename("txt", "_", *genFlag, "public")
		_, _, err = softsec.GenerateKeysRSA(pubKeyPathTXT)
		if err != nil {
			log.Fatalf("failed to generate RSA keys: %s", err.Error())
		}
	}
	
	// Give response to license request _______________
	if *licRespFlag != defaultValueGenLicRespFlag {
		err = softsec.HandleRSALicenseRequest(*licRespFlag, salt1, salt2)
		if err != nil {
			log.Fatalf("failed to handle message by RSA: %s", err.Error())
		}
	}

	// Generate license request _______________________
	if *licReqFlag != defaultValueGenLicReqFlag {
		err = softsec.GenerateRSALicenseRequest(*licReqFlag)
		if err != nil {
			log.Fatalf("failed to generate License Request keys: %s", err.Error())
		}
	}
}

Remember, this is just an example of how you can use it, but it can also be deployed as a server or something else.

Support

If you have any difficulties, problems or questions, you can just write to me by e-mail [email protected] or telegram https://t.me/single_focus.

softsec's People

Watchers

Imran avatar

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.