static void display_cert_info(struct SessionHandle *data, CERTCertificate *cert) { char *subject, *issuer, *common_name; PRExplodedTime printableTime; char timeString[256]; PRTime notBefore, notAfter; subject = CERT_NameToAscii(&cert->subject); issuer = CERT_NameToAscii(&cert->issuer); common_name = CERT_GetCommonName(&cert->subject); infof(data, "\tsubject: %s\n", subject); CERT_GetCertTimes(cert, ¬Before, ¬After); PR_ExplodeTime(notBefore, PR_GMTParameters, &printableTime); PR_FormatTime(timeString, 256, "%b %d %H:%M:%S %Y GMT", &printableTime); infof(data, "\tstart date: %s\n", timeString); PR_ExplodeTime(notAfter, PR_GMTParameters, &printableTime); PR_FormatTime(timeString, 256, "%b %d %H:%M:%S %Y GMT", &printableTime); infof(data, "\texpire date: %s\n", timeString); infof(data, "\tcommon name: %s\n", common_name); infof(data, "\tissuer: %s\n", issuer); PR_Free(subject); PR_Free(issuer); PR_Free(common_name); }
static int __pmCertificateTimestamp(SECItem *vtime, char *buffer, size_t size) { PRExplodedTime exploded; SECStatus secsts; int64 itime; switch (vtime->type) { case siUTCTime: secsts = DER_UTCTimeToTime(&itime, vtime); break; case siGeneralizedTime: secsts = DER_GeneralizedTimeToTime(&itime, vtime); break; default: return -EINVAL; } if (secsts != SECSuccess) return __pmSecureSocketsError(PR_GetError()); /* Convert to local time */ PR_ExplodeTime(itime, PR_GMTParameters, &exploded); if (!PR_FormatTime(buffer, size, "%a %b %d %H:%M:%S %Y", &exploded)) return __pmSecureSocketsError(PR_GetError()); return 0; }
static void PrintTimeString(char *buf, PRUint32 bufsize, PRUint32 t_sec) { PRExplodedTime et; PRTime t_usec = SecondsToPRTime(t_sec); PR_ExplodeTime(t_usec, PR_LocalTimeParameters, &et); PR_FormatTime(buf, bufsize, "%Y-%m-%d %H:%M:%S", &et); }
int sv_PrintTime(FILE *out, SECItem *t, char *m) { PRExplodedTime printableTime; PRTime time; char *timeString; int rv; rv = DER_DecodeTimeChoice(&time, t); if (rv) return rv; /* Convert to local time */ PR_ExplodeTime(time, PR_LocalTimeParameters, &printableTime); timeString = (char *)PORT_Alloc(256); if (timeString) { if (PR_FormatTime(timeString, 256, "%a %b %d %H:%M:%S %Y", &printableTime)) { fprintf(out, "%s%s\n", m, timeString); } PORT_Free(timeString); return 0; } return SECFailure; }
static void display_conn_info(struct connectdata *conn, PRFileDesc *sock) { SSLChannelInfo channel; SSLCipherSuiteInfo suite; CERTCertificate *cert; char *subject, *issuer, *common_name; PRExplodedTime printableTime; char timeString[256]; PRTime notBefore, notAfter; if(SSL_GetChannelInfo(sock, &channel, sizeof channel) == SECSuccess && channel.length == sizeof channel && channel.cipherSuite) { if(SSL_GetCipherSuiteInfo(channel.cipherSuite, &suite, sizeof suite) == SECSuccess) { infof(conn->data, "SSL connection using %s\n", suite.cipherSuiteName); } } infof(conn->data, "Server certificate:\n"); cert = SSL_PeerCertificate(sock); subject = CERT_NameToAscii(&cert->subject); issuer = CERT_NameToAscii(&cert->issuer); common_name = CERT_GetCommonName(&cert->subject); infof(conn->data, "\tsubject: %s\n", subject); CERT_GetCertTimes(cert, ¬Before, ¬After); PR_ExplodeTime(notBefore, PR_GMTParameters, &printableTime); PR_FormatTime(timeString, 256, "%b %d %H:%M:%S %Y GMT", &printableTime); infof(conn->data, "\tstart date: %s\n", timeString); PR_ExplodeTime(notAfter, PR_GMTParameters, &printableTime); PR_FormatTime(timeString, 256, "%b %d %H:%M:%S %Y GMT", &printableTime); infof(conn->data, "\texpire date: %s\n", timeString); infof(conn->data, "\tcommon name: %s\n", common_name); infof(conn->data, "\tissuer: %s\n", issuer); PR_Free(subject); PR_Free(issuer); PR_Free(common_name); CERT_DestroyCertificate(cert); return; }
static void TimeOfDayMessage(const char *msg, PRThread* me) { char buffer[100]; PRExplodedTime tod; PR_ExplodeTime(PR_Now(), PR_LocalTimeParameters, &tod); (void)PR_FormatTime(buffer, sizeof(buffer), "%H:%M:%S", &tod); TEST_LOG( cltsrv_log_file, TEST_LOG_ALWAYS, ("%s(0x%p): %s\n", msg, me, buffer)); } /* TimeOfDayMessage */
void nsCertTree::CmpInitCriterion(nsIX509Cert *cert, CompareCacheHashEntry *entry, sortCriterion crit, PRInt32 level) { NS_ENSURE_TRUE( (cert!=0 && entry!=0), RETURN_NOTHING ); entry->mCritInit[level] = true; nsXPIDLString &str = entry->mCrit[level]; switch (crit) { case sort_IssuerOrg: cert->GetIssuerOrganization(str); if (str.IsEmpty()) cert->GetCommonName(str); break; case sort_Org: cert->GetOrganization(str); break; case sort_Token: cert->GetTokenName(str); break; case sort_CommonName: cert->GetCommonName(str); break; case sort_IssuedDateDescending: { nsresult rv; nsCOMPtr<nsIX509CertValidity> validity; PRTime notBefore; rv = cert->GetValidity(getter_AddRefs(validity)); if (NS_SUCCEEDED(rv)) { rv = validity->GetNotBefore(¬Before); } if (NS_SUCCEEDED(rv)) { PRExplodedTime explodedTime; PR_ExplodeTime(notBefore, PR_GMTParameters, &explodedTime); char datebuf[20]; // 4 + 2 + 2 + 2 + 2 + 2 + 1 = 15 if (0 != PR_FormatTime(datebuf, sizeof(datebuf), "%Y%m%d%H%M%S", &explodedTime)) { str = NS_ConvertASCIItoUTF16(nsDependentCString(datebuf)); } } } break; case sort_Email: cert->GetEmailAddress(str); break; case sort_None: default: break; } }
int main() { char buffer[256]; PRTime now; PRExplodedTime tod; now = PR_Now(); PR_ExplodeTime(now, PR_LocalTimeParameters, &tod); (void)PR_FormatTime(buffer, sizeof(buffer), "%a %b %d %H:%M:%S %Z %Y", &tod); printf("%s\n", buffer); (void)PR_FormatTimeUSEnglish(buffer, sizeof(buffer), "%a %b %d %H:%M:%S %Z %Y", &tod); printf("%s\n", buffer); return 0; }
int main(int argc, char **argv) { PRIntn rv = 1; PLOptStatus os; PRIntn verbosity = 0; PRLibrary *runtime = NULL; const char *library_name = NULL; const PRVersionDescription *version_info; char buffer[100]; PRExplodedTime exploded; PLOptState *opt = PL_CreateOptState(argc, argv, "d"); PRFileDesc *err = PR_GetSpecialFD(PR_StandardError); while (PL_OPT_EOL != (os = PL_GetNextOpt(opt))) { if (PL_OPT_BAD == os) continue; switch (opt->option) { case 0: /* fully qualified library name */ library_name = opt->value; break; case 'd': /* verbodity */ verbosity += 1; break; default: PR_fprintf(err, "Usage: version [-d] {fully qualified library name}\n"); return 2; /* but not a lot else */ } } PL_DestroyOptState(opt); if (NULL != library_name) { runtime = PR_LoadLibrary(library_name); if (NULL == runtime) { PL_FPrintError(err, "PR_LoadLibrary"); return 3; } else { versionEntryPointType versionPoint = (versionEntryPointType) PR_FindSymbol(runtime, "libVersionPoint"); if (NULL == versionPoint) { PL_FPrintError(err, "PR_FindSymbol"); return 4; } version_info = versionPoint(); } } else version_info = libVersionPoint(); /* NSPR's version info */ (void)PR_fprintf(err, "Runtime library version information\n"); PR_ExplodeTime( version_info->buildTime, PR_GMTParameters, &exploded); (void)PR_FormatTime( buffer, sizeof(buffer), "%d %b %Y %H:%M:%S", &exploded); (void)PR_fprintf(err, " Build time: %s GMT\n", buffer); (void)PR_fprintf( err, " Build time: %s\n", version_info->buildTimeString); (void)PR_fprintf( err, " %s V%u.%u.%u (%s%s%s)\n", version_info->description, version_info->vMajor, version_info->vMinor, version_info->vPatch, (version_info->beta ? " beta " : ""), (version_info->debug ? " debug " : ""), (version_info->special ? " special" : "")); (void)PR_fprintf(err, " filename: %s\n", version_info->filename); (void)PR_fprintf(err, " security: %s\n", version_info->security); (void)PR_fprintf(err, " copyright: %s\n", version_info->copyright); (void)PR_fprintf(err, " comment: %s\n", version_info->comment); rv = 0; return rv; }