2015-01-22 03:40:55 +00:00
|
|
|
/*
|
2016-05-17 18:51:04 +00:00
|
|
|
* Copyright 2006-2016 The OpenSSL Project Authors. All Rights Reserved.
|
2006-02-12 23:11:56 +00:00
|
|
|
*
|
2016-05-17 18:51:04 +00:00
|
|
|
* Licensed under the OpenSSL license (the "License"). You may not use
|
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
2006-02-12 23:11:56 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2015-05-14 14:56:48 +00:00
|
|
|
#include "internal/cryptlib.h"
|
2006-02-12 23:11:56 +00:00
|
|
|
#include <openssl/objects.h>
|
|
|
|
#include <openssl/x509v3.h>
|
|
|
|
#include <openssl/ts.h>
|
2015-06-10 18:07:40 +00:00
|
|
|
#include "ts_lcl.h"
|
2006-02-12 23:11:56 +00:00
|
|
|
|
|
|
|
int TS_REQ_set_version(TS_REQ *a, long version)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
return ASN1_INTEGER_set(a->version, version);
|
|
|
|
}
|
2006-02-12 23:11:56 +00:00
|
|
|
|
2006-03-05 20:19:05 +00:00
|
|
|
long TS_REQ_get_version(const TS_REQ *a)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
return ASN1_INTEGER_get(a->version);
|
|
|
|
}
|
2006-02-12 23:11:56 +00:00
|
|
|
|
|
|
|
int TS_REQ_set_msg_imprint(TS_REQ *a, TS_MSG_IMPRINT *msg_imprint)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
TS_MSG_IMPRINT *new_msg_imprint;
|
|
|
|
|
|
|
|
if (a->msg_imprint == msg_imprint)
|
|
|
|
return 1;
|
|
|
|
new_msg_imprint = TS_MSG_IMPRINT_dup(msg_imprint);
|
|
|
|
if (new_msg_imprint == NULL) {
|
|
|
|
TSerr(TS_F_TS_REQ_SET_MSG_IMPRINT, ERR_R_MALLOC_FAILURE);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
TS_MSG_IMPRINT_free(a->msg_imprint);
|
|
|
|
a->msg_imprint = new_msg_imprint;
|
|
|
|
return 1;
|
|
|
|
}
|
2006-02-12 23:11:56 +00:00
|
|
|
|
|
|
|
TS_MSG_IMPRINT *TS_REQ_get_msg_imprint(TS_REQ *a)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
return a->msg_imprint;
|
|
|
|
}
|
2006-02-12 23:11:56 +00:00
|
|
|
|
|
|
|
int TS_MSG_IMPRINT_set_algo(TS_MSG_IMPRINT *a, X509_ALGOR *alg)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
X509_ALGOR *new_alg;
|
|
|
|
|
|
|
|
if (a->hash_algo == alg)
|
|
|
|
return 1;
|
|
|
|
new_alg = X509_ALGOR_dup(alg);
|
|
|
|
if (new_alg == NULL) {
|
|
|
|
TSerr(TS_F_TS_MSG_IMPRINT_SET_ALGO, ERR_R_MALLOC_FAILURE);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
X509_ALGOR_free(a->hash_algo);
|
|
|
|
a->hash_algo = new_alg;
|
|
|
|
return 1;
|
|
|
|
}
|
2006-02-12 23:11:56 +00:00
|
|
|
|
|
|
|
X509_ALGOR *TS_MSG_IMPRINT_get_algo(TS_MSG_IMPRINT *a)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
return a->hash_algo;
|
|
|
|
}
|
2006-02-12 23:11:56 +00:00
|
|
|
|
|
|
|
int TS_MSG_IMPRINT_set_msg(TS_MSG_IMPRINT *a, unsigned char *d, int len)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
return ASN1_OCTET_STRING_set(a->hashed_msg, d, len);
|
|
|
|
}
|
2006-02-12 23:11:56 +00:00
|
|
|
|
|
|
|
ASN1_OCTET_STRING *TS_MSG_IMPRINT_get_msg(TS_MSG_IMPRINT *a)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
return a->hashed_msg;
|
|
|
|
}
|
2006-02-12 23:11:56 +00:00
|
|
|
|
2016-07-31 17:38:09 +00:00
|
|
|
int TS_REQ_set_policy_id(TS_REQ *a, const ASN1_OBJECT *policy)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
ASN1_OBJECT *new_policy;
|
|
|
|
|
|
|
|
if (a->policy_id == policy)
|
|
|
|
return 1;
|
|
|
|
new_policy = OBJ_dup(policy);
|
|
|
|
if (new_policy == NULL) {
|
|
|
|
TSerr(TS_F_TS_REQ_SET_POLICY_ID, ERR_R_MALLOC_FAILURE);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
ASN1_OBJECT_free(a->policy_id);
|
|
|
|
a->policy_id = new_policy;
|
|
|
|
return 1;
|
|
|
|
}
|
2006-02-12 23:11:56 +00:00
|
|
|
|
|
|
|
ASN1_OBJECT *TS_REQ_get_policy_id(TS_REQ *a)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
return a->policy_id;
|
|
|
|
}
|
2006-02-12 23:11:56 +00:00
|
|
|
|
2006-03-05 20:19:05 +00:00
|
|
|
int TS_REQ_set_nonce(TS_REQ *a, const ASN1_INTEGER *nonce)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
ASN1_INTEGER *new_nonce;
|
|
|
|
|
|
|
|
if (a->nonce == nonce)
|
|
|
|
return 1;
|
|
|
|
new_nonce = ASN1_INTEGER_dup(nonce);
|
|
|
|
if (new_nonce == NULL) {
|
|
|
|
TSerr(TS_F_TS_REQ_SET_NONCE, ERR_R_MALLOC_FAILURE);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
ASN1_INTEGER_free(a->nonce);
|
|
|
|
a->nonce = new_nonce;
|
|
|
|
return 1;
|
|
|
|
}
|
2006-02-12 23:11:56 +00:00
|
|
|
|
2006-03-05 20:19:05 +00:00
|
|
|
const ASN1_INTEGER *TS_REQ_get_nonce(const TS_REQ *a)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
return a->nonce;
|
|
|
|
}
|
2006-02-12 23:11:56 +00:00
|
|
|
|
|
|
|
int TS_REQ_set_cert_req(TS_REQ *a, int cert_req)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
a->cert_req = cert_req ? 0xFF : 0x00;
|
|
|
|
return 1;
|
|
|
|
}
|
2006-02-12 23:11:56 +00:00
|
|
|
|
2006-03-05 20:19:05 +00:00
|
|
|
int TS_REQ_get_cert_req(const TS_REQ *a)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
return a->cert_req ? 1 : 0;
|
|
|
|
}
|
2006-02-12 23:11:56 +00:00
|
|
|
|
|
|
|
STACK_OF(X509_EXTENSION) *TS_REQ_get_exts(TS_REQ *a)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
return a->extensions;
|
|
|
|
}
|
2006-02-12 23:11:56 +00:00
|
|
|
|
|
|
|
void TS_REQ_ext_free(TS_REQ *a)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
if (!a)
|
|
|
|
return;
|
|
|
|
sk_X509_EXTENSION_pop_free(a->extensions, X509_EXTENSION_free);
|
|
|
|
a->extensions = NULL;
|
|
|
|
}
|
2006-02-12 23:11:56 +00:00
|
|
|
|
|
|
|
int TS_REQ_get_ext_count(TS_REQ *a)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
return X509v3_get_ext_count(a->extensions);
|
|
|
|
}
|
2006-02-12 23:11:56 +00:00
|
|
|
|
|
|
|
int TS_REQ_get_ext_by_NID(TS_REQ *a, int nid, int lastpos)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
return X509v3_get_ext_by_NID(a->extensions, nid, lastpos);
|
|
|
|
}
|
2006-02-12 23:11:56 +00:00
|
|
|
|
2016-07-31 17:38:09 +00:00
|
|
|
int TS_REQ_get_ext_by_OBJ(TS_REQ *a, const ASN1_OBJECT *obj, int lastpos)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
return X509v3_get_ext_by_OBJ(a->extensions, obj, lastpos);
|
|
|
|
}
|
2006-02-12 23:11:56 +00:00
|
|
|
|
|
|
|
int TS_REQ_get_ext_by_critical(TS_REQ *a, int crit, int lastpos)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
return X509v3_get_ext_by_critical(a->extensions, crit, lastpos);
|
|
|
|
}
|
2006-02-12 23:11:56 +00:00
|
|
|
|
|
|
|
X509_EXTENSION *TS_REQ_get_ext(TS_REQ *a, int loc)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
return X509v3_get_ext(a->extensions, loc);
|
|
|
|
}
|
2006-02-12 23:11:56 +00:00
|
|
|
|
|
|
|
X509_EXTENSION *TS_REQ_delete_ext(TS_REQ *a, int loc)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
return X509v3_delete_ext(a->extensions, loc);
|
|
|
|
}
|
2006-02-12 23:11:56 +00:00
|
|
|
|
|
|
|
int TS_REQ_add_ext(TS_REQ *a, X509_EXTENSION *ex, int loc)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
return X509v3_add_ext(&a->extensions, ex, loc) != NULL;
|
|
|
|
}
|
2006-02-12 23:11:56 +00:00
|
|
|
|
|
|
|
void *TS_REQ_get_ext_d2i(TS_REQ *a, int nid, int *crit, int *idx)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
return X509V3_get_d2i(a->extensions, nid, crit, idx);
|
|
|
|
}
|