xref: /PHP-8.1/ext/mysqli/tests/bug51647.phpt (revision b5a14e6c)
1--TEST--
2Bug #51647 (Certificate file without private key (pk in another file) doesn't work)
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
7require_once('skipifconnectfailure.inc');
8require_once("connect.inc");
9
10if (!defined('MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT'))
11    die("skip Requires MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT");
12
13if ($IS_MYSQLND && !extension_loaded("openssl"))
14    die("skip PHP streams lack support for SSL. mysqli is compiled to use mysqlnd which uses PHP streams in turn.");
15
16if (!($link = @my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)))
17    die(sprintf("skip Connect failed, [%d] %s", mysqli_connect_errno(), mysqli_connect_error()));
18
19if (false === strpos($link->host_info, 'TCP/IP'))
20    die(sprintf("skip SSL only supported on TCP/IP"));
21
22$row = NULL;
23if ($res = $link->query('SHOW VARIABLES LIKE "have_ssl"')) {
24    $row = $res->fetch_row();
25} else {
26    if ($link->errno == 1064 && ($res = $link->query("SHOW VARIABLES"))) {
27        while ($row = $res->fetch_row())
28            if ($row[0] == 'have_ssl')
29                break;
30    } else {
31        die(sprintf("skip Failed to test for MySQL SSL support, [%d] %s", $link->errno, $link->error));
32    }
33}
34
35
36if (empty($row))
37    die(sprintf("skip Failed to test for MySQL SSL support, [%d] %s", $link->errno, $link->error));
38
39if (($row[1] == 'NO') || ($row[1] == 'DISABLED'))
40    die(sprintf("skip MySQL has no SSL support, [%d] %s", $link->errno, $link->error));
41
42$link->close();
43?>
44--FILE--
45<?php
46    include ("connect.inc");
47
48    if (!is_object($link = mysqli_init()))
49        printf("[001] Cannot create link\n");
50
51    if (!my_mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket, MYSQLI_CLIENT_SSL | MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT)) {
52        printf("[003] Connect failed, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
53    }
54
55    if (!$res = $link->query('SHOW STATUS like "Ssl_cipher"')) {
56        if (1064 == $link->errno) {
57            /* ERROR 1064 (42000): You have an error in your SQL syntax;  = sql strict mode */
58            if ($res = $link->query("SHOW STATUS")) {
59                while ($row = $res->fetch_assoc())
60                    if ($row['Variable_name'] == 'Ssl_cipher')
61                        break;
62            } else {
63                printf("[005] [%d] %s\n", $link->errno, $link->error);
64            }
65        } else {
66            printf("[004] [%d] %s\n", $link->errno, $link->error);
67        }
68    } else {
69        if (!$row = $res->fetch_assoc())
70            printf("[006] [%d] %s\n", $link->errno, $link->error);
71        if (!strlen($row["Value"]))
72            printf("[007] Empty cipher. No encryption!");
73        var_dump($row);
74    }
75
76    $link->close();
77
78    if (!is_object($link = mysqli_init()))
79        printf("[008] Cannot create link\n");
80
81    if (!my_mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket, MYSQLI_CLIENT_SSL)) {
82        printf("[009] Connect failed, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
83    }
84
85    if (!$res = $link->query('SHOW STATUS like "Ssl_cipher"')) {
86        if (1064 == $link->errno) {
87            /* ERROR 1064 (42000): You have an error in your SQL syntax;  = sql strict mode */
88            if ($res = $link->query("SHOW STATUS")) {
89                while ($row = $res->fetch_assoc())
90                    if ($row['Variable_name'] == 'Ssl_cipher')
91                        break;
92            } else {
93                printf("[010] [%d] %s\n", $link->errno, $link->error);
94            }
95        } else {
96            printf("[011] [%d] %s\n", $link->errno, $link->error);
97        }
98    } else {
99        if (!$row = $res->fetch_assoc())
100            printf("[012] [%d] %s\n", $link->errno, $link->error);
101        if (!strlen($row["Value"]))
102            printf("[013] Empty cipher. No encryption!");
103        var_dump($row);
104    }
105
106    $link->close();
107
108    print "done!";
109?>
110--EXPECTF--
111array(2) {
112  ["Variable_name"]=>
113  string(10) "Ssl_cipher"
114  ["Value"]=>
115  string(%d) "%S"
116}
117array(2) {
118  ["Variable_name"]=>
119  string(10) "Ssl_cipher"
120  ["Value"]=>
121  string(%d) "%S"
122}
123done!
124