Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
P
PHP Cert Reporter
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Code Review
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
PHP Cert Reporter
Commits
33d4fba7
Commit
33d4fba7
authored
Apr 17, 2019
by
Erick Hitter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup
parent
24e56a88
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
69 additions
and
37 deletions
+69
-37
report-expiry.php
report-expiry.php
+69
-37
No files found.
report-expiry.php
View file @
33d4fba7
<?php
/**
* Report certificate details.
*
* @package PHP_Cert_Reporter
*/
require
__DIR__
.
'/vendor/autoload.php'
;
$data
=
[
[
'Filename'
,
'CN'
,
'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
;
}
namespace
PHP_Cert_Reporter
;
/**
* Load table renderer.
*/
require_once
__DIR__
.
'/vendor/autoload.php'
;
$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
=>
''
,
/**
* Display certificate details in a table.
*
* Suitable for use in CI.
*
* @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'
]
)
)
{
$sans
=
explode
(
','
,
$x509
[
'extensions'
][
'subjectAltName'
]
);
$dir_includes_expired
=
false
;
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
)
{
$san
=
explode
(
':'
,
$san
);
$sans
[
$i
]
=
array_pop
(
$san
);
if
(
!
$dir_includes_expired
&&
$cert_data
[
3
]
<=
0
)
{
$dir_includes_expired
;
}
$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
);
$table
->
sort
(
2
);
$table
->
display
();
if
(
$exit
)
{
exit
(
$dir_includes_expired
?
1
:
0
);
}
}
report
();
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment