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

date_epoc fails to convert date from cyrilic #818

Open
mslavkov opened this issue Nov 7, 2023 · 4 comments · May be fixed by #841
Open

date_epoc fails to convert date from cyrilic #818

mslavkov opened this issue Nov 7, 2023 · 4 comments · May be fixed by #841
Assignees
Labels

Comments

@mslavkov
Copy link

mslavkov commented Nov 7, 2023

Describe the bug
When locale is set to Bulgarian (bg_BG.UTF-8) date is unable to convert the string to check the certificate validity.
...
local cert is for domains: www.example.tld
Failed conversion of Feb 5 05:16:58 2024 GMT'' using format %b %d %T %Y %Z''
date: illegal time format
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
[-f fmt date | [[[[[cc]yy]mm]dd]HH]MM[.ss]] [+format]

www.example.tld: certificate needs renewal
...

After adding LC_ALL=C in front of date in date_epoc function:

...
local cert is valid until Feb 5 05:25:12 2024 GMT

local cert is for domains: www.example.tld
www.example.tld: certificate is valid for more than 30 days (until Feb 5 05:25:12 2024 GMT)
...

To Reproduce
On bsd system set locale to Bulgarian (bg_BG.UTF-8) and try to renew cert.

Expected behavior
local cert is valid until Feb 5 05:25:12 2024 GMT

local cert is for domains: www.example.tld
www.example.tld: certificate is valid for more than 30 days (until Feb 5 05:25:12 2024 GMT)

Operating system (please complete the following information):

  • OS: FreeBSD
  • Bash Version 5.2.15 (GNU)

Additional context
Add any other context about the problem here.

@mslavkov
Copy link
Author

mslavkov commented Nov 7, 2023

diff --git a/getssl b/getssl
index 30d8837..607044c 100755
--- a/getssl
+++ b/getssl
@@ -1256,14 +1256,14 @@ create_order() {

 date_epoc() { # convert the date into epoch time
   if [[ "$os" == "bsd" ]]; then
-    date -j -f "%b %d %T %Y %Z" "$1" +%s
+    LC_ALL=C date -j -f "%b %d %T %Y %Z" "$1" +%s
   elif [[ "$os" == "mac" ]]; then
-    date -j -f "%b %d %T %Y %Z" "$1" +%s
+    LC_ALL=C date -j -f "%b %d %T %Y %Z" "$1" +%s
   elif [[ "$os" == "busybox" ]]; then
     de_ld=$(echo "$1" | awk '{print $1 " " $2 " " $3 " " $4}')
-    date -D "%b %d %T %Y" -d "$de_ld" +%s
+    LC_ALL=C date -D "%b %d %T %Y" -d "$de_ld" +%s
   else
-    date -d "$1" +%s
+    LC_ALL=C date -d "$1" +%s
   fi

 }

This is how I got it to work on my FreeBSD machine.

@timkimber timkimber self-assigned this Nov 24, 2023
@timkimber timkimber added the bug label Nov 24, 2023
@timkimber
Copy link
Member

Hi @mslavkov

Thanks for this, and especially thanks for posting a fix. I'll add some tests and merge that in.

Note: I currently have very little time to work on getssl due to work commitments

@tlhackque
Copy link
Contributor

There are probably other dependencies on locale. This may be the tip of an iceberg.

Might be safer to save locale at startup and set (and export) LC_ALL="C" globally. If there are any cases where the current locale is needed, special case them. Will probably get in trouble either way, but system tools like getssl tend to be happier in the C locale. "It's not fair, but it's history."

tlhackque added a commit to tlhackque/getssl that referenced this issue Mar 24, 2024
FIXES srvrco#818 (I hope).

in srvrco#818, @mslavkov reported that date fails in the BG.UTF-8 locale, but
that LC_ALL=C resolved the issue.


Since we already export LANG=C, that would seem to indicate that LC_TIME
is overriding it.  LC_ALL is the safer (stronger) choice.
@tlhackque
Copy link
Contributor

Actually, getssl does `export LANG=C. I even was the one who did it (for another reason) in this commit.

So you must have LC_TIME set in your environment.

I've switchedtoLC_ALL` in my current PR (#841), which should solve this and any cousin bugs.

tlhackque added a commit to tlhackque/getssl that referenced this issue Apr 12, 2024
FIXES srvrco#818 (I hope).

in srvrco#818, @mslavkov reported that date fails in the BG.UTF-8 locale, but
that LC_ALL=C resolved the issue.


Since we already export LANG=C, that would seem to indicate that LC_TIME
is overriding it.  LC_ALL is the safer (stronger) choice.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants