note 117474 added to function.openssl-csr-new
| From: | james at kirk dot com | Date: | Mon, 15 Jun 2015 18:56:06 +0000 |
| Subject: | note 117474 added to function.openssl-csr-new | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-202870@lists.php.net to get a copy of this message | ||
When in doubt, read the source code to PHP!
$configargs is fairly opaque as to what is going on behind the scenes. That is, until you actually
look at php_openssl_parse_config() in '/ext/openssl/openssl.c':
SET_OPTIONAL_STRING_ARG("digest_alg", req->digest_name,
CONF_get_string(req->req_config, req->section_name, "default_md"));
SET_OPTIONAL_STRING_ARG("x509_extensions", req->extensions_section,
CONF_get_string(req->req_config, req->section_name, "x509_extensions"));
SET_OPTIONAL_STRING_ARG("req_extensions", req->request_extensions_section,
CONF_get_string(req->req_config, req->section_name, "req_extensions"));
SET_OPTIONAL_LONG_ARG("private_key_bits", req->priv_key_bits,
CONF_get_number(req->req_config, req->section_name, "default_bits"));
SET_OPTIONAL_LONG_ARG("private_key_type", req->priv_key_type,
OPENSSL_KEYTYPE_DEFAULT);
Here we can see that SET_OPTIONAL_STRING_ARG() is called for most inputs but for
'private_key_bits' SET_OPTIONAL_LONG_ARG() is called. Both calls are C macros that expand
to code that enforces the expected input type. The generated code ignores the input without
warning/notice if an unexpected type is used and just uses the default from the configuration file.
This is why using a string with 'private_key_bits' will result in unexpected behavior.
Further inspection of the earlier initialization in the same function:
SET_OPTIONAL_STRING_ARG("config", req->config_filename, default_ssl_conf_filename);
SET_OPTIONAL_STRING_ARG("config_section_name", req->section_name, "req");
req->global_config = CONF_load(NULL, default_ssl_conf_filename, NULL);
req->req_config = CONF_load(NULL, req->config_filename, NULL);
if (req->req_config == NULL) {
return FAILURE;
}
And elsewhere in another function:
/* default to 'openssl.cnf' if no environment variable is set */
if (config_filename == NULL) {
snprintf(default_ssl_conf_filename, sizeof(default_ssl_conf_filename), "%s/%s",
X509_get_default_cert_area(),
"openssl.cnf");
} else {
strlcpy(default_ssl_conf_filename, config_filename, sizeof(default_ssl_conf_filename));
}
Reveals that 'config' in $configargs is an override for any default setting elsewhere.
This actually negates the comment in the documentation that says "Note: You need to have a
valid openssl.cnf installed for this function to operate correctly. See the notes under the
installation section for more information." A more correct sentence would be "Note: You
need to either have a valid openssl.cnf set up or use $configargs to point at a valid openssl.cnf
file for this function to operate correctly."
All of that goes to show that looking at the PHP source code is the only real way to figure out what
is actually happening. Doing so saves time and effort.
----
Server IP: 72.52.91.14
Probable Submitter: 207.225.254.78
----
Manual Page -- http://php.net/manual/en/function.openssl-csr-new.php
Edit -- https://master.php.net/note/edit/117474
Del: integrated -- https://master.php.net/note/delete/117474/integrated
Del: useless -- https://master.php.net/note/delete/117474/useless
Del: bad code -- https://master.php.net/note/delete/117474/bad+code
Del: spam -- https://master.php.net/note/delete/117474/spam
Del: non-english -- https://master.php.net/note/delete/117474/non-english
Del: in docs -- https://master.php.net/note/delete/117474/in+docs
Del: other reasons-- https://master.php.net/note/delete/117474
Reject -- https://master.php.net/note/reject/117474
Search -- https://master.php.net/manage/user-notes.php