Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed the way of extracting certificates. #11

Closed
wants to merge 1 commit into from
Closed

Changed the way of extracting certificates. #11

wants to merge 1 commit into from

Conversation

mr-luke
Copy link

@mr-luke mr-luke commented Feb 25, 2020

I had situation when two different servers running same PHP & almost identical openssl ended up with extra "\n" chars. In my opinion that explode was "unfortunate" and is was environmental sensitive.

@mr-luke
Copy link
Author

mr-luke commented Feb 28, 2020

Is anyone maintaining this package? 😄

@trydocatch
Copy link
Collaborator

Hi @mr-luke ,

We'll look soon over your pull request :)

@trydocatch
Copy link
Collaborator

Hi @mr-luke ,

I'm curious if you've been able to identify the environmental difference that would case the issue.
Also, only some certificates would fail on that certain environment or all of them?

I'm trying to understand if the issue was caused only by a certain certificate, or only by a certain environment or by a combination of certain certificate&environment.

Thx,
Daniel

// may ended up with additional "\n" characters.
//
$certificates = explode(
"-----END CERTIFICATE-----\n",
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think a valid certificate does not always end in "END CERTIFICATE" but can also end in "END PKCS7"

if (count($certificates) > 1) {
// Let's fix first certificate by adding extracted "end" signature.
//
$certificates[0] = $certificates[0] . '-----END CERTIFICATE-----';
Copy link
Collaborator

Choose a reason for hiding this comment

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

This fixes the first certificate but not the second one.
I think a more reliable fix would be to still use the initial explode but after that loop through the result and apply trim to all items. In case an item is "" (empty) after the trim, discard it. Would this work on your particular certificate?

@crestoff
Copy link

crestoff commented May 6, 2020

I have some trouble. My solution is:
$certificatesChanged[] = $certificates[0] . ' ' . $certificates [1] . "\n\n" . $certificates[2];
$certificatesChanged[] = $certificates[3] . ' ' . $certificates [4] . "\n\n" . $certificates[5];
$certificates = $certificatesChanged;

@chencytw
Copy link

openssl 1.1.1 change print_cert output format to this https://i.imgur.com/Gt2U5et.jpg
cause certificates separate code by explode("\n\n") at PKCS7SignatureValidator->extractCertificates()
will not return list by certificates.

just change certificates separate code with
preg_match_all("/(^subject=.+\n-----END.+$)/imsU", $certificates, $match)
will match from "subject=" line to "-----END" line as one certificate,
which works on both openssl 1.0.x & 1.1.x print_certs format.

@mr-luke mr-luke closed this by deleting the head repository Jun 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants