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