Example #1
0
File: nss.c Project: flashfoxter/sx
int sxi_vcrypt_print_cert_info(sxc_client_t *sx, const char *file, int batch_mode)
{
    struct PK11_ctx ctx;
    CERTCertificate *cert = load_cert_file(sx, file, &ctx);

    if(!cert) {
        free_PK11_ctx(&ctx);
        return -1;
    }

    if (cert && !batch_mode) {
        char *subject = CERT_NameToAscii(&cert->subject);
        char *issuer = CERT_NameToAscii(&cert->issuer);
        char *common_name = CERT_GetCommonName(&cert->subject);
        struct sxi_fmt fmt;
        char hash[SXI_SHA1_TEXT_LEN+1];

        sxi_fmt_start(&fmt);
        sxi_fmt_msg(&fmt, "\tSubject: %s\n", subject);
        sxi_fmt_msg(&fmt, "\tIssuer: %s\n", issuer);
        if (!sxi_conns_hashcalc_core(sx, NULL, 0,
                                     cert->derCert.data,
                                     cert->derCert.len, hash)) {
            sxi_fmt_msg(&fmt, "\tSHA1 Fingerprint: %s\n", hash);
        }
        sxi_info(sx, "%s", fmt.buf);
        PR_Free(subject);
        PR_Free(issuer);
        PR_Free(common_name);
    }

    CERT_DestroyCertificate(cert);
    free_PK11_ctx(&ctx);
    return 0;
}
Example #2
0
File: libsx.c Project: michals/sx
void sxi_setclusterr(sxc_client_t *sx, const char *nodeid, const char *reqid, int status,
                     const char *msg, const char *details)
{
    char httpcode[16];
    if (!sx)
        return;
    if (!*msg) {
        snprintf(httpcode, sizeof(httpcode), "HTTP code %d", status);
        msg = httpcode;
    }
    sxi_fmt_start(&sx->log.fmt);
    sxi_fmt_msg(&sx->log.fmt, "Failed to %s: %s (", sx->op ? sx->op : "query cluster", msg);
    if (sx->op_host) {
        sxi_fmt_msg(&sx->log.fmt, "sx://%s", sx->op_host);
        if (sx->op_vol) {
            sxi_fmt_msg(&sx->log.fmt, "/%s", sx->op_vol);
            if (sx->op_path) {
                sxi_fmt_msg(&sx->log.fmt, "/%s", sx->op_path);
            }
        }
    }
    sxi_fmt_msg(&sx->log.fmt," on");
    if (nodeid)
        sxi_fmt_msg(&sx->log.fmt, " node:%s", nodeid);
    if (reqid)
        sxi_fmt_msg(&sx->log.fmt, " reqid:%s", reqid);
    sxi_fmt_msg(&sx->log.fmt, ")");
    if (status < 400 || status >= 500) {
        /* do not print details on 40x */
        if (sx->verbose && details && *details) {
            sxi_fmt_msg(&sx->log.fmt, "\nHTTP %d: %s", status, details);
        }
    }
    sxi_seterr(sx, SXE_ECOMM, "%s", sx->log.fmt.buf);
    sxi_clear_operation(sx);
    SXDEBUG("Cluster query failed (HTTP %d): %s", status, sx->errbuf);
    if (details && *details)
        SXDEBUG("Cluster error: %s", details);
}