You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by bh...@apache.org on 2013/10/25 15:12:09 UTC

webworks commit: [CB-4931] Updated signing process to allow passthrough of args

Updated Branches:
  refs/heads/master 2a4fd5074 -> bf0ef2b07


[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 <bh...@blackberry.com>
Tested by Jenny Gee <jg...@blackberry.com>


Project: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/commit/bf0ef2b0
Tree: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/tree/bf0ef2b0
Diff: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/diff/bf0ef2b0

Branch: refs/heads/master
Commit: bf0ef2b0720a86b19b11b672eb88f7b2bc3b22dc
Parents: 2a4fd50
Author: Jeffrey Heifetz <jh...@blackberry.com>
Authored: Thu Sep 26 16:27:21 2013 -0400
Committer: Bryan Higgins <bh...@blackberry.com>
Committed: Fri Oct 25 09:09:41 2013 -0400

----------------------------------------------------------------------
 blackberry10/bin/check_reqs.js                  | 13 ++--
 blackberry10/bin/lib/utils.js                   |  9 +++
 .../bin/templates/project/cordova/lib/build     |  8 +--
 .../project/cordova/lib/packager-validator.js   | 10 +--
 .../templates/project/cordova/lib/run-utils.js  | 33 +++++-----
 .../templates/project/cordova/lib/session.js    | 65 +++++++++++++++-----
 .../project/cordova/lib/signing-helper.js       | 18 ++++--
 .../project/cordova/lib/signing-utils.js        | 43 ++++++-------
 8 files changed, 130 insertions(+), 69 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/bf0ef2b0/blackberry10/bin/check_reqs.js
----------------------------------------------------------------------
diff --git a/blackberry10/bin/check_reqs.js b/blackberry10/bin/check_reqs.js
index e052335..933d813 100644
--- a/blackberry10/bin/check_reqs.js
+++ b/blackberry10/bin/check_reqs.js
@@ -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);

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/bf0ef2b0/blackberry10/bin/lib/utils.js
----------------------------------------------------------------------
diff --git a/blackberry10/bin/lib/utils.js b/blackberry10/bin/lib/utils.js
index cc7f01a..8ebae25 100644
--- a/blackberry10/bin/lib/utils.js
+++ b/blackberry10/bin/lib/utils.js
@@ -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;
     }
 
 };

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/bf0ef2b0/blackberry10/bin/templates/project/cordova/lib/build
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/cordova/lib/build b/blackberry10/bin/templates/project/cordova/lib/build
index d1d4af5..5273dd5 100755
--- a/blackberry10/bin/templates/project/cordova/lib/build
+++ b/blackberry10/bin/templates/project/cordova/lib/build
@@ -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) {

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/bf0ef2b0/blackberry10/bin/templates/project/cordova/lib/packager-validator.js
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/cordova/lib/packager-validator.js b/blackberry10/bin/templates/project/cordova/lib/packager-validator.js
index a04d818..f023e8e 100644
--- a/blackberry10/bin/templates/project/cordova/lib/packager-validator.js
+++ b/blackberry10/bin/templates/project/cordova/lib/packager-validator.js
@@ -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,10 +59,10 @@ _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);
             }
 
@@ -68,10 +70,10 @@ _self = {
         } 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);
             }
         }

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/bf0ef2b0/blackberry10/bin/templates/project/cordova/lib/run-utils.js
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/cordova/lib/run-utils.js b/blackberry10/bin/templates/project/cordova/lib/run-utils.js
index 18e8c58..8d6731f 100644
--- a/blackberry10/bin/templates/project/cordova/lib/run-utils.js
+++ b/blackberry10/bin/templates/project/cordova/lib/run-utils.js
@@ -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
         );
     },

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/bf0ef2b0/blackberry10/bin/templates/project/cordova/lib/session.js
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/cordova/lib/session.js b/blackberry10/bin/templates/project/cordova/lib/session.js
index d4c75be..5f1b6fe 100644
--- a/blackberry10/bin/templates/project/cordova/lib/session.js
+++ b/blackberry10/bin/templates/project/cordova/lib/session.js
@@ -22,16 +22,19 @@ 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);
                 }
@@ -39,35 +42,58 @@ function getParams(cmdline, toolName) {
                 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,10 +138,10 @@ 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,
@@ -114,7 +149,7 @@ module.exports = {
                 return getParams(cmdline, toolName);
             },
             isSigningRequired: function (config) {
-                return signingUtils.getKeyStorePath() && signingPassword;
+                return (keystore || signingUtils.getKeyStorePath()) && signingPassword;
             },
             "targets": ["simulator", "device"]
         };

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/bf0ef2b0/blackberry10/bin/templates/project/cordova/lib/signing-helper.js
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/cordova/lib/signing-helper.js b/blackberry10/bin/templates/project/cordova/lib/signing-helper.js
index ea8ad1a..69a8a08 100644
--- a/blackberry10/bin/templates/project/cordova/lib/signing-helper.js
+++ b/blackberry10/bin/templates/project/cordova/lib/signing-helper.js
@@ -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, {

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/bf0ef2b0/blackberry10/bin/templates/project/cordova/lib/signing-utils.js
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/cordova/lib/signing-utils.js b/blackberry10/bin/templates/project/cordova/lib/signing-utils.js
index 86b5bac..be5b410 100644
--- a/blackberry10/bin/templates/project/cordova/lib/signing-utils.js
+++ b/blackberry10/bin/templates/project/cordova/lib/signing-utils.js
@@ -17,47 +17,48 @@ function getDefaultPath(file) {
     var p = "";
     if (os.type().toLowerCase().indexOf("windows") >= 0) {
         // Try Windows XP location
-        p = process.env.HOMEDRIVE + process.env.HOMEPATH + "\\Local Settings\\Application Data\\Research In Motion\\" + file;
-        if (fs.existsSync(p)) {
-            return p;
-        }
-
-        // Try Windows Vista and Windows 7 location
-        p = process.env.HOMEDRIVE + process.env.HOMEPATH + "\\AppData\\Local\\Research In Motion\\" + file;
-        if (fs.existsSync(p)) {
-            return p;
+        p = process.env.HOMEDRIVE + process.env.HOMEPATH + "\\Local Settings\\Application Data\\Research In Motion\\";
+        if (!fs.existsSync(p)) {
+            // Try Windows Vista and Windows 7 location
+            p = process.env.HOMEDRIVE + process.env.HOMEPATH + "\\AppData\\Local\\Research In Motion\\";
         }
     } else if (os.type().toLowerCase().indexOf("darwin") >= 0) {
         // Try Mac OS location
-        p = process.env.HOME + "/Library/Research In Motion/" + file;
-        if (fs.existsSync(p)) {
-            return p;
-        }
+        p = process.env.HOME + "/Library/Research In Motion/";
     } else if (os.type().toLowerCase().indexOf("linux") >= 0) {
         // Try Linux location
-        p = process.env.HOME + "/.rim/" + file;
-        if (fs.existsSync(p)) {
-            return p;
-        }
+        p = process.env.HOME + "/.rim/";
+    }
+
+    return p + file;
+
+}
+
+function getDefaultPathIfExists(file) {
+    var p = getDefaultPath(file);
+    if (fs.existsSync(p)) {
+        return p;
     }
 }
 
 _self = {
+    getDefaultPath: getDefaultPath,
+
     getKeyStorePath : function () {
         // Todo: decide where to put sigtool.p12 which is genereated and used in WebWorks SDK for Tablet OS
-        return getDefaultPath(AUTHOR_P12);
+        return getDefaultPathIfExists(AUTHOR_P12);
     },
 
     getKeyStorePathBBID: function () {
-        return getDefaultPath(BBIDTOKEN);
+        return getDefaultPathIfExists(BBIDTOKEN);
     },
 
     getCskPath : function () {
-        return getDefaultPath(CSK);
+        return getDefaultPathIfExists(CSK);
     },
 
     getDbPath : function () {
-        return getDefaultPath(DB);
+        return getDefaultPathIfExists(DB);
     }
 };