61 #if defined(OPENSSL_SYS_UNIX)
72 static int def_time_cb(
struct TS_resp_ctx *,
void *,
long *sec,
long *usec);
81 static int TS_RESP_process_extensions(
TS_RESP_CTX *ctx);
86 static ESS_CERT_ID *ESS_CERT_ID_new_init(
X509 *cert,
int issuer_needed);
87 static int TS_TST_INFO_content_new(
PKCS7 *p7);
98 if (!serial)
goto err;
104 "Error during serial number generation.");
108 #if defined(OPENSSL_SYS_UNIX)
111 static int def_time_cb(
struct TS_resp_ctx *ctx,
void *data,
112 long *sec,
long *usec)
115 if (gettimeofday(&tv, NULL) != 0)
119 "Time is not available.");
133 static int def_time_cb(
struct TS_resp_ctx *ctx,
void *data,
134 long *sec,
long *usec)
137 if (time(&t) == (time_t) -1)
141 "Time is not available.");
159 "Unsupported extension.");
195 ASN1_INTEGER_free(ctx->
seconds);
196 ASN1_INTEGER_free(ctx->
millis);
197 ASN1_INTEGER_free(ctx->
micros);
243 if (!certs)
return 1;
265 if (!(copy =
OBJ_dup(policy)))
goto err;
289 #define TS_RESP_CTX_accuracy_free(ctx) \
290 ASN1_INTEGER_free(ctx->seconds); \
291 ctx->seconds = NULL; \
292 ASN1_INTEGER_free(ctx->millis); \
293 ctx->millis = NULL; \
294 ASN1_INTEGER_free(ctx->micros); \
298 int secs,
int millis,
int micros)
302 if (secs && (!(ctx->
seconds = ASN1_INTEGER_new())
305 if (millis && (!(ctx->
millis = ASN1_INTEGER_new())
308 if (micros && (!(ctx->
micros = ASN1_INTEGER_new())
344 int status,
const char *
text)
354 if (!(utf8_text = ASN1_UTF8STRING_new())
368 ASN1_UTF8STRING_free(utf8_text);
373 int status,
const char *
text)
424 TS_RESP_CTX_init(ctx);
437 "Bad request format or "
448 if (!TS_RESP_check_request(ctx))
goto end;
451 if (!(policy = TS_RESP_get_policy(ctx)))
goto end;
454 if (!(ctx->
tst_info = TS_RESP_create_tst_info(ctx, policy)))
458 if (!TS_RESP_process_extensions(ctx))
goto end;
461 if (!TS_RESP_sign(ctx))
goto end;
482 TS_RESP_CTX_cleanup(ctx);
520 "Bad request version.");
538 "Message digest algorithm is "
549 "Superfluous message digest "
559 "Bad message digest.");
588 if (!
OBJ_cmp(requested, current))
595 "Requested policy is not "
624 || !(asn1_time = TS_RESP_set_genTime_with_precision(NULL,
657 if (!(tsa_name = GENERAL_NAME_new()))
goto end;
661 if (!tsa_name->
d.
dirn)
goto end;
673 "Error during TSTInfo "
676 GENERAL_NAME_free(tsa_name);
678 ASN1_GENERALIZEDTIME_free(asn1_time);
679 ASN1_INTEGER_free(serial);
685 static int TS_RESP_process_extensions(
TS_RESP_CTX *ctx)
727 if (!(p7 = PKCS7_new())) {
770 if (!(sc = ESS_SIGNING_CERT_new_init(ctx->
signer_cert, certs)))
774 if (!ESS_add_signing_cert(si, sc))
781 if (!TS_TST_INFO_content_new(p7))
goto err;
812 "Error during signature "
833 if (!(cid = ESS_CERT_ID_new_init(signcert, 0))
840 if (!(cid = ESS_CERT_ID_new_init(cert, 1))
852 static ESS_CERT_ID *ESS_CERT_ID_new_init(
X509 *cert,
int issuer_needed)
873 if (!(name = GENERAL_NAME_new()))
goto err;
889 GENERAL_NAME_free(name);
895 static int TS_TST_INFO_content_new(
PKCS7 *p7)
901 if (!(ret = PKCS7_new()))
goto err;
902 if (!(ret->
d.
other = ASN1_TYPE_new()))
goto err;
904 if (!(octet_string = ASN1_OCTET_STRING_new()))
goto err;
913 ASN1_OCTET_STRING_free(octet_string);
921 unsigned char *
p, *
pp = NULL;
951 long sec,
long usec,
unsigned precision)
953 time_t time_sec = (time_t) sec;
954 struct tm *tm = NULL;
956 char *p = genTime_str;
957 char *p_end = genTime_str +
sizeof(genTime_str);
963 if (!(tm = gmtime(&time_sec)))
974 "%04d%02d%02d%02d%02d%02d",
975 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
976 tm->tm_hour, tm->tm_min, tm->tm_sec);
1012 ASN1_GENERALIZEDTIME_free(asn1_time);