Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial support for PFX (PKCS12) files.

  • Loading branch information...
commit 97a9aebcfaed402046940a3fe98748b1fa9cb248 1 parent 1ec14c8
@argon authored
Showing with 115 additions and 61 deletions.
  1. +57 −30 lib/connection.js
  2. +58 −31 lib/feedback.js
View
87 lib/connection.js
@@ -23,8 +23,10 @@ if(process.env.DEBUG) {
* @config {Buffer|String} [certData] The certificate data. If supplied, will be used instead of loading from disk.
* @config {String} [key="key.pem"] The filename of the connection key to load from disk
* @config {Buffer|String} [keyData] The key data. If supplied will be used instead of loading from disk.
+ * @config {Buffer[]|String[]} [ca] An array of strings or Buffers of trusted certificates. If this is omitted several well known "root" CAs will be used, like VeriSign. - You may need to use this as some environments don't include the CA used by Apple.
+ * @config {String} [pfx] File path for private key, certificate and CA certs in PFX or PKCS12 format. If supplied will be used instead of certificate and key above
+ * @config {Buffer|String} [pfxData] PFX or PKCS12 format data containing the private key, certificate and CA certs. If supplied will be used instead of loading from disk.
* @config {String} [passphrase] The passphrase for the connection key, if required
- * @config {Buffer[]|String[]} [ca] An array of strings or Buffers of trusted certificates. If this is omitted several well known "root" CAs will be used, like VeriSign. - You may need to use this as some environments don't include the CA used by Apple
* @config {String} [gateway="gateway.push.apple.com"] The gateway server to connect to.
* @config {Number} [port=2195] Gateway port
* @config {Boolean} [rejectUnauthorized=true] Reject Unauthorized property to be passed through to tls.connect()
@@ -39,8 +41,10 @@ function Connection (options) {
certData: null,
key: 'key.pem',
keyData: null,
- passphrase: null,
ca: null,
+ pfx: null,
+ pfxData: null,
+ passphrase: null,
gateway: 'gateway.push.apple.com',
port: 2195,
rejectUnauthorized: true,
@@ -53,6 +57,7 @@ function Connection (options) {
this.certData = null;
this.keyData = null;
+ this.pfxData = null;
this.deferredInitialize = null;
this.deferredConnection = null;
@@ -68,7 +73,7 @@ function Connection (options) {
* @private
*/
Connection.prototype.checkInitialized = function () {
- if (this.keyData && this.certData) {
+ if ((this.keyData && this.certData) || this.pfxData) {
this.deferredInitialize.resolve();
}
};
@@ -85,32 +90,49 @@ Connection.prototype.initialize = function () {
debug("Initialising module");
this.deferredInitialize = q.defer();
- if (this.options.certData) {
- this.certData = this.options.certData;
- }
- else {
- fs.readFile(this.options.cert, function (err, data) {
- if (err) {
- this.deferredInitialize.reject(err);
- return;
- }
- this.certData = data.toString();
- this.checkInitialized();
- }.bind(this));
- }
-
- if (this.options.keyData) {
- this.keyData = this.options.keyData;
+ if(this.options.pfx != null || this.options.pfxData != null) {
+ if(this.options.pxfData) {
+ this.pfxData = this.options.pfxData;
+ }
+ else {
+ fs.readFile(this.options.pfx, function (err, data) {
+ if (err) {
+ this.deferredInitialize.reject(err);
+ return;
+ }
+ this.pfxData = data.toString();
+ this.checkInitialized();
+ }.bind(this));
+ }
}
else {
- fs.readFile(this.options.key, function (err, data) {
- if (err) {
- this.deferredInitialize.reject(err);
- return;
- }
- this.keyData = data.toString();
- this.checkInitialized();
- }.bind(this));
+ if (this.options.certData) {
+ this.certData = this.options.certData;
+ }
+ else {
+ fs.readFile(this.options.cert, function (err, data) {
+ if (err) {
+ this.deferredInitialize.reject(err);
+ return;
+ }
+ this.certData = data.toString();
+ this.checkInitialized();
+ }.bind(this));
+ }
+
+ if (this.options.keyData) {
+ this.keyData = this.options.keyData;
+ }
+ else {
+ fs.readFile(this.options.key, function (err, data) {
+ if (err) {
+ this.deferredInitialize.reject(err);
+ return;
+ }
+ this.keyData = data.toString();
+ this.checkInitialized();
+ }.bind(this));
+ }
}
this.checkInitialized();
@@ -131,10 +153,15 @@ Connection.prototype.connect = function () {
this.initialize().then(function () {
var socketOptions = {};
- socketOptions.key = this.keyData;
- socketOptions.cert = this.certData;
+ if(this.pfxData) {
+ socketOptions.pfx = this.pfxData;
+ }
+ else {
+ socketOptions.key = this.keyData;
+ socketOptions.cert = this.certData;
+ socketOptions.ca = this.options.ca;
+ }
socketOptions.passphrase = this.options.passphrase;
- socketOptions.ca = this.options.ca;
socketOptions.rejectUnauthorized = this.options.rejectUnauthorized;
this.socket = tls.connect(
View
89 lib/feedback.js
@@ -23,8 +23,10 @@ if(process.env.DEBUG) {
* @config {Buffer|String} [certData] The certificate data. If supplied, will be used instead of loading from disk.
* @config {String} [key="key.pem"] The filename of the connection key to load from disk
* @config {Buffer|String} [keyData] The key data. If supplied will be used instead of loading from disk.
+ * @config {Buffer[]|String[]} [ca] An array of strings or Buffers of trusted certificates. If this is omitted several well known "root" CAs will be used, like VeriSign. - You may need to use this as some environments don't include the CA used by Apple.
+ * @config {String} [pfx] File path for private key, certificate and CA certs in PFX or PKCS12 format. If supplied will be used instead of certificate and key above
+ * @config {Buffer|String} [pfxData] PFX or PKCS12 format data containing the private key, certificate and CA certs. If supplied will be used instead of loading from disk.
* @config {String} [passphrase] The passphrase for the connection key, if required
- * @config {Buffer[]|String[]} [ca] An array of strings or Buffers of trusted certificates. If this is omitted several well known "root" CAs will be used, like VeriSign. - You may need to use this as some environments don't include the CA used by Apple
* @config {String} [address="feedback.push.apple.com"] The feedback server to connect to.
* @config {Number} [port=2195] Feedback server port
* @config {Function} [feedback] A callback which accepts 2 parameters (timestamp, {@link Device}). See: {@link <a href="https://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingWIthAPS/CommunicatingWIthAPS.html#//apple_ref/doc/uid/TP40008194-CH101-SW3">Communicating with APS</a>.
@@ -38,11 +40,13 @@ function Feedback(options) {
certData: null, /* Certificate data */
key: 'key.pem', /* Key file */
keyData: null, /* Key data */
+ ca: null, /* Certificate Authority */
+ pfx: null, /* PFX File */
+ pfxData: null, /* PFX Data */
passphrase: null, /* Passphrase for key */
- ca: null, /* Certificate Authority
address: 'feedback.push.apple.com', /* feedback address */
port: 2196, /* feedback port */
- rejectUnauthorized: true, /* Set this to false incase using a local proxy, reject otherwise */
+ rejectUnauthorized: true, /* Set this to false incase using a local proxy, reject otherwise */
feedback: false, /* enable feedback service, set to callback */
errorCallback: false, /* error handler to catch connection exceptions */
interval: 3600, /* interval in seconds to connect to feedback service */
@@ -52,6 +56,7 @@ function Feedback(options) {
this.certData = null;
this.keyData = null;
+ this.pfxData = null;
this.deferredInitialize = null;
this.deferredConnection = null;
@@ -70,7 +75,7 @@ function Feedback(options) {
* @private
*/
Feedback.prototype.checkInitialized = function () {
- if (this.keyData && this.certData) {
+ if ((this.keyData && this.certData) || this.pfxData) {
this.deferredInitialize.resolve();
}
};
@@ -86,32 +91,49 @@ Feedback.prototype.initialize = function () {
debug("Initialising module");
this.deferredInitialize = q.defer();
- if (this.options.certData) {
- this.certData = this.options.certData;
- }
- else {
- fs.readFile(this.options.cert, function (err, data) {
- if (err) {
- this.deferredInitialize.reject(err);
- return;
- }
- this.certData = data.toString();
- this.checkInitialized();
- }.bind(this));
- }
-
- if (this.options.keyData) {
- this.keyData = this.options.keyData;
+ if (this.options.pfx != null || this.options.pfxData != null) {
+ if (this.options.pfxData) {
+ this.pfxData = this.options.pfxData;
+ }
+ else {
+ fx.readFile(this.options.pfx, function (err, data) {
+ if (err) {
+ this.deferredInitialize.reject(err);
+ return;
+ }
+ this.pfxData = data.toString();
+ this.checkInitialized();
+ }.bind(this));
+ }
}
else {
- fs.readFile(this.options.key, function (err, data) {
- if (err) {
- this.deferredInitialize.reject(err);
- return;
- }
- this.keyData = data.toString();
- this.checkInitialized();
- }.bind(this));
+ if (this.options.certData) {
+ this.certData = this.options.certData;
+ }
+ else {
+ fs.readFile(this.options.cert, function (err, data) {
+ if (err) {
+ this.deferredInitialize.reject(err);
+ return;
+ }
+ this.certData = data.toString();
+ this.checkInitialized();
+ }.bind(this));
+ }
+
+ if (this.options.keyData) {
+ this.keyData = this.options.keyData;
+ }
+ else {
+ fs.readFile(this.options.key, function (err, data) {
+ if (err) {
+ this.deferredInitialize.reject(err);
+ return;
+ }
+ this.keyData = data.toString();
+ this.checkInitialized();
+ }.bind(this));
+ }
}
this.checkInitialized();
@@ -132,10 +154,15 @@ Feedback.prototype.connect = function () {
this.initialize().then(function() {
var socketOptions = {};
- socketOptions.key = this.keyData;
- socketOptions.cert = this.certData;
+ if (this.pfxData != null) {
+ socketOptions.pfx = this.pfxData;
+ }
+ else {
+ socketOptions.key = this.keyData;
+ socketOptions.cert = this.certData;
+ socketOptions.ca = this.options.ca;
+ }
socketOptions.passphrase = this.options.passphrase;
- socketOptions.ca = this.options.ca;
socketOptions.rejectUnauthorized = this.options.rejectUnauthorized;
this.socket = tls.connect(
Please sign in to comment.
Something went wrong with that request. Please try again.