static int GetOcspStatus(WOLFSSL_OCSP* ocsp, OcspRequest* request, OcspEntry* entry, CertStatus** status, buffer* responseBuffer) { int ret = OCSP_INVALID_STATUS; WOLFSSL_ENTER("GetOcspStatus"); *status = NULL; if (LockMutex(&ocsp->ocspLock) != 0) { WOLFSSL_LEAVE("CheckCertOCSP", BAD_MUTEX_E); return BAD_MUTEX_E; } for (*status = entry->status; *status; *status = (*status)->next) if ((*status)->serialSz == request->serialSz && !XMEMCMP((*status)->serial, request->serial, (*status)->serialSz)) break; if (responseBuffer && *status && !(*status)->rawOcspResponse) { /* force fetching again */ ret = OCSP_INVALID_STATUS; } else if (*status) { if (ValidateDate((*status)->thisDate, (*status)->thisDateFormat, BEFORE) && ((*status)->nextDate[0] != 0) && ValidateDate((*status)->nextDate, (*status)->nextDateFormat, AFTER)) { ret = xstat2err((*status)->status); if (responseBuffer) { responseBuffer->buffer = (byte*)XMALLOC( (*status)->rawOcspResponseSz, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (responseBuffer->buffer) { responseBuffer->length = (*status)->rawOcspResponseSz; XMEMCPY(responseBuffer->buffer, (*status)->rawOcspResponse, (*status)->rawOcspResponseSz); } } } } UnLockMutex(&ocsp->ocspLock); return ret; }
/// <summary> /// 得到一个月份的天数 /// </summary> /// <param name="year">年</param> /// <param name="month">月</param> /// <returns>返回该年该月的总天数,如果给定的参数有错误,则返回0</returns> int CDateTime::GetDaysOfMonth(int year, int month) { if (!ValidateDate(year, month)) { return 0; } if (month == 4 || month == 6 || month == 9 || month == 11) { return 30; } else if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) { return 31; } else if (2 == month) { if (IsLeapYear(year))//如果是闰年 { return 29; } else { return 28; } } return 0; }
/// <summary> /// 判定给定的年月日是否是一个有效的日期 /// </summary> /// <param name="year">给定的年份</param> /// <param name="month">给定的月份</param> /// <param name="day">给定的日子</param> /// <returns>true:给定的年月日是一个有效的日期。false:不是一个有效的日期。</returns> bool CDateTime::ValidateDate(int year, int month, int day) { if (!ValidateDate(year, month)) return false; if ((day < 1) || (day > GetDaysOfMonth(year, month))) return false; return true; }
/**************************************************************** * void SetDate(unsigned short month, unsigned short day, unsigned short year); * Parameters: unsigned short month //month * unsigned short day //day * unsigned short year //year * Return: none ***************************************************************/ void Date::SetDate(unsigned short month, unsigned short day, unsigned short year) { if(ValidateDate(month, day, year)) { dateMonth = month; dateDay = day; dateYear = year; } else { cout << "\nThat date is invalid" << endl; } }
/************************************************************************* * used to get the date from the user and use the validate methods to * check if the input is valid * _______________________________________________________________________ * month * day * year * _______________________________________________________________________ * returns nothing *************************************************************************/ void Date::GetDate(unsigned short &month, unsigned short &day, unsigned short &year) { // cout << "enter the month: "; // cin >> month; // cin.ignore(1000,'\n'); // cout << "enter the day: "; // cin >> day; // cin.ignore(1000,'\n'); // cout << "enter the year: "; // cin >> year; // cin.ignore(1000,'\n'); ValidateYear(year); ValidateMonth(month); ValidateDay(month, day, year); ValidateDate(month, day, year); }
// process a Date, either BEFORE or AFTER void CertDecoder::GetDate(DateType dt) { if (source_.GetError().What()) return; byte b = source_.next(); if (b != UTC_TIME && b != GENERALIZED_TIME) { source_.SetError(TIME_E); return; } word32 length = GetLength(source_); if (source_.IsLeft(length) == false) return; byte date[MAX_DATE_SZ]; if (length > MAX_DATE_SZ || length < MIN_DATE_SZ) { source_.SetError(DATE_SZ_E); return; } memcpy(date, source_.get_current(), length); source_.advance(length); if (!ValidateDate(date, b, dt) && verify_) { if (dt == BEFORE) source_.SetError(BEFORE_DATE_E); else source_.SetError(AFTER_DATE_E); } // save for later use if (dt == BEFORE) { memcpy(beforeDate_, date, length); beforeDate_[length] = 0; beforeDateType_= b; } else { // after memcpy(afterDate_, date, length); afterDate_[length] = 0; afterDateType_= b; } }
int CheckCertOCSP(CYASSL_OCSP* ocsp, DecodedCert* cert) { byte* ocspReqBuf = NULL; int ocspReqSz = 2048; byte* ocspRespBuf = NULL; OcspRequest ocspRequest; OcspResponse ocspResponse; int result = -1; OCSP_Entry* ocspe; CertStatus* certStatus = NULL; CertStatus newStatus; const char *url; int urlSz; CYASSL_ENTER("CheckCertOCSP"); if (LockMutex(&ocsp->ocspLock) != 0) { CYASSL_LEAVE("CheckCertOCSP", BAD_MUTEX_E); return BAD_MUTEX_E; } ocspe = ocsp->ocspList; while (ocspe) { if (XMEMCMP(ocspe->issuerHash, cert->issuerHash, SHA_DIGEST_SIZE) == 0 && XMEMCMP(ocspe->issuerKeyHash, cert->issuerKeyHash, SHA_DIGEST_SIZE) == 0) break; else ocspe = ocspe->next; } if (ocspe == NULL) { ocspe = (OCSP_Entry*)XMALLOC(sizeof(OCSP_Entry), NULL, DYNAMIC_TYPE_OCSP_ENTRY); if (ocspe != NULL) { InitOCSP_Entry(ocspe, cert); ocspe->next = ocsp->ocspList; ocsp->ocspList = ocspe; } else { UnLockMutex(&ocsp->ocspLock); CYASSL_LEAVE("CheckCertOCSP", MEMORY_ERROR); return MEMORY_ERROR; } } else { certStatus = ocspe->status; while (certStatus) { if (certStatus->serialSz == cert->serialSz && XMEMCMP(certStatus->serial, cert->serial, cert->serialSz) == 0) break; else certStatus = certStatus->next; } } if (certStatus != NULL) { if (!ValidateDate(certStatus->thisDate, certStatus->thisDateFormat, BEFORE) || (certStatus->nextDate[0] == 0) || !ValidateDate(certStatus->nextDate, certStatus->nextDateFormat, AFTER)) { CYASSL_MSG("\tinvalid status date, looking up cert"); } else { result = xstat2err(certStatus->status); UnLockMutex(&ocsp->ocspLock); CYASSL_LEAVE("CheckCertOCSP", result); return result; } } UnLockMutex(&ocsp->ocspLock); if (ocsp->cm->ocspUseOverrideURL) { url = ocsp->cm->ocspOverrideURL; if (url != NULL && url[0] != '\0') urlSz = (int)XSTRLEN(url); else return OCSP_NEED_URL; } else if (cert->extAuthInfoSz != 0 && cert->extAuthInfo != NULL) { url = (const char *)cert->extAuthInfo; urlSz = cert->extAuthInfoSz; } else { /* cert doesn't have extAuthInfo, assuming CERT_GOOD */ return 0; } ocspReqBuf = (byte*)XMALLOC(ocspReqSz, NULL, DYNAMIC_TYPE_IN_BUFFER); if (ocspReqBuf == NULL) { CYASSL_LEAVE("CheckCertOCSP", MEMORY_ERROR); return MEMORY_ERROR; } InitOcspRequest(&ocspRequest, cert, ocsp->cm->ocspSendNonce, ocspReqBuf, ocspReqSz); ocspReqSz = EncodeOcspRequest(&ocspRequest); if (ocsp->cm->ocspIOCb) result = ocsp->cm->ocspIOCb(ocsp->cm->ocspIOCtx, url, urlSz, ocspReqBuf, ocspReqSz, &ocspRespBuf); if (result >= 0 && ocspRespBuf) { XMEMSET(&newStatus, 0, sizeof(CertStatus)); InitOcspResponse(&ocspResponse, &newStatus, ocspRespBuf, result); OcspResponseDecode(&ocspResponse); if (ocspResponse.responseStatus != OCSP_SUCCESSFUL) result = OCSP_LOOKUP_FAIL; else { if (CompareOcspReqResp(&ocspRequest, &ocspResponse) == 0) { result = xstat2err(ocspResponse.status->status); if (LockMutex(&ocsp->ocspLock) != 0) result = BAD_MUTEX_E; else { if (certStatus != NULL) /* Replace existing certificate entry with updated */ XMEMCPY(certStatus, &newStatus, sizeof(CertStatus)); else { /* Save new certificate entry */ certStatus = (CertStatus*)XMALLOC(sizeof(CertStatus), NULL, DYNAMIC_TYPE_OCSP_STATUS); if (certStatus != NULL) { XMEMCPY(certStatus, &newStatus, sizeof(CertStatus)); certStatus->next = ocspe->status; ocspe->status = certStatus; ocspe->totalStatus++; } } UnLockMutex(&ocsp->ocspLock); } } else result = OCSP_LOOKUP_FAIL; } } else result = OCSP_LOOKUP_FAIL; if (ocspReqBuf != NULL) XFREE(ocspReqBuf, NULL, DYNAMIC_TYPE_IN_BUFFER); if (ocspRespBuf != NULL && ocsp->cm->ocspRespFreeCb) ocsp->cm->ocspRespFreeCb(ocsp->cm->ocspIOCtx, ocspRespBuf); CYASSL_LEAVE("CheckCertOCSP", result); return result; }
/* Is the cert ok with CRL, return 0 on success */ int CheckCertCRL(WOLFSSL_CRL* crl, DecodedCert* cert) { CRL_Entry* crle; int foundEntry = 0; int ret = 0; WOLFSSL_ENTER("CheckCertCRL"); if (LockMutex(&crl->crlLock) != 0) { WOLFSSL_MSG("LockMutex failed"); return BAD_MUTEX_E; } crle = crl->crlList; while (crle) { if (XMEMCMP(crle->issuerHash, cert->issuerHash, CRL_DIGEST_SIZE) == 0) { int doNextDate = 1; WOLFSSL_MSG("Found CRL Entry on list"); WOLFSSL_MSG("Checking next date validity"); #ifdef WOLFSSL_NO_CRL_NEXT_DATE if (crle->nextDateFormat == ASN_OTHER_TYPE) doNextDate = 0; /* skip */ #endif if (doNextDate && !ValidateDate(crle->nextDate, crle->nextDateFormat, AFTER)) { WOLFSSL_MSG("CRL next date is no longer valid"); ret = ASN_AFTER_DATE_E; } else foundEntry = 1; break; } crle = crle->next; } if (foundEntry) { RevokedCert* rc = crle->certs; while (rc) { if (XMEMCMP(rc->serialNumber, cert->serial, rc->serialSz) == 0) { WOLFSSL_MSG("Cert revoked"); ret = CRL_CERT_REVOKED; break; } rc = rc->next; } } UnLockMutex(&crl->crlLock); if (foundEntry == 0) { WOLFSSL_MSG("Couldn't find CRL for status check"); ret = CRL_MISSING; if (crl->cm->cbMissingCRL) { char url[256]; WOLFSSL_MSG("Issuing missing CRL callback"); url[0] = '\0'; if (cert->extCrlInfoSz < (int)sizeof(url) -1 ) { XMEMCPY(url, cert->extCrlInfo, cert->extCrlInfoSz); url[cert->extCrlInfoSz] = '\0'; } else { WOLFSSL_MSG("CRL url too long"); } crl->cm->cbMissingCRL(url); } } return ret; }
int CyaSSL_OCSP_Lookup_Cert(CYASSL_OCSP* ocsp, DecodedCert* cert) { byte* ocspReqBuf = NULL; int ocspReqSz = 2048; byte* ocspRespBuf = NULL; OcspRequest ocspRequest; OcspResponse ocspResponse; int result = 0; OCSP_Entry* ocspe; CertStatus* certStatus; const char *url; int urlSz; /* If OCSP lookups are disabled, return success. */ if (!ocsp->enabled) { CYASSL_MSG("OCSP lookup disabled, assuming CERT_GOOD"); return 0; } ocspe = find_ocsp_entry(ocsp, cert); if (ocspe == NULL) { CYASSL_MSG("alloc OCSP entry failed"); return MEMORY_ERROR; } certStatus = find_cert_status(ocspe, cert); if (certStatus == NULL) { CYASSL_MSG("alloc OCSP cert status failed"); return MEMORY_ERROR; } if (certStatus->status != -1) { if (!ValidateDate(certStatus->thisDate, certStatus->thisDateFormat, BEFORE) || (certStatus->nextDate[0] == 0) || !ValidateDate(certStatus->nextDate, certStatus->nextDateFormat, AFTER)) { CYASSL_MSG("\tinvalid status date, looking up cert"); certStatus->status = -1; } else { CYASSL_MSG("\tusing cached status"); result = xstat2err(certStatus->status); return result; } } if (ocsp->useOverrideUrl) { if (ocsp->overrideUrl[0] != '\0') { url = ocsp->overrideUrl; urlSz = (int)XSTRLEN(url); } else return OCSP_NEED_URL; } else if (cert->extAuthInfoSz != 0 && cert->extAuthInfo != NULL) { url = (const char *)cert->extAuthInfo; urlSz = cert->extAuthInfoSz; } else { CYASSL_MSG("\tcert doesn't have extAuthInfo, assuming CERT_GOOD"); return 0; } ocspReqBuf = (byte*)XMALLOC(ocspReqSz, NULL, DYNAMIC_TYPE_IN_BUFFER); if (ocspReqBuf == NULL) { CYASSL_MSG("\talloc OCSP request buffer failed"); return MEMORY_ERROR; } InitOcspRequest(&ocspRequest, cert, ocsp->useNonce, ocspReqBuf, ocspReqSz); ocspReqSz = EncodeOcspRequest(&ocspRequest); if (ocsp->CBIOOcsp) { result = ocsp->CBIOOcsp(ocsp->IOCB_OcspCtx, url, urlSz, ocspReqBuf, ocspReqSz, &ocspRespBuf); } if (result >= 0 && ocspRespBuf) { InitOcspResponse(&ocspResponse, certStatus, ocspRespBuf, result); OcspResponseDecode(&ocspResponse); if (ocspResponse.responseStatus != OCSP_SUCCESSFUL) { CYASSL_MSG("OCSP Responder failure"); result = OCSP_LOOKUP_FAIL; } else { if (CompareOcspReqResp(&ocspRequest, &ocspResponse) == 0) { result = xstat2err(ocspResponse.status->status); } else { CYASSL_MSG("OCSP Response incorrect for Request"); result = OCSP_LOOKUP_FAIL; } } } else { result = OCSP_LOOKUP_FAIL; } if (ocspReqBuf != NULL) { XFREE(ocspReqBuf, NULL, DYNAMIC_TYPE_IN_BUFFER); } if (ocspRespBuf != NULL && ocsp->CBIOOcspRespFree) { ocsp->CBIOOcspRespFree(ocsp->IOCB_OcspCtx, ocspRespBuf); } return result; }
void CContractTerm::OnOK() { GAL_ERROR Error; Arb_date TempDate; GAL_CONTRACT lpContractObject; int iWaive; int iWaiveUnmetObligationNrc; int iValidDate ; CString m_TermCharge; // Get data from screen and put it into the class if (!UpdateData(TRUE)) return; m_aeTerminateDate.GetWindowText(m_sTerminateDate); m_aecTerminateCharge.GetWindowText(m_TermCharge); iValidDate = ValidateDate(LPCTSTR(m_sTerminateDate), TRUE, /* date is required */ //For CAMqa72615 Date converion for Arabic // m_iDateFmt); ArbI18N::GetSysDateFmt()); if ( iValidDate != ABP_SUCCESS || m_sTerminateDate.Find(' ') != -1 ) { CGuiMsg::GuiMessage( GUIMSG_TERMINATION_DATE_INVALID); m_aeTerminateDate.SetFocus(); return; } zero_Arbdate(&TempDate); guiSetDate(*this, TempDate, (LPCTSTR)m_sTerminateDate ); if ((Arbdate_compare(&TempDate, &TerminateInfo.end_dt) ==1) && (!Arbdate_is_null(&TerminateInfo.end_dt)) && (!m_sTerminateDate.IsEmpty()) ) { CGuiMsg::GuiMessage( GUIMSG_TERMINATION_DATE_BEFORE_CURRENT_TERMINATION_DATE); return; } if (Arbdate_compare(&TempDate, &TerminateInfo.start_dt) == -1) { CGuiMsg::GuiMessage( GUIMSG_TERMINATION_DATE_EARLY_AFTER_CONTRACT_START_DATE); return; } //===CAMqa66118===For historic contracts get Prev Eval Date and Next Eval Date. Arb_date adtPreEvalDate; Arb_date adtNextEvalDate; if ((TerminateInfo.contract_category == CONTRACT_CAT_HIST_DISCOUNT) || (TerminateInfo.contract_category == CONTRACT_CAT_HIST_PAYBACK)) { //get Prev Eval date and Next eval date from DB if (galSelectContractEvalDates(m_hAPI, TerminateInfo.tracking_id, TerminateInfo.tracking_id_serv, &adtPreEvalDate, &adtNextEvalDate, &Error) == GAL_FAILURE) { GuiError(__FILE__, __LINE__, "Could not select Prev & Next Eval Date."); return; } //For Historic Contracts Check That termination date should not be less than or equal to Prev Eval date. if (Arbdate_compare(&TempDate, &adtPreEvalDate) == -1) { CGuiMsg::GuiMessage( GUIMSG_TERMINATION_DATE_EARLY_AFTER_CONTRACT_START_DATE); return; } //for historic contracts set next eval date as termination date if termination date is less than next eval date. /*DENqa40286 Begin This check is done in CUSTOMER_CONTRACT_VIEW table's trigger*/ /* if (Arbdate_compare(&adtNextEvalDate, &TempDate) == -1) //set next eval date as termination date //CAMqa80404 Arbdate_copy(&TerminateInfo.end_dt, &adtNextEvalDate); else guiSetDate(*this, TerminateInfo.end_dt, m_sTerminateDate ); DENqa40286 End */ } //CAMqa80404 guiSetDate(*this, TerminateInfo.end_dt, m_sTerminateDate ); if(m_bTerminateWaive.GetCheck() == 1) // if the button is checked iWaive = 1; else // if the button is not checked, indetermined, or in other status iWaive = 0; if(m_cWaiveUnmetObligationNrc.GetCheck() == 1) // if the waive unmet obligation nrc button is checked iWaiveUnmetObligationNrc = 1; else iWaiveUnmetObligationNrc = 0; lpContractObject = galNewContract(); if (galSetContract_tracking_id(lpContractObject, TerminateInfo.tracking_id, &Error) != GAL_SUCCESS) { GuiError(__FILE__, __LINE__, "galSetContract_tracking_id() failed."); galDeleteObjects(lpContractObject); return; } if (galSetContract_tracking_id_serv(lpContractObject, TerminateInfo.tracking_id_serv, &Error) != GAL_SUCCESS) { GuiError(__FILE__, __LINE__, "galSetContract_tracking_id_serv() failed."); galDeleteObjects(lpContractObject); return; } if (galSetContract_account_no(lpContractObject, TerminateInfo.account_no, &Error) != GAL_SUCCESS) { GuiError(__FILE__, __LINE__, "galSetContract_account_id() failed."); galDeleteObjects(lpContractObject); return; } if (galSetContract_contract_id(lpContractObject, TerminateInfo.contract_id, &Error) != GAL_SUCCESS) { GuiError(__FILE__, __LINE__, "galSetContract_contract_id() failed."); galDeleteObjects(lpContractObject); return; } if (galSetContract_start_dt(lpContractObject, &TerminateInfo.start_dt, &Error) != GAL_SUCCESS) { GuiError(__FILE__, __LINE__, "galSetContract_start_dt() failed."); galDeleteObjects(lpContractObject); return; } if (galSetContract_end_dt(lpContractObject, &TerminateInfo.end_dt, &Error) != GAL_SUCCESS) { GuiError(__FILE__, __LINE__, "galSetContract_end_dt() failed."); galDeleteObjects(lpContractObject); return; } if (galSetContract_termination_type_id_nrc(lpContractObject, TerminateInfo.type_id_nrc, &Error) != GAL_SUCCESS) { GuiError(__FILE__, __LINE__, "galSetContract_termination_type_id_nrc() failed."); galDeleteObjects(lpContractObject); return; } if (galSetContract_commitment_amount(lpContractObject, (const Arb_numeric *)m_aecTerminateCharge, &Error) != GAL_SUCCESS) { GuiError(__FILE__, __LINE__, "galSetContract_commitment_amount() failed."); galDeleteObjects(lpContractObject); return; } if (galTerminateContract(m_hAPI, lpContractObject, iWaive, iWaiveUnmetObligationNrc, &Error) == GAL_FAILURE) { GuiError(__FILE__, __LINE__, "Could not terminate contract."); } galDeleteObjects(lpContractObject); UpdateData(FALSE); m_aeTerminateDate.SetWindowText(m_sTerminateDate); CDialog::OnOK(); }
void CModiDueDate::OnOK() { GAL_ERROR Error; GAL_BALANCESUM lpBalanceSumObject = galNewBalanceSum(); GAL_BALANCELINEITEM lpOpenItemObject = galNewBalanceLineItem(); Arb_date dtPpddDate; CString DueDateString; int iValidDate; // If csr extered an empty string, make it to be null. // Otherwise sybase default to 01/01/00. /*DENqa09146 Begin */ if (!UpdateData(TRUE)) return; /*DENqa09146 End */ m_aeDueDate.GetWindowText(DueDateString); iValidDate = ValidateDate(LPCTSTR(DueDateString), TRUE, /* date is required */ //For CAMqa72615 Date converion for Arabic // m_iDateFmt); ArbI18N::GetSysDateFmt()); if ( iValidDate != ABP_SUCCESS || DueDateString.Find(' ') != -1 ) { CGuiMsg::GuiMessage( GUIMSG_DATE_INVALID); m_aeDueDate.SetFocus(); return; } if (!DueDateString.IsEmpty()) { guiSetDate(*this, dtPpddDate, DueDateString); if (m_iInvoiceMode == 0) { if (galSetBalanceSum_ppdd_date(lpBalanceSumObject, &dtPpddDate, &Error) != GAL_SUCCESS) { GuiError(__FILE__, __LINE__, "Could not set ppdd_date."); return; } } else { if (galSetBalanceLineItem_ppdd_date(lpOpenItemObject, &dtPpddDate, &Error) != GAL_SUCCESS) { GuiError(__FILE__, __LINE__, "Could not set ppdd_date."); return; } } } else { if (m_iInvoiceMode == 0) galNullBalanceSum_ppdd_date(lpBalanceSumObject, &Error); else galNullBalanceLineItem_ppdd_date(lpOpenItemObject, &Error); } if (m_iInvoiceMode == 0) { if ((galSetBalanceSum_account_no(lpBalanceSumObject, GetAccountNO(), &Error) != GAL_SUCCESS) || (galSetBalanceSum_bill_ref_no(lpBalanceSumObject, m_iBillRefNo, &Error) != GAL_SUCCESS) || (galSetBalanceSum_bill_ref_resets(lpBalanceSumObject, m_iBillRefResets, &Error) != GAL_SUCCESS)) { GuiError(__FILE__, __LINE__, "Could not set invoice data."); return; } if ((galUpdateBalanceSum(m_hAPI, lpBalanceSumObject, &Error) != GAL_SUCCESS)) { GuiError(__FILE__, __LINE__, "Failed to update balance sum."); return; } } else { if ((galSetBalanceLineItem_account_no(lpOpenItemObject, GetAccountNO(), &Error) != GAL_SUCCESS) || (galSetBalanceLineItem_bill_ref_no(lpOpenItemObject, m_iBillRefNo, &Error) != GAL_SUCCESS) || (galSetBalanceLineItem_bill_ref_resets(lpOpenItemObject, m_iBillRefResets, &Error) != GAL_SUCCESS) || (galSetBalanceLineItem_open_item_id(lpOpenItemObject, m_iOpenItemId, &Error) != GAL_SUCCESS)) { GuiError(__FILE__, __LINE__, "Could not set invoice data."); return; } if ((galUpdateBalanceLineItem(m_hAPI, lpOpenItemObject, &Error) != GAL_SUCCESS)) { GuiError(__FILE__, __LINE__, "Failed to update balance sum."); return; } } if (lpBalanceSumObject) galDeleteObjects(lpBalanceSumObject); if (lpOpenItemObject) galDeleteObjects(lpOpenItemObject); CDialog::OnOK(); }
/// <summary> /// 判定给定的年月日时分秒是否是一个有效的日期时间 /// </summary> /// <param name="year">给定的年份</param> /// <param name="month">给定的月份</param> /// <param name="day">给定的日子</param> /// <param name="hour">给定的小时</param> /// <param name="minute">给定的分钟</param> /// <param name="second">给定的秒</param> /// <returns>true:有效;false:无效</returns> bool CDateTime::ValidateDateTime(int year, int month, int day, int hour, int minute, int second) { return ValidateDate(year, month, day) && ValidateTime(hour, minute, second); }
/// <summary> /// 判定给定的年月是否有效 /// </summary> /// <param name="year">给定的年份</param> /// <param name="month">给定的月份</param> /// <returns>true:有效。false:无效。</returns> bool CDateTime::ValidateDate(int year,int month) { if (!ValidateDate(year)) return false; return (month > 0) && (month < 13); }
/* DecodeDateTime() * Interpret previously parsed fields for general date and time. * Return 0 if full date, 1 if only time, and negative DTERR code if problems. * (Currently, all callers treat 1 as an error return too.) * * External format(s): * "<weekday> <month>-<day>-<year> <hour>:<minute>:<second>" * "Fri Feb-7-1997 15:23:27" * "Feb-7-1997 15:23:27" * "2-7-1997 15:23:27" * "1997-2-7 15:23:27" * "1997.038 15:23:27" (day of year 1-366) * Also supports input in compact time: * "970207 152327" * "97038 152327" * "20011225T040506.789-07" * * Use the system-provided functions to get the current time zone * if not specified in the input string. * * If the date is outside the range of pg_time_t (in practice that could only * happen if pg_time_t is just 32 bits), then assume UTC time zone - thomas * 1997-05-27 */ int DecodeDateTime(char **field, int *ftype, int nf, int *dtype, struct tm *tm, fsec_t *fsec, int *tzp) { int fmask = 0, tmask, type; int ptype = 0; /* "prefix type" for ISO y2001m02d04 format */ int i; int val; int dterr; int mer = HR24; bool haveTextMonth = FALSE; bool isjulian = FALSE; bool is2digits = FALSE; bool bc = FALSE; pg_tz *namedTz = NULL; struct tm cur_tm; /* * We'll insist on at least all of the date fields, but initialize the * remaining fields in case they are not set later... */ *dtype = DTK_DATE; tm->tm_hour = 0; tm->tm_min = 0; tm->tm_sec = 0; *fsec = 0; /* don't know daylight savings time status apriori */ tm->tm_isdst = -1; if (tzp != NULL) *tzp = 0; for (i = 0; i < nf; i++) { switch (ftype[i]) { case DTK_DATE: /*** * Integral julian day with attached time zone? * All other forms with JD will be separated into * distinct fields, so we handle just this case here. ***/ if (ptype == DTK_JULIAN) { char *cp; int val; if (tzp == NULL) return DTERR_BAD_FORMAT; errno = 0; val = strtoi(field[i], &cp, 10); if (errno == ERANGE || val < 0) return DTERR_FIELD_OVERFLOW; j2date(val, &tm->tm_year, &tm->tm_mon, &tm->tm_mday); isjulian = TRUE; /* Get the time zone from the end of the string */ dterr = DecodeTimezone(cp, tzp); if (dterr) return dterr; tmask = DTK_DATE_M | DTK_TIME_M | DTK_M(TZ); ptype = 0; break; } /*** * Already have a date? Then this might be a time zone name * with embedded punctuation (e.g. "America/New_York") or a * run-together time with trailing time zone (e.g. hhmmss-zz). * - thomas 2001-12-25 * * We consider it a time zone if we already have month & day. * This is to allow the form "mmm dd hhmmss tz year", which * we've historically accepted. ***/ else if (ptype != 0 || ((fmask & (DTK_M(MONTH) | DTK_M(DAY))) == (DTK_M(MONTH) | DTK_M(DAY)))) { /* No time zone accepted? Then quit... */ if (tzp == NULL) return DTERR_BAD_FORMAT; if (isdigit((unsigned char) *field[i]) || ptype != 0) { char *cp; if (ptype != 0) { /* Sanity check; should not fail this test */ if (ptype != DTK_TIME) return DTERR_BAD_FORMAT; ptype = 0; } /* * Starts with a digit but we already have a time * field? Then we are in trouble with a date and time * already... */ if ((fmask & DTK_TIME_M) == DTK_TIME_M) return DTERR_BAD_FORMAT; if ((cp = strchr(field[i], '-')) == NULL) return DTERR_BAD_FORMAT; /* Get the time zone from the end of the string */ dterr = DecodeTimezone(cp, tzp); if (dterr) return dterr; *cp = '\0'; /* * Then read the rest of the field as a concatenated * time */ dterr = DecodeNumberField(strlen(field[i]), field[i], fmask, &tmask, tm, fsec, &is2digits); if (dterr < 0) return dterr; /* * modify tmask after returning from * DecodeNumberField() */ tmask |= DTK_M(TZ); } else { namedTz = pg_tzset(field[i]); if (!namedTz) { /* * We should return an error code instead of * ereport'ing directly, but then there is no way * to report the bad time zone name. */ warnx("time zone \"%s\" not recognized", field[i]); } /* we'll apply the zone setting below */ tmask = DTK_M(TZ); } } else { dterr = DecodeDate(field[i], fmask, &tmask, &is2digits, tm); if (dterr) return dterr; } break; case DTK_TIME: /* * This might be an ISO time following a "t" field. */ if (ptype != 0) { /* Sanity check; should not fail this test */ if (ptype != DTK_TIME) return DTERR_BAD_FORMAT; ptype = 0; } dterr = DecodeTime(field[i], fmask, INTERVAL_FULL_RANGE, &tmask, tm, fsec); if (dterr) return dterr; /* * Check upper limit on hours; other limits checked in * DecodeTime() */ /* test for > 24:00:00 */ if (tm->tm_hour > HOURS_PER_DAY || (tm->tm_hour == HOURS_PER_DAY && (tm->tm_min > 0 || tm->tm_sec > 0 || *fsec > 0))) return DTERR_FIELD_OVERFLOW; break; case DTK_TZ: { int tz; if (tzp == NULL) return DTERR_BAD_FORMAT; dterr = DecodeTimezone(field[i], &tz); if (dterr) return dterr; *tzp = tz; tmask = DTK_M(TZ); } break; case DTK_NUMBER: /* * Was this an "ISO date" with embedded field labels? An * example is "y2001m02d04" - thomas 2001-02-04 */ if (ptype != 0) { char *cp; int val; errno = 0; val = strtoi(field[i], &cp, 10); if (errno == ERANGE) return DTERR_FIELD_OVERFLOW; /* * only a few kinds are allowed to have an embedded * decimal */ if (*cp == '.') switch (ptype) { case DTK_JULIAN: case DTK_TIME: case DTK_SECOND: break; default: return DTERR_BAD_FORMAT; break; } else if (*cp != '\0') return DTERR_BAD_FORMAT; switch (ptype) { case DTK_YEAR: tm->tm_year = val; tmask = DTK_M(YEAR); break; case DTK_MONTH: /* * already have a month and hour? then assume * minutes */ if ((fmask & DTK_M(MONTH)) != 0 && (fmask & DTK_M(HOUR)) != 0) { tm->tm_min = val; tmask = DTK_M(MINUTE); } else { tm->tm_mon = val; tmask = DTK_M(MONTH); } break; case DTK_DAY: tm->tm_mday = val; tmask = DTK_M(DAY); break; case DTK_HOUR: tm->tm_hour = val; tmask = DTK_M(HOUR); break; case DTK_MINUTE: tm->tm_min = val; tmask = DTK_M(MINUTE); break; case DTK_SECOND: tm->tm_sec = val; tmask = DTK_M(SECOND); if (*cp == '.') { dterr = ParseFractionalSecond(cp, fsec); if (dterr) return dterr; tmask = DTK_ALL_SECS_M; } break; case DTK_TZ: tmask = DTK_M(TZ); dterr = DecodeTimezone(field[i], tzp); if (dterr) return dterr; break; case DTK_JULIAN: /* previous field was a label for "julian date" */ if (val < 0) return DTERR_FIELD_OVERFLOW; tmask = DTK_DATE_M; j2date(val, &tm->tm_year, &tm->tm_mon, &tm->tm_mday); isjulian = TRUE; /* fractional Julian Day? */ if (*cp == '.') { double time; errno = 0; time = strtod(cp, &cp); if (*cp != '\0' || errno != 0) return DTERR_BAD_FORMAT; #ifdef HAVE_INT64_TIMESTAMP time *= USECS_PER_DAY; #else time *= SECS_PER_DAY; #endif dt2time(time, &tm->tm_hour, &tm->tm_min, &tm->tm_sec, fsec); tmask |= DTK_TIME_M; } break; case DTK_TIME: /* previous field was "t" for ISO time */ dterr = DecodeNumberField(strlen(field[i]), field[i], (fmask | DTK_DATE_M), &tmask, tm, fsec, &is2digits); if (dterr < 0) return dterr; if (tmask != DTK_TIME_M) return DTERR_BAD_FORMAT; break; default: return DTERR_BAD_FORMAT; break; } ptype = 0; *dtype = DTK_DATE; } else { char *cp; int flen; flen = strlen(field[i]); cp = strchr(field[i], '.'); /* Embedded decimal and no date yet? */ if (cp != NULL && !(fmask & DTK_DATE_M)) { dterr = DecodeDate(field[i], fmask, &tmask, &is2digits, tm); if (dterr) return dterr; } /* embedded decimal and several digits before? */ else if (cp != NULL && flen - strlen(cp) > 2) { /* * Interpret as a concatenated date or time Set the * type field to allow decoding other fields later. * Example: 20011223 or 040506 */ dterr = DecodeNumberField(flen, field[i], fmask, &tmask, tm, fsec, &is2digits); if (dterr < 0) return dterr; } else if (flen > 4) { dterr = DecodeNumberField(flen, field[i], fmask, &tmask, tm, fsec, &is2digits); if (dterr < 0) return dterr; } /* otherwise it is a single date/time field... */ else { dterr = DecodeNumber(flen, field[i], haveTextMonth, fmask, &tmask, tm, fsec, &is2digits); if (dterr) return dterr; } } break; case DTK_STRING: case DTK_SPECIAL: type = DecodeSpecial(i, field[i], &val); if (type == IGNORE_DTF) continue; tmask = DTK_M(type); switch (type) { case RESERV: switch (val) { case DTK_CURRENT: warnx("date/time value \"current\" is no longer supported"); return DTERR_BAD_FORMAT; break; case DTK_NOW: tmask = (DTK_DATE_M | DTK_TIME_M | DTK_M(TZ)); *dtype = DTK_DATE; GetCurrentTimeUsec(tm, fsec, tzp); break; case DTK_YESTERDAY: tmask = DTK_DATE_M; *dtype = DTK_DATE; GetCurrentDateTime(&cur_tm); j2date(date2j(cur_tm.tm_year, cur_tm.tm_mon, cur_tm.tm_mday) - 1, &tm->tm_year, &tm->tm_mon, &tm->tm_mday); break; case DTK_TODAY: tmask = DTK_DATE_M; *dtype = DTK_DATE; GetCurrentDateTime(&cur_tm); tm->tm_year = cur_tm.tm_year; tm->tm_mon = cur_tm.tm_mon; tm->tm_mday = cur_tm.tm_mday; break; case DTK_TOMORROW: tmask = DTK_DATE_M; *dtype = DTK_DATE; GetCurrentDateTime(&cur_tm); j2date(date2j(cur_tm.tm_year, cur_tm.tm_mon, cur_tm.tm_mday) + 1, &tm->tm_year, &tm->tm_mon, &tm->tm_mday); break; case DTK_ZULU: tmask = (DTK_TIME_M | DTK_M(TZ)); *dtype = DTK_DATE; tm->tm_hour = 0; tm->tm_min = 0; tm->tm_sec = 0; if (tzp != NULL) *tzp = 0; break; default: *dtype = val; } break; case MONTH: /* * already have a (numeric) month? then see if we can * substitute... */ if ((fmask & DTK_M(MONTH)) && !haveTextMonth && !(fmask & DTK_M(DAY)) && tm->tm_mon >= 1 && tm->tm_mon <= 31) { tm->tm_mday = tm->tm_mon; tmask = DTK_M(DAY); } haveTextMonth = TRUE; tm->tm_mon = val; break; case DTZMOD: /* * daylight savings time modifier (solves "MET DST" * syntax) */ tmask |= DTK_M(DTZ); tm->tm_isdst = 1; if (tzp == NULL) return DTERR_BAD_FORMAT; *tzp += val * MINS_PER_HOUR; break; case DTZ: /* * set mask for TZ here _or_ check for DTZ later when * getting default timezone */ tmask |= DTK_M(TZ); tm->tm_isdst = 1; if (tzp == NULL) return DTERR_BAD_FORMAT; *tzp = val * MINS_PER_HOUR; break; case TZ: tm->tm_isdst = 0; if (tzp == NULL) return DTERR_BAD_FORMAT; *tzp = val * MINS_PER_HOUR; break; case IGNORE_DTF: break; case AMPM: mer = val; break; case ADBC: bc = (val == BC); break; case DOW: tm->tm_wday = val; break; case UNITS: tmask = 0; ptype = val; break; case ISOTIME: /* * This is a filler field "t" indicating that the next * field is time. Try to verify that this is sensible. */ tmask = 0; /* No preceding date? Then quit... */ if ((fmask & DTK_DATE_M) != DTK_DATE_M) return DTERR_BAD_FORMAT; /*** * We will need one of the following fields: * DTK_NUMBER should be hhmmss.fff * DTK_TIME should be hh:mm:ss.fff * DTK_DATE should be hhmmss-zz ***/ if (i >= nf - 1 || (ftype[i + 1] != DTK_NUMBER && ftype[i + 1] != DTK_TIME && ftype[i + 1] != DTK_DATE)) return DTERR_BAD_FORMAT; ptype = val; break; case UNKNOWN_FIELD: /* * Before giving up and declaring error, check to see * if it is an all-alpha timezone name. */ namedTz = pg_tzset(field[i]); if (!namedTz) return DTERR_BAD_FORMAT; /* we'll apply the zone setting below */ tmask = DTK_M(TZ); break; default: return DTERR_BAD_FORMAT; } break; default: return DTERR_BAD_FORMAT; } if (tmask & fmask) return DTERR_BAD_FORMAT; fmask |= tmask; } /* end loop over fields */ /* do final checking/adjustment of Y/M/D fields */ dterr = ValidateDate(fmask, isjulian, is2digits, bc, tm); if (dterr) return dterr; /* handle AM/PM */ if (mer != HR24 && tm->tm_hour > HOURS_PER_DAY / 2) return DTERR_FIELD_OVERFLOW; if (mer == AM && tm->tm_hour == HOURS_PER_DAY / 2) tm->tm_hour = 0; else if (mer == PM && tm->tm_hour != HOURS_PER_DAY / 2) tm->tm_hour += HOURS_PER_DAY / 2; /* do additional checking for full date specs... */ if (*dtype == DTK_DATE) { if ((fmask & DTK_DATE_M) != DTK_DATE_M) { if ((fmask & DTK_TIME_M) == DTK_TIME_M) return 1; return DTERR_BAD_FORMAT; } /* * If we had a full timezone spec, compute the offset (we could not do * it before, because we need the date to resolve DST status). */ if (namedTz != NULL) { /* daylight savings time modifier disallowed with full TZ */ if (fmask & DTK_M(DTZMOD)) return DTERR_BAD_FORMAT; *tzp = DetermineTimeZoneOffset(tm, namedTz); } /* timezone not specified? then find local timezone if possible */ if (tzp != NULL && !(fmask & DTK_M(TZ))) { /* * daylight savings time modifier but no standard timezone? then * error */ if (fmask & DTK_M(DTZMOD)) return DTERR_BAD_FORMAT; *tzp = DetermineTimeZoneOffset(tm, session_timezone); } } return 0; }
int CyaSSL_OCSP_Lookup_Cert(CYASSL_OCSP* ocsp, DecodedCert* cert) { byte ocspReqBuf[SCRATCH_BUFFER_SIZE]; int ocspReqSz = SCRATCH_BUFFER_SIZE; byte* ocspRespBuf = NULL; OcspRequest ocspRequest; OcspResponse ocspResponse; int result = 0; OCSP_Entry* ocspe; CertStatus* certStatus; /* If OCSP lookups are disabled, return success. */ if (!ocsp->enabled) { CYASSL_MSG("OCSP lookup disabled, assuming CERT_GOOD"); return 0; } ocspe = find_ocsp_entry(ocsp, cert); if (ocspe == NULL) { CYASSL_MSG("alloc OCSP entry failed"); return MEMORY_ERROR; } certStatus = find_cert_status(ocspe, cert); if (certStatus == NULL) { CYASSL_MSG("alloc OCSP cert status failed"); return MEMORY_ERROR; } if (certStatus->status != -1) { if (!ValidateDate(certStatus->thisDate, certStatus->thisDateFormat, BEFORE) || (certStatus->nextDate[0] == 0) || !ValidateDate(certStatus->nextDate, certStatus->nextDateFormat, AFTER)) { CYASSL_MSG("\tinvalid status date, looking up cert"); certStatus->status = -1; } else { CYASSL_MSG("\tusing cached status"); result = xstat2err(certStatus->status); return result; } } InitOcspRequest(&ocspRequest, cert, ocspReqBuf, ocspReqSz); ocspReqSz = EncodeOcspRequest(&ocspRequest); result = http_ocsp_transaction(ocsp, cert, ocspReqBuf, ocspReqSz, &ocspRespBuf); if (result < 0) return result; /* If the transaction failed, return that result. */ InitOcspResponse(&ocspResponse, certStatus, ocspRespBuf, result); OcspResponseDecode(&ocspResponse); if (ocspResponse.responseStatus != OCSP_SUCCESSFUL) { CYASSL_MSG("OCSP Responder failure"); result = OCSP_LOOKUP_FAIL; } else { if (CompareOcspReqResp(&ocspRequest, &ocspResponse) == 0) { result = xstat2err(ocspResponse.status->status); } else { CYASSL_MSG("OCSP Response incorrect for Request"); result = OCSP_LOOKUP_FAIL; } } if (ocspRespBuf != NULL) { XFREE(ocspRespBuf, NULL, DYNAMIC_TYPE_IN_BUFFER); } return result; }