1--TEST-- 2openssl_csr_sign() with serial and serial_hex parameters 3--EXTENSIONS-- 4openssl 5--FILE-- 6<?php 7$config = __DIR__ . DIRECTORY_SEPARATOR . 'openssl.cnf'; 8$config_arg = array('config' => $config); 9 10$dn = array( 11 "countryName" => "BR", 12 "stateOrProvinceName" => "Rio Grande do Sul", 13 "localityName" => "Porto Alegre", 14 "commonName" => "Henrique do N. Angelo", 15 "emailAddress" => "hnangelo@php.net" 16); 17 18$args = array( 19 "digest_alg" => "sha256", 20 "private_key_bits" => 2048, 21 "private_key_type" => OPENSSL_KEYTYPE_DSA, 22 "encrypt_key" => true, 23 "config" => $config 24); 25 26$privkey = openssl_pkey_new($config_arg); 27$csr = openssl_csr_new($dn, $privkey, $args); 28 29var_dump($cert1 = openssl_csr_sign($csr, null, $privkey, 365, $args, 1234567)); 30var_dump($cert2 = openssl_csr_sign($csr, null, $privkey, 365, $args, serial_hex: 'DEADBEEF')); 31var_dump($cert3 = openssl_csr_sign($csr, null, $privkey, 365, $args, 10, 'DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF')); 32 33var_dump(openssl_csr_sign($csr, null, $privkey, 365, $args, 0, 'DEADBEEG')); 34var_dump(openssl_csr_sign($csr, null, $privkey, 365, $args, 0, '0xDEADBEEF')); 35var_dump(openssl_csr_sign($csr, null, $privkey, 365, $args, 0, str_repeat('FF', 500))); 36 37var_dump(openssl_x509_parse($cert1)['serialNumber']); 38var_dump(openssl_x509_parse($cert1)['serialNumberHex']); 39var_dump(openssl_x509_parse($cert2)['serialNumber']); 40var_dump(openssl_x509_parse($cert2)['serialNumberHex']); 41var_dump(openssl_x509_parse($cert3)['serialNumber']); 42var_dump(openssl_x509_parse($cert3)['serialNumberHex']); 43?> 44--EXPECTF-- 45object(OpenSSLCertificate)#%d (0) { 46} 47object(OpenSSLCertificate)#%d (0) { 48} 49object(OpenSSLCertificate)#%d (0) { 50} 51 52Warning: openssl_csr_sign(): Error parsing serial number in %s on line %d 53bool(false) 54 55Warning: openssl_csr_sign(): Error parsing serial number in %s on line %d 56bool(false) 57 58Warning: openssl_csr_sign(): Error parsing serial number because it is too long in %s on line %d 59bool(false) 60string(7) "1234567" 61string(6) "12D687" 62string(10) "3735928559" 63string(8) "DEADBEEF" 64string(42) "0xDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF" 65string(40) "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF"