B2G/gecko/modules/libmar/tests/unit/test_sign_verify.js
/**
   * Verifies a MAR file.
   *
   * @param signedMAR Verifies a MAR file
  */
Verifies a MAR file.
@param signedMAR Verifies a MAR file
Verifies a MAR file . @param signedMAR Verifies a MAR file
function verifyMAR(signedMAR, wantSuccess, certs, useShortHandCmdLine) {
    let process = Cc["@mozilla.org/process/util;1"].
                  createInstance(Ci.nsIProcess);
    let signmarBin = do_get_file("signmar" + BIN_SUFFIX);
    do_check_true(signmarBin.exists());
    do_check_true(signmarBin.isExecutable());
    let args = [];
    var isWindows = ("@mozilla.org/windows-registry-key;1" in Cc);
    if (isWindows) {
      if (certs.length == 1 && useShortHandCmdLine) {
        args.push("-D", "data/" + certs[0] + ".der");
      } else {
        for (i = 0; i < certs.length; i++) {
          args.push("-D" + i, "data/" + certs[i] + ".der");
        }
      }
      args.push("-v", signedMAR.path);
    } else {
      let NSSConfigDir = do_get_file("data");
      args = ["-d", NSSConfigDir.path];
      if (certs.length == 1 && useShortHandCmdLine) {
        args.push("-n", certs[0]);
      } else {
        for (i = 0; i < certs.length; i++) {
          args.push("-n" + i, certs[i]);
        }
      }
      args.push("-v", signedMAR.path);
    }
    process.init(signmarBin);
    try {
      process.run(true, args, args.length);
    } catch (e) {
      process.exitValue = -1;
    }
    if (wantSuccess) {
      do_check_eq(process.exitValue, 0);
    } else {
      do_check_neq(process.exitValue, 0);
    }
  }
function verifyMAR ( signedMAR , wantSuccess , certs , useShortHandCmdLine ) { let process = Cc [ "@mozilla.org/process/util;1" ] . createInstance ( Ci . nsIProcess ) ; let signmarBin = do_get_file ( "signmar" + BIN_SUFFIX ) ; do_check_true ( signmarBin . exists ( ) ) ; do_check_true ( signmarBin . isExecutable ( ) ) ; let args = [ ] ; var isWindows = ( "@mozilla.org/windows-registry-key;1" in Cc ) ; if ( isWindows ) { if ( certs . length == 1 && useShortHandCmdLine ) { args . push ( "-D" , "data/" + certs [ 0 ] + ".der" ) ; } else { for ( i = 0 ; i < certs . length ; i ++ ) { args . push ( "-D" + i , "data/" + certs [ i ] + ".der" ) ; } } args . push ( "-v" , signedMAR . path ) ; } else { let NSSConfigDir = do_get_file ( "data" ) ; args = [ "-d" , NSSConfigDir . path ] ; if ( certs . length == 1 && useShortHandCmdLine ) { args . push ( "-n" , certs [ 0 ] ) ; } else { for ( i = 0 ; i < certs . length ; i ++ ) { args . push ( "-n" + i , certs [ i ] ) ; } } args . push ( "-v" , signedMAR . path ) ; } process . init ( signmarBin ) ; try { process . run ( true , args , args . length ) ; } catch ( e ) { process . exitValue = - 1 ; } if ( wantSuccess ) { do_check_eq ( process . exitValue , 0 ) ; } else { do_check_neq ( process . exitValue , 0 ) ; } }
Verifies a MAR file.
Verifies a MAR file .
// Get a process to the signmar binary from the dist/bin directory. // Make sure the signmar binary exists and is an executable. // Will reference the arguments to use for verification in signmar // The XPCShell test wiki indicates this is the preferred way for  // Windows detection. // Setup the command line arguments to create the MAR. // Windows vs. Linux/Mac/... have different command line for verification  // since  on Windows we verify with CryptoAPI and on all other platforms  // we verify with NSS. So on Windows we use an exported DER file and on  // other platforms we use the NSS config db. // We put this in a try block because nsIProcess doesn't like -1 returns // On Windows negative return value throws an exception // Verify signmar returned 0 for success.