Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TDDE53 Security Assignment
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bashar Al-Saify
TDDE53 Security Assignment
Commits
fe82c878
Commit
fe82c878
authored
1 year ago
by
Bashar Al-Saify
Browse files
Options
Downloads
Patches
Plain Diff
del
parent
d445c134
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
TDDE53_Security_Assignment_basal573.pdf
+0
-0
0 additions, 0 deletions
TDDE53_Security_Assignment_basal573.pdf
data/scripts/certificate_checker.js
+78
-0
78 additions, 0 deletions
data/scripts/certificate_checker.js
with
78 additions
and
0 deletions
TDDE53_Security_Assignment_basal573.pdf
deleted
100644 → 0
+
0
−
0
View file @
d445c134
File deleted
This diff is collapsed.
Click to expand it.
data/scripts/certificate_checker.js
0 → 100644
+
78
−
0
View file @
fe82c878
// Import JSDOM
const
{
JSDOM
}
=
require
(
'
jsdom
'
);
// Function to count expired and not expired certificates
async
function
countExpiredAndNotExpired
(
domain
)
{
try
{
// Construct the URL for crt.sh search
const
url
=
`https://crt.sh/?q=
${
domain
}
`
;
// Fetch the HTML content of the search results page
const
response
=
await
fetch
(
url
);
const
html
=
await
response
.
text
();
// Create a new JSDOM instance
const
dom
=
new
JSDOM
(
html
);
// Get the document object from JSDOM
const
doc
=
dom
.
window
.
document
;
// Find all certificate rows in the table
const
certificateRows
=
doc
.
querySelectorAll
(
'
table tr
'
);
// Initialize counters for expired and not expired certificates
let
expiredCount
=
0
;
let
notExpiredCount
=
0
;
// Iterate over each certificate row
certificateRows
.
forEach
(
row
=>
{
// Extract "Not Before" and "Not After" dates from the row
const
notBeforeCell
=
row
.
querySelector
(
'
td:nth-child(3)
'
);
const
notAfterCell
=
row
.
querySelector
(
'
td:nth-child(4)
'
);
// Check if both cells are found
if
(
notBeforeCell
&&
notAfterCell
)
{
const
notBeforeText
=
notBeforeCell
.
textContent
.
trim
();
const
notAfterText
=
notAfterCell
.
textContent
.
trim
();
// Convert date strings to Date objects
const
notBefore
=
new
Date
(
notBeforeText
);
const
notAfter
=
new
Date
(
notAfterText
);
// Check if the certificate is expired
if
(
notAfter
<
new
Date
())
{
expiredCount
++
;
}
else
{
notExpiredCount
++
;
}
}
});
// Return the counts of expired and not expired certificates
return
{
expiredCount
,
notExpiredCount
};
}
catch
(
error
)
{
console
.
error
(
'
An error occurred:
'
,
error
);
return
null
;
}
}
// Extract domain from command-line arguments
const
domain
=
process
.
argv
[
2
];
// Check if the domain name is provided
if
(
!
domain
)
{
console
.
error
(
'
Please provide a domain name as an argument.
'
);
process
.
exit
(
1
);
// Exit with a non-zero status code to indicate an error
}
// Example usage: Count expired and not expired certificates for a domain
countExpiredAndNotExpired
(
domain
)
.
then
(
result
=>
{
if
(
result
)
{
console
.
log
(
`Expired certificates:
${
result
.
expiredCount
}
`
);
console
.
log
(
`Not expired certificates:
${
result
.
notExpiredCount
}
`
);
}
else
{
console
.
log
(
'
Failed to retrieve certificate information.
'
);
}
})
.
catch
(
error
=>
console
.
error
(
'
An error occurred:
'
,
error
));
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