new apn.Connection(options) does not read config parameters #188

Closed
michaelsanford opened this Issue Jul 10, 2014 · 27 comments

Projects

None yet

8 participants

@michaelsanford

At least, it appears not to.

For example, instantiating a new apn.Connection(options); with var options = {} and a cert.pem and key.pem in the same location as the file being called works.

But renaming key.pem to server.pem and instantiating with

var options = { key: "server.pem" };

fails.

Similarly, adding passphrase: "<passphrase>" to the options does not decrypt the key. However, adding no passphrase element to the options object, I am prompted for one at the command line. (The above example uses a key.pem with the passphrase removed.)

@argon
Collaborator
argon commented Jul 10, 2014

I'm going to need more details about this problem, certificate and key loading currently has test coverage for this exact functionality and it's passing on my machine.

@michaelsanford

Thanks @argon.

My implementation flow went like this:

  1. I was provided a .p12 file by another developer, as well as extracted certificate and key .pem files. Both were protected by a passphrase.
  2. I placed the pfx block a certs/ folder, one level below the file requiring and using apn.
  3. I added the following to options:
{
  "pfx": "/absolute/path/to/pfx.p12",
  "passphrase": "passphrase"
}
  1. This threw an error from crypto.js, line 143 that a parameter was missing. It appeared to originate from tlsOptions.
  2. I then replaced options with this, but continued to get the same error:
{
  "cert": "/absolute/path/to/certs/cert.pem",
  "key": "/absolute/path/to/certs/key.pem",
  "passphrase": "passphrase"
}
  1. I moved the keys from their locations to the same folder as the js file running this script, same problem.
  2. I passed a null object as options, and was asked on the command line for a passphrase, at which point it worked.
  3. I extracted a passphrase-less rsa key, and the system works unattended.

I will not discount the possibility that I have done something incorrect, and I do not have any details on the keys' generation other than the passphrase (came from another developer).

I'm also running it on express with grunt, if that's relevant.

@argon
Collaborator
argon commented Jul 11, 2014

I have tested on a live system with a passphrase protected key in a non-default filename and both things work. If I move the file or change the passphrase then it fails with various errors. What I don't see is any errors from crypto.js.

When the passphrase is incorrect I see:
Error: [Error: error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt]

When the filename is incorrect I see:
Error: { [Error: ENOENT, open '/Users/argon/Projects/dev/node-apn/key3.pem'] errno: 34, code: 'ENOENT', path: '/Users/argon/Projects/dev/node-apn/key3.pem' }

A copy of the error would be helpful, along with the version of node you're running so I can look at the correct version of crypto.js and see what might be happening.

@michaelsanford

@argon I have since detected other issues with my local copy of node (0.10.26 from homebrew). Unable to repair it, I removed it and all global node modules and reinstalled the official package. It's working as expected now.

For reference, neither of the errors you referenced in your reply were what I saw. Very silly of me not to have saved the stack trace.

Thank you for taking the time to investigate this so quickly; it inspires confidence to use this in production.

@michaelsanford

I just experienced the problem again, attempting to use my old p12 key with passphrase.

P12 Keyfile

I configure the object with:

  var options = {
    pfx: "/full/path/to/certs/OUR-KEY.p12",
    passphrase: "OUR-PASSPHRASE"
  };

(Perhaps notably, both the key filename and the passphrase contain -.)

And then instantiate it with:
var apnConnection = new apn.Connection(options);

And then, upon reaching my controller in a browser, get this in the console:

GET / 200 556ms - 291b
  apn Module initialisation error: +465ms [Error: passed a null parameter]
  apn Raising error: +1ms [Error: passed a null parameter] 

{ JSON payload details }

apn Error occurred with trace: +1ms Error: passed a null parameter
    at Object.exports.createCredentials (crypto.js:143:17)
    at Object.exports.connect (tls.js:1329:27)
    at Connection.<anonymous> (/Users/me/server/gcm-apns/node_modules/apn/lib/connection.js:224:21)
    at /Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:1142:26
    at _fulfilled (/Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:787:54)
    at self.promiseDispatch.done (/Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:816:30)
    at Promise.promise.promiseDispatch (/Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:749:13)
    at /Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:509:49
    at flush (/Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:108:17)
    at process._tickCallback (node.js:419:13)
  apn Raising error: +1ms [Error: passed a null parameter] undefined undefined
  apn Error occurred with trace: +0ms Error: passed a null parameter
    at Object.exports.createCredentials (crypto.js:143:17)
    at Object.exports.connect (tls.js:1329:27)
    at Connection.<anonymous> (/Users/me/server/gcm-apns/node_modules/apn/lib/connection.js:224:21)
    at /Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:1142:26
    at _fulfilled (/Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:787:54)
    at self.promiseDispatch.done (/Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:816:30)
    at Promise.promise.promiseDispatch (/Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:749:13)
    at /Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:509:49
    at flush (/Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:108:17)
    at process._tickCallback (node.js:419:13)

Predictably, failing to pass the passphrase parameter in the options object, I get this:

GET /css/style.css 304 4ms
  apn Module initialisation error: +367ms [Error: mac verify failure]
  apn Raising error: +1ms [Error: mac verify failure] 

{ JSON payload details }

apn Error occurred with trace: +1ms Error: mac verify failure
    at Object.exports.createCredentials (crypto.js:145:17)
    at Object.exports.connect (tls.js:1329:27)
    at Connection.<anonymous> (/Users/me/server/gcm-apns/node_modules/apn/lib/connection.js:224:21)
    at /Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:1142:26
    at _fulfilled (/Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:787:54)
    at self.promiseDispatch.done (/Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:816:30)
    at Promise.promise.promiseDispatch (/Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:749:13)
    at /Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:509:49
    at flush (/Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:108:17)
    at process._tickCallback (node.js:419:13)
  apn Raising error: +0ms [Error: mac verify failure] undefined undefined
  apn Error occurred with trace: +0ms Error: mac verify failure
    at Object.exports.createCredentials (crypto.js:145:17)
    at Object.exports.connect (tls.js:1329:27)
    at Connection.<anonymous> (/Users/me/server/gcm-apns/node_modules/apn/lib/connection.js:224:21)
    at /Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:1142:26
    at _fulfilled (/Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:787:54)
    at self.promiseDispatch.done (/Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:816:30)
    at Promise.promise.promiseDispatch (/Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:749:13)
    at /Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:509:49
    at flush (/Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:108:17)
    at process._tickCallback (node.js:419:13)
  apn 0 left to send +0ms

I know nothing of the creation of the pfx keyfile; if you require additional details I'd be happy to provide them (given direction).

cert.pem and key.pem

Works correctly when providing a full path to the files and passphrase, or with passphrase-less .pem key + cert files.

When options.passphrase is missing, it prompts at the terminal.

Versions

I'm running

  • Node v0.10.29 from the stock OS X .pkg installer; with
  • npm 1.5.0-alpha-1; and
  • OpenSSL 0.9.8y 5 Feb 2013; however
  • OpenSSL stable 1.0.1h (from homebrew, bottled, not linked, not in PATH)
@argon
Collaborator
argon commented Jul 16, 2014

Thanks for writing this up, Michael. I will be sure to investigate this soon and keep you up to date.

—A

On 16 Jul 2014, at 22:17, Michael Sanford notifications@github.com wrote:

I just experienced the problem again, attempting to use my old p12 key with passphrase.

P12 Keyfile

I configure the object with:

var options = {
pfx: "/full/path/to/certs/OUR-KEY.p12",
passphrase: "OUR-PASSPHRASE"
};
(Perhaps notably, both the key filename and the passphrase contain -.)

And then instantiate it with:
var apnConnection = new apn.Connection(options);

And then, upon reaching my controller in a browser, get this in the console:

GET / 200 556ms - 291b
apn Module initialisation error: +465ms [Error: passed a null parameter]
apn Raising error: +1ms [Error: passed a null parameter]

{ JSON payload details }

apn Error occurred with trace: +1ms Error: passed a null parameter
at Object.exports.createCredentials (crypto.js:143:17)
at Object.exports.connect (tls.js:1329:27)
at Connection. (/Users/me/server/gcm-apns/node_modules/apn/lib/connection.js:224:21)
at /Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:1142:26
at _fulfilled (/Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:787:54)
at self.promiseDispatch.done (/Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:816:30)
at Promise.promise.promiseDispatch (/Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:749:13)
at /Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:509:49
at flush (/Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:108:17)
at process._tickCallback (node.js:419:13)
apn Raising error: +1ms [Error: passed a null parameter] undefined undefined
apn Error occurred with trace: +0ms Error: passed a null parameter
at Object.exports.createCredentials (crypto.js:143:17)
at Object.exports.connect (tls.js:1329:27)
at Connection. (/Users/me/server/gcm-apns/node_modules/apn/lib/connection.js:224:21)
at /Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:1142:26
at _fulfilled (/Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:787:54)
at self.promiseDispatch.done (/Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:816:30)
at Promise.promise.promiseDispatch (/Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:749:13)
at /Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:509:49
at flush (/Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:108:17)
at process._tickCallback (node.js:419:13)
Predictably, failing to pass the passphrase parameter in the options object, I get this:

GET /css/style.css 304 4ms
apn Module initialisation error: +367ms [Error: mac verify failure]
apn Raising error: +1ms [Error: mac verify failure]

{ JSON payload details }

apn Error occurred with trace: +1ms Error: mac verify failure
at Object.exports.createCredentials (crypto.js:145:17)
at Object.exports.connect (tls.js:1329:27)
at Connection. (/Users/me/server/gcm-apns/node_modules/apn/lib/connection.js:224:21)
at /Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:1142:26
at _fulfilled (/Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:787:54)
at self.promiseDispatch.done (/Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:816:30)
at Promise.promise.promiseDispatch (/Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:749:13)
at /Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:509:49
at flush (/Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:108:17)
at process._tickCallback (node.js:419:13)
apn Raising error: +0ms [Error: mac verify failure] undefined undefined
apn Error occurred with trace: +0ms Error: mac verify failure
at Object.exports.createCredentials (crypto.js:145:17)
at Object.exports.connect (tls.js:1329:27)
at Connection. (/Users/me/server/gcm-apns/node_modules/apn/lib/connection.js:224:21)
at /Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:1142:26
at _fulfilled (/Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:787:54)
at self.promiseDispatch.done (/Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:816:30)
at Promise.promise.promiseDispatch (/Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:749:13)
at /Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:509:49
at flush (/Users/me/server/gcm-apns/node_modules/apn/node_modules/q/q.js:108:17)
at process._tickCallback (node.js:419:13)
apn 0 left to send +0ms
I know nothing of the creation of the pfx keyfile; if you require additional details I'd be happy to provide them (given direction).

cert.pem and key.pem

Works correctly when providing a full path to the files, or with passphrase-less .pem key + cert files.

When options.passphrase is missing, it prompts at the terminal.

Versions

I'm running

Node v0.10.29 from the stock OS X .pkg installer; with
npm 1.5.0-alpha-1; and
OpenSSL 0.9.8y 5 Feb 2013; however
OpenSSL stable 1.0.1h (from homebrew, bottled, not linked, not in PATH)

Reply to this email directly or view it on GitHub.

@argon
Collaborator
argon commented Jul 17, 2014

Just to confirm, are you seeing this problem intermittently, or is it reproducible?

@argon
Collaborator
argon commented Aug 27, 2014

As you haven't replied to this I will close the issue soon.

Would you by any chance be prepared to share the PFX file that doesn't work with me? I completely understand if the answer is "no", however it may help me to understand what the problem is here.

@argon argon added the credentials label Feb 11, 2015
@1JasonB
1JasonB commented Mar 17, 2015

I just brought up a new server and I'm seeing a related issue at require('apn).

node_modules/apn/node_modules/q/q.js:128
throw e;
^
Error: ENOENT, open 'cert.pem'

I do not have a default cert.pem or key.pem file. I have renamed them.

My previous config worked fine:
node 0.10.32
apn@1.6.2
└── q@1.0.1

This one fails
node 0.10.37
apn@1.7.3
├── node-forge@0.6.21
└── q@1.2.0

If I rename my files to the default, I don't see the problem.

@argon
Collaborator
argon commented Mar 17, 2015

Would you be able to give me as much information as possible about your environment? Specifically OS version

An example of the code you’re using to load the module would be really helpful as nothing i’ve tried has reproduced the problem

Thanks

On 17 Mar 2015, at 21:22, Jason Brewer notifications@github.com wrote:

I just brought up a new server and I'm seeing a related issue at require('apn).

node_modules/apn/node_modules/q/q.js:128
throw e;
^
Error: ENOENT, open 'cert.pem'

I do not have a default cert.pem or key.pem file. I have renamed them.

My previous config worked fine:
node 0.10.32
apn@1.6.2
└── q@1.0.1

This one fails
node 0.10.37
apn@1.7.3
├── node-forge@0.6.21
└── q@1.2.0

If I rename my files to the default, I don't see the problem.


Reply to this email directly or view it on GitHub #188 (comment).

@1JasonB
1JasonB commented Mar 17, 2015

I�'m running Ubuntu Server 14.04 on EC2.

To load the module, I'm just doing

var apn      = require('apn�'),

I�'ll put it out of my server and try it in a simpler program in my
environment.

Thanks for your attention.

@1JasonB
1JasonB commented Mar 18, 2015

Found the problem while reducing. I was creating a feedback object in my
initialization. I guess in the earlier version, Feedback did not fail when I
did not specify the path to the cert file. I assume this is probably a fix
in APN for something that didn�'t impact me before.

Below fails.

var apn = require('apn');

var feedback = new apn.Feedback({
batchFeedback: true,
interval: 300,
});

Below passes.

var apn = require('apn');

var feedback = new apn.Feedback({
batchFeedback: true,
interval: 300,
cert: 'data/apncert_adhoc.pem',
key: 'data/apnkey_adhoc.pem',
production: true,
});

Thanks,
Jason

@hynese
hynese commented Mar 21, 2015

I also get this error:

Error: ENOENT, open 'cert.pem'

When I put "cert.pem" and "key.pem" in the same directory as the .js file, everything is file.

I'm trying to do:

var production = false;
if(dev_dist == "dist"){
  production = true;
}
var options = {};
options.cert = __dirname + "/" + dev_dist + "/cert.pem";
options.key = __dirname + "/" + dev_dist + "/key.pem";
options.production = production;

(i.e. put the dev the dist .pem files in separate directories...)

Ubuntu 14.04.2 (EC2 instance), 64-bit

Node.js v0.12.0

@argon
Collaborator
argon commented Mar 24, 2015

I have taken the example you gave above and run it on an EC2 instance. I have been unable to reproduce your problem
You can see the code I used here: https://gist.github.com/argon/b781f31d23eb4c215f70

> ubuntu@ip-172-30-0-153:~$ npm install apn
npm http GET https://registry.npmjs.org/apn
npm http 200 https://registry.npmjs.org/apn
npm http GET https://registry.npmjs.org/apn/-/apn-1.7.3.tgz
npm http 200 https://registry.npmjs.org/apn/-/apn-1.7.3.tgz
npm http GET https://registry.npmjs.org/node-forge
npm http GET https://registry.npmjs.org/q
npm http 200 https://registry.npmjs.org/q
npm http 200 https://registry.npmjs.org/node-forge
npm http GET https://registry.npmjs.org/q/-/q-1.2.0.tgz
npm http GET https://registry.npmjs.org/node-forge/-/node-forge-0.6.21.tgz
npm http 200 https://registry.npmjs.org/q/-/q-1.2.0.tgz
npm http 200 https://registry.npmjs.org/node-forge/-/node-forge-0.6.21.tgz
apn@1.7.3 node_modules/apn
├── q@1.2.0
└── node-forge@0.6.21
ubuntu@ip-172-30-0-153:~$ node apn
Dev/Dist:  dev
{ cert: '/home/ubuntu/dev/cert.pem',
  key: '/home/ubuntu/dev/key.pem',
  production: false }
Connected
Transmitted:  { encoding: 'utf8',
  payload: { aps: { alert: 'Hello' } },
  expiry: 0,
  priority: 10,
  retryLimit: -1,
  device: undefined,
  alert: 'Hello',
  badge: undefined,
  sound: undefined,
  newsstandAvailable: undefined,
  contentAvailable: undefined,
  mdm: undefined,
  compiled: '{"aps":{"alert":"Hello"}}',
  truncateAtWordEnd: false,
  urlArgs: undefined,
  category: undefined }
Completed!
ubuntu@ip-172-30-0-153:~$ vim apn.js
ubuntu@ip-172-30-0-153:~$ node apn
Dev/Dist:  dist
{ cert: '/home/ubuntu/dist/cert.pem',
  key: '/home/ubuntu/dist/key.pem',
  production: true }
Connected
Transmitted:  { encoding: 'utf8',
  payload: { aps: { alert: 'Hello' } },
  expiry: 0,
  priority: 10,
  retryLimit: -1,
  device: undefined,
  alert: 'Hello',
  badge: undefined,
  sound: undefined,
  newsstandAvailable: undefined,
  contentAvailable: undefined,
  mdm: undefined,
  compiled: '{"aps":{"alert":"Hello"}}',
  truncateAtWordEnd: false,
  urlArgs: undefined,
  category: undefined }
Completed!
Transmission Error 8
ubuntu@ip-172-30-0-153:~$
ubuntu@ip-172-30-0-153:~$ tree
.
|____apn.js
|____dev
| |____cert.pem
| |____key.pem
|____dist
| |____cert.pem
| |____key.pem
@hynese
hynese commented Mar 25, 2015

Hello,

Thank you for investigating this in detail. I just had a look at your gist. I successfully managed to run the code on node.js v0.12.0.

When I tried it originally, I had just set up nvm - I suspect there might have been some incorrect environment variables lingering around? There might have been some system conflict with Ubuntu's default "nodejs"? Though I can't be certain of this.

Sorry if I wasted your time. Though I really appreciate you investigating.

Also, I'm happy that it's working! I was using php-apns up until my latest app - your node.js library is so much more elegant and easy-to-use. Very good documentation and examples too.

@argon
Collaborator
argon commented Mar 25, 2015

It did seem like an unusual error to see, on the other hand it has been mentioned a couple of times so I will continue to look into it.

Thanks for your feedback. I'm always looking to improve the module further so if you get any ideas please open an issue.

@argon argon closed this Mar 31, 2015
@xswapnull

Getting the same issue on start of application.

Here is my configuration.

var options = {
"cert": __dirname + '/credentials' +'/cert.pem' ,
"key": __dirname + '/credentials' +'/key.pem' ,
"production" : true,
"passphrase": "asdfgh",
"gateway": "gateway.sandbox.push.apple.com",
"port": 2195,
"enhanced": true,
"cacheLength": 5
};

apnConnection = new apn.Connection(options);

This is the error.
/node_modules/apn/node_modules/q/q.js:155
throw e;
^
Error: ENOENT, open 'cert.pem'
at Error (native)

But, when I comment line 155 i.e. throw e
Error goes away and push notifications work fine.

Need help in resolving this.

@arturkiulian

Also experiencing this issue. MacOS Yosemite. Options simply don't rewrite default path.

function loadCredentials(credentials) {
    console.log('loadCredentials:', credentials)

loadCredentials: { cert: 'cert.pem',
  key: 'key.pem',
  ca: null,
  pfx: null,
  passphrase: null,
  production: false,
  port: 2196,
  rejectUnauthorized: true,
  feedback: false,
  batchFeedback: true,
  batchSize: 0,
  errorCallback: false,
  interval: 300,
  address: 'feedback.sandbox.push.apple.com' }
@argon
Collaborator
argon commented Aug 2, 2015

Please put the "new options" log after "util.extend" (as this is the line where the options are merged) and verify your results again.

―A

On 2 Aug 2015, at 19:32, Artur K notifications@github.com wrote:

Also experiencing this issue. MacOS Yosemite. Options simply don't rewrite default path.

This is what I see from doing console.log throughout the connection.js file:

default options: { cert: 'cert.pem',
key: 'key.pem',
ca: null,
pfx: null,
passphrase: null,
production: false,
voip: false,
address: null,
port: 2195,
rejectUnauthorized: true,
cacheLength: 1000,
autoAdjustCache: true,
maxConnections: 1,
connectTimeout: 10000,
connectionTimeout: 3600000,
connectionRetryLimit: 10,
buffersNotifications: true,
fastMode: false,
disableNagle: false,
disableEPIPEFix: false }

passed in options: { cert: '/Users/artur/bitbucket/capitanapi/lib/credentials/cert.pem',
key: 'stage_key.pem',
passphrase: 'CPTN!APNS28',
gateway: 'gateway.sandbox.push.apple.com',
port: 2195,
enhanced: true,
cacheLength: 5,
errorCallback: [Function] }

new options: { cert: 'cert.pem',
key: 'key.pem',
ca: null,
pfx: null,
passphrase: null,
production: false,
voip: false,
address: null,
port: 2195,
rejectUnauthorized: true,
cacheLength: 1000,
autoAdjustCache: true,
maxConnections: 1,
connectTimeout: 10000,
connectionTimeout: 3600000,
connectionRetryLimit: 10,
buffersNotifications: true,
fastMode: false,
disableNagle: false,
disableEPIPEFix: false }
function Connection (options) {
if(false === (this instanceof Connection)) {
return new Connection(options);
}
this.options = {
cert: "cert.pem",
key: "key.pem",
ca: null,
pfx: null,
passphrase: null,
production: (process.env.NODE_ENV === "production"),
voip: false,
address: null,
port: 2195,
rejectUnauthorized: true,
cacheLength: 1000,
autoAdjustCache: true,
maxConnections: 1,
connectTimeout: 10000,
connectionTimeout: 3600000,
connectionRetryLimit: 10,
buffersNotifications: true,
fastMode: false,
disableNagle: false,
disableEPIPEFix: false
};
console.log('\ndefault options:', this.options)
console.log('\npassed in options:', options)
for (var key in options) {
if (options[key] === null || options[key] === undefined) {
debug("Option [" + key + "] set to null. This may cause unexpected behaviour.");
}
}
console.log('\nnew options:', this.options)
util.extend(this.options, options);

Reply to this email directly or view it on GitHub.

@arturkiulian

@argon sorry about previous message, I've edit it right after posting to more relevant log, it indeed merges it after extend but loadCredentials is still using defaults

@danmusiccode

Hi Argon,

I experienced similar difficulties where using a non-default certificate name or path led to errors when using the default path/names worked just fine. This despite setting cusotm cert, key, ca, and passphrase in the options field for new apn.connection(options).

The problem turned out to be that I needed to set cert, key, ca, passphrase in feedbackOptions as well. I had assumed incorrectly that Feedback would use the same parameters as the apn.Connection which had already been instantiated.

@argon
Collaborator
argon commented Dec 8, 2015

I have come to realise this is the problem that a lot of people are having. I have 2 tasks to resolve this problem

  1. Add extra information to the certificate validation routines to indicate whether the error was caused by Connection or Feedback
  2. Update the documentation to make it clearer that the Feedback and Connection configuration is isolated

—A

On 8 Dec 2015, at 19:37, Dan Wuensch notifications@github.com wrote:

Hi Argon,

I experienced similar difficulties where using a non-default certificate name or path led to errors when using the default path/names worked just fine. This despite setting cusotm cert, key, ca, and passphrase in the options field for new apn.connection(options).

The problem turned out to be that I needed to set cert, key, ca, passphrase in feedbackOptions as well. I had assumed incorrectly that Feedback would use the same parameters as the apn.Connection which had already been instantiated.


Reply to this email directly or view it on GitHub.

@kirrg001

i also have this problem with version 1.7.5.
I actually expected that this issue is already solved.

Uncaught Error: ENOENT, open 'cert.pem'

Can you give a small update?

@argon
Collaborator
argon commented Jan 27, 2016

Can you confirm whether you're passing the correct options to the feedback service? I have yet to see any cases of this problem where apn.Connection was actually at fault. It was that apn.Feedback was misconfigured and throwing an error but people assumed the error was from apn.Connection

@kirrg001

Ha ok maybe its feedback service.
Here is my code:

var feedback = new Ios.Feedback({
  'batchFeedback': true,
  'interval': 300
});

feedback.on('feedback', function(devices) {
  ...
});

 __private__.connection = new Ios.Connection({
      cert: pushNotificationSettings.ios.cert,
      key: pushNotificationSettings.ios.key,
      passphrase: pushNotificationSettings.ios.secret,
      production: inProductionMode
});
@argon
Collaborator
argon commented Jan 27, 2016

Yep, that's the problem. You must use the same configuration for feedback. Something like this would work.

var feedback = new Ios.Feedback({
  cert: pushNotificationSettings.ios.cert,
  key: pushNotificationSettings.ios.key,
  passphrase: pushNotificationSettings.ios.secret,
  production: inProductionMode,
  batchFeedback: true,
  interval: 300
});

feedback.on('feedback', function(devices) {
  ...
});

 __private__.connection = new Ios.Connection({
  cert: pushNotificationSettings.ios.cert,
  key: pushNotificationSettings.ios.key,
  passphrase: pushNotificationSettings.ios.secret,
  production: inProductionMode
});
@kirrg001

Thanks for fast support. It helped!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment