Browse Source

Moved Credentials into crypto module. Added node_crypto into crypto module

v0.7.4-release
Rhys Jones 15 years ago
parent
commit
80174392bb
  1. 52
      lib/crypto.js
  2. 4
      lib/http.js
  3. 34
      lib/net.js
  4. 1
      src/node.cc
  5. 1599
      src/node_crypto.cc
  6. 7
      src/node_crypto.h

52
lib/crypto.js

@ -0,0 +1,52 @@
var sys = require("sys");
try {
var binding = process.binding('crypto');
var SecureContext = binding.SecureContext;
var SecureStream = binding.SecureStream;
var Hash = binding.Hash;
var Sign = binding.Sign;
var Verify = binding.Verify;
var crypto = true;
} catch (e) {
var crypto = false;
}
function Credentials(method) {
if (!crypto) {
throw new Error('node.js not compiled with openssl crypto support.');
}
this.context = new SecureContext();
if (method) this.context.init(method);
else this.context.init();
}
exports.createCredentials = function(cred) {
var c = new Credentials(cred.method);
if (cred.key) c.context.setKey(cred.key);
if (cred.cert) c.context.setCert(cred.cert);
if (cred.ca) {
if ( (typeof(cred.ca) == 'object') && cred.ca.length ) {
for(var i=0; i<cred.ca.length; i++)
c.context.addCACert(cred.ca[i]);
} else {
c.context.addCACert(cred.ca);
}
}
return c;
}
exports.Credentials = Credentials;
exports.Hash = Hash;
exports.createHash = function(hash) {
return (new Hash).init(hash);
}
exports.Sign = Sign;
exports.createSign = function(algorithm) {
return (new Sign).init(algorithm);
}
exports.Verify = Verify;
exports.createVerify = function(algorithm) {
return (new Verify).init(algorithm);
}

4
lib/http.js

@ -642,10 +642,6 @@ exports.createClient = function (port, host, https, credentials) {
return c; return c;
} }
exports.createCredentials = function (credentials) {
return net.createCredentials(credentials);
}
Client.prototype.get = function () { Client.prototype.get = function () {
throw new Error("client.get(...) is now client.request('GET', ...)"); throw new Error("client.get(...) is now client.request('GET', ...)");
}; };

34
lib/net.js

@ -1,6 +1,7 @@
var sys = require("sys"); var sys = require("sys");
var fs = require("fs"); var fs = require("fs");
var events = require("events"); var events = require("events");
var crypto= require("crypto");
var kMinPoolSpace = 128; var kMinPoolSpace = 128;
var kPoolSize = 40*1024; var kPoolSize = 40*1024;
@ -48,9 +49,9 @@ var END_OF_FILE = 42;
try { try {
var SecureContext = process.binding('crypto').SecureContext; var SecureContext = process.binding('crypto').SecureContext;
var SecureStream = process.binding('crypto').SecureStream; var SecureStream = process.binding('crypto').SecureStream;
var crypto = true; var have_crypto = true;
} catch (e) { } catch (e) {
var crypto = false; var have_crypto = false;
} }
// IDLE TIMEOUTS // IDLE TIMEOUTS
@ -390,31 +391,6 @@ function initStream (self) {
self.writable = false; self.writable = false;
} }
function Credentials(method) {
if (!crypto) {
throw new Error('node.js not compiled with openssl crypto support.');
}
this.context = new SecureContext();
if (method) this.context.init(method);
else this.context.init();
}
exports.createCredentials = function(cred) {
var c = new Credentials(cred.method);
if (cred.key) c.context.setKey(cred.key);
if (cred.cert) c.context.setCert(cred.cert);
if (cred.ca) {
if ( (typeof(cred.ca) == 'object') && cred.ca.length ) {
for(var i=0; i<cred.ca.length; i++)
c.context.addCACert(cred.ca[i]);
} else {
c.context.addCACert(cred.ca);
}
}
return c;
}
exports.Credentials = Credentials;
function Stream (fd) { function Stream (fd) {
events.EventEmitter.call(this); events.EventEmitter.call(this);
@ -429,14 +405,14 @@ sys.inherits(Stream, events.EventEmitter);
exports.Stream = Stream; exports.Stream = Stream;
Stream.prototype.setSecure = function(credentials) { Stream.prototype.setSecure = function(credentials) {
if (!crypto) { if (!have_crypto) {
throw new Error('node.js not compiled with openssl crypto support.'); throw new Error('node.js not compiled with openssl crypto support.');
} }
this.secure = true; this.secure = true;
this.secureEstablished = false; this.secureEstablished = false;
// If no credentials given, create a new one for just this Stream // If no credentials given, create a new one for just this Stream
if (!credentials) { if (!credentials) {
this.credentials = new Credentials(); this.credentials = new crypto.Credentials();
} else { } else {
this.credentials = credentials; this.credentials = credentials;
} }

1
src/node.cc

@ -1208,6 +1208,7 @@ static Handle<Value> Binding(const Arguments& args) {
exports->Set(String::New("fs"), String::New(native_fs)); exports->Set(String::New("fs"), String::New(native_fs));
exports->Set(String::New("http"), String::New(native_http)); exports->Set(String::New("http"), String::New(native_http));
exports->Set(String::New("http_old"), String::New(native_http_old)); exports->Set(String::New("http_old"), String::New(native_http_old));
exports->Set(String::New("crypto"), String::New(native_crypto));
exports->Set(String::New("ini"), String::New(native_ini)); exports->Set(String::New("ini"), String::New(native_ini));
exports->Set(String::New("mjsunit"), String::New(native_mjsunit)); exports->Set(String::New("mjsunit"), String::New(native_mjsunit));
exports->Set(String::New("multipart"), String::New(native_multipart)); exports->Set(String::New("multipart"), String::New(native_multipart));

1599
src/node_crypto.cc

File diff suppressed because it is too large

7
src/node_crypto.h

@ -7,6 +7,13 @@
#include <openssl/ssl.h> #include <openssl/ssl.h>
#include <openssl/err.h> #include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/pem.h>
#include <openssl/x509.h>
#include <openssl/hmac.h>
#define EVP_F_EVP_DECRYPTFINAL 101
namespace node { namespace node {

Loading…
Cancel
Save