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