int main(){ int days; days = numberOfDays(2, 2016); if(days < 0) printError(days); else printf("February 2016 has %d days.\n", days); days = remainingDays(5, 3, 2012); if(days < 0) printError(days); else printf("There are %d days until the end of the month at 5 March, 2012.\n", days); days = daysBtwDatesInAYear(2, 1, 3, 6, 2012); if(days < 0) printError(days); else printf("There are %d days between 2 January and 3 June in 2012.\n", days); days = daysBtwDates(2, 1, 2000, 5, 2, 2018); if(days < 0) printError(days); else printf("There are %d days between 2, January 2000 and 5 February 2018.\n", days); days = daysBtwDates(29, 2, 2011, 5, 3, 2015); if(days < 0) printError(days); else printf("%d days exists.\n", days); days = daysBtwDates(1, 2, 2005, 2, 1, 2005); if(days < 0) printError(days); else printf("%d days exists.\n", days); return 0; }
string Certificate::remainingTime( void ){ if ( m_behaviour == BEHAVIOR_NONE ) return( "SSL NOT INITIALIZED" ); if (( m_behaviour == BEHAVIOR_TRY ) && ( m_status == Certificate::STATUS_FAILED )) return( "Not Applicable: No Certificate Found" ); if ( m_status == Certificate::STATUS_FAILED ){ LOG(Log::ERR) << "certificate status failed, a problem occurred"; return( "CERTIFICATE STATUS FAILED" ); } if ( m_status == Certificate::STATUS_UNKNOWN ){ return( "CERTIFICATE STATUS UNKNOWN" ); } remainingValidityTime(); stringstream xx; xx << remainingDays() << string("days ") << setfill('0') << setw(2) << remainingHours() << ":" << setfill('0') << setw(2) << remainingMins() << ":" << setfill('0') << setw(2) << remainingSecs(); return( xx.str() ); }
int daysBtwDatesInAYear(int day1, int month1, int day2, int month2, int year){ int i; int totalDays = 0; if(month1 == month2){ /*dates are in the same month*/ if(day2 < day1) return WRONG_DATE_ORDER; return day2-day1; } else if(month2 > month1){ /*dates are in different months*/ /*days in the months between*/ for(i=month1+1; i<month2; i++) totalDays += numberOfDays(i, year); } else return WRONG_DATE_ORDER; /*add remaining days of the first date to the new month and the days in the month of the second date*/ totalDays = totalDays + remainingDays(day1, month1, year) + day2; return totalDays; }
/// loads one PEM file with one certificate, no chain, no CA int Certificate::loadCertificateFromFile( void ) { const int certificateFileCheckResult = validateCertificateFilename(m_certfn); if(certificateFileCheckResult < 0) return certificateFileCheckResult; m_ssl = SSL_new( SSL_CTX_new( SSLv23_method() ) ); SSL_use_certificate_file( m_ssl, m_certfn.c_str(), m_type); // or like this, including a CA // SSL_CTX_use_certificate_chain_file( _ssl_ctx, fname.c_str() ); X509 *x509crt = SSL_get_certificate( m_ssl ); // validity format is here: // https://github.com/openssl/openssl/commit/f48b83b4fb7d6689584cf25f61ca63a4891f5b11 // in fact these are strings in UTC format, need to convert them into time_t to become useful m_time_end = _timeASN1toTIME_T( x509crt->cert_info->validity->notAfter ); remainingValidityTime(); LOG(Log::INF) << " certificate remaining time= " << remainingDays() << "days " << remainingHours() << ":" << remainingMins() << ":" << remainingSecs(); return( 0 ); }
int Certificate::remainingSecs( void ) const { return m_remaining_validity_in_seconds - (remainingDays()*86400) - (remainingHours()*3600) - (remainingMins()*60);; }
int Certificate::remainingHours( void ) const { return (m_remaining_validity_in_seconds - (remainingDays()*86400) ) / 3600; }