Skip to content

Conversation

@StephenWall
Copy link
Contributor

This changes the days parameter of openssl_csr_sign() to a validity parameter, which can be either an integer specifying the number of days the certificate is to be valid for (compatible with current usage), or it can be an array of two integer or string values, representing the notBefore and notAfter times to use for the certificate. If they are integers or numeric strings, they are to be a time_t value. If they are non-numeric strings, they are to be an ASN.1 timestamp (YYMMDDHHMMSSZ or YYYYMMDDHHMMSSZ).

… a CSR

This changes the `days` parameter of `openssl_csr_sign()` to a
`validity` parameter, which can be either an integer specifying the
number of days the certificate is to be valid for (compatible with
current usage), or it can be an array of two integer or string values,
representing the notBefore and notAfter times to use for the
certificate.  If they are integers or numeric strings, they are to be a
time_t value.  If they are non-numeric strings, they are to be an ASN.1
timestamp (YYMMDDHHMMSSZ or YYYYMMDDHHMMSSZ).
Copy link
Member

@bukka bukka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So unless you want to do RFC proposing this BC break, I would suggest to go with additional parameter. We could maybe just go with something like $not_before_num_days or something like that so we don't have 2 params to change the same thing.

Also users can just use this to get number of days so the string form is not really that necessary (might be actually slightly confusing as that format is limited):

(new DateTime('now'))->diff(new DateTime($string_date))->days

* @param OpenSSLAsymmetricKey|OpenSSLCertificate|array|string $private_key
*/
function openssl_csr_sign(OpenSSLCertificateSigningRequest|string $csr, OpenSSLCertificate|string|null $ca_certificate, #[\SensitiveParameter] $private_key, int $days, ?array $options = null, int $serial = 0, ?string $serial_hex = null): OpenSSLCertificate|false {}
function openssl_csr_sign(OpenSSLCertificateSigningRequest|string $csr, OpenSSLCertificate|string|null $ca_certificate, #[\SensitiveParameter] $private_key, int|array $validity, ?array $options = null, int $serial = 0, ?string $serial_hex = null): OpenSSLCertificate|false {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a BC break because of named params. Renaming param is not acceptable without RFC.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would leaving the parameter named "$days" but accepting either an integer (existing usage) or an array (new usage) alleviate the breakage satisfactorily?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah that would be fine and it's actually better than extra param.

@StephenWall
Copy link
Contributor Author

Also users can just use this to get number of days so the string form is not really that necessary (might be actually slightly confusing as that format is limited):

Not really sure what you're getting at here. The new format for the parameter is array( $notBefore, $notAfter ), each of which can be a unix timestamp as an integer or a string, or an ASN.1 timestamp, which is the [YY]YYMMDDHHNNSSZ format, and must be a string because of the 'Z' at the end. I can drop the unix timestamp as a string, if that's what you mean, but I think the ASN.1 format is useful to have.
If you just want number of days string from right now, that still works as currently. The new format allows precise starting and ending times (for example, starting 2 days from now at midnight, valid to the exact end of the year).

@bukka
Copy link
Member

bukka commented Dec 9, 2025

It's more that name $days suggest number of dates and not date in string so I would just accept only int (or array of ints).

@StephenWall
Copy link
Contributor Author

StephenWall commented Dec 10, 2025

Making the notBefore and notAfter a count of days lacks the precision of using a timestamp, and is inconsistent with the use of those values within OpenSSL itself. I'd really like to find a way to incorporate that precision without breaking existing usage. It's unfortunate in this instance that PHP does not support overloading functions.
One possibility (though a bit ugly in my opinion) is to replace the positional $days with the $validity as implemented, and to add an optional $days parameter at the end of the parameter list, to preserve the named parameter functionality.
Another is to add $validity to the end as an optional parameter, and ignore $days if $validity is provided.
I think I am going to have to learn the RFC process for this one... I think I read something about needing a code to be able to register to create RFCs? Is that correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants