Skip to content

Commit

Permalink
replacing the deprecated crypto.createCredentials() with tls.createSe…
Browse files Browse the repository at this point in the history
…cureContext()
  • Loading branch information
ya7ya committed Jan 30, 2017
1 parent 7f88b51 commit 9d4058d
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions lib/core/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function BufferLayer(socket) {
//for ssl connection
this.securePair = null;
this.socket = socket;

var self = this;
// bind event
this.socket.on('data', function(data) {
Expand All @@ -50,7 +50,7 @@ function BufferLayer(socket) {
}).on('error', function (err) {
self.emit('error', err);
});

//buffer data
this.buffers = [];
this.bufferLength = 0;
Expand All @@ -67,17 +67,17 @@ inherits(BufferLayer, events.EventEmitter);
BufferLayer.prototype.recv = function(data) {
this.buffers[this.buffers.length] = data;
this.bufferLength += data.length;

while(this.bufferLength >= this.expectedSize) {
//linear buffer
var expectedData = new type.Stream(this.expectedSize);

//create expected data
while(expectedData.availableLength() > 0) {

var rest = expectedData.availableLength();
var buffer = this.buffers.shift();

if(buffer.length > expectedData.availableLength()) {
this.buffers.unshift(buffer.slice(rest));
new type.BinaryString(buffer, { readLength : new type.CallableValue(expectedData.availableLength()) }).write(expectedData);
Expand All @@ -86,7 +86,7 @@ BufferLayer.prototype.recv = function(data) {
new type.BinaryString(buffer).write(expectedData);
}
}

this.bufferLength -= this.expectedSize;
expectedData.offset = 0;
this.emit('data', expectedData);
Expand Down Expand Up @@ -124,14 +124,14 @@ BufferLayer.prototype.expect = function(expectedSize) {
BufferLayer.prototype.startTLS = function(callback) {
var options = {
socket : this.socket,
pair : tls.createSecurePair(crypto.createCredentials(), false, false, false)
pair : tls.createSecurePair(tls.createSecureContext(), false, false, false)
};
var self = this;
this.securePair = starttls(options, function(err) {
log.warn(err);
callback();
})

this.securePair.cleartext.on('data', function(data) {
try {
self.recv(data);
Expand All @@ -149,12 +149,12 @@ BufferLayer.prototype.startTLS = function(callback) {
* Convert connection to TLS server
* @param keyFilePath {string} key file path
* @param crtFilePath {string} certificat file path
* @param callback {function}
* @param callback {function}
*/
BufferLayer.prototype.listenTLS = function(keyFilePath, crtFilePath, callback) {
var options = {
socket : this.socket,
pair : tls.createSecurePair(crypto.createCredentials({
pair : tls.createSecurePair(tls.createSecureContext({
key: fs.readFileSync(keyFilePath),
cert: fs.readFileSync(crtFilePath),
}), true, false, false)
Expand All @@ -165,7 +165,7 @@ BufferLayer.prototype.listenTLS = function(keyFilePath, crtFilePath, callback) {
self.cleartext = this.cleartext;
callback();
});

this.securePair.cleartext.on('data', function(data) {
try {
self.recv(data);
Expand Down

1 comment on commit 9d4058d

@sunjith
Copy link

@sunjith sunjith commented on 9d4058d May 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version and npmjs module has not yet been updated.

Please sign in to comment.