bug51647.phpt 4.0 KB

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