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

Use Universal Time to Compare Certificates #636

Merged
merged 2 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -803,10 +803,10 @@ exit 4
}
if (Get-Member -inputObject $user.certInfo -name "deploymentDate" -MemberType Properties) {
# if ($userObjectFromTable.certInfo.deploymentDate) {
$user.certInfo.deploymentDate = (Get-Date)
$user.certInfo.deploymentDate = (Get-Date -Format "o")

} else {
$user.certInfo | Add-Member -Name 'deploymentDate' -Type NoteProperty -Value (Get-Date)
$user.certInfo | Add-Member -Name 'deploymentDate' -Type NoteProperty -Value (Get-Date -Format "o")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ function Get-CertInfo {
# Convert notAfter property into datetime format
if ($property.notAfter) {
$date = $property.notAfter
$date = $date.replace('GMT', '').Trim()
# $date = $date.replace('GMT', '').Trim()
$date = $date -replace '\s+', ' '
$property.notAfter = [datetime]::ParseExact($date , "MMM d HH:mm:ss yyyy", $null)
$date = ([datetime]::ParseExact($date , "MMM d HH:mm:ss yyyy GMT", $null)).ToUniversalTime()
$property.notAfter = Get-Date $date.ToUniversalTime() -UFormat '+%Y-%m-%dT%H:%M:%S.000Z'
}

$certHash += $property
Expand All @@ -84,9 +85,11 @@ function Get-CertInfo {
switch ($($property.keys)) {
'notAfter' {
$date = $property.notAfter
$date = $date.replace('GMT', '').Trim()
# $date = $date.replace('GMT', '').Trim()
$date = $date -replace '\s+', ' '
$property.notAfter = [datetime]::ParseExact($date , "MMM d HH:mm:ss yyyy", $null)
$date = [datetime]::ParseExact($date , "MMM d HH:mm:ss yyyy GMT", $null)
$property.notAfter = Get-Date $date.ToUniversalTime() -UFormat '+%Y-%m-%dT%H:%M:%S.000Z'

}
'sha1 Fingerprint' {
$property.Values = ($($property.Values)).ToLower().Replace(":", "")
Expand All @@ -108,7 +111,7 @@ function Get-CertInfo {
}

$certHash | Add-Member -Name 'username' -Type NoteProperty -Value $username
$certHash | Add-Member -Name 'generated' -Type NoteProperty -Value ($certFile.LastWriteTime.ToString('MM/dd/yyyy HH:mm:ss'))
$certHash | Add-Member -Name 'generated' -Type NoteProperty -Value (Get-Date $certFile.LastWriteTime.ToUniversalTime() -UFormat '+%Y-%m-%dT%H:%M:%S.000Z')
# Add hash to certObj array if the user is a member of the userGroup
if ($username -in $global:JCRRadiusMembers.username) {
$certObj.add( $certHash) | Out-Null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ function Get-ExpiringCertInfo {
)
begin {
$expiringCerts = New-Object System.Collections.ArrayList
$currentTime = Get-Date
$currentTime = (Get-Date -Format "o")
}
process {
foreach ($cert in $certInfo) {
$certTimespan = New-Timespan -Start $currentTime -End $cert.notAfter
$startDate = [datetime]$currentTime
$endDate = [datetime]$cert.notAfter
$certTimespan = New-Timespan -Start $startDate -End $endDate
# $cert
if ($certTimespan.days -lt 15) {
Write-Debug "$($cert.userName)'s certificate will expire in $($certTimespan.Days) days"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Function Invoke-CommandsRetry {
(($user.commandAssociations) | Where-Object { $_.commandId -eq $command.commandId }).commandPreviouslyRun = $true
(($user.commandAssociations) | Where-Object { $_.commandId -eq $command.commandId }).commandQueued = $true
$user.certInfo.deployed = $true
$user.certInfo.deploymentDate = (get-date)
$user.certInfo.deploymentDate = (Get-Date -Format "o")
Set-UserTable -index $userIndex -certInfoObject $user.certInfo -commandAssociationsObject $user.commandAssociations
# track retried commands
$RetryCommands += $command.commandId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ function Show-GenerationMenu {

if ($Global:expiringCerts) {
Write-Host $(PadCenter -string ' Certs Expiring Soon ' -char '-')
$Global:expiringCerts | Format-Table -Property username, @{name = 'Remaining Days'; expression = { (New-TimeSpan -Start (Get-Date) -End ("$($_.notAfter)")).Days } }, @{name = "Expires On"; expression = { $_.notAfter } }

$Global:expiringCerts | Format-Table -Property username, @{name = 'Remaining Days'; expression = {
(New-TimeSpan -Start (Get-Date -Format "o") -End ([dateTime]("$($_.notAfter)"))).Days
}
}, @{name = "Expires On"; expression = {
[datetime]($_.notAfter)
}
}
}

Write-Host $(PadCenter -string ' User Certificate Generation Options ' -char '-')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function New-JCRSettingsFile {
}
process {
# Define Default Settings for the Config file
$date = Get-Date
$date = (Get-Date).ToUniversalTime()
$config = @{
'globalVars' = @{
'lastUpdate' = @{value = $date; write = $true; copy = $true ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ function Get-JCRGlobalVars {

# get settings file
if ($IsMacOS) {
$lastUpdateTimespan = New-TimeSpan -Start $global:JCRConfig.globalvars.lastupdate -end (Get-Date)
$lastUpdateTimespan = New-TimeSpan -Start $global:JCRConfig.globalvars.lastupdate -end (Get-Date -Format "o")
}
if ($ifWindows) {
$lastUpdateTimespan = New-TimeSpan -Start $global:JCRConfig.globalvars.lastupdate.value -end (Get-Date)
$lastUpdateTimespan = New-TimeSpan -Start $global:JCRConfig.globalvars.lastupdate.value -end (Get-Date -Format "o")
}
if ($lastUpdateTimespan.TotalHours -gt 24) {
$update = $true
Expand Down Expand Up @@ -247,7 +247,7 @@ function Get-JCRGlobalVars {
$Global:JCRRadiusMembers = $radiusMemberList
$Global:JCRCertHash = $certHash
# update the settings date
Set-JCRSettingsFile -globalVarslastUpdate (Get-Date)
Set-JCRSettingsFile -globalVarslastUpdate (Get-Date -Format "o")
# update users.json
Update-JCRUsersJson
}
Expand Down
Loading