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: spawn openssl ENOENT #2

Closed
xeroxstar opened this issue May 26, 2019 · 12 comments
Closed

Error: spawn openssl ENOENT #2

xeroxstar opened this issue May 26, 2019 · 12 comments

Comments

@xeroxstar
Copy link

The module do not work on my end, not sure what does it mean but i get this error.

events.js:174
throw er; // Unhandled 'error' event
^

Error: spawn openssl ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:240:19)
    at onErrorNT (internal/child_process.js:415:16)
    at process._tickCallback (internal/process/next_tick.js:63:19)
    at Function.Module.runMain (internal/modules/cjs/loader.js:757:11)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
Emitted 'error' event at:
    at Process.ChildProcess._handle.onexit (internal/child_process.js:246:12)
    at onErrorNT (internal/child_process.js:415:16)
    [... lines matching original stack trace ...]
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
@codevibess codevibess pinned this issue May 27, 2019
@codevibess
Copy link
Owner

Hi Vadim,

I have tasted openssl-nodejs, and I don`t find any problems in the workflow.
Can you give me more information about what command you want to run what was pasted and what the type of param (just a simple string or raw data) .
It can help me to simulate the situation and find out what was wrong.

Regards,
Andrii

@xeroxstar
Copy link
Author

After playing with it, i successfully installed it. Thank you.

@Angramme
Copy link

Hi, what did you do to fix the error. I get the exact same one as you did. Do you have to install openssl cli for openssl-nodejs to work? or is it built in?

@tshiamor-adft
Copy link

@xeroxstar any details on how this was fixed? facing the same problem on windows. just tried running a minimal example from the readme provided.

@codevibess
Copy link
Owner

Hi @Angramme @tshiamor-adft , just make sure, that command what you try to invoke is correct (try in a terminal window)
If it doesn't solve your problem, please give me more information about the command that you trying to run. As I said above When I tested it I don`t find any problems in the workflow.

Sincerely,
Andrii

@tshiamor-adft
Copy link

Hi @codevibess , thanks for the reply. I first tried the examples in the readme, i.e

openssl('openssl req -config csr.cnf -x509 -sha256 -nodes -days 365 -newkey rsa:2048 -keyout key.key -out certificate.crt')

and got the same error as above, then figured there might be some changes on how some parameters are passed such as the "rsa:2048".

So on terminal this command is confirmed working however it fails when using the library

image

then the same command i tried:
image
response when running :
image

@codevibess
Copy link
Owner

@tshiamor-adft I tested all commands from a readme in Windows 10, macOS, Centos with different node versions, but I don't get the same error.

If about your peace of code:

I have noticed a bug/non covered use case in my code that can cause this behavior.
As I said in the README file:

When you used a command which generates additional output in file format this package will create a folder openssl/ in the directory where the command was invoked. All output files will appear in this folder (openssl).

But it creates a folder only when you use the Buffer parameter.

For example:
Code:

const openssl = require("openssl-nodejs")

openssl('openssl genpkey -out privkey.pem -algorithm RSA -pkeyopt rsa_keygen_bits:2018 -pkeyopt rsa_keygen_pubexp:3', (output) => console.log(output.toString()));

Output:

OpenSSL process ends with code 1
Can't open output file openssl/privkey.pem

Why?
Because the library trying to write a file in a non-existing directory (openssl. This directory will be automatically created only with Buffer parameter use case).

Workaround:
Try to escape from this directory using a relative path. For your use case it will look like this:

const openssl = require("openssl-nodejs")

openssl('openssl genpkey -out ../privkey.pem -algorithm RSA -pkeyopt rsa_keygen_bits:2018 -pkeyopt rsa_keygen_pubexp:3', (output) => console.log(output.toString()));

As you see I add a ../ to output private key. (for non-buffer command invocation which generates output to files use directory escaping).

About unhandled exception:
As soon as I find the root cause of it it will be fixed.

Summary
I will cover it in README or change the behavior of a package as soon as possible.
But before that, I need to analyze the impact of possible changes and decide which way is better.

But anyway for anyone who is faced with the same problem it can be a temporal workaround.

@tshiamor-adft Please try code written above.

@tshiamor-adft
Copy link

thanks again @codevibess ,I tried the minimal code on a few windows computers, not sure if im missing something because I still get the same error even when running the updated command i.e:

const openssl = require("openssl-nodejs")

openssl('openssl genpkey -out ../privkey.pem -algorithm RSA -pkeyopt rsa_keygen_bits:2018 -pkeyopt rsa_keygen_pubexp:3', (output) => console.log(output.toString()));

@tshiamor-adft
Copy link

tshiamor-adft commented Jan 31, 2020

its fine now, i suppose its more of an installation issue, likely that the terminal window did not have its system variables updated, with the openssl.exe path. got fixed when i ran the code from a different terminal.

@Moises-dev08
Copy link

thanks again @codevibess ,I tried the minimal code on a few windows computers, not sure if im missing something because I still get the same error even when running the updated command i.e:

const openssl = require("openssl-nodejs")

openssl('openssl genpkey -out ../privkey.pem -algorithm RSA -pkeyopt rsa_keygen_bits:2018 -pkeyopt rsa_keygen_pubexp:3', (output) => console.log(output.toString()));

Hi, where did you paste this code? Thanks

@ksw25
Copy link

ksw25 commented Feb 8, 2022

How to specify where to read the file from?
No matter what I do, the path for the file always starts on openssl/ directory.

Example:
openssl('openssl x509 -noout -text -in ../certs/ca-g3.pem', (output) => console.log(output.toString()));

Error:

    "errorType": "Error",
    "errorMessage": "spawn openssl ENOENT",
    "code": "ENOENT",
    "errno": "ENOENT",
    "syscall": "spawn openssl",
    "path": "openssl",
    "spawnargs": [
        "x509",
        "-noout",
        "-text",
        "-in",
        "openssl/../certs/ca-g3.pem"
    ],
    "stack": [
        "Error: spawn openssl ENOENT",
        "    at Process.ChildProcess._handle.onexit (internal/child_process.js:268:19)",
        "    at onErrorNT (internal/child_process.js:470:16)",
        "    at processTicksAndRejections (internal/process/task_queues.js:84:21)"
    ]
}

@Coldplayer1995
Copy link

Why is this closed if that has not been fixed? I am having the same difficulties to run this.

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

7 participants