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

sensor.live-things-registry

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sensor.live-things-registry - npm Package Compare versions

Comparing version 0.0.14 to 0.0.15

2

package.json
{
"name": "sensor.live-things-registry",
"version": "0.0.14",
"version": "0.0.15",
"description": "",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -5,6 +5,13 @@ const forge = require('node-forge');

class KeyGenerator {
generateDeviceKeyPair(thing_name, country_name, state_name, locality_name, organization_name, organization_unit_name) {
generateDeviceKeyPair() {
let keys = forge.pki.rsa.generateKeyPair(2048);
let key_pair = {
private_key: forge.pki.privateKeyToPem(keys.privateKey),
public_key: forge.pki.publicKeyToPem(keys.publicKey),
};
return key_pair;
}
generateDeviceCsr(public_key, private_key, thing_name, country_name, state_name, locality_name, organization_name, organization_unit_name) {
let csr = forge.pki.createCertificationRequest();
csr.publicKey = keys.publicKey;
csr.publicKey = public_key;
csr.setSubject([{

@@ -35,10 +42,5 @@ name: 'commonName',

// sign certification request
csr.sign(keys.privateKey, forge.md.sha256.create());
csr.sign(private_key, forge.md.sha256.create());
// PEM-format keys and csr
let key_pair = {
private_key: forge.pki.privateKeyToPem(keys.privateKey),
public_key: forge.pki.publicKeyToPem(keys.publicKey),
csr: forge.pki.certificationRequestToPem(csr)
};
return key_pair;
return forge.pki.certificationRequestToPem(csr);
}

@@ -45,0 +47,0 @@ generateDeviceCertificate(ca_certificate_path, ca_key_path, device_csr_pem) {

@@ -13,3 +13,4 @@ const fs = require('fs');

this.device_certificate = 'device.crt';
this.device_key = 'device.key';
this.device_public_key = 'device.public.key';
this.device_private_key = 'device.private.key';
}

@@ -34,5 +35,8 @@ setCertsPath(path) {

}
setDeviceKeyName(name) {
this.device_key = name;
setDevicePublicKeyName(name) {
this.device_public_key = name;
}
setDevicePrivateKeyName(name) {
this.device_private_key = name;
}
checkRootCACertificateFile() {

@@ -64,18 +68,28 @@ return fs.existsSync(

let ca_key_path = `${this.certs_path}/${this.ca_key}`
let device_key_pair = {};
if (fs.existsSync(this.getDeviceCsrPath()) && fs.existsSync(this.getDeviceKeyPath())) {
device_key_pair = {
csr: fs.readFileSync(
let device_public_key = null;
let device_private_key = null;
let device_csr = null;
if (fs.existsSync(this.getDevicePublicKeyPath()) && fs.existsSync(this.getDevicePrivateKeyPath())) {
if (!fs.existsSync(this.getDeviceCsrPath())) {
let device_public_key = fs.readFileSync(
this.getDevicePublicKeyPath()
);
let device_private_key = fs.readFileSync(
this.getDevicePrivateKeyPath()
);
device_csr = key_generator.generateDeviceCsr(device_public_key, device_private_key, thing_name, country_name, state_name, locality_name, organization_name, organization_unit_name)
fs.writeFileSync(this.getDeviceCsrPath(), device_csr)
} else {
device_csr = fs.readFileSync(
this.getDeviceCsrPath()
),
private_key: fs.readFileSync(
this.getDeviceKeyPath()
)
};
);
}
} else {
device_key_pair = key_generator.generateDeviceKeyPair(thing_name, country_name, state_name, locality_name, organization_name, organization_unit_name);
let key_pair = key_generator.generateDeviceKeyPair();
device_csr = key_generator.generateDeviceCsr(key_pair.public_key, key_pair.private_key, thing_name, country_name, state_name, locality_name, organization_name, organization_unit_name);
fs.writeFileSync(this.getDevicePublicKeyPath(), key_pair.public_key);
fs.writeFileSync(this.getDevicePrivateKeyPath(), key_pair.private_key);
fs.writeFileSync(this.getDeviceCsrPath(), device_csr)
}
let device_certificate = key_generator.generateDeviceCertificate(ca_certificate_path, ca_key_path, device_key_pair.csr);
fs.writeFileSync(this.getDeviceCsrPath(), device_key_pair.csr)
fs.writeFileSync(this.getDeviceKeyPath(), device_key_pair.private_key);
let device_certificate = key_generator.generateDeviceCertificate(ca_certificate_path, ca_key_path, device_csr);
fs.writeFileSync(this.getDeviceCertificatePath(), device_certificate);

@@ -100,3 +114,3 @@ }

return {
keyPath: this.getDeviceKeyPath(),
keyPath: this.getDevicePrivateKeyPath(),
certPath: this.getDeviceCertificatePath(),

@@ -121,7 +135,13 @@ caPath: this.getRootCACertificatePath()

}
getDeviceKeyPath() {
return `${this.certs_path}/${this.device_key}`;
getDeviceCsrPath() {
return `${this.certs_path}/${this.device_csr}`;
}
getDevicePublicKeyPath() {
return `${this.certs_path}/${this.device_public_key}`;
}
getDevicePrivateKeyPath() {
return `${this.certs_path}/${this.device_private_key}`;
}
}
module.exports = ThingRegistry;
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