Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
[CB-4931] Updated signing process to allow passthrough of args
- Allowed users to specify tool parameters through blackberry10.json
- Fixed signer logic to default to user parameters

Reviewed by Bryan Higgins <bhiggins@blackberry.com>
Tested by Jenny Gee <jgee@blackberry.com>
  • Loading branch information
Jeffrey Heifetz authored and bryanhiggins committed Oct 25, 2013
1 parent 2a4fd50 commit bf0ef2b0720a86b19b11b672eb88f7b2bc3b22dc
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 69 deletions.
@@ -32,12 +32,17 @@ if (!isNodeNewerThanMin()) {
process.exit(1);
}

if (!signingUtils.getKeyStorePath() && !signingUtils.getKeyStorePathBBID()) {
console.log('WARNING: Signing keys are not installed on this machine.');
if (!signingUtils.getKeyStorePath()) {
console.log("WARNING: Cannot sign applications. Author.p12 file cannot be found at default location: " + signingUtils.getDefaultPath("author.p12"));
}

if (signingUtils.getDbPath()) {
console.log('NOTE: BlackBerry ID tokens can now be used in place of your old signing keys. For more information on linking old signing keys with a BlackBerry ID token, please log in at http://developer.blackberry.com and click on Code Signing in the top menu bar.');
if (!signingUtils.getKeyStorePathBBID()) {

if (signingUtils.getCskPath() && signingUtils.getDbPath()) {
console.log('NOTE: BlackBerry ID tokens can now be used in place of your old signing keys. For more information on linking old signing keys with a BlackBerry ID token, please log in at http://developer.blackberry.com and click on Code Signing in the top menu bar.');
} else {
console.log('WARNING: Cannot sign applications. bbidtoken.csk file cannot be found at default location: ' + signingUtils.getDefaultPath("bbidtoken.csk"));
}
}

process.exit(0);
@@ -333,6 +333,15 @@ _self = {
prompt.get(promptSchema, function (err, results) {
done(err, results.property);
});
},

mixin: function (mixin, to) {
Object.getOwnPropertyNames(mixin).forEach(function (prop) {
if (Object.hasOwnProperty.call(mixin, prop)) {
Object.defineProperty(to, prop, Object.getOwnPropertyDescriptor(mixin, prop));
}
});
return to;
}

};
@@ -31,6 +31,7 @@ var path = require("path"),
childProcess = require("child_process"),
logger = require("./logger"),
pkgrUtils = require("./packager-utils"),
session = require("./session"),
commandStr;

function copyArgIfExists(arg) {
@@ -71,16 +72,15 @@ try {
},
function releaseBuild (allDone) {
var childTasks = [],
keystorepass = session.getKeyStorePass(command),
err;

if (command.release) {
copyArgIfExists("buildId");
//Note: Packager refers to signing password as "password" not "keystorepass"
bbwpArgv.push("--password");
if (command.keystorepass) {
bbwpArgv.push(command.keystorepass);
} else if (bbProperties.keystorepass) {
bbwpArgv.push(bbProperties.keystorepass);
if (keystorepass) {
bbwpArgv.push(keystorepass);
} else if (command.query) {
childTasks.push(utils.prompt.bind(this, {description: "Please enter your keystore password: ", hidden: true}));
childTasks.push(function (password, done) {
@@ -20,6 +20,7 @@ var check = require('validator').check,
path = require("path"),
fs = require("fs"),
packagerUtils = require("./packager-utils"),
signingUtils = require("./signing-utils"),
CORDOVA_JS_REGEX = /(cordova-.+js)|cordova\.js/,
_self;

@@ -32,6 +33,7 @@ _self = {
//The string checks below is to get around a really weird issue in commander
//where sometimes unspecified arguments come in as a function...
var keysFound = session.keystore,
keysDefault = session.keystore === signingUtils.getDefaultPath("author.p12"),
cskFound = session.keystoreCsk,//barsigner.csk
dbFound = session.keystoreDb,//barsigner.db
bbidFound = session.keystoreBBID,
@@ -57,21 +59,21 @@ _self = {
if (keysPassword || commandLinebuildId) {
if (!keysFound) {
signingFileError(AUTHOR_P12);
} else if (!cskFound && !bbidFound) {
} else if (keysDefault && !cskFound && !bbidFound) {
//Only warn about BBID since the old tokens are deprecated
signingFileError(BARSIGNER_BBID);
} else if (cskFound && !dbFound) {
} else if (keysDefault && cskFound && !dbFound) {
signingFileError(BARSIGNER_DB);
}

//If a buildId exists in config, but no keys were found, throw a warning
} else if (buildId) {
if (!keysFound) {
signingFileWarn(AUTHOR_P12);
} else if (!cskFound && !bbidFound) {
} else if (keysDefault && !cskFound && !bbidFound) {
//Only warn about BBID since the old tokens are deprecated
signingFileWarn(BARSIGNER_BBID);
} else if (cskFound && !dbFound) {
} else if (keysDefault && cskFound && !dbFound) {
signingFileWarn(BARSIGNER_DB);
}
}
@@ -24,6 +24,7 @@ var fs = require("fs"),
xml2js = require('xml2js'),
logger = require("./logger"),
async = require("async"),
session = require("./session"),
properties = utils.getProperties(),
workingdir = path.normalize(__dirname + "/..");

@@ -129,7 +130,7 @@ function validateTarget(options, targetName, allDone) {
}
//Options looking for are: (keystorepass, query). Calls back with: (error || target object)
function handleDebugToken(options, deployTarget, allDone) {
options.keystorepass = options.keystorepass || properties.keystorepass;
options.keystorepass = session.getKeyStorePass(options);

// if target has no pin, skip the debug token feature
if (deployTarget.pin && !options.emulator) {
@@ -149,22 +150,22 @@ function handleDebugToken(options, deployTarget, allDone) {
},
debugTokenHelper.createToken.bind(this, properties, "all")
],
function (err, results) {
// If the error is true, then the debug token is valid and creation was skipped.
if (err === true) {
logger.info(localize.translate("PROGRESS_DEBUG_TOKEN_IS_VALID"));
//Clear the error so it is still deployed
err = null;
}
function (err, results) {
// If the error is true, then the debug token is valid and creation was skipped.
if (err === true) {
logger.info(localize.translate("PROGRESS_DEBUG_TOKEN_IS_VALID"));
//Clear the error so it is still deployed
err = null;
}

if (!err) {
debugTokenHelper.deployToken(deployTarget.name, deployTarget.ip, deployTarget.password, function (code) {
allDone(code, deployTarget);
});
} else {
allDone(err);
}
if (!err) {
debugTokenHelper.deployToken(deployTarget.name, deployTarget.ip, deployTarget.password, function (code) {
allDone(code, deployTarget);
});
} else {
allDone(err);
}
}
);
} else {
allDone(null, deployTarget);
@@ -220,7 +221,7 @@ _self = {
[
getTargetName.bind(this, options),
validateTarget,
handleDebugToken,
handleDebugToken
], callback
);
},
@@ -22,52 +22,78 @@ var path = require("path"),
signingUtils = require("./signing-utils"),
barConf = require("./bar-conf"),
localize = require("./localize"),
params;
cmdParams;

function getParams(cmdline, toolName) {
var properties = utils.getProperties(),
params = properties[toolName];

if (cmdline.params) {
if (!params) {
if (!cmdParams) {
var paramsPath = path.resolve(cmdline.params);

if (fs.existsSync(paramsPath)) {
try {
params = require(paramsPath);
cmdParams = require(paramsPath);
} catch (e) {
throw localize.translate("EXCEPTION_PARAMS_FILE_ERROR", paramsPath);
}
} else {
throw localize.translate("EXCEPTION_PARAMS_FILE_NOT_FOUND", paramsPath);
}
}
}

if (cmdParams && cmdParams[toolName]) {
if (params) {
return params[toolName];
params = utils.mixin(cmdParams[toolName], params);
} else {
params = cmdParams[toolName];
}
}

return null;
return params;
}


module.exports = {
getKeyStorePass: function (cmdline) {
var properties = utils.getProperties(),
params = getParams(cmdline, "blackberry-signer") || {},
keystorepass;

//Check commandline first, then properties, then params
//Packager expects value provided as password
//Cordova scripts expects value provided as keystorepass
//String checks are to get around issue where commander sometimes passed in a function
if (cmdline.password && typeof cmdline.password === "string") {
keystorepass = cmdline.password;
} else if (cmdline.keystorepass && typeof cmdline.keystorepass === "string") {
keystorepass = cmdline.keystorepass;
} else if (properties.keystorepass) {
keystorepass = properties.keystorepass;
} else if (params["-storepass"]) {
keystorepass = params["-storepass"];
}

return keystorepass;
},
initialize: function (cmdline) {
var sourceDir,
signingPassword,
signingPassword = module.exports.getKeyStorePass(cmdline),
outputDir = cmdline.output,
properties = require("../../project.json"),
archivePath = path.resolve(cmdline.args[0] ? cmdline.args[0] : "../../www"),
archiveName = utils.genBarName(),
appdesc,
buildId = cmdline.buildId;
buildId = cmdline.buildId,
signerParams = getParams(cmdline, "blackberry-signer") || {},
keystore = signerParams["-keystore"],
bbidtoken = signerParams["-bbidtoken"];

//If -o option was not provided, default output location is the same as .zip
outputDir = outputDir || path.dirname(archivePath);

//Only set signingPassword if it contains a value
if (cmdline.password && "string" === typeof cmdline.password) {
signingPassword = cmdline.password;
}

if (cmdline.appdesc && "string" === typeof cmdline.appdesc) {
appdesc = path.resolve(cmdline.appdesc);
}
@@ -85,6 +111,15 @@ module.exports = {

logger.level(cmdline.loglevel || 'verbose');

//If signer params exist, check whether the files are there
//This is to be consistent with the default files
if (keystore && !fs.existsSync(keystore)) {
keystore = false;
}
if (bbidtoken && !fs.existsSync(bbidtoken)) {
bbidtoken = false;
}

return {
"conf": require("./conf"),
"keepSource": !!cmdline.source,
@@ -103,18 +138,18 @@ module.exports = {
"archiveName": archiveName,
"barPath": outputDir + "/%s/" + archiveName + ".bar",
"debug": !!cmdline.debug,
"keystore": signingUtils.getKeyStorePath(),
"keystore": keystore || signingUtils.getKeyStorePath(),
"keystoreCsk": signingUtils.getCskPath(),
"keystoreDb": signingUtils.getDbPath(),
"keystoreBBID": signingUtils.getKeyStorePathBBID(),
"keystoreBBID": bbidtoken || signingUtils.getKeyStorePathBBID(),
"storepass": signingPassword,
"buildId": buildId,
"appdesc" : appdesc,
getParams: function (toolName) {
return getParams(cmdline, toolName);
},
isSigningRequired: function (config) {
return signingUtils.getKeyStorePath() && signingPassword;
return (keystore || signingUtils.getKeyStorePath()) && signingPassword;
},
"targets": ["simulator", "device"]
};
@@ -30,11 +30,6 @@ function execSigner(session, target, callback) {
params = session.getParams("blackberry-signer"),
args = [];

args.push("-keystore");
args.push(session.keystore);
args.push("-storepass");
args.push(session.storepass);

if (params) {
Object.getOwnPropertyNames(params).forEach(function (p) {
args.push(p);
@@ -45,6 +40,19 @@ function execSigner(session, target, callback) {
});
}

//Only specify default args if they aren't specified by the user
if (args.indexOf("-keystore") === -1) {
args.push("-keystore");
args.push(session.keystore);
}
if (args.indexOf("-storepass") === -1) {
args.push("-storepass");
args.push(session.storepass);
}

//Validate arguments


args.push(path.resolve(util.format(session.barPath, target)));

utils.exec(script, args, {

0 comments on commit bf0ef2b

Please sign in to comment.