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

fix warnings #100

Merged
merged 11 commits into from
Nov 16, 2017
36 changes: 35 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ cmake_minimum_required(VERSION 3.6)
project(hermes_core)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wstrict-aliasing -fstrict-aliasing -pedantic -fno-common -Wno-unused-result -fno-common -fwrapv -Wstrict-prototypes")

# use clang as compiler explicitly
#set(CMAKE_C_COMPILER clang)
#set(CMAKE_CXX_COMPILER clang)

add_executable(hermes_client_example docs/examples/c/mid_hermes/client/hermes_client.c docs/examples/c/mid_hermes/common/transport.c docs/examples/c/utils/utils.c docs/examples/c/utils/base64.c src/secure_transport/utils.c src/secure_transport/utils.h docs/examples/c/mid_hermes/common/credential_store_client.c src/secure_transport/session_callback.c include/hermes/secure_transport/session_callback.h)
TARGET_LINK_LIBRARIES(hermes_client_example hermes_mid_hermes hermes_mid_hermes_ll hermes_credential_store hermes_data_store hermes_key_store hermes_rpc pthread hermes_common themis soter hermes_secure_transport)
Expand All @@ -25,4 +30,33 @@ TARGET_INCLUDE_DIRECTORIES(data_store_server_c PRIVATE docs/examples/c/mid_herme
FILE(GLOB MID_HERMES_TEST_SOURCE_FILES tests/mid_hermes/*c tests/common/*.c)
add_executable(mid_hermes_test ${MID_HERMES_TEST_SOURCE_FILES})
TARGET_INCLUDE_DIRECTORIES(mid_hermes_test PRIVATE tests)
TARGET_LINK_LIBRARIES(mid_hermes_test hermes_mid_hermes hermes_mid_hermes_ll hermes_credential_store hermes_data_store hermes_key_store hermes_rpc pthread hermes_common themis soter hermes_secure_transport)
TARGET_LINK_LIBRARIES(mid_hermes_test hermes_mid_hermes hermes_mid_hermes_ll hermes_credential_store hermes_data_store hermes_key_store hermes_rpc pthread hermes_common themis soter hermes_secure_transport)

FILE(GLOB CREDENTIAL_STORE_TEST_SOURCE_FILES tests/credential_store/*c tests/common/*.c)
add_executable(credential_store_test ${CREDENTIAL_STORE_TEST_SOURCE_FILES})
TARGET_INCLUDE_DIRECTORIES(credential_store_test PRIVATE tests)
TARGET_LINK_LIBRARIES(credential_store_test hermes_credential_store pthread hermes_common themis soter)

FILE(GLOB DATA_STORE_TEST_SOURCE_FILES tests/data_store/*c tests/common/*.c)
add_executable(data_store_test ${DATA_STORE_TEST_SOURCE_FILES})
TARGET_INCLUDE_DIRECTORIES(data_store_test PRIVATE tests)
TARGET_LINK_LIBRARIES(data_store_test hermes_data_store pthread hermes_common themis soter)

FILE(GLOB KEY_STORE_TEST_SOURCE_FILES tests/key_store/*c tests/common/*.c)
add_executable(key_store_test ${KEY_STORE_TEST_SOURCE_FILES})
TARGET_INCLUDE_DIRECTORIES(key_store_test PRIVATE tests)
TARGET_LINK_LIBRARIES(key_store_test hermes_key_store pthread hermes_common themis soter)

FILE(GLOB MID_HERMES_LL_TEST_SOURCE_FILES tests/mid_hermes_ll/*c tests/common/*.c)
add_executable(mid_hermes_ll_test ${MID_HERMES_LL_TEST_SOURCE_FILES})
TARGET_INCLUDE_DIRECTORIES(mid_hermes_ll_test PRIVATE tests)
TARGET_LINK_LIBRARIES(mid_hermes_ll_test hermes_mid_hermes_ll pthread hermes_common themis soter)

FILE(GLOB RPC_TEST_SOURCE_FILES tests/rpc/*c tests/common/*.c)
add_executable(rpc_test ${RPC_TEST_SOURCE_FILES})
TARGET_INCLUDE_DIRECTORIES(rpc_test PRIVATE tests)
TARGET_LINK_LIBRARIES(rpc_test hermes_common pthread hermes_rpc hermes_mid_hermes_ll themis soter)

FILE(GLOB MIDHERMES_LL_SOURCES docs/examples/c/mid_hermes_low_level/*.c docs/examples/c/utils/*.c)
add_executable(midhermes_ll ${MIDHERMES_LL_SOURCES})
TARGET_LINK_LIBRARIES(midhermes_ll hermes_mid_hermes_ll themis soter)
5 changes: 3 additions & 2 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ machine:
# gopath directories below
TEMP_GOPATH: ${HOME}/temp_gopath
GOPATH: $TEMP_GOPATH:$GOPATH
STRICT_CFLAGS: "-Wall -Wextra -Wstrict-aliasing -fstrict-aliasing -pedantic -fno-common -Wno-unused-result -fno-common -fwrapv -Wstrict-prototypes"
Copy link
Contributor

Choose a reason for hiding this comment

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

😈


dependencies:
pre:
- sudo apt-get update && sudo DEBIAN_FRONTEND=noninteractive apt-get -y install libssl-dev build-essential python-dev python3-dev python-setuptools python3-setuptools netcat
- git clone https://github.com/cossacklabs/themis && cd themis && sudo make install

override:
- make
- make CFLAGS="$STRICT_CFLAGS"
- sudo make install
- make CFLAGS=-DREUSE_SOCKET examples
- make CFLAGS="-DREUSE_SOCKET $STRICT_CFLAGS" examples
- sudo pip install tox
- pyenv global 2.7.12 3.3.6 3.4.4 3.5.3 3.6.2
- mkdir -p db/credential_store db/key_store db/data_store
Expand Down
22 changes: 2 additions & 20 deletions docs/examples/c/key_gen/key_gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ int main(int argc, char* argv[]){
size_t private_key_length=0;
uint8_t* public_key=NULL;
size_t public_key_length=0;
/* if(themis_gen_key_pair(THEMIS_SECURE_SIGNED_MESSAGE_DEFAULT_ALG, private_key, &private_key_length, public_key, &public_key_length)!=THEMIS_BUFFER_TOO_SMALL){
fprintf(stderr, "key generation error 1\n");
return 1;
}
*/

if(themis_gen_ec_key_pair(private_key, &private_key_length, public_key, &public_key_length)!=THEMIS_BUFFER_TOO_SMALL){
fprintf(stderr, "key generation error 1\n");
return 1;
Expand All @@ -46,12 +42,7 @@ int main(int argc, char* argv[]){
fprintf(stderr, "key generation error 1\n");
return 1;
}
/* if(themis_gen_key_pair(THEMIS_SECURE_SIGNED_MESSAGE_DEFAULT_ALG, private_key, &private_key_length, public_key, &public_key_length)!=THEMIS_SUCCESS){
fprintf(stderr, "key generation error\n");
return 3;
}
*/
int i;

FILE* pr=fopen(argv[1], "w");
if(!pr){
fprintf(stderr, "can`t open file: %s\n", argv[1]);
Expand All @@ -66,15 +57,6 @@ int main(int argc, char* argv[]){
}
fwrite(public_key, 1, public_key_length, pu);
fclose(pu);
// for(i=0;i<private_key_length;++i){
// fprintf(stdout, "0x%02x, ", private_key[i]);
// fprintf(stdout, "%c", private_key[i]);
// }
// fprintf(stdout, "\n");
// for(i=0;i<public_key_length;++i){
// fprintf(stderr, "0x%02x, ", public_key[i]);
// fprintf(stderr, "%c", public_key[i]);
// }
free(private_key);
free(public_key);
return 0;
Expand Down
40 changes: 20 additions & 20 deletions docs/examples/c/mid_hermes/client/hermes_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#define SUCCESS 0
#define FAIL 1

const char const* HELP = "usage: client <command> <user id> <base64 encoded user private key> <name of file for proceed> <meta> <for user>.\n"
const char* const HELP = "usage: client <command> <user id> <base64 encoded user private key> <name of file for proceed> <meta> <for user>.\n"
" <command> - executes the command to be performed by the client, see below;\n"
" <user id> - user identifier (user needs to be registered in Credential store);\n"
" <base64 encoded user private key> - base64 encoded private key of the user;\n"
Expand Down Expand Up @@ -104,12 +104,12 @@ int main(int argc, char **argv) {
fprintf(stderr, "error: params error\n\n%s\n", HELP);
return FAIL;
}
transports_container_t container = {0};
transports_container_t container = {NULL, NULL, NULL, NULL, NULL, NULL};

mid_hermes_t *mh = NULL;
uint8_t sk[1024];
size_t sk_length = sizeof(sk);
if (!(sk_length = base64_decode(sk, argv[3], sk_length))){
if (!(sk_length = (size_t)base64_decode(sk, argv[3], (int)sk_length))){
destroy_transports_container(&container);
return FAIL;
}
Expand All @@ -120,8 +120,8 @@ int main(int argc, char **argv) {
return FAIL;
}
container.credential_store_transport = create_secure_transport(
argv[2], strlen(argv[2]), sk, sk_length, credential_store_pk, sizeof(credential_store_pk),
credential_store_id, strlen(credential_store_id), container.raw_credential_store_transport, false);
(uint8_t*)argv[2], strlen(argv[2]), sk, sk_length, credential_store_pk, sizeof(credential_store_pk),
credential_store_id, strlen((char*)credential_store_id), container.raw_credential_store_transport, false);
if(!container.credential_store_transport){
fprintf(stderr, "can't initialize secure transport to credential store\n");
destroy_transports_container(&container);
Expand All @@ -135,8 +135,8 @@ int main(int argc, char **argv) {
return FAIL;
}
container.key_store_transport = create_secure_transport(
argv[2], strlen(argv[2]), sk, sk_length, key_store_pk, sizeof(key_store_pk),
key_store_id, strlen(key_store_id), container.raw_key_store_transport, false);
(uint8_t*)argv[2], strlen(argv[2]), sk, sk_length, key_store_pk, sizeof(key_store_pk),
key_store_id, strlen((char*)key_store_id), container.raw_key_store_transport, false);
if(!container.key_store_transport){
fprintf(stderr, "can't initialize secure transport to key store\n");
destroy_transports_container(&container);
Expand All @@ -150,15 +150,15 @@ int main(int argc, char **argv) {
return FAIL;
}
container.data_store_transport = create_secure_transport(
argv[2], strlen(argv[2]), sk, sk_length, data_store_pk, sizeof(data_store_pk),
data_store_id, strlen(data_store_id), container.raw_data_store_transport, false);
(uint8_t*)argv[2], strlen(argv[2]), sk, sk_length, data_store_pk, sizeof(data_store_pk),
data_store_id, strlen((char*)data_store_id), container.raw_data_store_transport, false);
if(!container.data_store_transport){
fprintf(stderr, "can't initialize secure transport to data store\n");
destroy_transports_container(&container);
return FAIL;
}
if (!(mh = mid_hermes_create(
argv[2], strlen(argv[2]), sk, sk_length, container.key_store_transport, container.data_store_transport,
(uint8_t*)argv[2], strlen(argv[2]), sk, sk_length, container.key_store_transport, container.data_store_transport,
container.credential_store_transport))) {
fprintf(stderr, "mid_hermes creation error ...\n");
destroy_transports_container(&container);
Expand All @@ -172,14 +172,14 @@ int main(int argc, char **argv) {
size_t block_length = 0;
if (argc != 6
|| (SUCCESS != read_whole_file(argv[4], &block, &block_length))
|| (0 != mid_hermes_create_block(mh, &idBuffer, &idLength, block, block_length, argv[5], strlen(argv[5])))) {
|| (0 != mid_hermes_create_block(mh, &idBuffer, &idLength, block, block_length, (uint8_t*)argv[5], strlen(argv[5])))) {
free(block);
fprintf(stderr, "error: block adding error\n");
destroy_transports_container(&container);
return FAIL;
}
fprintf(stdout, "block created with id: ");
for(int i=0; i<idLength; i++){
for(size_t i=0; i<idLength; i++){
fprintf(stdout, "%c", idBuffer[i]);
}
fprintf(stdout, "\n");
Expand All @@ -188,7 +188,7 @@ int main(int argc, char **argv) {
uint8_t *data = NULL, *meta = NULL;
size_t data_length = 0, meta_length = 0;
if (argc != 5 ||
0 != mid_hermes_read_block(mh, argv[4], strlen(argv[4]), &data, &data_length, &meta, &meta_length)) {
0 != mid_hermes_read_block(mh, (uint8_t*)argv[4], strlen(argv[4]), &data, &data_length, &meta, &meta_length)) {
fprintf(stderr, "error: block getting error\n");
destroy_transports_container(&container);
return FAIL;
Expand All @@ -202,7 +202,7 @@ int main(int argc, char **argv) {
free(meta);
} else if (strcmp(argv[1], "delete_block") == 0) {
if (argc != 5
|| 0 != mid_hermes_delete_block(mh, argv[4], strlen(argv[4]))) {
|| 0 != mid_hermes_delete_block(mh, (uint8_t*)argv[4], strlen(argv[4]))) {
fprintf(stderr, "error: block deleting error\n");
destroy_transports_container(&container);
return FAIL;
Expand All @@ -212,7 +212,7 @@ int main(int argc, char **argv) {
size_t block_length = 0;
if (argc != 6
|| (SUCCESS != read_whole_file(argv[4], &block, &block_length))
|| (0 != mid_hermes_update_block(mh, argv[4], strlen(argv[4]), block, block_length, argv[5], strlen(argv[5])))) {
|| (0 != mid_hermes_update_block(mh, (uint8_t*)argv[4], strlen(argv[4]), block, block_length, (uint8_t*)argv[5], strlen(argv[5])))) {
free(block);
fprintf(stderr, "error: block adding error\n");
destroy_transports_container(&container);
Expand All @@ -221,36 +221,36 @@ int main(int argc, char **argv) {
free(block);
} else if (strcmp(argv[1], "grant_read") == 0) {
if (argc != 6
|| 0 != mid_hermes_grant_read_access(mh, argv[4], strlen(argv[4]), argv[5], strlen(argv[5]))) {
|| 0 != mid_hermes_grant_read_access(mh, (uint8_t*)argv[4], strlen(argv[4]), (uint8_t*)argv[5], strlen(argv[5]))) {
fprintf(stderr, "error: block read access granting error\n");
destroy_transports_container(&container);
return FAIL;
}
} else if (strcmp(argv[1], "grant_update") == 0) {
if (argc != 6
|| 0 != mid_hermes_grant_update_access(mh, argv[4], strlen(argv[4]), argv[5], strlen(argv[5]))) {
|| 0 != mid_hermes_grant_update_access(mh, (uint8_t*)argv[4], strlen(argv[4]), (uint8_t*)argv[5], strlen(argv[5]))) {
fprintf(stderr, "error: block update access granting error\n");
destroy_transports_container(&container);
return FAIL;
}
} else if (strcmp(argv[1], "revoke_read") == 0) {
if (argc != 6
|| 0 != mid_hermes_deny_read_access(mh, argv[4], strlen(argv[4]), argv[5], strlen(argv[5]))) {
|| 0 != mid_hermes_deny_read_access(mh, (uint8_t*)argv[4], strlen(argv[4]), (uint8_t*)argv[5], strlen(argv[5]))) {
fprintf(stderr, "error: block read access denying error\n");
destroy_transports_container(&container);
return FAIL;
}
} else if (strcmp(argv[1], "revoke_update") == 0) {
if (argc != 6
|| 0 != mid_hermes_deny_update_access(mh, argv[4], strlen(argv[4]), argv[5], strlen(argv[5]))) {
|| 0 != mid_hermes_deny_update_access(mh, (uint8_t*)argv[4], strlen(argv[4]), (uint8_t*)argv[5], strlen(argv[5]))) {
fprintf(stderr, "error: block update access denying error\n");
mid_hermes_destroy(&mh);
destroy_transports_container(&container);
return FAIL;
}
} else if (strcmp(argv[1], "rotate") == 0) {
if (argc != 5
|| 0 != mid_hermes_rotate_block(mh, argv[4], strlen(argv[4]))) {
|| 0 != mid_hermes_rotate_block(mh, (uint8_t*)argv[4], strlen(argv[4]))) {
fprintf(stderr, "error: block rotate error\n");
mid_hermes_destroy(&mh);
destroy_transports_container(&container);
Expand Down
2 changes: 2 additions & 0 deletions docs/examples/c/mid_hermes/common/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

#include <stdint.h>

#define UNUSED(expr) (void)(expr)

#define CREDENTIAL_STORE_IP "127.0.0.1"
#define DATA_STORE_IP "127.0.0.1"
#define KEY_STORE_IP "127.0.0.1"
Expand Down
7 changes: 4 additions & 3 deletions docs/examples/c/mid_hermes/common/transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ uint32_t transport_send(void *t, const uint8_t *buf, const size_t buf_length) {
return HM_FAIL;
}
ssize_t written = write(transport->socket, buf, buf_length);
if (buf_length !=written) {
if (written < 0 || buf_length != (size_t)written) {
return HM_FAIL;
}
return HM_SUCCESS;
Expand All @@ -73,14 +73,15 @@ uint32_t transport_recv(void *t, uint8_t *buf, size_t buf_length) {
if (!t || !buf || !buf_length) {
return HM_FAIL;
}
ssize_t readed_bytes, total_read = 0;
ssize_t readed_bytes = 0;
size_t total_read = 0;
while (total_read < buf_length) {
readed_bytes = read(((transport_t *) t)->socket, buf + total_read, buf_length - total_read);
if (readed_bytes < 0) {
return HM_FAIL;
}
total_read += readed_bytes;
if(readed_bytes == 0 || readed_bytes < buf_length){
if(readed_bytes == 0 || (size_t)readed_bytes < buf_length){
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/c/mid_hermes/credential_store_service/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ uint32_t db_get_public_key(void* cs, const uint8_t* user_id, const size_t user_i
return read_whole_file(fpath, pub_key, pub_key_length);
}

hm_cs_db_t* db_create(){
hm_cs_db_t* db_create(void){
hm_cs_db_t* cs=calloc(1, sizeof(hm_cs_db_t));
assert(cs);
cs->user_data=calloc(1, sizeof(db_t));
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/c/mid_hermes/credential_store_service/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#include <hermes/credential_store/db.h>

hm_cs_db_t* db_create();
hm_cs_db_t* db_create(void);
uint32_t db_destroy(hm_cs_db_t** db);

#endif //DB_H
7 changes: 5 additions & 2 deletions docs/examples/c/mid_hermes/credential_store_service/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@
int socket_desc=0;

void exit_handler(int s){
UNUSED(s);
fprintf(stderr, "\rexited...\n");
close(socket_desc);
exit(1);
}

void* credential_store(void* arg){
hm_rpc_transport_t* client_transport=transport_create((int)arg);
hm_rpc_transport_t* client_transport=transport_create((int)(intptr_t)arg);
if(!client_transport){
perror("client transport creation error ...\n");
return (void*)FAIL;
Expand All @@ -64,7 +65,7 @@ void* credential_store(void* arg){
secure_session_user_callbacks_t* session_callback = get_session_callback_with_local_credential_store(db);

hm_rpc_transport_t* secure_transport = create_secure_transport_with_callback(
credential_store_id, strlen(credential_store_id),
credential_store_id, strlen((char*)credential_store_id),
credential_store_private_key, sizeof(credential_store_private_key),
session_callback, client_transport, true);

Expand All @@ -83,6 +84,8 @@ void* credential_store(void* arg){
}

int main(int argc, char** argv){
UNUSED(argc);
UNUSED(argv);
struct sockaddr_in server , client;
socket_desc = socket(AF_INET , SOCK_STREAM , 0);
if (socket_desc == -1){
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/c/mid_hermes/data_store_service/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#include <hermes/data_store/db.h>

hm_ds_db_t* db_create();
hm_ds_db_t* db_create(void);
uint32_t db_destroy(hm_ds_db_t** db);

#endif //DB_H
Loading