qcrypto_tls_creds_x509_sanity_check(QCryptoTLSCredsX509 *creds,

                                    bool isServer,

                                    const char *cacertFile,

                                    const char *certFile,

                                    Error **errp)

{

    gnutls_x509_crt_t cert = NULL;

    gnutls_x509_crt_t cacerts[MAX_CERTS];

    size_t ncacerts = 0;

    size_t i;

    int ret = -1;



    memset(cacerts, 0, sizeof(cacerts));

    if (access(certFile, R_OK) == 0) {

        cert = qcrypto_tls_creds_load_cert(creds,

                                           certFile, isServer,

                                           errp);

        if (!cert) {

            goto cleanup;

        }

    }

    if (access(cacertFile, R_OK) == 0) {

        if (qcrypto_tls_creds_load_ca_cert_list(creds,

                                                cacertFile, cacerts,

                                                MAX_CERTS, &ncacerts,

                                                errp) < 0) {

            goto cleanup;

        }

    }



    if (cert &&

        qcrypto_tls_creds_check_cert(creds,

                                     cert, certFile, isServer,

                                     false, errp) < 0) {

        goto cleanup;

    }



    for (i = 0; i < ncacerts; i++) {

        if (qcrypto_tls_creds_check_cert(creds,

                                         cacerts[i], cacertFile,

                                         isServer, true, errp) < 0) {

            goto cleanup;

        }

    }



    if (cert && ncacerts &&

        qcrypto_tls_creds_check_cert_pair(cert, certFile, cacerts,

                                          ncacerts, cacertFile,

                                          isServer, errp) < 0) {

        goto cleanup;

    }



    ret = 0;



 cleanup:

    if (cert) {

        gnutls_x509_crt_deinit(cert);

    }

    for (i = 0; i < ncacerts; i++) {

        gnutls_x509_crt_deinit(cacerts[i]);

    }

    return ret;

}

qcrypto_tls_creds_x509_sanity_check(QCryptoTLSCredsX509 *creds,

                                    bool isServer,

                                    const char *cacertFile,

                                    const char *certFile,

                                    Error **errp)

{

    gnutls_x509_crt_t cert = NULL;

    gnutls_x509_crt_t cacerts[MAX_CERTS];

    size_t ncacerts = 0;

    size_t i;

    int ret = -1;



    memset(cacerts, 0, sizeof(cacerts));

    if (access(certFile, R_OK) == 0) {

        cert = qcrypto_tls_creds_load_cert(creds,

                                           certFile, isServer,

                                           errp);

        if (!cert) {

            goto cleanup;

        }

    }

    if (access(cacertFile, R_OK) == 0) {

        if (qcrypto_tls_creds_load_ca_cert_list(creds,

                                                cacertFile, cacerts,

                                                MAX_CERTS, &ncacerts,

                                                errp) < 0) {

            goto cleanup;

        }

    }



    if (cert &&

        qcrypto_tls_creds_check_cert(creds,

                                     cert, certFile, isServer,

                                     false, errp) < 0) {

        goto cleanup;

    }



    for (i = 0; i < ncacerts; i++) {

        if (qcrypto_tls_creds_check_cert(creds,

                                         cacerts[i], cacertFile,

                                         isServer, true, errp) < 0) {

            goto cleanup;

        }

    }



    if (cert && ncacerts &&

        qcrypto_tls_creds_check_cert_pair(cert, certFile, cacerts,

                                          ncacerts, cacertFile,

                                          isServer, errp) < 0) {

        goto cleanup;

    }



    ret = 0;



 cleanup:

    if (cert) {

        gnutls_x509_crt_deinit(cert);

    }

    for (i = 0; i < ncacerts; i++) {

        gnutls_x509_crt_deinit(cacerts[i]);

    }

    return ret;

}

FUNC_0(QCryptoTLSCredsX509 *VAR_0,

                                    bool VAR_1,

                                    const char *VAR_2,

                                    const char *VAR_3,

                                    Error **VAR_4)

{

    gnutls_x509_crt_t cert = NULL;

    gnutls_x509_crt_t cacerts[MAX_CERTS];

    size_t ncacerts = 0;

    size_t i;

    int VAR_5 = -1;



    memset(cacerts, 0, sizeof(cacerts));

    if (access(VAR_3, R_OK) == 0) {

        cert = qcrypto_tls_creds_load_cert(VAR_0,

                                           VAR_3, VAR_1,

                                           VAR_4);

        if (!cert) {

            goto cleanup;

        }

    }

    if (access(VAR_2, R_OK) == 0) {

        if (qcrypto_tls_creds_load_ca_cert_list(VAR_0,

                                                VAR_2, cacerts,

                                                MAX_CERTS, &ncacerts,

                                                VAR_4) < 0) {

            goto cleanup;

        }

    }



    if (cert &&

        qcrypto_tls_creds_check_cert(VAR_0,

                                     cert, VAR_3, VAR_1,

                                     false, VAR_4) < 0) {

        goto cleanup;

    }



    for (i = 0; i < ncacerts; i++) {

        if (qcrypto_tls_creds_check_cert(VAR_0,

                                         cacerts[i], VAR_2,

                                         VAR_1, true, VAR_4) < 0) {

            goto cleanup;

        }

    }



    if (cert && ncacerts &&

        qcrypto_tls_creds_check_cert_pair(cert, VAR_3, cacerts,

                                          ncacerts, VAR_2,

                                          VAR_1, VAR_4) < 0) {

        goto cleanup;

    }



    VAR_5 = 0;



 cleanup:

    if (cert) {

        gnutls_x509_crt_deinit(cert);

    }

    for (i = 0; i < ncacerts; i++) {

        gnutls_x509_crt_deinit(cacerts[i]);

    }

    return VAR_5;

}

FUNC_0(QCryptoTLSCredsX509 *VAR_0,
bool VAR_1,
const char *VAR_2,
const char *VAR_3,
Error **VAR_4)
{ gnutls_x509_crt_t cert = NULL; gnutls_x509_crt_t cacerts[MAX_CERTS]; size_t ncacerts = 0; size_t i; int VAR_5 = -1; memset(cacerts, 0, sizeof(cacerts)); if (access(VAR_3, R_OK) == 0) { cert = qcrypto_tls_creds_load_cert(VAR_0,
VAR_3, VAR_1,
VAR_4); if (!cert) { goto cleanup; } } if (access(VAR_2, R_OK) == 0) { if (qcrypto_tls_creds_load_ca_cert_list(VAR_0,
VAR_2, cacerts,
MAX_CERTS, &ncacerts,
VAR_4) < 0) { goto cleanup; } } if (cert &&
qcrypto_tls_creds_check_cert(VAR_0,
cert, VAR_3, VAR_1,
false, VAR_4) < 0) { goto cleanup; } for (i = 0; i < ncacerts; i++) { if (qcrypto_tls_creds_check_cert(VAR_0,
cacerts[i], VAR_2,
VAR_1, true, VAR_4) < 0) { goto cleanup; } } if (cert && ncacerts &&
qcrypto_tls_creds_check_cert_pair(cert, VAR_3, cacerts,
ncacerts, VAR_2,
VAR_1, VAR_4) < 0) { goto cleanup; } VAR_5 = 0; cleanup:
if (cert) { gnutls_x509_crt_deinit(cert); } for (i = 0; i < ncacerts; i++) { gnutls_x509_crt_deinit(cacerts[i]); } return VAR_5; }