Skip to content

Commit

Permalink
Merge pull request #209 from msalle/fix_gct_make_time
Browse files Browse the repository at this point in the history
Replace make_time function to work after 2050
  • Loading branch information
fscheiner authored Jan 21, 2023
2 parents 50fc40b + 8950ef7 commit 200cb06
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 91 deletions.
2 changes: 1 addition & 1 deletion gsi/cert_utils/source/configure.ac
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
AC_PREREQ([2.60])

AC_INIT([globus_gsi_cert_utils], [10.10], [https://github.com/gridcf/gct/issues])
AC_INIT([globus_gsi_cert_utils], [10.11], [https://github.com/gridcf/gct/issues])
AC_CONFIG_MACRO_DIR([m4])
AC_SUBST([MAJOR_VERSION], [${PACKAGE_VERSION%%.*}])
AC_SUBST([MINOR_VERSION], [${PACKAGE_VERSION##*.}])
Expand Down
89 changes: 11 additions & 78 deletions gsi/cert_utils/source/library/globus_gsi_cert_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,109 +171,42 @@ globus_l_gsi_cert_utils_deactivate(void)
#endif

/**
* @brief Convert ASN1_UTCTIME to time_t
* @brief Convert ASN1_TIME to time_t
* @ingroup globus_gsi_cert_utils
* @details
* Convert a ASN1_UTCTIME structure to a time_t
* Convert a ASN1_TIME structure to a time_t
*
* @param ctm
* The ASN1_UTCTIME to convert
* The ASN1_TIME to convert
* @param newtime
* The converted time
*
* @return
* GLOBUS_SUCCESS or an error captured in a globus_result_t
* GLOBUS_SUCCESS or GLOBUS_FAILURE on error
*/
globus_result_t
globus_gsi_cert_utils_make_time(
const ASN1_UTCTIME * ctm,
const ASN1_TIME * ctm,
time_t * newtime)
{
char * str;
time_t offset;
char buff1[24];
char * p;
int i;
struct tm tm;
int pday, psec;
globus_result_t result;
static char * _function_name_ =
"globus_gsi_cert_utils_make_time";

GLOBUS_I_GSI_CERT_UTILS_DEBUG_ENTER;

p = buff1;
i = ctm->length;
str = (char *)ctm->data;
if ((i < 11) || (i > 17))
{
*newtime = 0;
}
memcpy(p,str,10);
p += 10;
str += 10;

if ((*str == 'Z') || (*str == '-') || (*str == '+'))
if (ASN1_TIME_diff(&pday, &psec, NULL, ctm))
{
*(p++)='0'; *(p++)='0';
*newtime = time(NULL)+pday*86400L+psec;
result = GLOBUS_SUCCESS;
}
else
{
*(p++)= *(str++); *(p++)= *(str++);
}
*(p++)='Z';
*(p++)='\0';

if (*str == 'Z')
{
offset=0;
}
else
{
if ((*str != '+') && (str[5] != '-'))
{
*newtime = 0;
}
offset=((str[1]-'0')*10+(str[2]-'0'))*60;
offset+=(str[3]-'0')*10+(str[4]-'0');
if (*str == '-')
{
offset=-offset;
}
}

tm.tm_isdst = 0;
tm.tm_year = (buff1[0]-'0')*10+(buff1[1]-'0');

if (tm.tm_year < 70)
{
tm.tm_year+=100;
*newtime = 0;
result = GLOBUS_FAILURE;
}

tm.tm_mon = (buff1[2]-'0')*10+(buff1[3]-'0')-1;
tm.tm_mday = (buff1[4]-'0')*10+(buff1[5]-'0');
tm.tm_hour = (buff1[6]-'0')*10+(buff1[7]-'0');
tm.tm_min = (buff1[8]-'0')*10+(buff1[9]-'0');
tm.tm_sec = (buff1[10]-'0')*10+(buff1[11]-'0');

/*
* mktime assumes local time, so subtract off
* timezone, which is seconds off of GMT. first
* we need to initialize it with tzset() however.
*/

tzset();

#if defined(HAVE_TIME_T_TIMEZONE)
*newtime = (mktime(&tm) + offset*60*60 - timezone);
#elif defined(HAVE_TIME_T__TIMEZONE)
*newtime = (mktime(&tm) + offset*60*60 - _timezone);
#elif defined(HAVE_TIMEGM)
*newtime = (timegm(&tm) + offset*60*60);
#else
*newtime = (mktime(&tm) + offset*60*60);
#endif

result = GLOBUS_SUCCESS;
GLOBUS_I_GSI_CERT_UTILS_DEBUG_EXIT;

return result;
Expand Down
2 changes: 1 addition & 1 deletion gsi/cert_utils/source/library/globus_gsi_cert_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ globus_module_descriptor_t globus_i_gsi_cert_utils_module;

globus_result_t
globus_gsi_cert_utils_make_time(
const ASN1_UTCTIME * ctm,
const ASN1_TIME * ctm,
time_t * newtime);

globus_result_t
Expand Down
2 changes: 1 addition & 1 deletion gsi/credential/source/configure.ac
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
AC_PREREQ([2.60])

AC_INIT([globus_gsi_credential],[8.3],[https://github.com/gridcf/gct/issues])
AC_INIT([globus_gsi_credential],[8.4],[https://github.com/gridcf/gct/issues])
AC_CONFIG_MACRO_DIR([m4])
AC_SUBST([MAJOR_VERSION], [${PACKAGE_VERSION%%.*}])
AC_SUBST([MINOR_VERSION], [${PACKAGE_VERSION##*.}])
Expand Down
9 changes: 1 addition & 8 deletions gsi/credential/source/library/globus_gsi_cred_handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,6 @@ globus_gsi_cred_get_lifetime(
globus_gsi_cred_handle_t cred_handle,
time_t * lifetime)
{
time_t time_now;
ASN1_UTCTIME * asn1_time;
globus_result_t result;

GLOBUS_I_GSI_CRED_DEBUG_ENTER;
Expand All @@ -413,12 +411,7 @@ globus_gsi_cred_get_lifetime(
goto error_exit;
}

asn1_time = ASN1_UTCTIME_new();
X509_gmtime_adj(asn1_time, 0);
globus_gsi_cert_utils_make_time(asn1_time, &time_now);

*lifetime = cred_handle->goodtill - time_now;
ASN1_UTCTIME_free(asn1_time);
*lifetime = cred_handle->goodtill - time(NULL);

result = GLOBUS_SUCCESS;

Expand Down
6 changes: 6 additions & 0 deletions packaging/debian/globus-gsi-cert-utils/debian/changelog.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
globus-gsi-cert-utils (10.11-1+gct.@distro@) @distro@; urgency=medium

* Fix parsing of ASN1 timestamps

-- Mischa Sallé <[email protected]> Thu, 19 Jan 2023 14:58:23 +0100

globus-gsi-cert-utils (10.10-1+gct.@distro@) @distro@; urgency=medium

* Can't use non-existing or non-accessible files as source for random
Expand Down
6 changes: 6 additions & 0 deletions packaging/debian/globus-gsi-credential/debian/changelog.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
globus-gsi-credential (8.4-1+gct.@distro@) @distro@; urgency=medium

* Greatly simplify getting current time

-- Mischa Sallé <[email protected]> Thu, 19 Jan 2023 14:55:00 +0100

globus-gsi-credential (8.3-1+gct.@distro@) @distro@; urgency=medium

* Typo fixes
Expand Down
5 changes: 4 additions & 1 deletion packaging/fedora/globus-gsi-cert-utils.spec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Name: globus-gsi-cert-utils
%global soname 0
%global _name %(echo %{name} | tr - _)
Version: 10.10
Version: 10.11
Release: 1%{?dist}
Summary: Grid Community Toolkit - Globus GSI Cert Utils Library

Expand Down Expand Up @@ -180,6 +180,9 @@ make %{?_smp_mflags} check VERBOSE=1
%doc %{_pkgdocdir}/GLOBUS_LICENSE

%changelog
* Thu Jan 19 2023 Mischa Salle <[email protected]> - 10.11-1
- Fix parsing of ASN1 timestamps

* Sat May 07 2022 Mattias Ellert <[email protected]> - 10.10-1
- Can't use non-existing or non-accessible files as source for random data

Expand Down
5 changes: 4 additions & 1 deletion packaging/fedora/globus-gsi-credential.spec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Name: globus-gsi-credential
%global soname 1
%global _name %(echo %{name} | tr - _)
Version: 8.3
Version: 8.4
Release: 1%{?dist}
Summary: Grid Community Toolkit - Globus GSI Credential Library

Expand Down Expand Up @@ -137,6 +137,9 @@ rm $RPM_BUILD_ROOT%{_libdir}/*.la
%doc %{_pkgdocdir}/GLOBUS_LICENSE

%changelog
* Thu Jan 19 2023 Mischa Salle <[email protected]> - 8.4-1
- Greatly simplify getting current time

* Fri Aug 20 2021 Mattias Ellert <[email protected]> - 8.3-1
- Typo fixes

Expand Down

0 comments on commit 200cb06

Please sign in to comment.