RE: [PHP-CVS] com php-src: LDAP - Added support to change the certificates verification: ext/ldap/ldap.c ext/ldap/tests/ldap_option_reqcert_basic.phpt
ext/ldap/tests/ldap_option_reqcert_error.phpt ext/ldap/tests/ldap_set_option_reqcert_basic.phpt ext/ldap
| From: | Anatol Belski | Date: | Tue, 01 Mar 2016 07:37:49 +0000 |
| Subject: | RE: [PHP-CVS] com php-src: LDAP - Added support to change the certificates verification: ext/ldap/ldap.c ext/ldap/tests/ldap_option_reqcert_basic.phpt ext/ldap/tests/ldap_option_reqcert_error.phpt ext/ldap/tests/ldap_set_option_reqcert_basic.phpt ext/ldap |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-91202@lists.php.net to get a copy of this message | ||
Hi Côme,
> -----Original Message-----
> From: Côme Bernigaud [mailto:mcmic@php.net]
> Sent: Tuesday, March 1, 2016 5:00 AM
> To: php-cvs@lists.php.net
> Subject: [PHP-CVS] com php-src: LDAP - Added support to change the
> certificates verification: ext/ldap/ldap.c
> ext/ldap/tests/ldap_option_reqcert_basic.phpt
> ext/ldap/tests/ldap_option_reqcert_error.phpt
> ext/ldap/tests/ldap_set_option_reqcert_basic.phpt ext/ldap/tes
>
> Commit: ba9650667693089f0969c57f14bdfe851ae801ae
> Author: Edwin Hoksberg <edwin@edwinhoksberg.nl> Tue, 16 Feb 2016
> 09:39:58 +0100
> Committer: Côme Bernigaud <mcmic@php.net> Tue, 1 Mar 2016 04:59:30
> +0100
> Parents: 9fc0517328a248825703bef90d631ec687fb0d58
> Branches: PHP-7.0
>
> Link: http://git.php.net/?p=php-
> src.git;a=commitdiff;h=ba9650667693089f0969c57f14bdfe851ae801ae
>
> Log:
> LDAP - Added support to change the certificates verification
>
Thanks for taking care about this PR. Please also mention these new parts in UPGRADING, probably
they'll be available in 7.0.5.
Thanks
Anatol
> Changed paths:
> M ext/ldap/ldap.c
> A ext/ldap/tests/ldap_option_reqcert_basic.phpt
> A ext/ldap/tests/ldap_option_reqcert_error.phpt
> A ext/ldap/tests/ldap_set_option_reqcert_basic.phpt
> A ext/ldap/tests/ldap_set_option_reqcert_error.phpt
>
>
> Diff:
> diff --git a/ext/ldap/ldap.c b/ext/ldap/ldap.c index 68e8c95..c439c73 100644
> --- a/ext/ldap/ldap.c
> +++ b/ext/ldap/ldap.c
> @@ -227,6 +227,16 @@ PHP_MINIT_FUNCTION(ldap)
> REGISTER_LONG_CONSTANT("GSLC_SSL_TWOWAY_AUTH",
> GSLC_SSL_TWOWAY_AUTH, CONST_PERSISTENT | CONST_CS); #endif
>
> +#if (LDAP_API_VERSION > 2000)
> + REGISTER_LONG_CONSTANT("LDAP_OPT_X_TLS_REQUIRE_CERT",
> +LDAP_OPT_X_TLS_REQUIRE_CERT, CONST_PERSISTENT | CONST_CS);
> +
> + REGISTER_LONG_CONSTANT("LDAP_OPT_X_TLS_NEVER",
> LDAP_OPT_X_TLS_NEVER, CONST_PERSISTENT | CONST_CS);
> + REGISTER_LONG_CONSTANT("LDAP_OPT_X_TLS_HARD",
> LDAP_OPT_X_TLS_HARD, CONST_PERSISTENT | CONST_CS);
> + REGISTER_LONG_CONSTANT("LDAP_OPT_X_TLS_DEMAND",
> LDAP_OPT_X_TLS_DEMAND, CONST_PERSISTENT | CONST_CS);
> + REGISTER_LONG_CONSTANT("LDAP_OPT_X_TLS_ALLOW",
> LDAP_OPT_X_TLS_ALLOW, CONST_PERSISTENT | CONST_CS);
> + REGISTER_LONG_CONSTANT("LDAP_OPT_X_TLS_TRY",
> LDAP_OPT_X_TLS_TRY,
> +CONST_PERSISTENT | CONST_CS); #endif
> +
> REGISTER_LONG_CONSTANT("LDAP_ESCAPE_FILTER",
> PHP_LDAP_ESCAPE_FILTER, CONST_PERSISTENT | CONST_CS);
> REGISTER_LONG_CONSTANT("LDAP_ESCAPE_DN",
> PHP_LDAP_ESCAPE_DN, CONST_PERSISTENT | CONST_CS);
>
> @@ -2083,6 +2093,9 @@ PHP_FUNCTION(ldap_get_option) #ifdef
> LDAP_OPT_RESTART
> case LDAP_OPT_RESTART:
> #endif
> +#ifdef LDAP_OPT_X_TLS_REQUIRE_CERT
> + case LDAP_OPT_X_TLS_REQUIRE_CERT:
> +#endif
> {
> int val;
>
> @@ -2213,6 +2226,9 @@ PHP_FUNCTION(ldap_set_option) #ifdef
> LDAP_OPT_DEBUG_LEVEL
> case LDAP_OPT_DEBUG_LEVEL:
> #endif
> +#ifdef LDAP_OPT_X_TLS_REQUIRE_CERT
> + case LDAP_OPT_X_TLS_REQUIRE_CERT:
> +#endif
> {
> int val;
>
> diff --git a/ext/ldap/tests/ldap_option_reqcert_basic.phpt
> b/ext/ldap/tests/ldap_option_reqcert_basic.phpt
> new file mode 100644
> index 0000000..009ef83
> --- /dev/null
> +++ b/ext/ldap/tests/ldap_option_reqcert_basic.phpt
> @@ -0,0 +1,21 @@
> +--TEST--
> +ldap_option_reqcert_basic() - Basic test to check if PHP can connect to
> +a LDAP server with an invalid certificate with certificate checking
> +disabled
> +--CREDITS--
> +Edwin Hoksberg <edwin@edwinhoksberg.nl>
> +--SKIPIF--
> +<?php require_once dirname(__FILE__) .'/skipif.inc'; ?>
> +--FILE--
> +<?php
> +require "connect.inc";
> +
> +ldap_set_option(null, LDAP_OPT_X_TLS_REQUIRE_CERT,
> +LDAP_OPT_X_TLS_NEVER);
> +
> +$link = ldap_connect($host, $port);
> +ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, $protocol_version);
> +
> +var_dump(@ldap_bind($link, $user, $passwd)); ?> ===DONE===
> +--EXPECT--
> +bool(true)
> +===DONE===
> diff --git a/ext/ldap/tests/ldap_option_reqcert_error.phpt
> b/ext/ldap/tests/ldap_option_reqcert_error.phpt
> new file mode 100644
> index 0000000..1f5ac42
> --- /dev/null
> +++ b/ext/ldap/tests/ldap_option_reqcert_error.phpt
> @@ -0,0 +1,21 @@
> +--TEST--
> +ldap_option_reqcert_error() - A test to check if ldap cant connect to a
> +LDAP server with a invalid certificate with certificate checking
> +enabled
> +--CREDITS--
> +Edwin Hoksberg <edwin@edwinhoksberg.nl>
> +--SKIPIF--
> +<?php require_once dirname(__FILE__) .'/skipif.inc'; ?>
> +--FILE--
> +<?php
> +require "connect.inc";
> +
> +ldap_set_option(null, LDAP_OPT_X_TLS_REQUIRE_CERT,
> +LDAP_OPT_X_TLS_HARD);
> +
> +$link = ldap_connect($host, $port);
> +ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, $protocol_version);
> +
> +var_dump(@ldap_bind($link, $user, $passwd)); ?> ===DONE===
> +--EXPECT--
> +bool(true)
> +===DONE===
> diff --git a/ext/ldap/tests/ldap_set_option_reqcert_basic.phpt
> b/ext/ldap/tests/ldap_set_option_reqcert_basic.phpt
> new file mode 100644
> index 0000000..e31bf35
> --- /dev/null
> +++ b/ext/ldap/tests/ldap_set_option_reqcert_basic.phpt
> @@ -0,0 +1,36 @@
> +--TEST--
> +ldap_option_reqcert_basic() - Error test for TLS require cert ldap
> +option
> +--CREDITS--
> +Edwin Hoksberg <edwin@edwinhoksberg.nl>
> +--FILE--
> +<?php
> +require "connect.inc";
> +$link = ldap_connect($host, $port);
> +
> +foreach([
> + LDAP_OPT_X_TLS_NEVER,
> + LDAP_OPT_X_TLS_HARD,
> + LDAP_OPT_X_TLS_DEMAND,
> + LDAP_OPT_X_TLS_ALLOW,
> + LDAP_OPT_X_TLS_TRY,
> +] as $option) {
> + $result = ldap_set_option($link, LDAP_OPT_X_TLS_REQUIRE_CERT,
> $option);
> + var_dump($result);
> +
> + ldap_get_option($link, LDAP_OPT_X_TLS_REQUIRE_CERT, $optionval);
> + var_dump($optionval);
> +}
> +?>
> +===DONE===
> +--EXPECT--
> +bool(true)
> +int(0)
> +bool(true)
> +int(1)
> +bool(true)
> +int(2)
> +bool(true)
> +int(3)
> +bool(true)
> +int(4)
> +===DONE===
> diff --git a/ext/ldap/tests/ldap_set_option_reqcert_error.phpt
> b/ext/ldap/tests/ldap_set_option_reqcert_error.phpt
> new file mode 100644
> index 0000000..1a7796b
> --- /dev/null
> +++ b/ext/ldap/tests/ldap_set_option_reqcert_error.phpt
> @@ -0,0 +1,17 @@
> +--TEST--
> +ldap_option_reqcert_basic() - Error test for TLS require cert ldap
> +option
> +--CREDITS--
> +Edwin Hoksberg <edwin@edwinhoksberg.nl>
> +--SKIPIF--
> +<?php require_once dirname(__FILE__) .'/skipif.inc'; ?>
> +--FILE--
> +<?php
> +require "connect.inc";
> +$link = ldap_connect($host, $port);
> +$result = ldap_set_option($link, LDAP_OPT_X_TLS_REQUIRE_CERT, 9001);
> +var_dump($result); ?> ===DONE===
> +--EXPECT--
> +bool(false)
> +===DONE===
>
>
> --
> PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit:
> http://www.php.net/unsub.php