what am I doing wrong when generating my server https with ruby in kali?

0

Turns out I'm trying to mount a https web server and when I try it I get an error, the code is as follows:

with this code generate the certificate:

require 'webrick'
require 'webrick/https'

cert_name = [
%w[CN localhost],
]

server = WEBrick::HTTPServer.new(:Port => 8000,
:SSLEnable => true,
:SSLCertName => cert_name)

After generating it, edit the file and put this:

require 'webrick'
require 'webrick/https'
require 'openssl'

cert = OpenSSL::X509::Certificate.new File.read '/path/to/cert.pem'
pkey = OpenSSL::PKey::RSA.new File.read '/path/to/pkey.pem'

server = WEBrick::HTTPServer.new(:Port => 8000,
:SSLEnable => true,
:SSLCertificate => cert,
:SSLPrivateKey => pkey)

and I get this error:

./Servidorweb.rb:11:in 'read': No such file or directory @ rb_sysopen - /path/to/cert.pem (Errno::ENOENT)
from ./Servidorweb.rb:11:in '<main>'

Does anyone know what can be done? probe with port 9000 and also gives me error

    
asked by Tondrax 22.06.2017 в 12:20
source

1 answer

0

The error you get is because the file cert.pem is not found in the specified path (i.e. /path/to/ ). Probably the route you currently have in your code (i.e. /path/to/cert.pem ) is just an example, where you should replace /path/to with the actual location of the file cert.pem .

For example, if your file were a subdirectory certificados , which in turn is inside the directory pruebas which is in the root (ie root> tests> certificates ), the path would be /pruebas/certificados/cert.pem .

To solve the problem, change the path to the one where the files cert.pem and pkey.pem are found.

Considering the path of the previous example ( /pruebas/certificados ), your code would look like this:

cert = OpenSSL::X509::Certificate.new File.read '/pruebas/certificados/cert.pem'
pkey = OpenSSL::PKey::RSA.new File.read '/pruebas/certificados/pkey.pem'

On relative and absolute paths

Consider that when you use / at the start you are using an absolute path, so you must have your file on that route.

If you want to use a relative path, then remove the first / ; although he considers that in this way you should always run the program from the same directory.

For example, your relative route would look like this:

File.read 'path/to/cert.pem'

Then if you run your program from /home/app :

home/app $ ruby Servidorweb.rb

This would search the file in

home/app/path/to/cert.pem

Considering the above, I always recommend using absolute routes, just as you have it in your program; just verify that this route is the correct one (in your case it is not, that's why it shows the error).

    
answered by 22.06.2017 в 13:09