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