Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@igor-lemon/secure-electron-license-keys-cli

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@igor-lemon/secure-electron-license-keys-cli - npm Package Compare versions

Comparing version 1.2.0 to 1.2.2

2

lib/index.js

@@ -1,1 +0,1 @@

"use strict";var _arg=_interopRequireDefault(require("arg"));Object.defineProperty(exports,"__esModule",{value:!0}),exports.cli=cli;function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}var crypto=require("crypto"),fs=require("fs"),path=require("path"),uuid=require("uuid");function parseArgumentsIntoOptions(a){var b=(0,_arg["default"])({"--major":String,"--minor":String,"--patch":String,"--user":String,"--expire":String,"--public":String,"--private":String,"--license":String,"--output":String,"--private-key":String,"--public-key":String,"-ma":"--major","-mi":"--minor","-p":"--patch","-u":"--user","-e":"--expire","-pu":"--public","-pr":"--private","-l":"--license","-o":"--output","-pk":"--private-key","-pubk":"--public-key"},{permissive:!1,argv:a.slice(2),stopAtPositional:!1});return{major:b["--major"]||"*",minor:b["--minor"]||"*",patch:b["--patch"]||"*",user:b["--user"]||"",expire:b["--expire"]||"",public:b["--public"]||"public.key",private:b["--private"]||"private.key",license:b["--license"]||"license.data",output:b["--output"]||process.cwd(),privateKey:b["--private-key"]||null,publicKey:b["--public-key"]||null}}var cryptoKeyPairOptions={modulusLength:4096,publicKeyEncoding:{type:"spki",format:"pem"},privateKeyEncoding:{type:"pkcs8",format:"pem"}};function cli(a){var b=parseArgumentsIntoOptions(a),c=b.user;if(!c)throw new Error("Please pass an email of the user");var d,e,f={id:uuid.v4(),major:b.major,minor:b.minor,patch:b.patch,user:c,created:Date.now(),expire:b.expire},g=b.privateKeyPath,h=b.publicKeyPath;if(g&&h)d=fs.readFileSync(g),e=fs.readFileSync(h);else{var m=crypto.generateKeyPairSync("rsa",cryptoKeyPairOptions);e=m.publicKey,d=m.privateKey}var i=crypto.privateEncrypt(d,Buffer.from(JSON.stringify(f))),j=path.join(b.output,b["public"]),k=path.join(b.output,b["private"]),l=path.join(b.output,b.license);console.log("Saving public key file to '".concat(j,"'.")),fs.writeFileSync(j,e),console.log("Saving private key file to '".concat(k,"'.")),fs.writeFileSync(k,d),console.log("Saving license file to '".concat(l,"'.")),fs.writeFileSync(l,i)}
"use strict";var _arg=_interopRequireDefault(require("arg"));Object.defineProperty(exports,"__esModule",{value:!0}),exports.cli=cli;function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}var crypto=require("crypto"),fs=require("fs"),path=require("path"),uuid=require("uuid"),add=require("date-fns/add");function parseArgumentsIntoOptions(a){var b=(0,_arg["default"])({"--major":String,"--minor":String,"--patch":String,"--user":String,"--expire":String,"--public":String,"--private":String,"--license":String,"--output":String,"--private-key":String,"--public-key":String,"--valid-to":String,"-ma":"--major","-mi":"--minor","-p":"--patch","-u":"--user","-e":"--expire","-pu":"--public","-pr":"--private","-l":"--license","-o":"--output","-pk":"--private-key","-pubk":"--public-key","-vt":"--valid-to"},{permissive:!1,argv:a.slice(2),stopAtPositional:!1});return{major:b["--major"]||"*",minor:b["--minor"]||"*",patch:b["--patch"]||"*",user:b["--user"]||"",expire:b["--expire"]||"",public:b["--public"]||"public.key",private:b["--private"]||"private.key",license:b["--license"]||"license.data",output:b["--output"]||process.cwd(),privateKey:b["--private-key"]||null,publicKey:b["--public-key"]||null,validTo:b["--valid-to"]||null}}var cryptoKeyPairOptions={modulusLength:4096,publicKeyEncoding:{type:"spki",format:"pem"},privateKeyEncoding:{type:"pkcs8",format:"pem"}};function cli(a){var b=parseArgumentsIntoOptions(a),c=b.user,d=b.validTo,e=b.expire;if(!c)throw new Error("Please pass an email of the user");var f=null,g=new Date;if(d){console.log("validTo",d);var h=d.match(/^years-(\d*)$/i),i=d.match(/^months-(\d*)$/i),j=d.match(/^days-(\d*)$/i),k=d.match(/^hours-(\d*)$/i),l=d.match(/^minutes-(\d*)$/i),m=d.match(/^seconds-(\d*)$/i);console.log("validToYearsPattern",h),console.log("validToMonthsPattern",i),console.log("validToDaysPattern",j),console.log("validToHoursPattern",k),console.log("validToMinutesPattern",l),console.log("validToSecondsPattern",m),h&&h[1]?f=add(g,{years:h[1]}):i&&i[1]?f=add(g,{months:i[1]}):j&&j[1]?f=add(g,{days:j[1]}):k&&k[1]?f=add(g,{hours:k[1]}):l&&l[1]?f=add(g,{minutes:l[1]}):m&&m[1]&&(f=add(g,{seconds:m[1]}))}var n={id:uuid.v4(),major:b.major,minor:b.minor,patch:b.patch,user:c,created:g,validTo:f,expire:e?new Date(e):null};console.log("Put data",n);var o,p,q=b.privateKeyPath,r=b.publicKeyPath;if(q&&r)o=fs.readFileSync(q),p=fs.readFileSync(r);else{var w=crypto.generateKeyPairSync("rsa",cryptoKeyPairOptions);p=w.publicKey,o=w.privateKey}var s=crypto.privateEncrypt(o,Buffer.from(JSON.stringify(n))),t=path.join(b.output,b["public"]),u=path.join(b.output,b["private"]),v=path.join(b.output,b.license);console.log("Saving public key file to '".concat(t,"'.")),fs.writeFileSync(t,p),console.log("Saving private key file to '".concat(u,"'.")),fs.writeFileSync(u,o),console.log("Saving license file to '".concat(v,"'.")),fs.writeFileSync(v,s)}
{
"name": "@igor-lemon/secure-electron-license-keys-cli",
"version": "1.2.0",
"version": "1.2.2",
"description": "A CLI to create and offline license keys for your Electron apps.",

@@ -36,4 +36,5 @@ "main": "lib/index.js",

"esm": "^3.2.25",
"uuid": "^8.3.2"
"uuid": "^8.3.2",
"date-fns": "^2.23.0"
}
}

@@ -38,2 +38,3 @@ # secure-electron-license-keys-cli

|--public-key|-pubk|null|The path to the public key|
|--valid-to|-vt|null|Set the time of license valid. Patterns: `years-<num>`, `months-<num>`, `days-<num>`, `hours-<num>`, `minutes-<num>`, `seconds-<num>`|

@@ -55,2 +56,6 @@ ### Samples

```shell
> secure-electron-license-keys-cli --expire "2022-12-25" --user "uniqueuseremail@account.com" --valid-to "months-6"
```
> Note - you can also use the shorthand (ie. `selkc` instead of `secure-electron-license-keys-cli`)

@@ -6,2 +6,3 @@ import arg from "arg";

const uuid = require("uuid");
const add = require("date-fns/add");

@@ -21,2 +22,3 @@ function parseArgumentsIntoOptions(rawArgs) {

"--public-key": String,
"--valid-to": String,
"-ma": "--major",

@@ -33,2 +35,3 @@ "-mi": "--minor",

"-pubk": "--public-key",
"-vt": "--valid-to",
}, {

@@ -51,2 +54,3 @@ permissive: false,

publicKey: args["--public-key"] || null,
validTo: args["--valid-to"] || null,
};

@@ -70,3 +74,3 @@ }

const { user } = options;
const { user, validTo, expire } = options;

@@ -77,2 +81,41 @@ if (!user) {

let validToDate = null
const now = new Date()
if (validTo) {
const validToYearsPattern = validTo.match(/^years-(\d*)$/i)
const validToMonthsPattern = validTo.match(/^months-(\d*)$/i)
const validToDaysPattern = validTo.match(/^days-(\d*)$/i)
const validToHoursPattern = validTo.match(/^hours-(\d*)$/i)
const validToMinutesPattern = validTo.match(/^minutes-(\d*)$/i)
const validToSecondsPattern = validTo.match(/^seconds-(\d*)$/i)
if (validToYearsPattern && validToYearsPattern[1]) {
validToDate = add(now, {
years: validToYearsPattern[1],
})
} else if (validToMonthsPattern && validToMonthsPattern[1]) {
validToDate = add(now, {
months: validToMonthsPattern[1],
})
} else if (validToDaysPattern && validToDaysPattern[1]) {
validToDate = add(now, {
days: validToDaysPattern[1],
})
} else if (validToHoursPattern && validToHoursPattern[1]) {
validToDate = add(now, {
hours: validToHoursPattern[1],
})
} else if (validToMinutesPattern && validToMinutesPattern[1]) {
validToDate = add(now, {
minutes: validToMinutesPattern[1],
})
} else if (validToSecondsPattern && validToSecondsPattern[1]) {
validToDate = add(now, {
seconds: validToSecondsPattern[1],
})
}
}
// Define user license options/values

@@ -85,4 +128,5 @@ const userData = {

user,
created: Date.now(),
expire: options.expire,
created: now,
validTo: validToDate,
expire: expire ? new Date(expire) : null,
};

@@ -89,0 +133,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc