Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
PHP Cert Reporter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open-source
PHP Cert Reporter
Commits
33d4fba7
Commit
33d4fba7
authored
6 years ago
by
Erick Hitter
Browse files
Options
Downloads
Patches
Plain Diff
Cleanup
parent
24e56a88
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
report-expiry.php
+69
-37
69 additions, 37 deletions
report-expiry.php
with
69 additions
and
37 deletions
report-expiry.php
+
69
−
37
View file @
33d4fba7
<?php
<?php
/**
* Report certificate details.
*
* @package PHP_Cert_Reporter
*/
require
__DIR__
.
'/vendor/autoload.php'
;
namespace
PHP_Cert_Reporter
;
$data
=
[
/**
[
* Load table renderer.
'Filename'
,
*/
'CN'
,
require_once
__DIR__
.
'/vendor/autoload.php'
;
'Expires'
,
'Days Left'
,
'SAN'
,
],
];
foreach
(
glob
(
'*.crt'
,
GLOB_NOSORT
)
as
$cert
)
{
$path
=
getcwd
()
.
'/'
.
$cert
;
$x509
=
openssl_x509_parse
(
file_get_contents
(
$path
)
);
if
(
!
is_array
(
$x509
)
)
{
printf
(
'Failed to parse certificate from `%1$s`%2$s'
,
$path
,
"
\n\n
"
);
continue
;
}
$cert_data
=
[
/**
0
=>
$cert
,
* Display certificate details in a table.
1
=>
$x509
[
'subject'
][
'CN'
],
*
2
=>
date
(
'Y-m-d H:i:s T'
,
$x509
[
'validTo_time_t'
]
),
* Suitable for use in CI.
3
=>
(
int
)
round
(
(
$x509
[
'validTo_time_t'
]
-
time
()
)
/
86400
),
*
4
=>
''
,
* @param bool $exit Exit with status code indicating if expired certificates were found.
*/
function
report
(
$exit
=
true
):
void
{
$data
=
[
[
'Filename'
,
'CN'
,
'Expires'
,
'Days Left'
,
'SAN'
,
],
];
];
if
(
isset
(
$x509
[
'extensions'
][
'subjectAltName'
]
)
)
{
$dir_includes_expired
=
false
;
$sans
=
explode
(
','
,
$x509
[
'extensions'
][
'subjectAltName'
]
);
printf
(
'RESULTS FOR `%1$s`%2$s'
,
getcwd
(),
"
\n
"
);
foreach
(
glob
(
'*.crt'
,
GLOB_NOSORT
)
as
$cert
)
{
$path
=
getcwd
()
.
'/'
.
$cert
;
$x509
=
openssl_x509_parse
(
file_get_contents
(
$path
)
);
if
(
!
is_array
(
$x509
)
)
{
printf
(
'Failed to parse certificate from `%1$s`%2$s'
,
$path
,
"
\n\n
"
);
continue
;
}
$cert_data
=
[
0
=>
$cert
,
1
=>
$x509
[
'subject'
][
'CN'
],
2
=>
date
(
'Y-m-d H:i:s T'
,
$x509
[
'validTo_time_t'
]
),
3
=>
(
int
)
round
(
(
$x509
[
'validTo_time_t'
]
-
time
()
)
/
86400
),
4
=>
''
,
];
foreach
(
$sans
as
$i
=>
$san
)
{
if
(
!
$dir_includes_expired
&&
$cert_data
[
3
]
<=
0
)
{
$san
=
explode
(
':'
,
$san
);
$dir_includes_expired
;
$sans
[
$i
]
=
array_pop
(
$san
);
}
}
$cert_data
[
4
]
=
implode
(
' '
,
$sans
);
if
(
isset
(
$x509
[
'extensions'
][
'subjectAltName'
]
)
)
{
$sans
=
explode
(
','
,
$x509
[
'extensions'
][
'subjectAltName'
]
);
foreach
(
$sans
as
$i
=>
$san
)
{
$san
=
explode
(
':'
,
$san
);
$sans
[
$i
]
=
array_pop
(
$san
);
}
$cert_data
[
4
]
=
implode
(
' '
,
$sans
);
}
$data
[]
=
$cert_data
;
}
}
$data
[]
=
$cert_data
;
$table
=
new
\cli\Table
(
array_shift
(
$data
),
$data
);
}
$table
->
sort
(
2
);
$table
->
display
();
$table
=
new
\cli\Table
(
array_shift
(
$data
),
$data
);
if
(
$exit
)
{
$table
->
sort
(
2
);
exit
(
$dir_includes_expired
?
1
:
0
);
$table
->
display
();
}
}
report
();
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment