Пример #1
0
int RSA_meth_set1_name(RSA_METHOD *meth, const char *name)
{
    OPENSSL_free(meth->name);
    meth->name = OPENSSL_strdup(name);

    return meth->name != NULL;
}
static void YAK_CTX_init(YAK_CTX *ctx, const char *name,
                         const char *peer_name, const BIGNUM *p,
                         const EC_POINT *g, const BIGNUM *q,
                         const BIGNUM *secret)
{
    ctx->p.name = OPENSSL_strdup(name);
    ctx->p.peer_name = OPENSSL_strdup(peer_name);
    ctx->p.p = BN_dup(p);
    ctx->p.g = BN_dup(g);
    ctx->p.q = BN_dup(q);
    ctx->secret = BN_dup(secret);
    
    ctx->xa = BN_new();
    ctx->key = BN_new();
    ctx->ctx = BN_CTX_new();
}
Пример #3
0
char *DSO_convert_filename(DSO *dso, const char *filename)
{
    char *result = NULL;

    if (dso == NULL) {
        DSOerr(DSO_F_DSO_CONVERT_FILENAME, ERR_R_PASSED_NULL_PARAMETER);
        return (NULL);
    }
    if (filename == NULL)
        filename = dso->filename;
    if (filename == NULL) {
        DSOerr(DSO_F_DSO_CONVERT_FILENAME, DSO_R_NO_FILENAME);
        return (NULL);
    }
    if ((dso->flags & DSO_FLAG_NO_NAME_TRANSLATION) == 0) {
        if (dso->name_converter != NULL)
            result = dso->name_converter(dso, filename);
        else if (dso->meth->dso_name_converter != NULL)
            result = dso->meth->dso_name_converter(dso, filename);
    }
    if (result == NULL) {
        result = OPENSSL_strdup(filename);
        if (result == NULL) {
            DSOerr(DSO_F_DSO_CONVERT_FILENAME, ERR_R_MALLOC_FAILURE);
            return (NULL);
        }
    }
    return (result);
}
Пример #4
0
int ssl_get_new_session(SSL *s, int session)
{
    /* This gets used by clients and servers. */

    SSL_SESSION *ss = NULL;

    if ((ss = SSL_SESSION_new()) == NULL) {
        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL_GET_NEW_SESSION,
                 ERR_R_MALLOC_FAILURE);
        return 0;
    }

    /* If the context has a default timeout, use it */
    if (s->session_ctx->session_timeout == 0)
        ss->timeout = SSL_get_default_timeout(s);
    else
        ss->timeout = s->session_ctx->session_timeout;

    SSL_SESSION_free(s->session);
    s->session = NULL;

    if (session) {
        if (!ssl_generate_session_id(s, ss)) {
            /* SSLfatal() already called */
            SSL_SESSION_free(ss);
            return 0;
        }

        if (s->ext.hostname) {
            ss->ext.hostname = OPENSSL_strdup(s->ext.hostname);
            if (ss->ext.hostname == NULL) {
                SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL_GET_NEW_SESSION,
                         ERR_R_INTERNAL_ERROR);
                SSL_SESSION_free(ss);
                return 0;
            }
        }
    } else {
        ss->session_id_length = 0;
    }

    if (s->sid_ctx_length > sizeof ss->sid_ctx) {
        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL_GET_NEW_SESSION,
                 ERR_R_INTERNAL_ERROR);
        SSL_SESSION_free(ss);
        return 0;
    }
    memcpy(ss->sid_ctx, s->sid_ctx, s->sid_ctx_length);
    ss->sid_ctx_length = s->sid_ctx_length;
    s->session = ss;
    ss->ssl_version = s->version;
    ss->verify_result = X509_V_OK;

    /* If client supports extended master secret set it in session */
    if (s->s3->flags & TLS1_FLAGS_RECEIVED_EXTMS)
        ss->flags |= SSL_SESS_FLAG_EXTMS;

    return 1;
}
Пример #5
0
UI_METHOD *UI_create_method(char *name)
{
    UI_METHOD *ui_method = OPENSSL_zalloc(sizeof(*ui_method));

    if (ui_method != NULL)
        ui_method->name = OPENSSL_strdup(name);
    return ui_method;
}
Пример #6
0
int X509_VERIFY_PARAM_set1_name(X509_VERIFY_PARAM *param, const char *name)
{
    OPENSSL_free(param->name);
    param->name = OPENSSL_strdup(name);
    if (param->name)
        return 1;
    return 0;
}
Пример #7
0
char *BIO_ADDR_path_string(const BIO_ADDR *ap)
{
#ifdef AF_UNIX
    if (ap->sa.sa_family == AF_UNIX)
        return OPENSSL_strdup(ap->s_un.sun_path);
#endif
    return NULL;
}
Пример #8
0
/*
 * Set private init args for module
 */
void pkcs11_CTX_init_args(PKCS11_CTX * ctx, const char *init_args)
{
	PKCS11_CTX_private *cpriv = PRIVCTX(ctx);
	/* Free previously duplicated string */
	if (cpriv->init_args) {
		OPENSSL_free(cpriv->init_args);
	}
	cpriv->init_args = init_args ? OPENSSL_strdup(init_args) : NULL;
}
Пример #9
0
static void PSPAKE_CTX_init(PSPAKE_CTX *ctx, const char *password, const char *name, const char *peer_name)
{
    ctx->g = BN_bin2bn(pspake_g, sizeof(pspake_g), NULL);
    ctx->h = BN_bin2bn(pspake_h, sizeof(pspake_h), NULL);
    ctx->q = BN_bin2bn(pspake_q, sizeof(pspake_q), NULL);

    ctx->ctx = BN_CTX_new();
    ctx->r = BN_new();
    ctx->y = BN_new();
    ctx->key = NULL;
    ctx->y_ = NULL;

    ctx->name = OPENSSL_strdup(name);
    ctx->peer_name = OPENSSL_strdup(peer_name);

    /* hash the given string password to get a Big Number ctx->secret */
    ctx->secret = BN_new();
    hashpassword(ctx->secret, password, ctx->ctx, ctx->q);
}
Пример #10
0
EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_new(int id, int flags,
                                        const char *pem_str, const char *info)
{
    EVP_PKEY_ASN1_METHOD *ameth = OPENSSL_zalloc(sizeof(*ameth));

    if (ameth == NULL)
        return NULL;

    ameth->pkey_id = id;
    ameth->pkey_base_id = id;
    ameth->pkey_flags = flags | ASN1_PKEY_DYNAMIC;

    if (info) {
        ameth->info = OPENSSL_strdup(info);
        if (!ameth->info)
            goto err;
    }

    /*
     * One of the following must be true:
     *
     * pem_str == NULL AND ASN1_PKEY_ALIAS is set
     * pem_str != NULL AND ASN1_PKEY_ALIAS is clear
     *
     * Anything else is an error and may lead to a corrupt ASN1 method table
     */
    if (!((pem_str == NULL && (flags & ASN1_PKEY_ALIAS) != 0)
          || (pem_str != NULL && (flags & ASN1_PKEY_ALIAS) == 0)))
        goto err;

    if (pem_str) {
        ameth->pem_str = OPENSSL_strdup(pem_str);
        if (!ameth->pem_str)
            goto err;
    }

    return ameth;

 err:
    EVP_PKEY_asn1_free(ameth);
    return NULL;

}
Пример #11
0
/* Setters */
int ossl_provider_set_module_path(OSSL_PROVIDER *prov, const char *module_path)
{
    OPENSSL_free(prov->path);
    if (module_path == NULL)
        return 1;
    if ((prov->path = OPENSSL_strdup(module_path)) != NULL)
        return 1;
    CRYPTOerr(CRYPTO_F_OSSL_PROVIDER_SET_MODULE_PATH, ERR_R_MALLOC_FAILURE);
    return 0;
}
Пример #12
0
int X509_TRUST_add(int id, int flags, int (*ck) (X509_TRUST *, X509 *, int),
                   char *name, int arg1, void *arg2)
{
    int idx;
    X509_TRUST *trtmp;
    /*
     * This is set according to what we change: application can't set it
     */
    flags &= ~X509_TRUST_DYNAMIC;
    /* This will always be set for application modified trust entries */
    flags |= X509_TRUST_DYNAMIC_NAME;
    /* Get existing entry if any */
    idx = X509_TRUST_get_by_id(id);
    /* Need a new entry */
    if (idx == -1) {
        if ((trtmp = OPENSSL_malloc(sizeof(*trtmp))) == NULL) {
            X509err(X509_F_X509_TRUST_ADD, ERR_R_MALLOC_FAILURE);
            return 0;
        }
        trtmp->flags = X509_TRUST_DYNAMIC;
    } else
        trtmp = X509_TRUST_get0(idx);

    /* OPENSSL_free existing name if dynamic */
    if (trtmp->flags & X509_TRUST_DYNAMIC_NAME)
        OPENSSL_free(trtmp->name);
    /* dup supplied name */
    if ((trtmp->name = OPENSSL_strdup(name)) == NULL) {
        X509err(X509_F_X509_TRUST_ADD, ERR_R_MALLOC_FAILURE);
        return 0;
    }
    /* Keep the dynamic flag of existing entry */
    trtmp->flags &= X509_TRUST_DYNAMIC;
    /* Set all other flags */
    trtmp->flags |= flags;

    trtmp->trust = id;
    trtmp->check_trust = ck;
    trtmp->arg1 = arg1;
    trtmp->arg2 = arg2;

    /* If its a new entry manage the dynamic table */
    if (idx == -1) {
        if (trtable == NULL
            && (trtable = sk_X509_TRUST_new(tr_cmp)) == NULL) {
            X509err(X509_F_X509_TRUST_ADD, ERR_R_MALLOC_FAILURE);
            return 0;
        }
        if (!sk_X509_TRUST_push(trtable, trtmp)) {
            X509err(X509_F_X509_TRUST_ADD, ERR_R_MALLOC_FAILURE);
            return 0;
        }
    }
    return 1;
}
Пример #13
0
DSA_METHOD *DSA_meth_new(const char *name, int flags)
{
    DSA_METHOD *dsam = OPENSSL_zalloc(sizeof(DSA_METHOD));

    if (dsam != NULL) {
        dsam->name = OPENSSL_strdup(name);
        dsam->flags = flags;
    }

    return dsam;
}
Пример #14
0
RSA_METHOD *RSA_meth_new(const char *name, int flags)
{
    RSA_METHOD *meth = OPENSSL_zalloc(sizeof(RSA_METHOD));

    if (meth != NULL) {
        meth->name = OPENSSL_strdup(name);
        meth->flags = flags;
    }

    return meth;
}
Пример #15
0
int SSL_SESSION_set1_hostname(SSL_SESSION *s, const char *hostname)
{
    OPENSSL_free(s->ext.hostname);
    if (hostname == NULL) {
        s->ext.hostname = NULL;
        return 1;
    }
    s->ext.hostname = OPENSSL_strdup(hostname);

    return s->ext.hostname != NULL;
}
Пример #16
0
DH_METHOD *DH_meth_new(const char *name, int flags)
{
    DH_METHOD *dhm = OPENSSL_zalloc(sizeof(DH_METHOD));

    if (dhm != NULL) {
        dhm->name = OPENSSL_strdup(name);
        dhm->flags = flags;
    }

    return dhm;
}
Пример #17
0
static RSA_METHOD *RSA_meth_new(const char *name, int flags)
{
	RSA_METHOD *meth = OPENSSL_malloc(sizeof(RSA_METHOD));

	if (meth == NULL)
		return NULL;
	memcpy(meth, RSA_get_default_method(), sizeof(RSA_METHOD));
	meth->name = OPENSSL_strdup(name);
	meth->flags = flags;
	return meth;
}
Пример #18
0
int ossl_provider_add_parameter(OSSL_PROVIDER *prov,
                                const char *name, const char *value)
{
    INFOPAIR *pair = NULL;

    if ((pair = OPENSSL_zalloc(sizeof(*pair))) != NULL
        && (prov->parameters != NULL
            || (prov->parameters = sk_INFOPAIR_new_null()) != NULL)
        && (pair->name = OPENSSL_strdup(name)) != NULL
        && (pair->value = OPENSSL_strdup(value)) != NULL
        && sk_INFOPAIR_push(prov->parameters, pair) > 0)
        return 1;

    if (pair != NULL) {
        OPENSSL_free(pair->name);
        OPENSSL_free(pair->value);
        OPENSSL_free(pair);
    }
    CRYPTOerr(CRYPTO_F_OSSL_PROVIDER_ADD_PARAMETER, ERR_R_MALLOC_FAILURE);
    return 0;
}
Пример #19
0
static int test_good_configuration()
{
    SETUP_SSL_TEST_CTX_TEST_FIXTURE();
    fixture.test_section = "ssltest_good";
    fixture.expected_ctx->method = SSL_TEST_METHOD_DTLS;
    fixture.expected_ctx->handshake_mode = SSL_TEST_HANDSHAKE_RESUME;
    fixture.expected_ctx->app_data_size = 1024;
    fixture.expected_ctx->max_fragment_size = 2048;

    fixture.expected_ctx->expected_result = SSL_TEST_SERVER_FAIL;
    fixture.expected_ctx->expected_client_alert = SSL_AD_UNKNOWN_CA;
    fixture.expected_ctx->expected_server_alert = 0;  /* No alert. */
    fixture.expected_ctx->expected_protocol = TLS1_1_VERSION;
    fixture.expected_ctx->expected_servername = SSL_TEST_SERVERNAME_SERVER2;
    fixture.expected_ctx->session_ticket_expected = SSL_TEST_SESSION_TICKET_YES;
    fixture.expected_ctx->compression_expected = SSL_TEST_COMPRESSION_NO;
    fixture.expected_ctx->resumption_expected = 1;

    fixture.expected_ctx->extra.client.verify_callback =
        SSL_TEST_VERIFY_REJECT_ALL;
    fixture.expected_ctx->extra.client.servername = SSL_TEST_SERVERNAME_SERVER2;
    fixture.expected_ctx->extra.client.npn_protocols =
        OPENSSL_strdup("foo,bar");
    TEST_check(fixture.expected_ctx->extra.client.npn_protocols != NULL);

    fixture.expected_ctx->extra.server.servername_callback =
        SSL_TEST_SERVERNAME_IGNORE_MISMATCH;
    fixture.expected_ctx->extra.server.broken_session_ticket = 1;

    fixture.expected_ctx->resume_extra.server2.alpn_protocols =
        OPENSSL_strdup("baz");
    TEST_check(
        fixture.expected_ctx->resume_extra.server2.alpn_protocols != NULL);

    fixture.expected_ctx->resume_extra.client.ct_validation =
        SSL_TEST_CT_VALIDATION_STRICT;

    EXECUTE_SSL_TEST_CTX_TEST();
}
Пример #20
0
RSA_METHOD *RSA_meth_dup(const RSA_METHOD *meth)
{
    RSA_METHOD *ret;

    ret = OPENSSL_malloc(sizeof(RSA_METHOD));

    if (ret != NULL) {
        memcpy(ret, meth, sizeof(*meth));
        ret->name = OPENSSL_strdup(meth->name);
    }

    return ret;
}
Пример #21
0
DSA_METHOD *DSA_meth_dup(const DSA_METHOD *dsam)
{
    DSA_METHOD *ret;

    ret = OPENSSL_malloc(sizeof(DSA_METHOD));

    if (ret != NULL) {
        memcpy(ret, dsam, sizeof(*dsam));
        ret->name = OPENSSL_strdup(dsam->name);
    }

    return ret;
}
Пример #22
0
DH_METHOD *DH_meth_dup(const DH_METHOD *dhm)
{
    DH_METHOD *ret;

    ret = OPENSSL_malloc(sizeof(DH_METHOD));

    if (ret != NULL) {
        memcpy(ret, dhm, sizeof(*dhm));
        ret->name = OPENSSL_strdup(dhm->name);
    }

    return ret;
}
Пример #23
0
int UI_dup_error_string(UI *ui, const char *text)
{
    char *text_copy = NULL;

    if (text != NULL) {
        text_copy = OPENSSL_strdup(text);
        if (text_copy == NULL) {
            UIerr(UI_F_UI_DUP_ERROR_STRING, ERR_R_MALLOC_FAILURE);
            return -1;
        }
    }
    return general_allocate_string(ui, text_copy, 1, UIT_ERROR, 0, NULL,
                                   0, 0, NULL);
}
Пример #24
0
int DSA_meth_set1_name(DSA_METHOD *dsam, const char *name)
{
    char *tmpname = OPENSSL_strdup(name);

    if (tmpname == NULL) {
        DSAerr(DSA_F_DSA_METH_SET1_NAME, ERR_R_MALLOC_FAILURE);
        return 0;
    }

    OPENSSL_free(dsam->name);
    dsam->name = tmpname;

    return 1;
}
int RSA_meth_set1_name(RSA_METHOD *meth, const char *name)
{
    char *tmpname;

    tmpname = OPENSSL_strdup(name);
    if (tmpname == NULL) {
        return 0;
    }

    OPENSSL_free((char *)meth->name);
    meth->name = tmpname;

    return 1;
}
Пример #26
0
UI_METHOD *UI_create_method(const char *name)
{
    UI_METHOD *ui_method = OPENSSL_zalloc(sizeof(*ui_method));

    if (ui_method != NULL) {
        ui_method->name = OPENSSL_strdup(name);
        if (ui_method->name == NULL) {
            OPENSSL_free(ui_method);
            UIerr(UI_F_UI_CREATE_METHOD, ERR_R_MALLOC_FAILURE);
            return NULL;
        }
    }
    return ui_method;
}
Пример #27
0
int RSA_meth_set1_name(RSA_METHOD *meth, const char *name)
{
    char *tmpname = OPENSSL_strdup(name);

    if (tmpname == NULL) {
        RSAerr(RSA_F_RSA_METH_SET1_NAME, ERR_R_MALLOC_FAILURE);
        return 0;
    }

    OPENSSL_free(meth->name);
    meth->name = tmpname;

    return 1;
}
Пример #28
0
int main(int argc, char *argv[])
{
    char *p, *q = 0, *program;

    p = strrchr(argv[0], '/');
    if (!p)
        p = strrchr(argv[0], '\\');
#ifdef OPENSSL_SYS_VMS
    if (!p)
        p = strrchr(argv[0], ']');
    if (p)
        q = strrchr(p, '>');
    if (q)
        p = q;
    if (!p)
        p = strrchr(argv[0], ':');
    q = 0;
#endif
    if (p)
        p++;
    if (!p)
        p = argv[0];
    if (p)
        q = strchr(p, '.');
    if (p && !q)
        q = p + strlen(p);

    if (!p)
        program = OPENSSL_strdup("(unknown)");
    else {
        program = OPENSSL_malloc((q - p) + 1);
        strncpy(program, p, q - p);
        program[q - p] = '\0';
    }

    for (p = program; *p; p++)
        if (islower((unsigned char)(*p)))
            *p = toupper((unsigned char)(*p));

    q = strstr(program, "TEST");
    if (q > p && q[-1] == '_')
        q--;
    *q = '\0';

    printf("No %s support\n", program);

    OPENSSL_free(program);
    return (0);
}
Пример #29
0
int SSL_CONF_CTX_set1_prefix(SSL_CONF_CTX *cctx, const char *pre)
{
    char *tmp = NULL;
    if (pre) {
        tmp = OPENSSL_strdup(pre);
        if (tmp == NULL)
            return 0;
    }
    OPENSSL_free(cctx->prefix);
    cctx->prefix = tmp;
    if (tmp)
        cctx->prefixlen = strlen(tmp);
    else
        cctx->prefixlen = 0;
    return 1;
}
Пример #30
0
UI_METHOD *UI_create_method(const char *name)
{
    UI_METHOD *ui_method = NULL;

    if ((ui_method = OPENSSL_zalloc(sizeof(*ui_method))) == NULL
        || (ui_method->name = OPENSSL_strdup(name)) == NULL
        || !CRYPTO_new_ex_data(CRYPTO_EX_INDEX_UI_METHOD, ui_method,
                               &ui_method->ex_data)) {
        if (ui_method)
            OPENSSL_free(ui_method->name);
        OPENSSL_free(ui_method);
        UIerr(UI_F_UI_CREATE_METHOD, ERR_R_MALLOC_FAILURE);
        return NULL;
    }
    return ui_method;
}