Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update soter/openssl to fix compatibility with new openssl version #258

Merged
merged 30 commits into from
Dec 13, 2017

Conversation

Lagovas
Copy link
Collaborator

@Lagovas Lagovas commented Dec 8, 2017

due to changes in openssl 1.1.0 was changed:

  • using openssl structs allocated in heap instead stack because now their structs are opaque in openssl (1, 2)
  • pass soter fields to functions like some_func(ctx->field) instead some_func(&(ctx->field)) because now they are not public and allocated in heap
  • create structs using openssl functions *_create and *_new instead struct variable declaration (1)
  • use getters/setters to access to hidden struct fields (EVP_PKEY_type/EVP_PKEY_base_id, RSA_get0_key, RSA_get0_factors, RSA_get0_crt_params, RSA_set0_key, RSA_set0_factors, RSA_set0_crt_params)

want to ask @secumod to check at least src/soter/openssl/soter_rsa_key.c file where work with rsa keys

@@ -63,6 +63,7 @@ typedef int soter_status_t;
#define SOTER_DEBUG_OUT(message)
#endif

#define UNUSED(x) (void)(x)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:D

@@ -826,7 +827,7 @@ static themis_status_t secure_session_finish_client(secure_session_t *session_ct
return THEMIS_INVALID_PARAMETER;
}

if (memcmp(proto_message->tag, THEMIS_SESSION_PROTO_TAG, SOTER_CONTAINER_TAG_LENGTH))
if (memcmp(proto_message->tag, THEMIS_SESSION_PROTO_TAG, SOTER_CONTAINER_TAG_LENGTH) != 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we do compare public data here, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually yes, it's trying to check that it's correct secure session packet or no

// testsuite_enter_suite("soter rand: NIST STS (make take some time...)");
// testsuite_run_test(test_rand_with_nist);
// always fail under ci
#ifndef CIRICLE_TEST
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:D

@vixentael
Copy link
Contributor

should close #208 after merge

@vixentael vixentael added the core Themis Core written in C, its packages label Dec 8, 2017
@@ -97,6 +97,7 @@ soter_status_t soter_asym_cipher_init(soter_asym_cipher_t* asym_cipher, const vo
return SOTER_FAIL;
}
SOTER_IF_FAIL(soter_asym_cipher_import_key(asym_cipher, key, key_length)==SOTER_SUCCESS, (EVP_PKEY_free(pkey), EVP_PKEY_CTX_free(asym_cipher->pkey_ctx)));
EVP_PKEY_free(pkey);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clearly breaks file indentation here

@@ -152,8 +150,8 @@ soter_status_t soter_asym_cipher_encrypt(soter_asym_cipher_t* asym_cipher, const
}

rsa_mod_size = RSA_size(rsa);

if (plain_data_length > (rsa_mod_size - 2 - (2 * OAEP_HASH_SIZE)))
int temp = (rsa_mod_size - 2 - (2 * OAEP_HASH_SIZE));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • indent
  • let's not name stuff temp, but something more context aware, like oaep_max_payload_length

@@ -105,6 +111,7 @@ soter_hash_ctx_t* soter_hash_create(soter_hash_algo_t algo)
{
return NULL;
}
ctx->evp_md_ctx = NULL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indent

EVP_MD_CTX_cleanup(&(hash_ctx->evp_md_ctx));

EVP_MD_CTX_destroy(hash_ctx->evp_md_ctx);
hash_ctx->evp_md_ctx = NULL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indent

EVP_PKEY_free(pkey);
}
EVP_PKEY_CTX_free(asym_cipher->pkey_ctx);
asym_cipher->pkey_ctx = NULL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • indentation
  • can you confirm that EVP_PKEY_CTX_free also frees "contained" pkey?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/openssl/openssl/blob/master/crypto/evp/pmeth_lib.c#L339
and also checked with valgrind (he warned that there was double free when I leave EVP_PKEY_free(pkey))

{
return SOTER_SUCCESS;
}
else
{
soter_hash_cleanup(hash_ctx);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indent

@@ -99,15 +101,16 @@ soter_sym_ctx_t* soter_sym_ctx_init(const uint32_t alg,
ctx->alg=alg;
uint8_t key_[SOTER_SYM_MAX_KEY_LENGTH];
size_t key_length_=(alg&SOTER_SYM_KEY_LENGTH_MASK)/8;
EVP_CIPHER_CTX_init(&(ctx->evp_sym_ctx));
//EVP_CIPHER_CTX_init(ctx->evp_sym_ctx);
ctx->evp_sym_ctx = EVP_CIPHER_CTX_new();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably should be some failure check here

@@ -128,12 +132,12 @@ soter_sym_ctx_t* soter_sym_aead_ctx_init(const uint32_t alg,
ctx->alg=alg;
uint8_t key_[SOTER_SYM_MAX_KEY_LENGTH];
size_t key_length_=(alg&SOTER_SYM_KEY_LENGTH_MASK)/8;
EVP_CIPHER_CTX_init(&(ctx->evp_sym_ctx));
ctx->evp_sym_ctx = EVP_CIPHER_CTX_new();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

failure check?

@@ -46,23 +46,24 @@ soter_status_t soter_hmac_init(soter_hmac_ctx_t *hmac_ctx, soter_hash_algo_t alg
return SOTER_INVALID_PARAMETER;
}

hmac_ctx->hash_ctx = soter_hash_create(algo);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation?

if (SOTER_SUCCESS != res)
{
soter_hash_destroy(hmac_ctx->hash_ctx);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation

fix incorrect indentation
@vixentael vixentael merged commit 4925be9 into cossacklabs:master Dec 13, 2017
@Lagovas Lagovas deleted the lagovas/fix-openssl-usage branch February 6, 2018 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Themis Core written in C, its packages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants