bug51647.phpt 3.4 KB

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