aboutsummaryrefslogtreecommitdiffstats
path: root/apps/apps.c
diff options
context:
space:
mode:
authorDr. Stephen Henson <steve@openssl.org>2001-03-16 02:04:17 +0000
committerDr. Stephen Henson <steve@openssl.org>2001-03-16 02:04:17 +0000
commit791bd0cd2b267d38fcbe7eb4dd3df2aa92877f11 (patch)
tree5fdf5eae1304f65185c74b4884bad7a33f8a2c32 /apps/apps.c
parente890dcdb196aa2b971f3c85ccc94389bb01edb91 (diff)
downloadopenssl-791bd0cd2b267d38fcbe7eb4dd3df2aa92877f11.tar.gz
Add copy_extensions option to 'ca' utility.
Diffstat (limited to 'apps/apps.c')
-rw-r--r--apps/apps.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/apps/apps.c b/apps/apps.c
index d8d9140075..4aeabdfa38 100644
--- a/apps/apps.c
+++ b/apps/apps.c
@@ -809,6 +809,62 @@ int set_name_ex(unsigned long *flags, const char *arg)
return set_multi_opts(flags, arg, ex_tbl);
}
+int set_ext_copy(int *copy_type, const char *arg)
+{
+ if (!strcasecmp(arg, "none"))
+ *copy_type = EXT_COPY_NONE;
+ else if (!strcasecmp(arg, "copy"))
+ *copy_type = EXT_COPY_ADD;
+ else if (!strcasecmp(arg, "copyall"))
+ *copy_type = EXT_COPY_ALL;
+ else
+ return 0;
+ return 1;
+}
+
+int copy_extensions(X509 *x, X509_REQ *req, int copy_type)
+{
+ STACK_OF(X509_EXTENSION) *exts = NULL;
+ X509_EXTENSION *ext, *tmpext;
+ ASN1_OBJECT *obj;
+ int i, idx, ret = 0;
+ if (!x || !req || (copy_type == EXT_COPY_NONE))
+ return 1;
+ exts = X509_REQ_get_extensions(req);
+
+ for(i = 0; i < sk_X509_EXTENSION_num(exts); i++) {
+ ext = sk_X509_EXTENSION_value(exts, i);
+ obj = X509_EXTENSION_get_object(ext);
+ idx = X509_get_ext_by_OBJ(x, obj, -1);
+ /* Does extension exist? */
+ if (idx != -1) {
+ /* If normal copy don't override existing extension */
+ if (copy_type == EXT_COPY_ADD)
+ continue;
+ /* Delete all extensions of same type */
+ do {
+ tmpext = X509_get_ext(x, idx);
+ X509_delete_ext(x, idx);
+ X509_EXTENSION_free(tmpext);
+ idx = X509_get_ext_by_OBJ(x, obj, -1);
+ } while (idx != -1);
+ }
+ if (!X509_add_ext(x, ext, -1))
+ goto end;
+ }
+
+ ret = 1;
+
+ end:
+
+ sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
+
+ return ret;
+}
+
+
+
+
static int set_multi_opts(unsigned long *flags, const char *arg, const NAME_EX_TBL *in_tbl)
{
STACK_OF(CONF_VALUE) *vals;