Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 610a403

Browse files
author
Josef Fröhle
committed
fix(package): dep updates and fix deprecated api
Signed-off-by: Josef Fröhle <[email protected]>
1 parent 98a63c9 commit 610a403

File tree

8 files changed

+42
-42
lines changed

8 files changed

+42
-42
lines changed

lib/convert.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ module.exports.PEM2PFX = function (pathBundleIN, pathOUT, password, callback) {
169169
})
170170
}
171171
var delTempPWFiles = []
172-
helper.createPasswordFile({'cipher': '', 'password': password, 'passType': 'in'}, params, delTempPWFiles[delTempPWFiles.length])
173-
helper.createPasswordFile({'cipher': '', 'password': password, 'passType': 'out'}, params, delTempPWFiles[delTempPWFiles.length])
172+
helper.createPasswordFile({ 'cipher': '', 'password': password, 'passType': 'in' }, params, delTempPWFiles[delTempPWFiles.length])
173+
helper.createPasswordFile({ 'cipher': '', 'password': password, 'passType': 'out' }, params, delTempPWFiles[delTempPWFiles.length])
174174
openssl.spawnWrapper(params, false, function (error, code) {
175175
function done (error) {
176176
if (error) {
@@ -202,8 +202,8 @@ module.exports.PFX2PEM = function (pathIN, pathOUT, password, callback) {
202202
'-nodes'
203203
]
204204
var delTempPWFiles = []
205-
helper.createPasswordFile({'cipher': '', 'password': password, 'passType': 'in'}, params, delTempPWFiles[delTempPWFiles.length])
206-
helper.createPasswordFile({'cipher': '', 'password': password, 'passType': 'out'}, params, delTempPWFiles[delTempPWFiles.length])
205+
helper.createPasswordFile({ 'cipher': '', 'password': password, 'passType': 'in' }, params, delTempPWFiles[delTempPWFiles.length])
206+
helper.createPasswordFile({ 'cipher': '', 'password': password, 'passType': 'out' }, params, delTempPWFiles[delTempPWFiles.length])
207207
openssl.spawnWrapper(params, false, function (error, code) {
208208
function done (error) {
209209
if (error) {
@@ -259,8 +259,8 @@ module.exports.P7B2PFX = function (pathBundleIN, pathOUT, password, callback) {
259259
})
260260
}
261261
var delTempPWFiles = [tmpfile]
262-
helper.createPasswordFile({'cipher': '', 'password': password, 'passType': 'in'}, params, delTempPWFiles[delTempPWFiles.length])
263-
helper.createPasswordFile({'cipher': '', 'password': password, 'passType': 'out'}, params, delTempPWFiles[delTempPWFiles.length])
262+
helper.createPasswordFile({ 'cipher': '', 'password': password, 'passType': 'in' }, params, delTempPWFiles[delTempPWFiles.length])
263+
helper.createPasswordFile({ 'cipher': '', 'password': password, 'passType': 'out' }, params, delTempPWFiles[delTempPWFiles.length])
264264
openssl.spawnWrapper(params, false, function (error, code) {
265265
function done (error) {
266266
if (error) {

lib/openssl.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var Buffer = require('safe-buffer').Buffer
1+
var Buffer = require('buffer')
22
var helper = require('./helper.js')
33
var cpspawn = require('child_process').spawn
44
var pathlib = require('path')
@@ -122,7 +122,7 @@ function spawn (params, binary, callback) {
122122
var openssl = cpspawn(pathBin, params)
123123
var stderr = ''
124124

125-
var stdout = (binary ? new Buffer(0) : '')
125+
var stdout = (binary ? Buffer.alloc ? Buffer.alloc(0) : new Buffer(0).fill(0) : '')
126126
openssl.stdout.on('data', function (data) {
127127
if (!binary) {
128128
stdout += data.toString('binary')
@@ -171,8 +171,8 @@ function spawn (params, binary, callback) {
171171
})
172172

173173
openssl.on('close', function () {
174-
stdout = (binary ? stdout : new Buffer(stdout, 'binary').toString('utf-8'))
175-
stderr = new Buffer(stderr, 'binary').toString('utf-8')
174+
stdout = (binary ? stdout : Buffer.from(stdout, 'binary').toString('utf-8'))
175+
stderr = Buffer.from(stderr, 'binary').toString('utf-8')
176176
done()
177177
})
178178
})

lib/pem.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function createPrivateKey (keyBitsize, options, callback) {
6868
var delTempPWFiles = []
6969

7070
if (options && options.cipher && (Number(helper.ciphers.indexOf(options.cipher)) !== -1) && options.password) {
71-
helper.createPasswordFile({'cipher': options.cipher, 'password': options.password, 'passType': 'out'}, params, delTempPWFiles[delTempPWFiles.length])
71+
helper.createPasswordFile({ 'cipher': options.cipher, 'password': options.password, 'passType': 'out' }, params, delTempPWFiles[delTempPWFiles.length])
7272
}
7373

7474
params.push(keyBitsize)
@@ -263,7 +263,7 @@ function createCSR (options, callback) {
263263

264264
var delTempPWFiles = []
265265
if (options.clientKeyPassword) {
266-
helper.createPasswordFile({'cipher': '', 'password': options.clientKeyPassword, 'passType': 'in'}, params, delTempPWFiles[delTempPWFiles.length])
266+
helper.createPasswordFile({ 'cipher': '', 'password': options.clientKeyPassword, 'passType': 'in' }, params, delTempPWFiles[delTempPWFiles.length])
267267
}
268268

269269
openssl.exec(params, 'CERTIFICATE REQUEST', tmpfiles, function (sslErr, data) {
@@ -384,15 +384,15 @@ function createCertificate (options, callback) {
384384
}
385385
}
386386
if (options.serviceKeyPassword) {
387-
helper.createPasswordFile({'cipher': '', 'password': options.serviceKeyPassword, 'passType': 'in'}, params, delTempPWFiles[delTempPWFiles.length])
387+
helper.createPasswordFile({ 'cipher': '', 'password': options.serviceKeyPassword, 'passType': 'in' }, params, delTempPWFiles[delTempPWFiles.length])
388388
}
389389
tmpfiles.push(options.serviceCertificate)
390390
tmpfiles.push(options.serviceKey)
391391
} else {
392392
params.push('-signkey')
393393
params.push('--TMPFILE--')
394394
if (options.serviceKeyPassword) {
395-
helper.createPasswordFile({'cipher': '', 'password': options.serviceKeyPassword, 'passType': 'in'}, params, delTempPWFiles[delTempPWFiles.length])
395+
helper.createPasswordFile({ 'cipher': '', 'password': options.serviceKeyPassword, 'passType': 'in' }, params, delTempPWFiles[delTempPWFiles.length])
396396
}
397397
tmpfiles.push(options.serviceKey)
398398
}
@@ -409,7 +409,7 @@ function createCertificate (options, callback) {
409409
}
410410

411411
if (options.clientKeyPassword) {
412-
helper.createPasswordFile({'cipher': '', 'password': options.clientKeyPassword, 'passType': 'in'}, params, delTempPWFiles[delTempPWFiles.length])
412+
helper.createPasswordFile({ 'cipher': '', 'password': options.clientKeyPassword, 'passType': 'in' }, params, delTempPWFiles[delTempPWFiles.length])
413413
}
414414

415415
openssl.exec(params, 'CERTIFICATE', tmpfiles, function (sslErr, data) {
@@ -560,7 +560,7 @@ function getModulus (certificate, password, hash, callback) {
560560
]
561561
var delTempPWFiles = []
562562
if (password) {
563-
helper.createPasswordFile({'cipher': '', 'password': password, 'passType': 'in'}, params, delTempPWFiles[delTempPWFiles.length])
563+
helper.createPasswordFile({ 'cipher': '', 'password': password, 'passType': 'in' }, params, delTempPWFiles[delTempPWFiles.length])
564564
}
565565

566566
openssl.spawnWrapper(params, certificate, function (sslErr, code, stdout, stderr) {
@@ -704,11 +704,11 @@ function createPkcs12 (key, certificate, password, options, callback) {
704704
if (options.cipher && options.clientKeyPassword) {
705705
// NOTICE: The password field is needed! self if it is empty.
706706
// create password file for the import "-passin"
707-
helper.createPasswordFile({'cipher': options.cipher, 'password': options.clientKeyPassword, 'passType': 'in'}, params, delTempPWFiles[delTempPWFiles.length])
707+
helper.createPasswordFile({ 'cipher': options.cipher, 'password': options.clientKeyPassword, 'passType': 'in' }, params, delTempPWFiles[delTempPWFiles.length])
708708
}
709709
// NOTICE: The password field is needed! self if it is empty.
710710
// create password file for the password "-password"
711-
helper.createPasswordFile({'cipher': '', 'password': password, 'passType': 'word'}, params, delTempPWFiles[delTempPWFiles.length])
711+
helper.createPasswordFile({ 'cipher': '', 'password': password, 'passType': 'word' }, params, delTempPWFiles[delTempPWFiles.length])
712712

713713
params.push('-in')
714714
params.push('--TMPFILE--')
@@ -758,15 +758,15 @@ function readPkcs12 (bufferOrPath, options, callback) {
758758
var delTempPWFiles = []
759759
var args = ['pkcs12', '-in', bufferOrPath]
760760

761-
helper.createPasswordFile({'cipher': '', 'password': options.p12Password, 'passType': 'in'}, args, delTempPWFiles[delTempPWFiles.length])
761+
helper.createPasswordFile({ 'cipher': '', 'password': options.p12Password, 'passType': 'in' }, args, delTempPWFiles[delTempPWFiles.length])
762762

763763
if (Buffer.isBuffer(bufferOrPath)) {
764764
tmpfiles = [bufferOrPath]
765765
args[2] = '--TMPFILE--'
766766
}
767767

768768
if (options.clientKeyPassword) {
769-
helper.createPasswordFile({'cipher': '', 'password': options.clientKeyPassword, 'passType': 'out'}, args, delTempPWFiles[delTempPWFiles.length])
769+
helper.createPasswordFile({ 'cipher': '', 'password': options.clientKeyPassword, 'passType': 'out' }, args, delTempPWFiles[delTempPWFiles.length])
770770
} else {
771771
args.push('-nodes')
772772
}
@@ -834,7 +834,7 @@ function checkCertificate (certificate, passphrase, callback) {
834834
params = ['x509', '-text', '-noout', '-in', '--TMPFILE--']
835835
}
836836
if (passphrase) {
837-
helper.createPasswordFile({'cipher': '', 'password': passphrase, 'passType': 'in'}, params, delTempPWFiles[delTempPWFiles.length])
837+
helper.createPasswordFile({ 'cipher': '', 'password': passphrase, 'passType': 'in' }, params, delTempPWFiles[delTempPWFiles.length])
838838
}
839839

840840
openssl.spawnWrapper(params, certificate, function (sslErr, code, stdout, stderr) {
@@ -877,7 +877,7 @@ function checkPkcs12 (bufferOrPath, passphrase, callback) {
877877
var delTempPWFiles = []
878878
var args = ['pkcs12', '-info', '-in', bufferOrPath, '-noout', '-maciter', '-nodes']
879879

880-
helper.createPasswordFile({'cipher': '', 'password': passphrase, 'passType': 'in'}, args, delTempPWFiles[delTempPWFiles.length])
880+
helper.createPasswordFile({ 'cipher': '', 'password': passphrase, 'passType': 'in' }, args, delTempPWFiles[delTempPWFiles.length])
881881

882882
if (Buffer.isBuffer(bufferOrPath)) {
883883
tmpfiles = [bufferOrPath]

package-lock.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"changelog": "auto-changelog --output HISTORY.md",
2424
"coverage": "cross-env NODE_ENV=development nyc ./node_modules/.bin/_mocha --opts mocha.opts $(find . -type f -name '*.spec.js' ! -path './nyc_output/*' ! -path './coverage/*' ! -path './node_modules/*')",
2525
"semantic-release": "semantic-release",
26-
"lint": "eslint --fix --config=./.eslintrc.js *.js *.md *.json lib/*.js test/*.js test/*.spec.js",
26+
"lint": "eslint --fix --config=./.eslintrc.js lib/*.js *.md *.json lib/*.js test/*.js test/*.spec.js",
2727
"test": "npm run lint --silent && npm run coverage --silent"
2828
},
2929
"nyc": {
@@ -39,7 +39,6 @@
3939
"dependencies": {
4040
"md5": "^2.2.1",
4141
"os-tmpdir": "^1.0.1",
42-
"safe-buffer": "^5.1.2",
4342
"which": "^1.3.1"
4443
},
4544
"devDependencies": {

test/convert.spec.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe('convert.js tests', function () {
4343
})
4444
})
4545
it('#.PEM2P7B()', function (done) {
46-
pem.convert.PEM2P7B({cert: './test/fixtures/nopkey.pem'}, './test/fixtures/tmp.p7b', function (error, result) {
46+
pem.convert.PEM2P7B({ cert: './test/fixtures/nopkey.pem' }, './test/fixtures/tmp.p7b', function (error, result) {
4747
hlp.checkError(error, true)
4848
done()
4949
})
@@ -72,7 +72,7 @@ describe('convert.js tests', function () {
7272
})
7373
})
7474
it('#.P7B2PFX() [error in 1st step]', function (done) {
75-
pem.convert.P7B2PFX({cert: './test/fixtures/test.p7b', key: './test/fixtures/test.key', ca: './test/fixtures/GeoTrust_Primary_CA.pem'}, './test/fixtures/tmp.pfx', 'password', function (error, result) {
75+
pem.convert.P7B2PFX({ cert: './test/fixtures/test.p7b', key: './test/fixtures/test.key', ca: './test/fixtures/GeoTrust_Primary_CA.pem' }, './test/fixtures/tmp.pfx', 'password', function (error, result) {
7676
hlp.checkError(error, true)
7777
done()
7878
})
@@ -81,7 +81,7 @@ describe('convert.js tests', function () {
8181
pem.config({
8282
pathOpenSSL: process.env.OPENSSL_BIN || 'openssl'
8383
})
84-
pem.convert.P7B2PFX({cert: './test/fixtures/test.p7b', key: './test/fixtures/test404.key', ca: './test/fixtures/ca404.pem'}, './test/fixtures/tmp.pfx', 'password', function (error, result) {
84+
pem.convert.P7B2PFX({ cert: './test/fixtures/test.p7b', key: './test/fixtures/test404.key', ca: './test/fixtures/ca404.pem' }, './test/fixtures/tmp.pfx', 'password', function (error, result) {
8585
hlp.checkError(error, true)
8686
done()
8787
})
@@ -128,23 +128,23 @@ describe('convert.js tests', function () {
128128
})
129129

130130
it('#.PEM2P7B() [providing a CA cert; no array format]', function (done) {
131-
pem.convert.PEM2P7B({cert: './test/fixtures/nopkey.pem', ca: './test/fixtures/GeoTrust_Primary_CA.pem'}, './test/fixtures/tmp.p7b', function (error, result) {
131+
pem.convert.PEM2P7B({ cert: './test/fixtures/nopkey.pem', ca: './test/fixtures/GeoTrust_Primary_CA.pem' }, './test/fixtures/tmp.p7b', function (error, result) {
132132
hlp.checkError(error)
133133
expect(result).to.be.true()
134134
done()
135135
})
136136
})
137137

138138
it('#.PEM2P7B() [providing a CA cert; array format]', function (done) {
139-
pem.convert.PEM2P7B({cert: './test/fixtures/nopkey.pem', ca: ['./test/fixtures/GeoTrust_Primary_CA.pem']}, './test/fixtures/tmp.p7b', function (error, result) {
139+
pem.convert.PEM2P7B({ cert: './test/fixtures/nopkey.pem', ca: ['./test/fixtures/GeoTrust_Primary_CA.pem'] }, './test/fixtures/tmp.p7b', function (error, result) {
140140
hlp.checkError(error)
141141
expect(result).to.be.true()
142142
done()
143143
})
144144
})
145145

146146
it('#.PEM2P7B() [not providing a CA cert]', function (done) {
147-
pem.convert.PEM2P7B({cert: './test/fixtures/nopkey.pem'}, './test/fixtures/tmp.p7b', function (error, result) {
147+
pem.convert.PEM2P7B({ cert: './test/fixtures/nopkey.pem' }, './test/fixtures/tmp.p7b', function (error, result) {
148148
hlp.checkError(error)
149149
expect(result).to.be.true()
150150
done()
@@ -229,23 +229,23 @@ describe('convert.js tests', function () {
229229
})
230230

231231
it('#.P7B2PFX() [providing ca cert; no array format]', function (done) {
232-
pem.convert.P7B2PFX({cert: './test/fixtures/test.p7b', key: './test/fixtures/test.key', ca: './test/fixtures/GeoTrust_Primary_CA.pem'}, './test/fixtures/tmp.pfx', 'password', function (error, result) {
232+
pem.convert.P7B2PFX({ cert: './test/fixtures/test.p7b', key: './test/fixtures/test.key', ca: './test/fixtures/GeoTrust_Primary_CA.pem' }, './test/fixtures/tmp.pfx', 'password', function (error, result) {
233233
hlp.checkError(error)
234234
expect(result).to.be.true()
235235
done()
236236
})
237237
})
238238

239239
it('#.P7B2PFX() [providing ca cert; array format]', function (done) {
240-
pem.convert.P7B2PFX({cert: './test/fixtures/test.p7b', key: './test/fixtures/test.key', ca: ['./test/fixtures/GeoTrust_Primary_CA.pem']}, './test/fixtures/tmp.pfx', 'password', function (error, result) {
240+
pem.convert.P7B2PFX({ cert: './test/fixtures/test.p7b', key: './test/fixtures/test.key', ca: ['./test/fixtures/GeoTrust_Primary_CA.pem'] }, './test/fixtures/tmp.pfx', 'password', function (error, result) {
241241
hlp.checkError(error)
242242
expect(result).to.be.true()
243243
done()
244244
})
245245
})
246246

247247
it('#.P7B2PFX() [not providing ca cert]', function (done) {
248-
pem.convert.P7B2PFX({cert: './test/fixtures/test.p7b', key: './test/fixtures/test.key'}, './test/fixtures/tmp.pfx', 'password', function (error, result) {
248+
pem.convert.P7B2PFX({ cert: './test/fixtures/test.p7b', key: './test/fixtures/test.key' }, './test/fixtures/tmp.pfx', 'password', function (error, result) {
249249
hlp.checkError(error)
250250
expect(result).to.be.true()
251251
done()

test/helper.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe('helper.js tests', function () {
2727
var tmpfiles = []
2828
var bufferOrPath = fs.readFileSync('./test/fixtures/idsrv3test.pfx')
2929
helper.createPasswordFile(
30-
{cipher: '', bla: true, blub: true},
30+
{ cipher: '', bla: true, blub: true },
3131
['pkcs12', '-info', '-in', bufferOrPath, '-noout', '-maciter', '-nodes'],
3232
tmpfiles[tmpfiles.length]
3333
)
@@ -40,7 +40,7 @@ describe('helper.js tests', function () {
4040
var tmpfiles = []
4141
var bufferOrPath = fs.readFileSync('./test/fixtures/idsrv3test.pfx')
4242
helper.createPasswordFile(
43-
{cipher: '', password: 'gregegegeg', passType: 'in', mustPass: 'password'},
43+
{ cipher: '', password: 'gregegegeg', passType: 'in', mustPass: 'password' },
4444
['pkcs12', '-info', '-in', bufferOrPath, '-noout', '-maciter', '-nodes'],
4545
tmpfiles[tmpfiles.length]
4646
)

test/pem.spec.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -801,9 +801,9 @@ describe('General Tests', function () {
801801
},
802802
san: {
803803
dns: [
804-
"example.com",
805-
"*.app.example.com",
806-
"www.example.com"
804+
'example.com',
805+
'*.app.example.com',
806+
'www.example.com'
807807
],
808808
email: [],
809809
ip: []
@@ -850,9 +850,9 @@ describe('General Tests', function () {
850850
},
851851
san: {
852852
dns: [
853-
"example.com",
854-
"*.app.example.com",
855-
"www.example.com"
853+
'example.com',
854+
'*.app.example.com',
855+
'www.example.com'
856856
],
857857
email: [],
858858
ip: []

0 commit comments

Comments
 (0)