Skip to content

Commit

Permalink
Added debugging to challenge creation
Browse files Browse the repository at this point in the history
  • Loading branch information
stephen committed Nov 23, 2014
1 parent 66f7fe8 commit 3adef1f
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/helper.js
Expand Up @@ -5,6 +5,7 @@ var rsa = forge.pki.rsa;

var fs = require('fs');
var crypto = require('crypto');
var debug = require('debug')('nodetunes:helper');

var parseSdp = function(msg) {
var multi = [ 'a', 'p', 'b' ];
Expand Down Expand Up @@ -78,6 +79,9 @@ var getPrivateKey = function() {
var privateKey = getPrivateKey();

var generateAppleResponse = function(challengeBuf, ipAddr, macAddr) {
debug = require('debug')('nodetunes:helper'); // HACK: need to reload debug here (https://github.com/visionmedia/debug/issues/150)
debug('building challenge for %s (ip: %s, mac: %s)', challengeBuf.toString('base64'), ipAddr.toString('hex'), macAddr.toString('hex'));

var fullChallenge = Buffer.concat([ challengeBuf, ipAddr, macAddr ]);

// im sure there's an easier way to pad this buffer
Expand All @@ -88,6 +92,7 @@ var generateAppleResponse = function(challengeBuf, ipAddr, macAddr) {

fullChallenge = Buffer.concat([ fullChallenge, new Buffer(padding) ]).toString('binary');
var response = forge.pki.rsa.encrypt(fullChallenge, privateKey, 0x01);
debug('computed challenge: %s', forge.util.encode64(response));

return forge.util.encode64(response);
};
Expand Down

0 comments on commit 3adef1f

Please sign in to comment.