Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error in events.js on t2 key generate (Windows) #24

Open
dalestone opened this issue Jul 16, 2015 · 16 comments
Open

error in events.js on t2 key generate (Windows) #24

dalestone opened this issue Jul 16, 2015 · 16 comments

Comments

@dalestone
Copy link

Hi,

So I have installed virtual box on my machine and have t2-cli installed. I type the following:

t2 key generate

I then encounter the following error:

events.js:85
      throw er; // Unhandled 'error' event
            ^
Error: spawn ssh-keygen ENOENT
    at exports._errnoException (util.js:746:11)
    at Process.ChildProcess._handle.onexit (child_process.js:1053:32)
    at child_process.js:1144:20
    at process._tickCallback (node.js:355:11)

Any idea what might be causing?

Thanks

@dalestone dalestone changed the title error on t2 key generate (Windows) error in events.js on t2 key generate (Windows) Jul 16, 2015
@johnnyman727
Copy link
Contributor

@dalestone This is actually an issue with the t2-cli key generation not being compatible with Windows. It uses the ssh-keygen library which is just a wrapper around the ssh-keygen command line utility which Windows doesn't support. We'll need to figure out how to extend key generation support to Windows - do you know of any good SSH libraries?

@dalestone
Copy link
Author

@johnnyman727 Ah I see that explains why! There is SharpSSH

@ondreian
Copy link
Contributor

@johnnyman727

if you allowed your install of Git to enhance your %PATH% with unix tools this shouldn't be a problem.
Linux Tools
For instance on my system, after installing Git with its built in enhancers, ssh-keygen is available at the following location:

C:\Program Files (x86)\Git\bin\ssh-keygen.EXE

You could do a warn about it with insurePath and then not have to support a second type of SSH library perhaps?

@LinusU
Copy link

LinusU commented Jul 16, 2015

I'm trying to fix this here: ericvicenti/ssh-keygen#5

I would love it if you could help me try it out since I don't have access to windows.

If you could change the dependency in t2-cli from "ssh-keygen": "^0.2.1" to "ssh-keygen": "LinusU/ssh-keygen#windows-support" and try it again :)

@dalestone
Copy link
Author

@ondreian Yep I can confirm if I runt2 key generate in the directory C:\Program Files (x86)\Git\bin\ it works OK!

cmd

@LinusU Sure I will try it, I first need to remove the key its just generated though, how do I do that?

@johnnyman727
Copy link
Contributor

@dalestone I didn't get around to writing the t2 key remove command yet 😛

You can manually rm -rf ~/.tessel/id_rsa*

@dalestone
Copy link
Author

@johnnyman727 Thanks that removed it. 👍

@LinusU No luck so far! 😢. I changed the package.json and did a npm installl. I have had a look at your source code it seems to be looking in this directory t2-cli\node_modules\ssh-keygen\src\bin\ssh-keygen-64.exe but the files are actually in t2-cli\node_modules\ssh-keygen\bin\ssh-keygen-64.exe.

INFO Creating public and private keys for Tessel authentication...
events.js:85
      throw er; // Unhandled 'error' event
            ^
Error: spawn C:\development\learning\tessel\t2-cli\node_modules\ssh-keygen\src\bin\ssh-keygen-64.exe ENOENT
    at exports._errnoException (util.js:746:11)
    at Process.ChildProcess._handle.onexit (child_process.js:1053:32)
    at child_process.js:1144:20
    at process._tickCallback (node.js:355:11)

So I created the directory it was looking for and copied the *.exe over but then got this error:

PS C:\development\learning\tessel\t2-cli> t2 key generate
INFO Creating public and private keys for Tessel authentication...
C:\development\learning\tessel\t2-cli\lib\tessel\provision.js:61
      var privateKey = out.key;
                          ^
TypeError: Cannot read property 'key' of undefined
    at C:\development\learning\tessel\t2-cli\lib\tessel\provision.js:61:27
    at C:\development\learning\tessel\t2-cli\node_modules\ssh-keygen\src\ssh-keygen.js:81:22
    at FSReqWrap.oncomplete (fs.js:95:15)

@LinusU
Copy link

LinusU commented Jul 17, 2015

@dalestone Fixed the first error, taking a look at the second one now...

@LinusU
Copy link

LinusU commented Jul 17, 2015

@dalestone There is a bug in t2-cli which prevents you from seeing the error that actually happens, could you try with this patch applied? tessel/t2-cli#206

@dalestone
Copy link
Author

@LinusU Ah OK, I have added your provision.js update but it seems to just print out line 1 and no key gets generated, so I added another logs.info to see what was in err and it seems to be looking for id_rsa but it doesn't exist in the directory

PS C:\development\learning\tessel\t2-cli> t2 key generate
1. INFO Creating public and private keys for Tessel authentication...
2. INFO { [Error: ENOENT, unlink 'C:\Users\Dale\AppData\Local\Temp\id_rsa']
  errno: -4058,
  code: 'ENOENT',
  path: 'C:\\Users\\Dale\\AppData\\Local\\Temp\\id_rsa' }

@LinusU
Copy link

LinusU commented Jul 17, 2015

I hate to ask you to do the debugging for me when we really should have better error handling and logging in place but here goes. If you could log err.stack that would give me where the error is occurring and then I will try and solve it for you :)

Also, my patch got merged so you can just use t2-cli from the master branch.

@dalestone
Copy link
Author

@LinusU No problem its fun to look at the code 👍. I added err.stack but it doesn't mention any line numbers and gives a rather vague error, unless I have added the logs.info in a bad place?

...
    logs.info('Creating public and private keys for Tessel authentication...');
    // Generate SSH key
    keygen({}, function(err, out) {

      logs.info(err.stack);

      if (err) {
        return reject(err);
      }
...

Error returned:

PS C:\development\learning\tessel\t2-cli> t2 key generate
INFO Creating public and private keys for Tessel authentication...
INFO Error: ENOENT, unlink 'C:\Users\Dale\AppData\Local\Temp\id_rsa'
    at Error (native)

@LinusU
Copy link

LinusU commented Jul 17, 2015

Sorry for the late reply, I got stuck inside the spaghetti code and realized that this is the wrong way to solve this. We shouldn't depend on a third party library to ship up to date binaries when it comes to cryptography.

Instead we should the version of openssl that Node.js provides for us, and that is exactly what I have done in tessel/t2-cli#209. Unfortunately this doesn't work on windows until nodejs/node-v0.x-archive#4051 gets resolved.

If you have any experience with compiling it would be really cool if you could take a look at LinusU/node-generate-rsa-keypair to see if you can get it to build on windows. It could work by installing openssl locally and pointing out the path to it, but ideally we really would like to link against the openssl that node provides for us. That way we will always stay in sync with them.

@johnnyman727
Copy link
Contributor

I should dig out my Windows computer for this...

@LinusU I applaud your library! Would love to get this working.

@dalestone
Copy link
Author

@LinusU I gave it a try but when I build in visual studio I get a lot of link errors.

Error   8   error LNK1120: 7 unresolved externals   C:\development\learning\tessel\node-generate-rsa-keypair\build\Debug\generate-rsa-keypair.node  generate-rsa-keypair
Error   3   error LNK2019: unresolved external symbol BIO_ctrl referenced in function "void __cdecl generate_rsa_keypair(class v8::FunctionCallbackInfo<class v8::Value> const &)" (?generate_rsa_keypair@@YAXAEBV?$FunctionCallbackInfo@VValue@v8@@@v8@@@Z)    C:\development\learning\tessel\node-generate-rsa-keypair\build\binding.obj  generate-rsa-keypair
Error   1   error LNK2019: unresolved external symbol BIO_new referenced in function "void __cdecl generate_rsa_keypair(class v8::FunctionCallbackInfo<class v8::Value> const &)" (?generate_rsa_keypair@@YAXAEBV?$FunctionCallbackInfo@VValue@v8@@@v8@@@Z) C:\development\learning\tessel\node-generate-rsa-keypair\build\binding.obj  generate-rsa-keypair
Error   4   error LNK2019: unresolved external symbol BIO_s_mem referenced in function "void __cdecl generate_rsa_keypair(class v8::FunctionCallbackInfo<class v8::Value> const &)" (?generate_rsa_keypair@@YAXAEBV?$FunctionCallbackInfo@VValue@v8@@@v8@@@Z)   C:\development\learning\tessel\node-generate-rsa-keypair\build\binding.obj  generate-rsa-keypair
Error   2   error LNK2019: unresolved external symbol BIO_vfree referenced in function "void __cdecl generate_rsa_keypair(class v8::FunctionCallbackInfo<class v8::Value> const &)" (?generate_rsa_keypair@@YAXAEBV?$FunctionCallbackInfo@VValue@v8@@@v8@@@Z)   C:\development\learning\tessel\node-generate-rsa-keypair\build\binding.obj  generate-rsa-keypair
Error   7   error LNK2019: unresolved external symbol PEM_write_bio_RSA_PUBKEY referenced in function "void __cdecl generate_rsa_keypair(class v8::FunctionCallbackInfo<class v8::Value> const &)" (?generate_rsa_keypair@@YAXAEBV?$FunctionCallbackInfo@VValue@v8@@@v8@@@Z)    C:\development\learning\tessel\node-generate-rsa-keypair\build\binding.obj  generate-rsa-keypair
Error   6   error LNK2019: unresolved external symbol PEM_write_bio_RSAPrivateKey referenced in function "void __cdecl generate_rsa_keypair(class v8::FunctionCallbackInfo<class v8::Value> const &)" (?generate_rsa_keypair@@YAXAEBV?$FunctionCallbackInfo@VValue@v8@@@v8@@@Z) C:\development\learning\tessel\node-generate-rsa-keypair\build\binding.obj  generate-rsa-keypair
Error   5   error LNK2019: unresolved external symbol RSA_generate_key referenced in function "void __cdecl generate_rsa_keypair(class v8::FunctionCallbackInfo<class v8::Value> const &)" (?generate_rsa_keypair@@YAXAEBV?$FunctionCallbackInfo@VValue@v8@@@v8@@@Z)    C:\development\learning\tessel\node-generate-rsa-keypair\build\binding.obj  generate-rsa-keypair

Also running node-gyp build gives pretty much the same:

C:\development\learning\tessel\node-generate-rsa-keypair>node-gyp build
gyp info it worked if it ends with ok
gyp info using node-gyp@2.0.2
gyp info using node@0.12.3 | win32 | x64
gyp info spawn C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe
gyp info spawn args [ 'build/binding.sln',
gyp info spawn args   '/clp:Verbosity=minimal',
gyp info spawn args   '/nologo',
gyp info spawn args   '/p:Configuration=Release;Platform=x64' ]
Building the projects in this solution one at a time. To enable parallel build,
please add the "/m" switch.
     Creating library C:\development\learning\tessel\node-generate-rsa-keypair\
  build\Release\generate-rsa-keypair.lib and object C:\development\learning\tes
  sel\node-generate-rsa-keypair\build\Release\generate-rsa-keypair.exp
binding.obj : error LNK2001: unresolved external symbol RSA_generate_key [C:\de
velopment\learning\tessel\node-generate-rsa-keypair\build\generate-rsa-keypair.
vcxproj]
binding.obj : error LNK2001: unresolved external symbol PEM_write_bio_RSA_PUBKE
Y [C:\development\learning\tessel\node-generate-rsa-keypair\build\generate-rsa-
keypair.vcxproj]
binding.obj : error LNK2001: unresolved external symbol BIO_new [C:\development
\learning\tessel\node-generate-rsa-keypair\build\generate-rsa-keypair.vcxproj]
binding.obj : error LNK2001: unresolved external symbol BIO_ctrl [C:\developmen
t\learning\tessel\node-generate-rsa-keypair\build\generate-rsa-keypair.vcxproj]
binding.obj : error LNK2001: unresolved external symbol BIO_s_mem [C:\developme
nt\learning\tessel\node-generate-rsa-keypair\build\generate-rsa-keypair.vcxproj
]
binding.obj : error LNK2001: unresolved external symbol PEM_write_bio_RSAPrivat
eKey [C:\development\learning\tessel\node-generate-rsa-keypair\build\generate-r
sa-keypair.vcxproj]
binding.obj : error LNK2001: unresolved external symbol BIO_vfree [C:\developme
nt\learning\tessel\node-generate-rsa-keypair\build\generate-rsa-keypair.vcxproj
]
C:\development\learning\tessel\node-generate-rsa-keypair\build\Release\generate
-rsa-keypair.node : fatal error LNK1120: 7 unresolved externals [C:\development
\learning\tessel\node-generate-rsa-keypair\build\generate-rsa-keypair.vcxproj]
gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe` fail
ed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Users\Dale\AppData\Roaming\npm\nod
e_modules\node-gyp\lib\build.js:269:23)
gyp ERR! stack     at ChildProcess.emit (events.js:110:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:1074
:12)
gyp ERR! System Windows_NT 6.3.9600
gyp ERR! command "node" "C:\\Users\\Dale\\AppData\\Roaming\\npm\\node_modules\\n
ode-gyp\\bin\\node-gyp.js" "build"
gyp ERR! cwd C:\development\learning\tessel\node-generate-rsa-keypair
gyp ERR! node -v v0.12.3
gyp ERR! node-gyp -v v2.0.2
gyp ERR! not ok

@LinusU
Copy link

LinusU commented Jul 18, 2015

Hmm, yes the link errors must be because of nodejs/node-v0.x-archive#4051. It makes it so that openssl dosen't export any functions at all, which makes the linker fail to find them...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants