int ASN1_GENERALIZEDTIME_print(BIO *bp, const ASN1_GENERALIZEDTIME *tm)
{
    char *v;
    int gmt = 0;
    int i;
    int y = 0, M = 0, d = 0, h = 0, m = 0, s = 0;
    char *f = NULL;
    int f_len = 0;
    i = tm->length;
    v = (char *)tm->data;
    if (i < 12)
        goto err;
    if (v[i - 1] == 'Z')
        gmt = 1;
    for (i = 0; i < 12; i++)
        if ((v[i] > '9') || (v[i] < '0'))
            goto err;
    y = (v[0] - '0') * 1000 + (v[1] - '0') * 100
        + (v[2] - '0') * 10 + (v[3] - '0');
    M = (v[4] - '0') * 10 + (v[5] - '0');
    if ((M > 12) || (M < 1))
        goto err;
    d = (v[6] - '0') * 10 + (v[7] - '0');
    h = (v[8] - '0') * 10 + (v[9] - '0');
    m = (v[10] - '0') * 10 + (v[11] - '0');
    if (tm->length >= 14 &&
        (v[12] >= '0') && (v[12] <= '9') &&
        (v[13] >= '0') && (v[13] <= '9')) {
        s = (v[12] - '0') * 10 + (v[13] - '0');
        if (tm->length >= 15 && v[14] == '.') {
            int l = tm->length;
            f = &v[14];
            f_len = 1;
            while (14 + f_len < l && f[f_len] >= '0' && f[f_len] <= '9')
                ++f_len;
        }
    }
    if (BIO_printf(bp, "%s %2d %02d:%02d:%02d%.*s %d%s",
                   _asn1_mon[M - 1], d, h, m, s, f_len, f, y,
                   (gmt) ? " GMT" : "") <= 0)
        return (0);
    else
        return (1);
 err:
    BIO_write(bp, "Bad time value", 14);
    return (0);
}
['int x509_main(int argc, char **argv)\n{\n    ASN1_INTEGER *sno = NULL;\n    ASN1_OBJECT *objtmp;\n    BIO *out = NULL;\n    CONF *extconf = NULL;\n    EVP_PKEY *Upkey = NULL, *CApkey = NULL, *fkey = NULL;\n    STACK_OF(ASN1_OBJECT) *trust = NULL, *reject = NULL;\n    STACK_OF(OPENSSL_STRING) *sigopts = NULL;\n    X509 *x = NULL, *xca = NULL;\n    X509_REQ *req = NULL, *rq = NULL;\n    X509_STORE *ctx = NULL;\n    const EVP_MD *digest = NULL;\n    char *CAkeyfile = NULL, *CAserial = NULL, *fkeyfile = NULL, *alias = NULL;\n    char *checkhost = NULL, *checkemail = NULL, *checkip = NULL;\n    char *extsect = NULL, *extfile = NULL, *passin = NULL, *passinarg = NULL;\n    char *infile = NULL, *outfile = NULL, *keyfile = NULL, *CAfile = NULL;\n    char buf[256], *prog;\n    int x509req = 0, days = DEF_DAYS, modulus = 0, pubkey = 0, pprint = 0;\n    int C = 0, CAformat = FORMAT_PEM, CAkeyformat = FORMAT_PEM;\n    int fingerprint = 0, reqfile = 0, need_rand = 0, checkend = 0;\n    int informat = FORMAT_PEM, outformat = FORMAT_PEM, keyformat = FORMAT_PEM;\n    int next_serial = 0, subject_hash = 0, issuer_hash = 0, ocspid = 0;\n    int noout = 0, sign_flag = 0, CA_flag = 0, CA_createserial = 0, email = 0;\n    int ocsp_uri = 0, trustout = 0, clrtrust = 0, clrreject = 0, aliasout = 0;\n    int ret = 1, i, num = 0, badsig = 0, clrext = 0, nocert = 0;\n    int text = 0, serial = 0, subject = 0, issuer = 0, startdate = 0;\n    int checkoffset = 0, enddate = 0;\n    unsigned long nmflag = 0, certflag = 0;\n    char nmflag_set = 0;\n    OPTION_CHOICE o;\n    ENGINE *e = NULL;\n#ifndef OPENSSL_NO_MD5\n    int subject_hash_old = 0, issuer_hash_old = 0;\n#endif\n    ctx = X509_STORE_new();\n    if (ctx == NULL)\n        goto end;\n    X509_STORE_set_verify_cb(ctx, callb);\n    prog = opt_init(argc, argv, x509_options);\n    while ((o = opt_next()) != OPT_EOF) {\n        switch (o) {\n        case OPT_EOF:\n        case OPT_ERR:\n opthelp:\n            BIO_printf(bio_err, "%s: Use -help for summary.\\n", prog);\n            goto end;\n        case OPT_HELP:\n            opt_help(x509_options);\n            ret = 0;\n            goto end;\n        case OPT_INFORM:\n            if (!opt_format(opt_arg(), OPT_FMT_ANY, &informat))\n                goto opthelp;\n            break;\n        case OPT_IN:\n            infile = opt_arg();\n            break;\n        case OPT_OUTFORM:\n            if (!opt_format(opt_arg(), OPT_FMT_ANY, &outformat))\n                goto opthelp;\n            break;\n        case OPT_KEYFORM:\n            if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &keyformat))\n                goto opthelp;\n            break;\n        case OPT_CAFORM:\n            if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &CAformat))\n                goto opthelp;\n            break;\n        case OPT_CAKEYFORM:\n            if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &CAkeyformat))\n                goto opthelp;\n            break;\n        case OPT_OUT:\n            outfile = opt_arg();\n            break;\n        case OPT_REQ:\n            reqfile = need_rand = 1;\n            break;\n        case OPT_SIGOPT:\n            if (!sigopts)\n                sigopts = sk_OPENSSL_STRING_new_null();\n            if (!sigopts || !sk_OPENSSL_STRING_push(sigopts, opt_arg()))\n                goto opthelp;\n            break;\n        case OPT_FORCE_VERSION:\n#ifdef OPENSSL_SSL_DEBUG_BROKEN_PROTOCOL\n            force_version = atoi(opt_arg()) - 1;\n#endif\n            break;\n        case OPT_DAYS:\n            days = atoi(opt_arg());\n            break;\n        case OPT_PASSIN:\n            passinarg = opt_arg();\n            break;\n        case OPT_EXTFILE:\n            extfile = opt_arg();\n            break;\n        case OPT_EXTENSIONS:\n            extsect = opt_arg();\n            break;\n        case OPT_SIGNKEY:\n            keyfile = opt_arg();\n            sign_flag = ++num;\n            need_rand = 1;\n            break;\n        case OPT_CA:\n            CAfile = opt_arg();\n            CA_flag = ++num;\n            need_rand = 1;\n            break;\n        case OPT_CAKEY:\n            CAkeyfile = opt_arg();\n            break;\n        case OPT_CASERIAL:\n            CAserial = opt_arg();\n            break;\n        case OPT_SET_SERIAL:\n            if ((sno = s2i_ASN1_INTEGER(NULL, opt_arg())) == NULL)\n                goto opthelp;\n            break;\n        case OPT_FORCE_PUBKEY:\n            fkeyfile = opt_arg();\n            break;\n        case OPT_ADDTRUST:\n            if ((objtmp = OBJ_txt2obj(opt_arg(), 0)) == NULL) {\n                BIO_printf(bio_err,\n                           "%s: Invalid trust object value %s\\n",\n                           prog, opt_arg());\n                goto opthelp;\n            }\n            if (trust == NULL && (trust = sk_ASN1_OBJECT_new_null()) == NULL)\n                goto end;\n            sk_ASN1_OBJECT_push(trust, objtmp);\n            trustout = 1;\n            break;\n        case OPT_ADDREJECT:\n            if ((objtmp = OBJ_txt2obj(opt_arg(), 0)) == NULL) {\n                BIO_printf(bio_err,\n                           "%s: Invalid reject object value %s\\n",\n                           prog, opt_arg());\n                goto opthelp;\n            }\n            if (reject == NULL\n                && (reject = sk_ASN1_OBJECT_new_null()) == NULL)\n                goto end;\n            sk_ASN1_OBJECT_push(reject, objtmp);\n            trustout = 1;\n            break;\n        case OPT_SETALIAS:\n            alias = opt_arg();\n            trustout = 1;\n            break;\n        case OPT_CERTOPT:\n            if (!set_cert_ex(&certflag, opt_arg()))\n                goto opthelp;\n            break;\n        case OPT_NAMEOPT:\n            nmflag_set = 1;\n            if (!set_name_ex(&nmflag, opt_arg()))\n                goto opthelp;\n            break;\n        case OPT_ENGINE:\n            e = setup_engine(opt_arg(), 0);\n            break;\n        case OPT_C:\n            C = ++num;\n            break;\n        case OPT_EMAIL:\n            email = ++num;\n            break;\n        case OPT_OCSP_URI:\n            ocsp_uri = ++num;\n            break;\n        case OPT_SERIAL:\n            serial = ++num;\n            break;\n        case OPT_NEXT_SERIAL:\n            next_serial = ++num;\n            break;\n        case OPT_MODULUS:\n            modulus = ++num;\n            break;\n        case OPT_PUBKEY:\n            pubkey = ++num;\n            break;\n        case OPT_X509TOREQ:\n            x509req = ++num;\n            break;\n        case OPT_TEXT:\n            text = ++num;\n            break;\n        case OPT_SUBJECT:\n            subject = ++num;\n            break;\n        case OPT_ISSUER:\n            issuer = ++num;\n            break;\n        case OPT_FINGERPRINT:\n            fingerprint = ++num;\n            break;\n        case OPT_HASH:\n            subject_hash = ++num;\n            break;\n        case OPT_ISSUER_HASH:\n            issuer_hash = ++num;\n            break;\n        case OPT_PURPOSE:\n            pprint = ++num;\n            break;\n        case OPT_STARTDATE:\n            startdate = ++num;\n            break;\n        case OPT_ENDDATE:\n            enddate = ++num;\n            break;\n        case OPT_NOOUT:\n            noout = ++num;\n            break;\n        case OPT_NOCERT:\n            nocert = 1;\n            break;\n        case OPT_TRUSTOUT:\n            trustout = 1;\n            break;\n        case OPT_CLRTRUST:\n            clrtrust = ++num;\n            break;\n        case OPT_CLRREJECT:\n            clrreject = ++num;\n            break;\n        case OPT_ALIAS:\n            aliasout = ++num;\n            break;\n        case OPT_CACREATESERIAL:\n            CA_createserial = ++num;\n            break;\n        case OPT_CLREXT:\n            clrext = 1;\n            break;\n        case OPT_OCSPID:\n            ocspid = ++num;\n            break;\n        case OPT_BADSIG:\n            badsig = 1;\n            break;\n#ifndef OPENSSL_NO_MD5\n        case OPT_SUBJECT_HASH_OLD:\n            subject_hash_old = ++num;\n            break;\n        case OPT_ISSUER_HASH_OLD:\n            issuer_hash_old = ++num;\n            break;\n#else\n        case OPT_SUBJECT_HASH_OLD:\n        case OPT_ISSUER_HASH_OLD:\n            break;\n#endif\n        case OPT_DATES:\n            startdate = ++num;\n            enddate = ++num;\n            break;\n        case OPT_CHECKEND:\n            checkoffset = atoi(opt_arg());\n            checkend = 1;\n            break;\n        case OPT_CHECKHOST:\n            checkhost = opt_arg();\n            break;\n        case OPT_CHECKEMAIL:\n            checkemail = opt_arg();\n            break;\n        case OPT_CHECKIP:\n            checkip = opt_arg();\n            break;\n        case OPT_MD:\n            if (!opt_md(opt_unknown(), &digest))\n                goto opthelp;\n        }\n    }\n    argc = opt_num_rest();\n    argv = opt_rest();\n    if (argc != 0) {\n        BIO_printf(bio_err, "%s: Unknown parameter %s\\n", prog, argv[0]);\n        goto opthelp;\n    }\n    if (!nmflag_set)\n        nmflag = XN_FLAG_ONELINE;\n    out = bio_open_default(outfile, \'w\', outformat);\n    if (out == NULL)\n        goto end;\n    if (need_rand)\n        app_RAND_load_file(NULL, 0);\n    if (!app_passwd(passinarg, NULL, &passin, NULL)) {\n        BIO_printf(bio_err, "Error getting password\\n");\n        goto end;\n    }\n    if (!X509_STORE_set_default_paths(ctx)) {\n        ERR_print_errors(bio_err);\n        goto end;\n    }\n    if (fkeyfile) {\n        fkey = load_pubkey(fkeyfile, keyformat, 0, NULL, e, "Forced key");\n        if (fkey == NULL)\n            goto end;\n    }\n    if ((CAkeyfile == NULL) && (CA_flag) && (CAformat == FORMAT_PEM)) {\n        CAkeyfile = CAfile;\n    } else if ((CA_flag) && (CAkeyfile == NULL)) {\n        BIO_printf(bio_err,\n                   "need to specify a CAkey if using the CA command\\n");\n        goto end;\n    }\n    if (extfile) {\n        X509V3_CTX ctx2;\n        if ((extconf = app_load_config(extfile)) == NULL)\n            goto end;\n        if (!extsect) {\n            extsect = NCONF_get_string(extconf, "default", "extensions");\n            if (!extsect) {\n                ERR_clear_error();\n                extsect = "default";\n            }\n        }\n        X509V3_set_ctx_test(&ctx2);\n        X509V3_set_nconf(&ctx2, extconf);\n        if (!X509V3_EXT_add_nconf(extconf, &ctx2, extsect, NULL)) {\n            BIO_printf(bio_err,\n                       "Error Loading extension section %s\\n", extsect);\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n    }\n    if (reqfile) {\n        EVP_PKEY *pkey;\n        BIO *in;\n        if (!sign_flag && !CA_flag) {\n            BIO_printf(bio_err, "We need a private key to sign with\\n");\n            goto end;\n        }\n        in = bio_open_default(infile, \'r\', informat);\n        if (in == NULL)\n            goto end;\n        req = PEM_read_bio_X509_REQ(in, NULL, NULL, NULL);\n        BIO_free(in);\n        if (req == NULL) {\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n        if ((pkey = X509_REQ_get_pubkey(req)) == NULL) {\n            BIO_printf(bio_err, "error unpacking public key\\n");\n            goto end;\n        }\n        i = X509_REQ_verify(req, pkey);\n        EVP_PKEY_free(pkey);\n        if (i < 0) {\n            BIO_printf(bio_err, "Signature verification error\\n");\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n        if (i == 0) {\n            BIO_printf(bio_err,\n                       "Signature did not match the certificate request\\n");\n            goto end;\n        } else\n            BIO_printf(bio_err, "Signature ok\\n");\n        print_name(bio_err, "subject=", X509_REQ_get_subject_name(req),\n                   nmflag);\n        if ((x = X509_new()) == NULL)\n            goto end;\n        if (sno == NULL) {\n            sno = ASN1_INTEGER_new();\n            if (sno == NULL || !rand_serial(NULL, sno))\n                goto end;\n            if (!X509_set_serialNumber(x, sno))\n                goto end;\n            ASN1_INTEGER_free(sno);\n            sno = NULL;\n        } else if (!X509_set_serialNumber(x, sno))\n            goto end;\n        if (!X509_set_issuer_name(x, X509_REQ_get_subject_name(req)))\n            goto end;\n        if (!X509_set_subject_name(x, X509_REQ_get_subject_name(req)))\n            goto end;\n        X509_gmtime_adj(X509_get_notBefore(x), 0);\n        X509_time_adj_ex(X509_get_notAfter(x), days, 0, NULL);\n        if (fkey)\n            X509_set_pubkey(x, fkey);\n        else {\n            pkey = X509_REQ_get_pubkey(req);\n            X509_set_pubkey(x, pkey);\n            EVP_PKEY_free(pkey);\n        }\n    } else\n        x = load_cert(infile, informat, NULL, e, "Certificate");\n    if (x == NULL)\n        goto end;\n    if (CA_flag) {\n        xca = load_cert(CAfile, CAformat, NULL, e, "CA Certificate");\n        if (xca == NULL)\n            goto end;\n    }\n    if (!noout || text || next_serial) {\n        OBJ_create("2.99999.3", "SET.ex3", "SET x509v3 extension 3");\n    }\n    if (alias)\n        X509_alias_set1(x, (unsigned char *)alias, -1);\n    if (clrtrust)\n        X509_trust_clear(x);\n    if (clrreject)\n        X509_reject_clear(x);\n    if (trust) {\n        for (i = 0; i < sk_ASN1_OBJECT_num(trust); i++) {\n            objtmp = sk_ASN1_OBJECT_value(trust, i);\n            X509_add1_trust_object(x, objtmp);\n        }\n    }\n    if (reject) {\n        for (i = 0; i < sk_ASN1_OBJECT_num(reject); i++) {\n            objtmp = sk_ASN1_OBJECT_value(reject, i);\n            X509_add1_reject_object(x, objtmp);\n        }\n    }\n    if (num) {\n        for (i = 1; i <= num; i++) {\n            if (issuer == i) {\n                print_name(out, "issuer= ", X509_get_issuer_name(x), nmflag);\n            } else if (subject == i) {\n                print_name(out, "subject= ",\n                           X509_get_subject_name(x), nmflag);\n            } else if (serial == i) {\n                BIO_printf(out, "serial=");\n                i2a_ASN1_INTEGER(out, X509_get_serialNumber(x));\n                BIO_printf(out, "\\n");\n            } else if (next_serial == i) {\n                BIGNUM *bnser;\n                ASN1_INTEGER *ser;\n                ser = X509_get_serialNumber(x);\n                bnser = ASN1_INTEGER_to_BN(ser, NULL);\n                if (!bnser)\n                    goto end;\n                if (!BN_add_word(bnser, 1))\n                    goto end;\n                ser = BN_to_ASN1_INTEGER(bnser, NULL);\n                if (!ser)\n                    goto end;\n                BN_free(bnser);\n                i2a_ASN1_INTEGER(out, ser);\n                ASN1_INTEGER_free(ser);\n                BIO_puts(out, "\\n");\n            } else if ((email == i) || (ocsp_uri == i)) {\n                int j;\n                STACK_OF(OPENSSL_STRING) *emlst;\n                if (email == i)\n                    emlst = X509_get1_email(x);\n                else\n                    emlst = X509_get1_ocsp(x);\n                for (j = 0; j < sk_OPENSSL_STRING_num(emlst); j++)\n                    BIO_printf(out, "%s\\n",\n                               sk_OPENSSL_STRING_value(emlst, j));\n                X509_email_free(emlst);\n            } else if (aliasout == i) {\n                unsigned char *alstr;\n                alstr = X509_alias_get0(x, NULL);\n                if (alstr)\n                    BIO_printf(out, "%s\\n", alstr);\n                else\n                    BIO_puts(out, "<No Alias>\\n");\n            } else if (subject_hash == i) {\n                BIO_printf(out, "%08lx\\n", X509_subject_name_hash(x));\n            }\n#ifndef OPENSSL_NO_MD5\n            else if (subject_hash_old == i) {\n                BIO_printf(out, "%08lx\\n", X509_subject_name_hash_old(x));\n            }\n#endif\n            else if (issuer_hash == i) {\n                BIO_printf(out, "%08lx\\n", X509_issuer_name_hash(x));\n            }\n#ifndef OPENSSL_NO_MD5\n            else if (issuer_hash_old == i) {\n                BIO_printf(out, "%08lx\\n", X509_issuer_name_hash_old(x));\n            }\n#endif\n            else if (pprint == i) {\n                X509_PURPOSE *ptmp;\n                int j;\n                BIO_printf(out, "Certificate purposes:\\n");\n                for (j = 0; j < X509_PURPOSE_get_count(); j++) {\n                    ptmp = X509_PURPOSE_get0(j);\n                    purpose_print(out, x, ptmp);\n                }\n            } else if (modulus == i) {\n                EVP_PKEY *pkey;\n                pkey = X509_get_pubkey(x);\n                if (pkey == NULL) {\n                    BIO_printf(bio_err, "Modulus=unavailable\\n");\n                    ERR_print_errors(bio_err);\n                    goto end;\n                }\n                BIO_printf(out, "Modulus=");\n#ifndef OPENSSL_NO_RSA\n                if (pkey->type == EVP_PKEY_RSA)\n                    BN_print(out, pkey->pkey.rsa->n);\n                else\n#endif\n#ifndef OPENSSL_NO_DSA\n                if (pkey->type == EVP_PKEY_DSA)\n                    BN_print(out, pkey->pkey.dsa->pub_key);\n                else\n#endif\n                    BIO_printf(out, "Wrong Algorithm type");\n                BIO_printf(out, "\\n");\n                EVP_PKEY_free(pkey);\n            } else if (pubkey == i) {\n                EVP_PKEY *pkey;\n                pkey = X509_get_pubkey(x);\n                if (pkey == NULL) {\n                    BIO_printf(bio_err, "Error getting public key\\n");\n                    ERR_print_errors(bio_err);\n                    goto end;\n                }\n                PEM_write_bio_PUBKEY(out, pkey);\n                EVP_PKEY_free(pkey);\n            } else if (C == i) {\n                unsigned char *d;\n                char *m;\n                int len;\n                X509_NAME_oneline(X509_get_subject_name(x), buf, sizeof buf);\n                BIO_printf(out, "/*\\n"\n                                " * Subject: %s\\n", buf);\n                m = X509_NAME_oneline(X509_get_issuer_name(x), buf, sizeof buf);\n                BIO_printf(out, " * Issuer:  %s\\n"\n                                " */\\n", buf);\n                len = i2d_X509(x, NULL);\n                m = app_malloc(len, "x509 name buffer");\n                d = (unsigned char *)m;\n                len = i2d_X509_NAME(X509_get_subject_name(x), &d);\n                print_array(out, "the_subject_name", len, (unsigned char *)m);\n                d = (unsigned char *)m;\n                len = i2d_X509_PUBKEY(X509_get_X509_PUBKEY(x), &d);\n                print_array(out, "the_public_key", len, (unsigned char *)m);\n                d = (unsigned char *)m;\n                len = i2d_X509(x, &d);\n                print_array(out, "the_certificate", len, (unsigned char *)m);\n                OPENSSL_free(m);\n            } else if (text == i) {\n                X509_print_ex(out, x, nmflag, certflag);\n            } else if (startdate == i) {\n                BIO_puts(out, "notBefore=");\n                ASN1_TIME_print(out, X509_get_notBefore(x));\n                BIO_puts(out, "\\n");\n            } else if (enddate == i) {\n                BIO_puts(out, "notAfter=");\n                ASN1_TIME_print(out, X509_get_notAfter(x));\n                BIO_puts(out, "\\n");\n            } else if (fingerprint == i) {\n                int j;\n                unsigned int n;\n                unsigned char md[EVP_MAX_MD_SIZE];\n                const EVP_MD *fdig = digest;\n                if (!fdig)\n                    fdig = EVP_sha1();\n                if (!X509_digest(x, fdig, md, &n)) {\n                    BIO_printf(bio_err, "out of memory\\n");\n                    goto end;\n                }\n                BIO_printf(out, "%s Fingerprint=",\n                           OBJ_nid2sn(EVP_MD_type(fdig)));\n                for (j = 0; j < (int)n; j++) {\n                    BIO_printf(out, "%02X%c", md[j], (j + 1 == (int)n)\n                               ? \'\\n\' : \':\');\n                }\n            }\n            else if ((sign_flag == i) && (x509req == 0)) {\n                BIO_printf(bio_err, "Getting Private key\\n");\n                if (Upkey == NULL) {\n                    Upkey = load_key(keyfile, keyformat, 0,\n                                     passin, e, "Private key");\n                    if (Upkey == NULL)\n                        goto end;\n                }\n                assert(need_rand);\n                if (!sign(x, Upkey, days, clrext, digest, extconf, extsect))\n                    goto end;\n            } else if (CA_flag == i) {\n                BIO_printf(bio_err, "Getting CA Private Key\\n");\n                if (CAkeyfile != NULL) {\n                    CApkey = load_key(CAkeyfile, CAkeyformat,\n                                      0, passin, e, "CA Private Key");\n                    if (CApkey == NULL)\n                        goto end;\n                }\n                assert(need_rand);\n                if (!x509_certify(ctx, CAfile, digest, x, xca,\n                                  CApkey, sigopts,\n                                  CAserial, CA_createserial, days, clrext,\n                                  extconf, extsect, sno, reqfile))\n                    goto end;\n            } else if (x509req == i) {\n                EVP_PKEY *pk;\n                BIO_printf(bio_err, "Getting request Private Key\\n");\n                if (keyfile == NULL) {\n                    BIO_printf(bio_err, "no request key file specified\\n");\n                    goto end;\n                } else {\n                    pk = load_key(keyfile, keyformat, 0,\n                                  passin, e, "request key");\n                    if (pk == NULL)\n                        goto end;\n                }\n                BIO_printf(bio_err, "Generating certificate request\\n");\n                rq = X509_to_X509_REQ(x, pk, digest);\n                EVP_PKEY_free(pk);\n                if (rq == NULL) {\n                    ERR_print_errors(bio_err);\n                    goto end;\n                }\n                if (!noout) {\n                    X509_REQ_print(out, rq);\n                    PEM_write_bio_X509_REQ(out, rq);\n                }\n                noout = 1;\n            } else if (ocspid == i) {\n                X509_ocspid_print(out, x);\n            }\n        }\n    }\n    if (checkend) {\n        time_t tcheck = time(NULL) + checkoffset;\n        if (X509_cmp_time(X509_get_notAfter(x), &tcheck) < 0) {\n            BIO_printf(out, "Certificate will expire\\n");\n            ret = 1;\n        } else {\n            BIO_printf(out, "Certificate will not expire\\n");\n            ret = 0;\n        }\n        goto end;\n    }\n    print_cert_checks(out, x, checkhost, checkemail, checkip);\n    if (noout || nocert) {\n        ret = 0;\n        goto end;\n    }\n    if (badsig) {\n        ASN1_BIT_STRING *signature;\n        unsigned char *s;\n        X509_get0_signature(&signature, NULL, x);\n        s = ASN1_STRING_data(signature);\n        s[ASN1_STRING_length(signature) - 1] ^= 0x1;\n    }\n    if (outformat == FORMAT_ASN1)\n        i = i2d_X509_bio(out, x);\n    else if (outformat == FORMAT_PEM) {\n        if (trustout)\n            i = PEM_write_bio_X509_AUX(out, x);\n        else\n            i = PEM_write_bio_X509(out, x);\n    } else {\n        BIO_printf(bio_err, "bad output format specified for outfile\\n");\n        goto end;\n    }\n    if (!i) {\n        BIO_printf(bio_err, "unable to write certificate\\n");\n        ERR_print_errors(bio_err);\n        goto end;\n    }\n    ret = 0;\n end:\n    if (need_rand)\n        app_RAND_write_file(NULL);\n    OBJ_cleanup();\n    NCONF_free(extconf);\n    BIO_free_all(out);\n    X509_STORE_free(ctx);\n    X509_REQ_free(req);\n    X509_free(x);\n    X509_free(xca);\n    EVP_PKEY_free(Upkey);\n    EVP_PKEY_free(CApkey);\n    EVP_PKEY_free(fkey);\n    sk_OPENSSL_STRING_free(sigopts);\n    X509_REQ_free(rq);\n    ASN1_INTEGER_free(sno);\n    sk_ASN1_OBJECT_pop_free(trust, ASN1_OBJECT_free);\n    sk_ASN1_OBJECT_pop_free(reject, ASN1_OBJECT_free);\n    OPENSSL_free(passin);\n    return (ret);\n}', 'int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a)\n{\n    int i, n = 0;\n    static const char *h = "0123456789ABCDEF";\n    char buf[2];\n    if (a == NULL)\n        return (0);\n    if (a->type & V_ASN1_NEG) {\n        if (BIO_write(bp, "-", 1) != 1)\n            goto err;\n        n = 1;\n    }\n    if (a->length == 0) {\n        if (BIO_write(bp, "00", 2) != 2)\n            goto err;\n        n += 2;\n    } else {\n        for (i = 0; i < a->length; i++) {\n            if ((i != 0) && (i % 35 == 0)) {\n                if (BIO_write(bp, "\\\\\\n", 2) != 2)\n                    goto err;\n                n += 2;\n            }\n            buf[0] = h[((unsigned char)a->data[i] >> 4) & 0x0f];\n            buf[1] = h[((unsigned char)a->data[i]) & 0x0f];\n            if (BIO_write(bp, buf, 2) != 2)\n                goto err;\n            n += 2;\n        }\n    }\n    return (n);\n err:\n    return (-1);\n}', 'int ASN1_TIME_print(BIO *bp, const ASN1_TIME *tm)\n{\n    if (tm->type == V_ASN1_UTCTIME)\n        return ASN1_UTCTIME_print(bp, tm);\n    if (tm->type == V_ASN1_GENERALIZEDTIME)\n        return ASN1_GENERALIZEDTIME_print(bp, tm);\n    BIO_write(bp, "Bad time value", 14);\n    return (0);\n}', 'int ASN1_GENERALIZEDTIME_print(BIO *bp, const ASN1_GENERALIZEDTIME *tm)\n{\n    char *v;\n    int gmt = 0;\n    int i;\n    int y = 0, M = 0, d = 0, h = 0, m = 0, s = 0;\n    char *f = NULL;\n    int f_len = 0;\n    i = tm->length;\n    v = (char *)tm->data;\n    if (i < 12)\n        goto err;\n    if (v[i - 1] == \'Z\')\n        gmt = 1;\n    for (i = 0; i < 12; i++)\n        if ((v[i] > \'9\') || (v[i] < \'0\'))\n            goto err;\n    y = (v[0] - \'0\') * 1000 + (v[1] - \'0\') * 100\n        + (v[2] - \'0\') * 10 + (v[3] - \'0\');\n    M = (v[4] - \'0\') * 10 + (v[5] - \'0\');\n    if ((M > 12) || (M < 1))\n        goto err;\n    d = (v[6] - \'0\') * 10 + (v[7] - \'0\');\n    h = (v[8] - \'0\') * 10 + (v[9] - \'0\');\n    m = (v[10] - \'0\') * 10 + (v[11] - \'0\');\n    if (tm->length >= 14 &&\n        (v[12] >= \'0\') && (v[12] <= \'9\') &&\n        (v[13] >= \'0\') && (v[13] <= \'9\')) {\n        s = (v[12] - \'0\') * 10 + (v[13] - \'0\');\n        if (tm->length >= 15 && v[14] == \'.\') {\n            int l = tm->length;\n            f = &v[14];\n            f_len = 1;\n            while (14 + f_len < l && f[f_len] >= \'0\' && f[f_len] <= \'9\')\n                ++f_len;\n        }\n    }\n    if (BIO_printf(bp, "%s %2d %02d:%02d:%02d%.*s %d%s",\n                   _asn1_mon[M - 1], d, h, m, s, f_len, f, y,\n                   (gmt) ? " GMT" : "") <= 0)\n        return (0);\n    else\n        return (1);\n err:\n    BIO_write(bp, "Bad time value", 14);\n    return (0);\n}']