LDAP Linux LDAP TLS

Материал из noname.com.ua
Перейти к навигацииПерейти к поиску

LDAP Шифрование

ТУТ я просто дублирую статью со своими комментариями.


1

0010_prepere_CA.sh
mkdir /root/CA

chmod u=rwx,g=,o= /root/CA
pushd /root/CA
umask 066


mkdir certs crl newcerts private.
chmod 700 private
touch index.txt
echo 1000 > serial


# Create key pass = r00tme
openssl genrsa -aes256 -out private/rootca.key 4096
chmod 400 private/rootca.key
chattr +i private/rootca.key

popd

2

0011_rootCa_crt.sh
openssl req \
-sha256 \
-new \
-x509 \
-days 3650 \
-extensions v3_ca \
-key private/rootca.key \
-out certs/rootca.crt \
-subj /C=UA/ST=Kharkov/L=Kharkov/O=MirantisInc/OU=ServicesDepartment/CN=ca-server/emailAddress=mmaxur@mirantis.com

chmod 444 certs/rootca.crt
chattr +i certs/rootca.crt

openssl x509 -in certs/rootca.crt -noout -text

popd

3

0012_private_key_for_ldap1.sh
pushd /root/CA
openssl genrsa \
-out private/ldap1.key 4096

chmod 400 private/ldap1.key

popd

3

0013_create_cert_request_for_ldap1.sh
pushd /root/CA

openssl req \
-sha256 -new \
-key private/ldap1.key \
-out certs/ldap1.csr \
-subj /C=UA/ST=Kharkov/L=Kharkov/O=MirantisInc/OU=ServicesDepartment/CN=ldap1/emailAddress=mmaxur@mirantis.com

popd

3

0014_create_and_sign_cert_for_ldap1.sh
pushd /root/CA

openssl ca \
-extensions usr_cert \
-notext \
-md sha256 \
-keyfile private/rootca.key \
-cert certs/rootca.crt \
-in certs/ldap1.csr \
-out certs/ldap1.crt

chmod 444 certs/ldap1.crt

popd

3

0015_move_certs_to_ldap_config_dir.sh
pushd /root/CA

mkdir /etc/ldap/ssl
chown openldap:openldap /etc/ldap/ssl
chmod 0500 /etc/ldap/ssl
cp certs/ldap1.crt private/ldap1.key /etc/ldap/ssl


chown openldap:openldap /etc/ldap/ssl/{ldap1.crt,ldap1.key}
chmod 0400 /etc/ldap/ssl/{ldap1.crt,ldap1.key}

cp certs/rootca.crt /etc/ssl/certs/

chmod 0644 /etc/ssl/certs/rootca.crt

popd

3

0016_check_cert.sh
openssl verify -verbose -CAfile /etc/ssl/certs/rootca.crt  /etc/ldap/ssl/ldap1.crt

3

0201_install_tls_certs.ldif
dn: cn=config
add: olcTLSVerifyClient
olcTLSVerifyClient: never
-
add: olcTLSCertificateFile
olcTLSCertificateFile: /etc/ldap/ssl/ldap1.crt
-
add: olcTLSCertificateKeyFile
olcTLSCertificateKeyFile: /etc/ldap/ssl/ldap1.key
-
add: olcTLSCACertificateFile
olcTLSCACertificateFile: /etc/ssl/certs/rootca.crt


0202_configure_ldap_to_use_tls.sh
ldapmodify -Y EXTERNAL -H ldapi:/// <0201_install_tls_certs.ldif

3

0203_check_config.sh
ldapsearch -QLLLY EXTERNAL -H ldapi:/// -b cn=config -s base | grep -i tls

3

0204_check_tls_connection.sh
gnutls-cli \
-p 636 ldap1 \
-d 1 \
--print-cert \
--x509cafile  /etc/ssl/certs/rootca.crt

3

1012_private_key_for_ldap2.sh
pushd /root/CA
openssl genrsa \
-out private/ldap2.key 4096


chmod 400 private/ldap2.key


popd

3

1013_create_cert_request_for_ldap2.sh
pushd /root/CA


openssl req \
-sha256 -new \
-key private/ldap2.key \
-out certs/ldap2.csr \
-subj /C=UA/ST=Kharkov/L=Kharkov/O=MirantisInc/OU=ServicesDepartment/CN=ldap2/emailAddress=mmaxur@mirantis.com

popd

3

1014_create_and_sign_cert_for_ldap2.sh
pushd /root/CA

openssl ca \
-extensions usr_cert \
-notext \
-md sha256 \
-keyfile private/rootca.key \
-cert certs/rootca.crt \
-in certs/ldap2.csr \
-out certs/ldap2.crt

chmod 444 certs/ldap2.crt

popd

3

2012_private_key_for_ldap.sh
pushd /root/CA
openssl genrsa \
-out private/ldap.key 4096

chmod 400 private/ldap.key

popd

3



3



3



3



3



3



3

3

3

3

3

3

3

3

3

 \ldapmodify  -Y EXTERNAL  -H ldapi:/// < 01_certs.ldif
SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
modifying entry "cn=config"
\ldapsearch -Y EXTERNAL -H ldapi:/// -b cn=config -s base

Вывод:

# config
dn: cn=config
objectClass: olcGlobal
cn: config
olcArgsFile: /var/run/slapd/slapd.args
olcLogLevel: none
olcPidFile: /var/run/slapd/slapd.pid
olcToolThreads: 1
olcTLSVerifyClient: never
olcTLSCertificateFile: /etc/ldap/ssl/ldap-srv.example.com.crt
olcTLSCertificateKeyFile: /etc/ldap/ssl/ldap-srv.example.com.key
olcTLSCACertificateFile: /etc/ssl/certs/rootca.crt



root@node-3:/etc/ldap# netstat  -ntpl | grep slap
tcp        0      0 0.0.0.0:389             0.0.0.0:*               LISTEN      2875/slapd
tcp6       0      0 :::389                  :::*                    LISTEN      2875/slapd
# /etc/init.d/slapd restart
 * Stopping OpenLDAP slapd                                                                                                                                                                                                                                                                                          [ OK ]
 * Starting OpenLDAP slapd                                                                                                                                                                                                                                                                                          [ OK ]
# netstat  -ntpl | grep slap
tcp        0      0 0.0.0.0:636             0.0.0.0:*               LISTEN      6294/slapd
tcp        0      0 0.0.0.0:389             0.0.0.0:*               LISTEN      6294/slapd
tcp6       0      0 :::636                  :::*                    LISTEN      6294/slapd
tcp6       0      0 :::389                  :::*                    LISTEN      6294/slapd


Проверка

gnutls-cli -p 636 ldap1 -d 1 --print-cert --x509cafile  /etc/ssl/certs/rootca.crt
Processed 1 CA certificate(s).
Resolving 'ldap1'...
Connecting to '10.20.0.3:636'...
- Certificate type: X.509
 - Got a certificate list of 2 certificates.
 - Certificate[0] info:
  - subject `C=UA,ST=Kharkov,O=MirantisInc,OU=ServicesDepartment,CN=ldap1,EMAIL=mmaxur@mirantis.com', issuer `C=UA,ST=Kharkov,L=Kharkov,O=MirantisInc,OU=ServicesDepartment,CN=ca-server,EMAIL=mmaxur@mirantis.com', RSA key 4096 bits, signed using RSA-SHA256, activated `2016-05-26 10:25:31 UTC', expires `2026-05-24 10:25:31 UTC', SHA-1 fingerprint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2VHI
M7woolzYH+/vlOK+5aQrgcsanCy/7s4prux4IRTx5SGzqW+idA2UW26+5WyKbg==
-----END CERTIFICATE-----

 - Certificate[1] info:
  - subject `C=UA,ST=Kharkov,L=Kharkov,O=MirantisInc,OU=ServicesDepartment,CN=ca-server,EMAIL=mmaxur@mirantis.com', issuer `C=UA,ST=Kharkov,L=Kharkov,O=MirantisInc,OU=ServicesDepartment,CN=ca-server,EMAIL=mmaxur@mirantis.com', RSA key 4096 bits, signed using RSA-SHA256, activated `2016-05-26 10:16:07 UTC', expires `2026-05-24 10:16:07 UTC', SHA-1 fingerprint `0f74fdaf2195ae2b1f599e3963e3b18970cb81a3'

-----BEGIN CERTIFICATE-----
MIIGGjCCBAKgAwIBAgIJAN1rpxx3AA9AMA0GCSqGSIb3DQEBCwUAMIGcMQswCQYD
VQQGEwJVQTEQMA4GA1UECAwHS2hhcmtvdjEQMA4GA1UEBwwHS2hhcmtvdjEUMBIG
A1UECgwLTWlyYW50aXNJbmMxGzAZBgNVBAsMElNlcnZpY2VzRGVwYXJ0bWVudDES
MBAGA1UEAwwJY2Etc2VydmVyMSIwIAYJKoZIhvcNAQkBFhNtbWF4dXJAbWlyYW50
aXMuY29tMB4XDTE2MDUyNjEwMTYwN1oXDTI2MDUyNDEwMTYwN1owgZwxCzAJBgNV
BAYTAlVBMRAwDgYDVQQIDAdLaGFya292MRAwDgYDVQQHDAdLaGFya292MRQwEgYD
VQQKDAtNaXJhbnRpc0luYzEbMBkGA1UECwwSU2VydmljZXNEZXBhcnRtZW50MRIw
EAYDVQQDDAljYS1zZXJ2ZXIxIjAgBgkqhkiG9w0BCQEWE21tYXh1ckBtaXJhbnRp
cy5jb20wggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQCuZEMVa87WGQJl
1foQGNt4Qh/CWcggjjIqn8IYSPPtqn3YAxvUnubA+DQxkH7PNYR6G9PdNgQon2mV
xvwVFL6YouDkPtEO101B3vM28U3vEEOSLUcign+2XqzKf7lq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y8/B+77W1yli/VbzK6H4jwrVGy7
EAEzpfbwRJnSIIUczG8//1G6a5yrpcjohKhWY1uBrv56LJdq16OVN3aK5nacMKmQ
p+YpPu/ZT5LVUOzt8I32Q8i1Tn9YZma7vEftvGCZKVcgqlVIpb3P7/7dyRXoMuFD
bErDIDxScMvg82Vg2JF4NzaOp+CXRAYuXbel5anoFOt7FFfnO2w0/aLQpAT+jpze
qcL37IGyCGxOloej7NkdQsX9eJJNIdy5oLjniJ8/d402A0zziPdfrqa0c3FpGukZ
syWlWH0RCerDgVmq+i6l5zGbtx/tKPpLYcJkAetJ
-----END CERTIFICATE-----

- The hostname in the certificate matches 'ldap1'.
- Peer's certificate is trusted
- Version: TLS1.2
- Key Exchange: RSA
- Cipher: AES-128-CBC
- MAC: SHA1
- Compression: NULL
- Handshake was completed

- Simple Client Mode: