Как позволить openssl отвечать на http / s получать напрямую из командной строки во время прослушивания

An awk solution:

awk -F'[,-]' '{printf "%s,%s,%s,%s/%s/%s,%s\n", $1, $2, $3, $6, $5, $4, $7}' file

Explanation:

  • -F'[,-]: установите разделитель в , или -
  • '{printf "%s,%s,%s,%s/%s/%s,%s\n", $1, $2, $3, $6, $5, $4, $7}': распечатайте деталь в желаемом порядке и новую строку в конце.

And a sed solution:

sed 's|\([0-9]*\)-\([0-9]*\)-\([0-9]*\)|\3/\2/\1|g' file

Explanation:

  • \([0-9]*\)-\([0-9]*\)-\([0-9]*\): search for digits-dash-dash-digits (save the digits in subpatterns \1, \2 и \3)
  • \3/\2/\1 и заменяем их в обратном порядке на / между ними.
1
01.06.2015, 13:05
1 ответ

с -WWW или -HTTP , s_server ] действует как HTTPS-сервер статического содержимого, используя файлы в текущем каталоге. Вот моя полная демонстрация.

$ openssl req -x509 -nodes -newkey rsa -keyout key.pem -out cert.pem -subj /CN=localhost
$ echo 'hello, world.' >index.txt
$ openssl s_server -key key.pem -cert cert.pem -WWW
Using default temp DH parameters
Using default temp ECDH parameters
ACCEPT

s_server теперь ожидает запросов HTTPS на порту 4433. Из другой оболочки вы можете сделать запрос к s_server , используя curl .

$ curl -kv https://localhost:4433/index.txt
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 4433 (#0)
* successfully set certificate verify locations:
*   CAfile: none
  CApath: /etc/ssl/certs
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server key exchange (12):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* Server certificate:
*    subject: CN=localhost
*    start date: 2015-06-01 15:29:02 GMT
*    expire date: 2015-07-01 15:29:02 GMT
*    issuer: CN=localhost
*    SSL certificate verify result: self signed certificate (18), continuing anyway.
> GET /index.txt HTTP/1.1
> User-Agent: curl/7.38.0
> Host: localhost:4433
> Accept: */*
> 
* HTTP 1.0, assume close after body
< HTTP/1.0 200 ok
< Content-type: text/plain
< 
hello, world.
* Closing connection 0
* SSLv3, TLS alert, Client hello (1):

$ curl -k https://localhost:4433/not-existence
Error opening 'not-existence'
140226499298960:error:02001002:system library:fopen:No such file or directory:bss_file.c:169:fopen('not-existence','r')
140226499298960:error:2006D080:BIO routines:BIO_new_file:no such file:bss_file.c:172:

При каждом запросе s_server печатает запрошенный путь и снова ждет следующего запроса.

FILE:index.txt
ACCEPT

Если вы хотите запускать сценарий по запросам (как это делает CGI), возможно, вам придется использовать другой инструмент, например socat .

$ echo 'echo "Your request is $(head -1)"' > server.sh
$ socat openssl-listen:4433,cert=cert.pem,key=key.pem,verify=0,reuseaddr,fork exec:"bash server.sh"

Результат:

$ curl -k https://localhost:4433/index.txt
Your request is GET /index.txt HTTP/1.1
1
27.01.2020, 23:50

Теги

Похожие вопросы