|
Packit Service |
084de1 |
/*
|
|
Packit Service |
084de1 |
* Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
|
|
Packit Service |
084de1 |
*
|
|
Packit Service |
084de1 |
* Licensed under the OpenSSL license (the "License"). You may not use
|
|
Packit Service |
084de1 |
* this file except in compliance with the License. You can obtain a copy
|
|
Packit Service |
084de1 |
* in the file LICENSE in the source distribution or at
|
|
Packit Service |
084de1 |
* https://www.openssl.org/source/license.html
|
|
Packit Service |
084de1 |
*/
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
#include <stddef.h>
|
|
Packit Service |
084de1 |
#include "internal/cryptlib.h"
|
|
Packit Service |
084de1 |
#include <openssl/asn1.h>
|
|
Packit Service |
084de1 |
#include <openssl/asn1t.h>
|
|
Packit Service |
084de1 |
#include <openssl/objects.h>
|
|
Packit Service |
084de1 |
#include <openssl/buffer.h>
|
|
Packit Service |
084de1 |
#include <openssl/err.h>
|
|
Packit Service |
084de1 |
#include <openssl/x509v3.h>
|
|
Packit Service |
084de1 |
#include "crypto/asn1.h"
|
|
Packit Service |
084de1 |
#include "asn1_local.h"
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
/*
|
|
Packit Service |
084de1 |
* Print routines.
|
|
Packit Service |
084de1 |
*/
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
/* ASN1_PCTX routines */
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
static ASN1_PCTX default_pctx = {
|
|
Packit Service |
084de1 |
ASN1_PCTX_FLAGS_SHOW_ABSENT, /* flags */
|
|
Packit Service |
084de1 |
0, /* nm_flags */
|
|
Packit Service |
084de1 |
0, /* cert_flags */
|
|
Packit Service |
084de1 |
0, /* oid_flags */
|
|
Packit Service |
084de1 |
0 /* str_flags */
|
|
Packit Service |
084de1 |
};
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
ASN1_PCTX *ASN1_PCTX_new(void)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
ASN1_PCTX *ret;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
ret = OPENSSL_zalloc(sizeof(*ret));
|
|
Packit Service |
084de1 |
if (ret == NULL) {
|
|
Packit Service |
084de1 |
ASN1err(ASN1_F_ASN1_PCTX_NEW, ERR_R_MALLOC_FAILURE);
|
|
Packit Service |
084de1 |
return NULL;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
return ret;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
void ASN1_PCTX_free(ASN1_PCTX *p)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
OPENSSL_free(p);
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
unsigned long ASN1_PCTX_get_flags(const ASN1_PCTX *p)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
return p->flags;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
void ASN1_PCTX_set_flags(ASN1_PCTX *p, unsigned long flags)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
p->flags = flags;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
unsigned long ASN1_PCTX_get_nm_flags(const ASN1_PCTX *p)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
return p->nm_flags;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
void ASN1_PCTX_set_nm_flags(ASN1_PCTX *p, unsigned long flags)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
p->nm_flags = flags;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
unsigned long ASN1_PCTX_get_cert_flags(const ASN1_PCTX *p)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
return p->cert_flags;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
void ASN1_PCTX_set_cert_flags(ASN1_PCTX *p, unsigned long flags)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
p->cert_flags = flags;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
unsigned long ASN1_PCTX_get_oid_flags(const ASN1_PCTX *p)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
return p->oid_flags;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
void ASN1_PCTX_set_oid_flags(ASN1_PCTX *p, unsigned long flags)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
p->oid_flags = flags;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
unsigned long ASN1_PCTX_get_str_flags(const ASN1_PCTX *p)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
return p->str_flags;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
void ASN1_PCTX_set_str_flags(ASN1_PCTX *p, unsigned long flags)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
p->str_flags = flags;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
/* Main print routines */
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
|
|
Packit Service |
084de1 |
const ASN1_ITEM *it,
|
|
Packit Service |
084de1 |
const char *fname, const char *sname,
|
|
Packit Service |
084de1 |
int nohdr, const ASN1_PCTX *pctx);
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
static int asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
|
|
Packit Service |
084de1 |
const ASN1_TEMPLATE *tt, const ASN1_PCTX *pctx);
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld,
|
|
Packit Service |
084de1 |
const ASN1_ITEM *it, int indent,
|
|
Packit Service |
084de1 |
const char *fname, const char *sname,
|
|
Packit Service |
084de1 |
const ASN1_PCTX *pctx);
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
static int asn1_print_fsname(BIO *out, int indent,
|
|
Packit Service |
084de1 |
const char *fname, const char *sname,
|
|
Packit Service |
084de1 |
const ASN1_PCTX *pctx);
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
int ASN1_item_print(BIO *out, ASN1_VALUE *ifld, int indent,
|
|
Packit Service |
084de1 |
const ASN1_ITEM *it, const ASN1_PCTX *pctx)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
const char *sname;
|
|
Packit Service |
084de1 |
if (pctx == NULL)
|
|
Packit Service |
084de1 |
pctx = &default_pctx;
|
|
Packit Service |
084de1 |
if (pctx->flags & ASN1_PCTX_FLAGS_NO_STRUCT_NAME)
|
|
Packit Service |
084de1 |
sname = NULL;
|
|
Packit Service |
084de1 |
else
|
|
Packit Service |
084de1 |
sname = it->sname;
|
|
Packit Service |
084de1 |
return asn1_item_print_ctx(out, &ifld, indent, it, NULL, sname, 0, pctx);
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
|
|
Packit Service |
084de1 |
const ASN1_ITEM *it,
|
|
Packit Service |
084de1 |
const char *fname, const char *sname,
|
|
Packit Service |
084de1 |
int nohdr, const ASN1_PCTX *pctx)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
const ASN1_TEMPLATE *tt;
|
|
Packit Service |
084de1 |
const ASN1_EXTERN_FUNCS *ef;
|
|
Packit Service |
084de1 |
ASN1_VALUE **tmpfld;
|
|
Packit Service |
084de1 |
const ASN1_AUX *aux = it->funcs;
|
|
Packit Service |
084de1 |
ASN1_aux_cb *asn1_cb;
|
|
Packit Service |
084de1 |
ASN1_PRINT_ARG parg;
|
|
Packit Service |
084de1 |
int i;
|
|
Packit Service |
084de1 |
if (aux && aux->asn1_cb) {
|
|
Packit Service |
084de1 |
parg.out = out;
|
|
Packit Service |
084de1 |
parg.indent = indent;
|
|
Packit Service |
084de1 |
parg.pctx = pctx;
|
|
Packit Service |
084de1 |
asn1_cb = aux->asn1_cb;
|
|
Packit Service |
084de1 |
} else
|
|
Packit Service |
084de1 |
asn1_cb = 0;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
if (((it->itype != ASN1_ITYPE_PRIMITIVE)
|
|
Packit Service |
084de1 |
|| (it->utype != V_ASN1_BOOLEAN)) && *fld == NULL) {
|
|
Packit Service |
084de1 |
if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_ABSENT) {
|
|
Packit Service |
084de1 |
if (!nohdr && !asn1_print_fsname(out, indent, fname, sname, pctx))
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
if (BIO_puts(out, "<ABSENT>\n") <= 0)
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
return 1;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
switch (it->itype) {
|
|
Packit Service |
084de1 |
case ASN1_ITYPE_PRIMITIVE:
|
|
Packit Service |
084de1 |
if (it->templates) {
|
|
Packit Service |
084de1 |
if (!asn1_template_print_ctx(out, fld, indent,
|
|
Packit Service |
084de1 |
it->templates, pctx))
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
break;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
/* fall through */
|
|
Packit Service |
084de1 |
case ASN1_ITYPE_MSTRING:
|
|
Packit Service |
084de1 |
if (!asn1_primitive_print(out, fld, it, indent, fname, sname, pctx))
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
break;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
case ASN1_ITYPE_EXTERN:
|
|
Packit Service |
084de1 |
if (!nohdr && !asn1_print_fsname(out, indent, fname, sname, pctx))
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
/* Use new style print routine if possible */
|
|
Packit Service |
084de1 |
ef = it->funcs;
|
|
Packit Service |
084de1 |
if (ef && ef->asn1_ex_print) {
|
|
Packit Service |
084de1 |
i = ef->asn1_ex_print(out, fld, indent, "", pctx);
|
|
Packit Service |
084de1 |
if (!i)
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
if ((i == 2) && (BIO_puts(out, "\n") <= 0))
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
return 1;
|
|
Packit Service |
084de1 |
} else if (sname &&
|
|
Packit Service |
084de1 |
BIO_printf(out, ":EXTERNAL TYPE %s\n", sname) <= 0)
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
break;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
case ASN1_ITYPE_CHOICE:
|
|
Packit Service |
084de1 |
/* CHOICE type, get selector */
|
|
Packit Service |
084de1 |
i = asn1_get_choice_selector(fld, it);
|
|
Packit Service |
084de1 |
/* This should never happen... */
|
|
Packit Service |
084de1 |
if ((i < 0) || (i >= it->tcount)) {
|
|
Packit Service |
084de1 |
if (BIO_printf(out, "ERROR: selector [%d] invalid\n", i) <= 0)
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
return 1;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
tt = it->templates + i;
|
|
Packit Service |
084de1 |
tmpfld = asn1_get_field_ptr(fld, tt);
|
|
Packit Service |
084de1 |
if (!asn1_template_print_ctx(out, tmpfld, indent, tt, pctx))
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
break;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
case ASN1_ITYPE_SEQUENCE:
|
|
Packit Service |
084de1 |
case ASN1_ITYPE_NDEF_SEQUENCE:
|
|
Packit Service |
084de1 |
if (!nohdr && !asn1_print_fsname(out, indent, fname, sname, pctx))
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
if (fname || sname) {
|
|
Packit Service |
084de1 |
if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) {
|
|
Packit Service |
084de1 |
if (BIO_puts(out, " {\n") <= 0)
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
} else {
|
|
Packit Service |
084de1 |
if (BIO_puts(out, "\n") <= 0)
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
if (asn1_cb) {
|
|
Packit Service |
084de1 |
i = asn1_cb(ASN1_OP_PRINT_PRE, fld, it, &parg;;
|
|
Packit Service |
084de1 |
if (i == 0)
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
if (i == 2)
|
|
Packit Service |
084de1 |
return 1;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
/* Print each field entry */
|
|
Packit Service |
084de1 |
for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) {
|
|
Packit Service |
084de1 |
const ASN1_TEMPLATE *seqtt;
|
|
Packit Service |
084de1 |
seqtt = asn1_do_adb(fld, tt, 1);
|
|
Packit Service |
084de1 |
if (!seqtt)
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
tmpfld = asn1_get_field_ptr(fld, seqtt);
|
|
Packit Service |
084de1 |
if (!asn1_template_print_ctx(out, tmpfld,
|
|
Packit Service |
084de1 |
indent + 2, seqtt, pctx))
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) {
|
|
Packit Service |
084de1 |
if (BIO_printf(out, "%*s}\n", indent, "") < 0)
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
if (asn1_cb) {
|
|
Packit Service |
084de1 |
i = asn1_cb(ASN1_OP_PRINT_POST, fld, it, &parg;;
|
|
Packit Service |
084de1 |
if (i == 0)
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
break;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
default:
|
|
Packit Service |
084de1 |
BIO_printf(out, "Unprocessed type %d\n", it->itype);
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
return 1;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
static int asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
|
|
Packit Service |
084de1 |
const ASN1_TEMPLATE *tt, const ASN1_PCTX *pctx)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
int i, flags;
|
|
Packit Service |
084de1 |
const char *sname, *fname;
|
|
Packit Service |
084de1 |
ASN1_VALUE *tfld;
|
|
Packit Service |
084de1 |
flags = tt->flags;
|
|
Packit Service |
084de1 |
if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_FIELD_STRUCT_NAME)
|
|
Packit Service |
084de1 |
sname = ASN1_ITEM_ptr(tt->item)->sname;
|
|
Packit Service |
084de1 |
else
|
|
Packit Service |
084de1 |
sname = NULL;
|
|
Packit Service |
084de1 |
if (pctx->flags & ASN1_PCTX_FLAGS_NO_FIELD_NAME)
|
|
Packit Service |
084de1 |
fname = NULL;
|
|
Packit Service |
084de1 |
else
|
|
Packit Service |
084de1 |
fname = tt->field_name;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
/*
|
|
Packit Service |
084de1 |
* If field is embedded then fld needs fixing so it is a pointer to
|
|
Packit Service |
084de1 |
* a pointer to a field.
|
|
Packit Service |
084de1 |
*/
|
|
Packit Service |
084de1 |
if (flags & ASN1_TFLG_EMBED) {
|
|
Packit Service |
084de1 |
tfld = (ASN1_VALUE *)fld;
|
|
Packit Service |
084de1 |
fld = &tfl;;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
if (flags & ASN1_TFLG_SK_MASK) {
|
|
Packit Service |
084de1 |
char *tname;
|
|
Packit Service |
084de1 |
ASN1_VALUE *skitem;
|
|
Packit Service |
084de1 |
STACK_OF(ASN1_VALUE) *stack;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
/* SET OF, SEQUENCE OF */
|
|
Packit Service |
084de1 |
if (fname) {
|
|
Packit Service |
084de1 |
if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SSOF) {
|
|
Packit Service |
084de1 |
if (flags & ASN1_TFLG_SET_OF)
|
|
Packit Service |
084de1 |
tname = "SET";
|
|
Packit Service |
084de1 |
else
|
|
Packit Service |
084de1 |
tname = "SEQUENCE";
|
|
Packit Service |
084de1 |
if (BIO_printf(out, "%*s%s OF %s {\n",
|
|
Packit Service |
084de1 |
indent, "", tname, tt->field_name) <= 0)
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
} else if (BIO_printf(out, "%*s%s:\n", indent, "", fname) <= 0)
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
stack = (STACK_OF(ASN1_VALUE) *)*fld;
|
|
Packit Service |
084de1 |
for (i = 0; i < sk_ASN1_VALUE_num(stack); i++) {
|
|
Packit Service |
084de1 |
if ((i > 0) && (BIO_puts(out, "\n") <= 0))
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
skitem = sk_ASN1_VALUE_value(stack, i);
|
|
Packit Service |
084de1 |
if (!asn1_item_print_ctx(out, &skitem, indent + 2,
|
|
Packit Service |
084de1 |
ASN1_ITEM_ptr(tt->item), NULL, NULL, 1,
|
|
Packit Service |
084de1 |
pctx))
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
if (i == 0 && BIO_printf(out, "%*s<%s>\n", indent + 2, "",
|
|
Packit Service |
084de1 |
stack == NULL ? "ABSENT" : "EMPTY") <= 0)
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) {
|
|
Packit Service |
084de1 |
if (BIO_printf(out, "%*s}\n", indent, "") <= 0)
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
return 1;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
return asn1_item_print_ctx(out, fld, indent, ASN1_ITEM_ptr(tt->item),
|
|
Packit Service |
084de1 |
fname, sname, 0, pctx);
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
static int asn1_print_fsname(BIO *out, int indent,
|
|
Packit Service |
084de1 |
const char *fname, const char *sname,
|
|
Packit Service |
084de1 |
const ASN1_PCTX *pctx)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
static const char spaces[] = " ";
|
|
Packit Service |
084de1 |
static const int nspaces = sizeof(spaces) - 1;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
while (indent > nspaces) {
|
|
Packit Service |
084de1 |
if (BIO_write(out, spaces, nspaces) != nspaces)
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
indent -= nspaces;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
if (BIO_write(out, spaces, indent) != indent)
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
if (pctx->flags & ASN1_PCTX_FLAGS_NO_STRUCT_NAME)
|
|
Packit Service |
084de1 |
sname = NULL;
|
|
Packit Service |
084de1 |
if (pctx->flags & ASN1_PCTX_FLAGS_NO_FIELD_NAME)
|
|
Packit Service |
084de1 |
fname = NULL;
|
|
Packit Service |
084de1 |
if (!sname && !fname)
|
|
Packit Service |
084de1 |
return 1;
|
|
Packit Service |
084de1 |
if (fname) {
|
|
Packit Service |
084de1 |
if (BIO_puts(out, fname) <= 0)
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
if (sname) {
|
|
Packit Service |
084de1 |
if (fname) {
|
|
Packit Service |
084de1 |
if (BIO_printf(out, " (%s)", sname) <= 0)
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
} else {
|
|
Packit Service |
084de1 |
if (BIO_puts(out, sname) <= 0)
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
if (BIO_write(out, ": ", 2) != 2)
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
return 1;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
static int asn1_print_boolean(BIO *out, int boolval)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
const char *str;
|
|
Packit Service |
084de1 |
switch (boolval) {
|
|
Packit Service |
084de1 |
case -1:
|
|
Packit Service |
084de1 |
str = "BOOL ABSENT";
|
|
Packit Service |
084de1 |
break;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
case 0:
|
|
Packit Service |
084de1 |
str = "FALSE";
|
|
Packit Service |
084de1 |
break;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
default:
|
|
Packit Service |
084de1 |
str = "TRUE";
|
|
Packit Service |
084de1 |
break;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
if (BIO_puts(out, str) <= 0)
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
return 1;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
static int asn1_print_integer(BIO *out, const ASN1_INTEGER *str)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
char *s;
|
|
Packit Service |
084de1 |
int ret = 1;
|
|
Packit Service |
084de1 |
s = i2s_ASN1_INTEGER(NULL, str);
|
|
Packit Service |
084de1 |
if (s == NULL)
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
if (BIO_puts(out, s) <= 0)
|
|
Packit Service |
084de1 |
ret = 0;
|
|
Packit Service |
084de1 |
OPENSSL_free(s);
|
|
Packit Service |
084de1 |
return ret;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
static int asn1_print_oid(BIO *out, const ASN1_OBJECT *oid)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
char objbuf[80];
|
|
Packit Service |
084de1 |
const char *ln;
|
|
Packit Service |
084de1 |
ln = OBJ_nid2ln(OBJ_obj2nid(oid));
|
|
Packit Service |
084de1 |
if (!ln)
|
|
Packit Service |
084de1 |
ln = "";
|
|
Packit Service |
084de1 |
OBJ_obj2txt(objbuf, sizeof(objbuf), oid, 1);
|
|
Packit Service |
084de1 |
if (BIO_printf(out, "%s (%s)", ln, objbuf) <= 0)
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
return 1;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
static int asn1_print_obstring(BIO *out, const ASN1_STRING *str, int indent)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
if (str->type == V_ASN1_BIT_STRING) {
|
|
Packit Service |
084de1 |
if (BIO_printf(out, " (%ld unused bits)\n", str->flags & 0x7) <= 0)
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
} else if (BIO_puts(out, "\n") <= 0)
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
if ((str->length > 0)
|
|
Packit Service |
084de1 |
&& BIO_dump_indent(out, (const char *)str->data, str->length,
|
|
Packit Service |
084de1 |
indent + 2) <= 0)
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
return 1;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld,
|
|
Packit Service |
084de1 |
const ASN1_ITEM *it, int indent,
|
|
Packit Service |
084de1 |
const char *fname, const char *sname,
|
|
Packit Service |
084de1 |
const ASN1_PCTX *pctx)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
long utype;
|
|
Packit Service |
084de1 |
ASN1_STRING *str;
|
|
Packit Service |
084de1 |
int ret = 1, needlf = 1;
|
|
Packit Service |
084de1 |
const char *pname;
|
|
Packit Service |
084de1 |
const ASN1_PRIMITIVE_FUNCS *pf;
|
|
Packit Service |
084de1 |
pf = it->funcs;
|
|
Packit Service |
084de1 |
if (!asn1_print_fsname(out, indent, fname, sname, pctx))
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
if (pf && pf->prim_print)
|
|
Packit Service |
084de1 |
return pf->prim_print(out, fld, it, indent, pctx);
|
|
Packit Service |
084de1 |
if (it->itype == ASN1_ITYPE_MSTRING) {
|
|
Packit Service |
084de1 |
str = (ASN1_STRING *)*fld;
|
|
Packit Service |
084de1 |
utype = str->type & ~V_ASN1_NEG;
|
|
Packit Service |
084de1 |
} else {
|
|
Packit Service |
084de1 |
utype = it->utype;
|
|
Packit Service |
084de1 |
if (utype == V_ASN1_BOOLEAN)
|
|
Packit Service |
084de1 |
str = NULL;
|
|
Packit Service |
084de1 |
else
|
|
Packit Service |
084de1 |
str = (ASN1_STRING *)*fld;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
if (utype == V_ASN1_ANY) {
|
|
Packit Service |
084de1 |
ASN1_TYPE *atype = (ASN1_TYPE *)*fld;
|
|
Packit Service |
084de1 |
utype = atype->type;
|
|
Packit Service |
084de1 |
fld = &atype->value.asn1_value;
|
|
Packit Service |
084de1 |
str = (ASN1_STRING *)*fld;
|
|
Packit Service |
084de1 |
if (pctx->flags & ASN1_PCTX_FLAGS_NO_ANY_TYPE)
|
|
Packit Service |
084de1 |
pname = NULL;
|
|
Packit Service |
084de1 |
else
|
|
Packit Service |
084de1 |
pname = ASN1_tag2str(utype);
|
|
Packit Service |
084de1 |
} else {
|
|
Packit Service |
084de1 |
if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_TYPE)
|
|
Packit Service |
084de1 |
pname = ASN1_tag2str(utype);
|
|
Packit Service |
084de1 |
else
|
|
Packit Service |
084de1 |
pname = NULL;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
if (utype == V_ASN1_NULL) {
|
|
Packit Service |
084de1 |
if (BIO_puts(out, "NULL\n") <= 0)
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
return 1;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
if (pname) {
|
|
Packit Service |
084de1 |
if (BIO_puts(out, pname) <= 0)
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
if (BIO_puts(out, ":") <= 0)
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
switch (utype) {
|
|
Packit Service |
084de1 |
case V_ASN1_BOOLEAN:
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
int boolval = *(int *)fld;
|
|
Packit Service |
084de1 |
if (boolval == -1)
|
|
Packit Service |
084de1 |
boolval = it->size;
|
|
Packit Service |
084de1 |
ret = asn1_print_boolean(out, boolval);
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
break;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
case V_ASN1_INTEGER:
|
|
Packit Service |
084de1 |
case V_ASN1_ENUMERATED:
|
|
Packit Service |
084de1 |
ret = asn1_print_integer(out, str);
|
|
Packit Service |
084de1 |
break;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
case V_ASN1_UTCTIME:
|
|
Packit Service |
084de1 |
ret = ASN1_UTCTIME_print(out, str);
|
|
Packit Service |
084de1 |
break;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
case V_ASN1_GENERALIZEDTIME:
|
|
Packit Service |
084de1 |
ret = ASN1_GENERALIZEDTIME_print(out, str);
|
|
Packit Service |
084de1 |
break;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
case V_ASN1_OBJECT:
|
|
Packit Service |
084de1 |
ret = asn1_print_oid(out, (const ASN1_OBJECT *)*fld);
|
|
Packit Service |
084de1 |
break;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
case V_ASN1_OCTET_STRING:
|
|
Packit Service |
084de1 |
case V_ASN1_BIT_STRING:
|
|
Packit Service |
084de1 |
ret = asn1_print_obstring(out, str, indent);
|
|
Packit Service |
084de1 |
needlf = 0;
|
|
Packit Service |
084de1 |
break;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
case V_ASN1_SEQUENCE:
|
|
Packit Service |
084de1 |
case V_ASN1_SET:
|
|
Packit Service |
084de1 |
case V_ASN1_OTHER:
|
|
Packit Service |
084de1 |
if (BIO_puts(out, "\n") <= 0)
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
if (ASN1_parse_dump(out, str->data, str->length, indent, 0) <= 0)
|
|
Packit Service |
084de1 |
ret = 0;
|
|
Packit Service |
084de1 |
needlf = 0;
|
|
Packit Service |
084de1 |
break;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
default:
|
|
Packit Service |
084de1 |
ret = ASN1_STRING_print_ex(out, str, pctx->str_flags);
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
if (!ret)
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
if (needlf && BIO_puts(out, "\n") <= 0)
|
|
Packit Service |
084de1 |
return 0;
|
|
Packit Service |
084de1 |
return 1;
|
|
Packit Service |
084de1 |
}
|