sensor.live-things-registry
Advanced tools
Comparing version 0.0.7 to 0.0.8
{ | ||
"name": "sensor.live-things-registry", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -7,6 +7,9 @@ const fs = require('fs'); | ||
constructure() { | ||
this.certs_path = ''; | ||
this.certs_path = './certs'; | ||
this.root_ca_crt = 'root_ca.crt'; | ||
this.signer_ca_crt = 'signer_ca.crt'; | ||
this.signer_ca_key = 'signer_ca.key'; | ||
this.device_key = null; | ||
this.device_csr = 'device.csr'; | ||
this.device_crt = 'device.crt'; | ||
this.device_key = 'device.key'; | ||
this.device_cert = null; | ||
@@ -23,10 +26,33 @@ } | ||
} | ||
setRootCaCertName(name) { | ||
this.root_ca_crt = name; | ||
} | ||
setDeviceCsrName(name) { | ||
this.device_csr = name; | ||
} | ||
setDeviceCrtName(name) { | ||
this.device_crt = name; | ||
} | ||
setDeviceKeyName(name) { | ||
this.device_key = name; | ||
} | ||
checkRootCaCertFile() { | ||
return fs.existsSync( | ||
this.getRootCaCertPath() | ||
); | ||
} | ||
checkSignerCaCertFile() { | ||
return fs.existsSync(`${this.certs_path}/${this.signer_ca_crt}`); | ||
return fs.existsSync( | ||
this.getSignCaCertPath() | ||
); | ||
} | ||
checkSignerCaKeyFile() { | ||
return fs.existsSync(`${this.certs_path}/${this.signer_ca_key}`); | ||
return fs.existsSync( | ||
this.getSignCaKeyPath() | ||
); | ||
} | ||
hasDeviceCert() { | ||
return fs.existsSync(`${this.certs_path}/device.crt`); | ||
return fs.existsSync( | ||
this.getDeviceCertPath() | ||
); | ||
} | ||
@@ -37,9 +63,13 @@ generateDeviceCert({ country_name = 'TW', state_name = 'Taipei', locality_name = 'Nangang', organization_name = 'SoftChef', organization_unit_name = 'IT'}) { | ||
} | ||
let signer_ca_cert_path = `${this.certs_path}/signer_ca.crt` | ||
let signer_ca_private_key_path = `${this.certs_path}/signer_ca.key` | ||
let signer_ca_cert_path = `${this.certs_path}/${this.signer_ca_crt}` | ||
let signer_ca_private_key_path = `${this.certs_path}/${this.signer_ca_key}` | ||
let device_pem = {}; | ||
if (fs.existsSync(`${this.certs_path}/device.csr`) && fs.existsSync(`${this.certs_path}/device.key`)) { | ||
if (fs.existsSync(this.getDeviceCsrPath()) && fs.existsSync(this.getDeviceKeyPath())) { | ||
device_pem = { | ||
csr: fs.readFileSync(`${this.certs_path}/device.csr`), | ||
private_key: fs.readFileSync(`${this.certs_path}/device.key`) | ||
csr: fs.readFileSync( | ||
this.getDeviceCsrPath() | ||
), | ||
private_key: fs.readFileSync( | ||
this.getDeviceKeyPath() | ||
) | ||
}; | ||
@@ -51,9 +81,11 @@ } else { | ||
this.device_cert = device_cert; | ||
fs.writeFileSync(`${this.certs_path}/device.csr`, device_pem.csr) | ||
fs.writeFileSync(`${this.certs_path}/device.key`, device_pem.private_key); | ||
fs.writeFileSync(`${this.certs_path}/device.crt`, device_cert); | ||
fs.writeFileSync(this.getDeviceCsrPath(), device_pem.csr) | ||
fs.writeFileSync(this.getDeviceKeyPath(), device_pem.private_key); | ||
fs.writeFileSync(this.getDeviceCertPath(), device_cert); | ||
} | ||
getThingName() { | ||
if (!this.device_cert) { | ||
this.device_cert = fs.readFileSync(`${this.certs_path}/device.crt`).toString(); | ||
this.device_cert = fs.readFileSync( | ||
this.getDeviceCertPath() | ||
).toString(); | ||
} | ||
@@ -69,9 +101,27 @@ let lines = this.device_cert.split('\n'); | ||
return { | ||
keyPath: `${this.certs_path}/device.key`, | ||
certPath: `${this.certs_path}/device.crt`, | ||
caPath: `${this.certs_path}/root_ca.key` | ||
keyPath: this.getDeviceKeyPath(), | ||
certPath: this.getDeviceCertPath(), | ||
caPath: this.getRootCaCertPath() | ||
}; | ||
} | ||
getRootCaCertPath() { | ||
return `${this.certs_path}/${this.root_ca_crt}`; | ||
} | ||
getSignCaCertPath() { | ||
return `${this.certs_path}/${this.signer_ca_crt}`; | ||
} | ||
getSignCaKeyPath() { | ||
return `${this.certs_path}/${this.signer_ca_key}`; | ||
} | ||
getDeviceCsrPath() { | ||
return `${this.certs_path}/${this.device_csr}`; | ||
} | ||
getDeviceCertPath() { | ||
return `${this.certs_path}/${this.device_crt}`; | ||
} | ||
getDeviceKeyPath() { | ||
return `${this.certs_path}/${this.device_key}`; | ||
} | ||
} | ||
module.exports = ThingRegistry; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7161
188