Curl 60 SSL certificate problem self signed certificate in certificate chain elasticsearch

curl 은 기본적으로 https 사이트의 SSL 인증서를 검증한다. 인증 기관의 인증서 목록이 없거나 모르는 기관에서 발급한 인증서일 경우 다음과 같은 인증서 검증 에러를 발생시키고 동작을 중지하게 된다.

cURL error 60: SSL certificate problem: unable to get local issuer certificate (see //curl.haxx.se/libcurl/c/libcurl-errors.html)

BASH

해결방법은 3가지가 있다.

1. 인증서 검증 안 함

검증을 하지 않는 옵션인 -k(--insecure) 옵션을 주고 curl 을 구동하면 된다.

curl -k -L google.com

BASH

curl --insecure -L google.com

BASH

2. 인증기관 목록 추가하기

2번째 방법은 curl 의 신뢰하는 인증 기관 목록(CA List; Certificate Authority List)에 접속하려는 사이트의 인증서를 발급한 기관을 추가하는 방법이다.

1.  먼저 curl 을 -v 옵션을 주고 실행해서 CA List 파일이 어디에 있는지 위치를 확인한다.

RHEL/CentOS 는 아래와 같이 /etc/pki/tls/certs/ca-bundle.crt 에서 CA 목록을 로딩함

lesstif@localhost:~> curl -v //google.com   * About to connect() to google.com port 443 (#0) * Trying 74.125.128.139... connected * Connected to google.com (74.125.128.139) port 443 (#0) * Initializing NSS with certpath: sql:/etc/pki/nssdb * CAfile: /etc/pki/tls/certs/ca-bundle.crt CApath: none

BASH

Ubuntu 는 /etc/ssl/certs/ca-certificates.crt 또는  /etc/ssl/certs 디렉터리에서 CA 목록 로딩

Windows 에서 curl.exe 를 사용시 다음 순서대로 ca-bundle.crt 를 찾음

  1. application's directory
  2. current working directory
  3. Windows System directory (e.g. C:\windows\system32)
  4. Windows Directory (e.g. C:\windows)
  5. all directories along %PATH%

2. 서버 인증서 및 CA List 를  BASE64 로 저장한 내용을 위에서 확인한 ca-bundle.crt 파일에 추가해 준다. 자세한 방법은 https 연결시 서버의 SSL 인증서 추출하기 (curl 또는 web browser 사용) 를 참고한다.

3. 런타임에 옵션으로 CA List 파일을 지정하려면 curl 실행시 --cacert  옵션으로 CA  List를 지정할 수 있다.

curl -v --cacert myca-bundle.crt //google.com

BASH

3. CA 인증서 파일 갱신

새로운 인증 기관이 생겼는데 OS 에 포함된 curl 에는 반영이 안 되서 발생할 수 있다. curl 홈페이지에서는 주기적으로 최신 인증 기관 목록을 갱신햇 배포하므로 CA 인증서 목록을 다운받아서 기존 파일에 덮어써도 된다.

1. wget 또는 curl  명령을 사용해서 //curl.haxx.se/ca/cacert.pem 에서 인증서를 다운받는다. 

wget 사용

wget --no-check-certificate //curl.haxx.se/ca/cacert.pem

BASH

curl 사용

curl -k -O //curl.haxx.se/ca/cacert.pem

CODE

2. curl -v 옵션으로 CA 인증서 목록 파일의 위치를 확인한 후에 예전 파일은 백업하고 다운받은 인증서 파일을 덮어쓴다.

curl 사용

sudo cp cacert.pem  /etc/ssl/certs/ca-certificates.crt 

CODE

PHP 에서 curl 사용시

Guzzle - cURL error 60: SSL certificate problem: unable to get local issuer certificate 문제 해결 을 참고

같이 보기

  • java keytool 사용법 - Keystore 생성, 키쌍 생성, 인증서 등록 및 관리
  • Guzzle - cURL error 60: SSL certificate problem: unable to get local issuer certificate 문제 해결
  • git 에서 https repository 연결시 SSL 인증서 오류 해결법
  • Java 에서 ValidatorException 등 인증서 관련 에러 해결 - keystore에 SSL/TLS 인증서를 import 하기
  • SSL Intermediate 인증서 모음(github gist)

To configure SSL Certificate in Elasticsearch, the following certificates are
needed:

  • CA Certificate
  • Admin Certificate
  • Node Certificate

To configure SSL in elasticsearch, CA Certificate and CA Key is mandatory

👍

Note

Contact your organization for a third-party CA Certificate and CA Key, or use the steps below to generate an SSL Certificate.
To run Openssl, go to extracted path and run exe file as an Administrator
Example : C:\Users\Administrator\Downloads\openssl-1.1.1j-dev\openssl-1.1\x64\bin\openssl.exe

  1. To generate a private key using the genrsa command. As the name suggests, you should keep this file private.
  2. Private keys need to be of sufficient length in order to be secure, so specify 2048:

openssl genrsa -out root-ca-key.pem 2048

If desired, add the -aes256 option to encrypt the key using the AES-256 standard. This option requires a password.

  1. Next, use the key to generate a self-signed certificate for the root CA:

openssl req -new -x509 -sha256 -key root-ca-key.pem -out root-ca.pem

* The `-x509` option specifies that you want a self-signed certificate rather than a certificate request. * The `-sha256` option sets the hash algorithm to SHA-256. SHA-256 is the default in newer versions of OpenSSL, but older versions might use SHA-1. * Optionally, add` -days 3650` (10 years) or some other number of days to set an expiration date.
  1. Specify details for your organization as prompted. Together, these details form the Distinguished Name (DN) of your CA.

Run the following commands to generate certificates. Once the certificates are generated, you can find those certificates inside the bin folder.
(Eg: C:\Users\Administrator\Downloads\openssl-1.1.1j-dev\openssl-1.1\x64\bin)

  1. To Generate Admin/Node certificate
    openssl> genrsa -out admin-key-temp.pem 2048
    openssl> pkcs8 -inform PEM -outform PEM -in admin-key-temp.pem -topk8 -nocrypt -v1 PBE-SHA1-3DES -out admin-key.pem

  2. To Generate csr file from admin-key.pem file
    openssl> req -new -key adminkey.pem -out admin.csr

  3. To Generate admin.pem file
    openssl> x509 -req -in admin.csr -CA root-ca.pem -CAkey root-ca-key.pem -CAcreateserial -sha256 -out admin.pem

👍

Note:

root-ca.pem - You can use your CA cert or rename your CA cert file to root-ca.pem
root-ca-key - You can use your CA key file or rename your CA key file to
root-ca-key.pem

  1. Using the following command you can find DN
    openssl>x509 -subject -nameopt RFC2253 -noout -in admin.pem
    Example : subject= CN=node1.example.com,OU=UNIT,O=ORG,L=TORONTO,ST=ONTARIO,C=CA
    Note : You can configure the above DN value in elasticsearch.yml
    Example : Opendistro_security.authcz.admin_dn:
    -CN=node1.example.com,OU=UNIT,O=ORG,L=TORONTO,ST=ONTARIO,C=CA

  2. Copy all generated certificates [admin.pem, admin-key.pem] to
    C:\SearchBloxServer\elasticsearch\config.

  3. Provide full permissions for certificates in C:\SearchBloxServer\elasticsearch\config

👍

Note:

Right click on PEM file-properties-security-edit(give full permissions)

  1. Go to C:\SearchBloxServer\elasticsearch\config and edit elasticsearch.yml and make
    sure the pem certificate names are properly given.

Example:
opendistro_security.ssl.transport.pemcert_filepath: admin.pem
opendistro_security.ssl.transport.pemkey_filepath: admin_key.pem
opendistro_security.ssl.transport.pemtrustedcas_filepath: root-ca.pem
opendistro_security.ssl.transport.enforce_hostname_verification: false
opendistro_security.ssl.http.enabled: true
opendistro_security.ssl.http.pemcert_filepath: admin.pem
opendistro_security.ssl.http.pemkey_filepath: admin_key.pem
opendistro_security.ssl.http.pemtrustedcas_filepath: root-ca.pem
opendistro_security.allow_unsafe_democetificates: false
opendistro_security.allow_default_init_securiotyindex: true
opendistro_security.authcz.admin_dn:
-CN=elastic,OU=it,O=searchblox,L=V, C=US
opendistro_security.nodes_dn:
-CN=node1.test.com,OU=dev,O=searchblox,L=chennai,ST=tamilnadu,C=in

  1. Restart the OpenDistro Elasticsearch service and check for SSL updates.

  2. To Check cluster health
    //localhost:9200/_cluster/health?pretty

  3. Open command prompt and navigate to
    C:\SearchBloxServer\elasticsearch\plugins\opendistro_security\tools and run the following
    command to initialize the security plugins:
    securityadmin.bat -cd ../securityconfig/ -icl -nhnv -cacert ../../../config/root-ca.pem -cert ../../../config/admin.pem -key ../../../config/admin-key.pem

  4. Start searchblox service.

Updated 8 months ago

  • Table of Contents
    • Prerequisites:
    • Steps to generate self-signed CA Certificate
    • Steps to generate self-signed Admin certificates:

Toplist

Neuester Beitrag

Stichworte