nowsecure / node-applesign

NodeJS module and commandline utility for re-signing iOS applications (IPA files).
https://www.nowsecure.com
MIT License
420 stars 77 forks source link

Version 3.1.0 doesn't work whereas 2.5.1 does. #80

Closed useignition closed 4 years ago

useignition commented 5 years ago

Hi, i have just noticed that version 3.1.0 doesn't allow me to do anything with what is in the README. I have tried compiling from the source and using NPM however only 2.5.1 allows me to use it.

Particularly listing identities doesn't work it just gives no output on 3.1.0.

Is this a known issue?

trufae commented 5 years ago

Can you try again with current master? (or the freshly released 3.3)

useignition commented 5 years ago

I will try again in a few hours. I'm at work right now.

useignition commented 5 years ago

Sorry, I forgot to post an update!

There is still no output.

Here is my code.


const Applesign = require('applesign');
const readline = require('readline');
const { exec } = require('child_process');
// const iosdeploy = require('ios-deploy');

const as = new Applesign();

as.getIdentities((err, ids) => {
  if (err) {
    console.error(err, ids);
  } else {
    ids.forEach((id) => {
      console.log(id.hash, id.name);
    });
    const rl = readline.createInterface({
      input: process.stdin,
      output: process.stdout
    });

    rl.question('Which Identity do you want to use? ', (answer) => {
      console.log('Using: ', answer);
      // const as = new Applesign({
      //   bundleid: 'cn.com.hjr',
      //   identity: answer,
      //   outfile: 'app-resigned.ipa',
      //   mobileprovision: 'dev.mobileprovision',
      //   withoutWatchapp: true
      // });

      // const s = as.signIPA('app.ipa', onEnd)
      //   .on('warning', (msg) => {
      //     console.log('WARNING', msg);
      //   })
      //   .on('message', (msg) => {
      //     console.log('msg', msg);
      //   });

      // function onEnd(err, data) {
      //   if (err) {
      //     console.error(err);
      //     s.cleanup();
      //     process.exit(1);
      //   } else {
      //     // console.log('ios-deploy -b', as.config.outfile);

      //     exec('ios-deploy -b ' + as.config.outfile, (err, stdout, stderr) => {
      //       if (err) {
      //         // node couldn't execute the command
      //         return;
      //       }

      //       // the *entire* stdout and stderr (buffered)
      //       console.log(`stdout: ${stdout}`);
      //       console.log(`stderr: ${stderr}`);
      //     });

      //     process.exit(0);
      //   }
      // }
      rl.close();
    });
  }
});
trufae commented 5 years ago

The API between v2 and v3 has changed, this is why there was a major version bump.

The new v3 API is enforcing async/await pattern instead of the callback based. Which makes the code more readable and easy to maintain. As long as Javascript doesn't provide a static check about argument types, the only solution to provide a transition helper for developers would be to provide a Typescript interface or rewrite the whole thing in Typescript.

For next release i will probably go for providing the types interface for ts, but that wont help you unless you switch to typescript.. so i have written a function arguments check helper to help identify problems when using the public APIs in a wrong way, therefor identify those v2->v3 transition issues.

Current master spits this error instead of silently failing:

$ node as.js 
(node:57697) UnhandledPromiseRejectionWarning: Error: Incorrect arguments count
    at module.exports (node-applesign/lib/fchk.js:3:11)
    at Applesign.getIdentities (node-applesign/index.js:45:5)
    at Object.<anonymous> (node-applesign/as.js:8:4)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:283:19)
(node:57697) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:57697) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
trufae commented 5 years ago

can we close this issue?

trufae commented 4 years ago

Closing because of inactivity, please reopen if you can't use applesign3 yet