Openssl create self-signed cert

ПОследовательность действий:

  1. Создать ключ
  2. Создать CSR
  3. Подписать CSR своим же ключом
openssl genrsa -out cert.key 2048
openssl req -new -key cert.key -out cert.csr
openssl x509 -req -days 1100 -in cert.csr -signkey cert.key -out cert.crt

Сертификаты

OpenSSL connect selfsigned

Когда мы в тестируемом сервере имеем неполную цепочку сертификатов или сертификат тестируемого сервера иным образом невозможно проверить, то на попытку подключения к серверу через OpenSSL мы видим ругань:

openssl s_client -connect servername:port
.......
    Verify return code: 21 (unable to verify the first certificate)

В этом случае нам поможет наличие на компе, с которого подключаемся, сертификата CA, подписавшего сертификат тестируемого сервера.

Команда будет такая:

openssl s_client -connect servername:port -CAfile /path/to/cert/sub.server.sha1.ca.pem
........
    Verify return code: 0 (ok)

Ура, соединение установлено.

Источники:

Теория разжеванная: (взято http://stackoverflow.com/questions/21050366/testing-ssl-tls-client-authentication-with-openssl )

To ensure openssl s_client (or openssl s_server) uses your root, use the following options:

  • -CAfile option to specify the root
  • -cert option for the certificate to use
  • -key option for the private key of the certificate

See the docs on s_client(1) and s_server(1) for details.

To do the same programmatically on the client, you would use:

  • SSL_CTX_load_verify_locations to load the trusted root
  • SSL_CTX_use_certificate to specify the client certificate
  • SSL_CTX_use_PrivateKey to load the private key for the client certificate

To do the same programmatically on the server, you would use:

  • SSL_CTX_load_verify_locations to load the trusted root
  • SSL_CTX_use_certificate_chain_file to specify the server certificate
  • SSL_CTX_use_PrivateKey to load the private key for the server certificate

If you don't want to use the parameters for every connection (i.e. the common context), then set it for each SSL connection with, for example, SSL_use_certificate and SSL_use_PrivateKey.

See the docs on SSL_CTX_load_verify_locations(3), SSL_CTX_use_certificate(3) and friends.

PS. CA Серты от Startcom (в том числе Class 2 и 3) можно взять тут: http://www.startssl.com/certs/

openssl imap connect error

При попытке подключения оно отказывается подключаться к серверу с IMAP по 143 порту с TLS. И, если в случае roundcube, проблема фактически лежала в области некорректного сертификата (надо было поставить домен, от которого серт), то для openssl

openssl s_client -connect admmail.bigtelecom.ru:143 -tls1_2

оно ругалось, мол,

CONNECTED(00000003)
34380834056:error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number:/usr/src/secure/lib/libssl/../../../crypto/openssl/ssl/s3_pkt.c:362:

Оказалось, что надо правильно писать команду.

openssl s_client -connect admmail.bigtelecom.ru:143 -starttls imap -tls1_2

И все будет ОК

security_lab/openssl_selfsigned.txt · Last modified: 2016/12/28 16:41 by rybario
About this template
CC Attribution-Share Alike 4.0 International
Powered by PHP Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0 Valid HTML5