Skip to content

Commit

Permalink
Merge pull request #270 from mfrey/remove_c_includes
Browse files Browse the repository at this point in the history
removes source file includes in ccnl-utils
  • Loading branch information
mfrey committed Jun 14, 2018
2 parents 48b17eb + 2d47ca5 commit a72c2c8
Show file tree
Hide file tree
Showing 29 changed files with 667 additions and 172 deletions.
66 changes: 32 additions & 34 deletions src/ccnl-utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,83 +9,81 @@ link_directories(
${CMAKE_CURRENT_BINARY_DIR}/../lib
)

include_directories(
../ccnl-pkt/include
../ccnl-fwd/include
../ccnl-core/include
../ccnl-unix/include
../ccnl-nfn/include
)
# set include directories
include_directories(include ../ccnl-pkt/include ../ccnl-fwd/include ../ccnl-core/include ../ccnl-unix/include ../ccnl-nfn/include)

add_library(common STATIC src/ccnl-common.c src/base64.c src/ccnl-socket.c)
add_library(ccnl-crypto STATIC src/ccnl-crypto.c src/ccnl-ext-hmac.c src/lib-sha256.c)

add_executable(ccn-lite-peek ccn-lite-peek.c)
add_executable(ccn-lite-peek src/ccn-lite-peek.c)
#add_executable(ccn-lite-peekcomputation ccn-lite-peekcomputation.c) #todo work to do
add_executable(ccn-lite-ctrl ccn-lite-ctrl.c)
add_executable(ccn-lite-fetch ccn-lite-fetch.c)
add_executable(ccn-lite-ctrl src/ccn-lite-ctrl.c)
add_executable(ccn-lite-fetch src/ccn-lite-fetch.c)
if(OpenSSL_FOUND)
add_executable(ccn-lite-ccnb2xml ccn-lite-ccnb2xml.c)
add_executable(ccn-lite-cryptoserver ccn-lite-cryptoserver.c)
add_executable(ccn-lite-ccnb2xml src/ccn-lite-ccnb2xml.c)
add_executable(ccn-lite-cryptoserver src/ccn-lite-cryptoserver.c)
#add_executable(ccn-lite-deF ccn-lite-deF.c)
add_executable(ccn-lite-mkC ccn-lite-mkC.c)
add_executable(ccn-lite-valid ccn-lite-valid.c)
add_executable(ccn-lite-rpc ccn-lite-rpc.c)
add_executable(ccn-lite-mkC src/ccn-lite-mkC.c)
add_executable(ccn-lite-valid src/ccn-lite-valid.c)
add_executable(ccn-lite-rpc src/ccn-lite-rpc.c)
endif()

if(USE_FRAG)
add_executable(ccn-lite-mkF ccn-lite-mkF.c)
add_executable(ccn-lite-mkF src/ccn-lite-mkF.c)
endif()
add_executable(ccn-lite-mkI ccn-lite-mkI.c)
add_executable(ccn-lite-pktdump ccn-lite-pktdump.c)
add_executable(ccn-lite-produce ccn-lite-produce.c)
add_executable(ccn-lite-mkI src/ccn-lite-mkI.c)
add_executable(ccn-lite-pktdump src/ccn-lite-pktdump.c)
add_executable(ccn-lite-produce src/ccn-lite-produce.c)

add_executable(ccn-lite-simplenfn ccn-lite-simplenfn.c)
add_executable(ccn-lite-simplenfn src/ccn-lite-simplenfn.c)


target_link_libraries(ccn-lite-peek ${PROJECT_LINK_LIBS} ${EXT_LINK_LIBS})
target_link_libraries(ccn-lite-peek ccnl-core ccnl-pkt ccnl-fwd ccnl-unix ccnl-nfn)
target_link_libraries(ccn-lite-peek ccnl-core ccnl-pkt ccnl-fwd ccnl-unix ccnl-nfn common)

#target_link_libraries(ccn-lite-peekcomputation ${PROJECT_LINK_LIBS} ${EXT_LINK_LIBS})#todo work to do
#target_link_libraries(ccn-lite-peekcomputation ccnl-core ccnl-pkt ccnl-fwd ccnl-unix ccnl-nfn)

target_link_libraries(ccn-lite-ctrl ${PROJECT_LINK_LIBS} ${EXT_LINK_LIBS})
target_link_libraries(ccn-lite-ctrl ccnl-core ccnl-pkt ccnl-fwd ccnl-unix ccnl-nfn)
target_link_libraries(ccn-lite-ctrl ccnl-core ccnl-pkt ccnl-fwd ccnl-unix ccnl-nfn crypto)

if(OpenSSL_FOUND)
target_link_libraries(ccn-lite-ccnb2xml ${PROJECT_LINK_LIBS} ${EXT_LINK_LIBS} ${OPENSSL_LIBRARIES})
target_link_libraries(ccn-lite-ccnb2xml ccnl-core ccnl-pkt ccnl-fwd ccnl-unix ccnl-nfn ${OPENSSL_LIBRARIES})
target_link_libraries(ccn-lite-ccnb2xml ccnl-core ccnl-pkt ccnl-fwd ccnl-unix ccnl-nfn ccnl-crypto ${OPENSSL_LIBRARIES})

target_link_libraries(ccn-lite-cryptoserver ${PROJECT_LINK_LIBS} ${EXT_LINK_LIBS} ${OPENSSL_LIBRARIES})
target_link_libraries(ccn-lite-cryptoserver ccnl-core ccnl-pkt ccnl-fwd ccnl-unix ccnl-nfn ${OPENSSL_LIBRARIES})
target_link_libraries(ccn-lite-cryptoserver ccnl-core ccnl-pkt ccnl-fwd ccnl-unix ccnl-nfn ccnl-crypto ${OPENSSL_LIBRARIES} common)

#target_link_libraries(ccn-lite-deF ${PROJECT_LINK_LIBS} ${EXT_LINK_LIBS} ${OPENSSL_LIBRARIES})
#target_link_libraries(ccn-lite-deF ccnl-core ccnl-pkt ccnl-fwd ccnl-unix ccnl-nfn ${OPENSSL_LIBRARIES})

target_link_libraries(ccn-lite-mkC ${PROJECT_LINK_LIBS} ${EXT_LINK_LIBS} ${OPENSSL_LIBRARIES})
target_link_libraries(ccn-lite-mkC ccnl-core ccnl-pkt ccnl-fwd ccnl-unix ccnl-nfn ${OPENSSL_LIBRARIES})
target_link_libraries(ccn-lite-mkC ${PROJECT_LINK_LIBS} ${EXT_LINK_LIBS} ${OPENSSL_LIBRARIES} common)
target_link_libraries(ccn-lite-mkC ccnl-core ccnl-pkt ccnl-fwd ccnl-unix ccnl-nfn ccnl-crypto ${OPENSSL_LIBRARIES})

target_link_libraries(ccn-lite-valid ${PROJECT_LINK_LIBS} ${EXT_LINK_LIBS} ${OPENSSL_LIBRARIES})
target_link_libraries(ccn-lite-valid ${PROJECT_LINK_LIBS} ${EXT_LINK_LIBS} ${OPENSSL_LIBRARIES} common ccnl-crypto)
target_link_libraries(ccn-lite-valid ccnl-core ccnl-pkt ccnl-fwd ccnl-unix ccnl-nfn ${OPENSSL_LIBRARIES})

target_link_libraries(ccn-lite-rpc ${PROJECT_LINK_LIBS} ${EXT_LINK_LIBS} ${OPENSSL_LIBRARIES})
target_link_libraries(ccn-lite-rpc ${PROJECT_LINK_LIBS} ${EXT_LINK_LIBS} ${OPENSSL_LIBRARIES} common)
target_link_libraries(ccn-lite-rpc ccnl-core ccnl-pkt ccnl-fwd ccnl-unix ccnl-nfn ${OPENSSL_LIBRARIES})

endif()

target_link_libraries(ccn-lite-fetch ${PROJECT_LINK_LIBS} ${EXT_LINK_LIBS})
target_link_libraries(ccn-lite-fetch ccnl-core ccnl-pkt ccnl-fwd ccnl-unix ccnl-nfn)
target_link_libraries(ccn-lite-fetch ccnl-core ccnl-pkt ccnl-fwd ccnl-unix ccnl-nfn common)

if(USE_FRAG)
target_link_libraries(ccn-lite-mkF ${PROJECT_LINK_LIBS} ${EXT_LINK_LIBS})
target_link_libraries(ccn-lite-mkF ccnl-core ccnl-pkt ccnl-fwd ccnl-unix ccnl-nfn)
target_link_libraries(ccn-lite-mkF ccnl-core ccnl-pkt ccnl-fwd ccnl-unix ccnl-nfn common)
endif()

target_link_libraries(ccn-lite-mkI ${PROJECT_LINK_LIBS} ${EXT_LINK_LIBS})
target_link_libraries(ccn-lite-mkI ccnl-core ccnl-pkt ccnl-fwd ccnl-unix ccnl-nfn)
target_link_libraries(ccn-lite-mkI ccnl-core ccnl-pkt ccnl-fwd ccnl-unix ccnl-nfn common)

target_link_libraries(ccn-lite-pktdump ${PROJECT_LINK_LIBS} ${EXT_LINK_LIBS})
target_link_libraries(ccn-lite-pktdump ccnl-core ccnl-pkt ccnl-fwd ccnl-unix ccnl-nfn)
target_link_libraries(ccn-lite-pktdump ccnl-core ccnl-pkt ccnl-fwd ccnl-unix ccnl-nfn common)

target_link_libraries(ccn-lite-produce ${PROJECT_LINK_LIBS} ${EXT_LINK_LIBS})
target_link_libraries(ccn-lite-produce ccnl-core ccnl-pkt ccnl-fwd ccnl-unix ccnl-nfn)
target_link_libraries(ccn-lite-produce ccnl-core ccnl-pkt ccnl-fwd ccnl-unix ccnl-nfn common ccnl-crypto)

target_link_libraries(ccn-lite-simplenfn ${PROJECT_LINK_LIBS} ${EXT_LINK_LIBS})
target_link_libraries(ccn-lite-simplenfn ccnl-core ccnl-pkt ccnl-fwd ccnl-unix ccnl-nfn)
target_link_libraries(ccn-lite-simplenfn ccnl-core ccnl-pkt ccnl-fwd ccnl-unix ccnl-nfn common)
55 changes: 55 additions & 0 deletions src/ccnl-utils/include/base64.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// base64.c
// from stackoverflow.com, user RYYST

#ifndef BASE64_H
#define BASE64_H

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdint.h>

/**
* @brief Initializes the base64 decoding table
*/
void base64_build_decoding_table(void);

/**
* @brief Encodes a string \p data into a base64 string
*
* @param[in] data The data to encode
* @param[in] input_length The size of the data to encode
* @param[out] output_length The size of the encoded date
*
* @return Upon success, a base64 encoded representation of \p data
* @return NULL if \p data was NULL
* @return NULL if allocating the result string failed
* @return NULL if \p input_length is not in multiples of four
*/
char *base64_encode(const char *data,
size_t input_length,
size_t *output_length);

/**
* @brief Decodes a string \p data into a base64 string
*
* @param[in] data The data to decode
* @param[in] input_length The size of the data to decode
* @param[out] output_length The size of the decoded date
*
* @return Upon success, the base64 decoded \p data
* @return NULL if \p data was NULL
* @return NULL if allocating the result string failed
* @return NULL if \p input_length is not in multiples of four
*/
unsigned char *base64_decode(const char *data,
size_t input_length,
size_t *output_length);

/**
* @brief Frees the previously allocated decoding table
*/
void base64_cleanup(void);

#endif // EOF
/** @} */
154 changes: 154 additions & 0 deletions src/ccnl-utils/include/ccnl-common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/**
* @addtogroup CCNL-utils
* @{
*
* @file ccnl-common.h
* @brief Common functions for the CCN-lite utilities
*
* Copyright (C) 2013-18 Christian Tschudin, University of Basel
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef CCNL_COMMON_H
#define CCNL_COMMON_H

#ifndef CCNL_UAPI_H_ // if CCNL_UAPI_H_ is defined then the following config is taken care elsewhere in the code composite


#define _DEFAULT_SOURCE
#define _BSD_SOURCE
#define _SVID_SOURCE

#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <getopt.h>
#include <limits.h>

#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/stat.h>
#include <sys/un.h>

#include "base64.h"

#include "ccnl-os-includes.h"
#include "ccnl-defs.h"
#include "ccnl-core.h"
#include "ccnl-pkt-builder.h"
#include "ccnl-malloc.h"
#include "ccnl-os-time.h"
#include "ccnl-logging.h"
#include "ccnl-pkt-builder.h"

#ifndef USE_DEBUG_MALLOC
#define ccnl_malloc(s) malloc(s)
#define ccnl_calloc(n,s) calloc(n,s)
#define ccnl_realloc(p,s) realloc(p,s)
#define ccnl_free(p) free(p)
#endif //USE_DEBUG_MALLOC
#define free_2ptr_list(a,b) ccnl_free(a), ccnl_free(b)

struct ccnl_prefix_s* ccnl_prefix_new(int suite, int cnt);
int ccnl_pkt_prependComponent(int suite, char *src, int *offset, unsigned char *buf);

#include "ccnl-core.h"
#include "ccnl-pkt-ccnb.h"
#include "ccnl-pkt-ccntlv.h"
#include "ccnl-pkt-localrpc.h"
#include "ccnl-pkt-ndntlv.h"
#include "ccnl-pkt-switch.h"

#include "ccnl-socket.h"

#define ccnl_core_addToCleanup(b) do{}while(0)

// include only the utils, not the core routines:
#ifdef USE_FRAG
#include "../ccnl-frag.h"
#endif

#else // CCNL_UAPI_H_ is defined

#include "base64.c"
#ifdef RIOT_VERSION
#include "ccnl-defs.h"
#include "net/packet.h"
#include <unistd.h>
#include "sys/socket.h"
#include "ccn-lite-riot.h"
#include "ccnl-headers.h"
#include "ccnl-pkt-ndntlv.h"
#include "ccnl-pkt-ccntlv.h"
#include "ccnl-pkt-ccnb.h"


extern int ccnl_suite2defaultPort(int suite);
#endif

#endif // CCNL_UAPI_H_


// ----------------------------------------------------------------------

const char* ccnl_enc2str(int enc);

// ----------------------------------------------------------------------

#define extractStr(VAR,DTAG) \
if (typ == CCN_TT_DTAG && num == DTAG) { \
char *s; unsigned char *valptr; int vallen; \
if (ccnl_ccnb_consume(typ, num, &buf, &buflen, &valptr, &vallen) < 0) \
goto Bail; \
s = ccnl_malloc(vallen+1); if (!s) goto Bail; \
memcpy(s, valptr, vallen); s[vallen] = '\0'; \
ccnl_free(VAR); \
VAR = (unsigned char*) s; \
continue; \
} do {} while(0)

#define extractStr2(VAR,DTAG) \
if (typ == CCN_TT_DTAG && num == DTAG) { \
char *s; unsigned char *valptr; int vallen; \
if (ccnl_ccnb_consume(typ, num, buf, buflen, &valptr, &vallen) < 0) \
goto Bail; \
s = ccnl_malloc(vallen+1); if (!s) goto Bail; \
memcpy(s, valptr, vallen); s[vallen] = '\0'; \
ccnl_free(VAR); \
VAR = (unsigned char*) s; \
continue; \
} do {} while(0)

// ----------------------------------------------------------------------

struct key_s {
struct key_s *next;
unsigned char* key;
int keylen;
};

struct key_s* load_keys_from_file(char *path);

// ----------------------------------------------------------------------

int
ccnl_parseUdp(char *udp, int suite, char **addr, int *port);

#endif
/** @} */
47 changes: 47 additions & 0 deletions src/ccnl-utils/include/ccnl-crypto.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* @addtogroup CCNL-utils
* @{
*
* @file ccnl-crypto.h
* @brief Crypto functions for CCN-lite utilities
*
* Copyright (C) 2013-2018, Christian Tschudin, University of Basel
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef CCNL_CRYPTO_H
#define CCNL_CRYPTO_H

#ifdef USE_SIGNATURES
#include <openssl/pem.h>
#include <openssl/sha.h>
#include <openssl/rsa.h>
#include <openssl/objects.h>
#include <openssl/err.h>
#endif

int sha(void* input, unsigned long length, unsigned char* md);

int sign(char* private_key_path, unsigned char *msg, int msg_len,
unsigned char *sig, unsigned int *sig_len);

int
verify(char* public_key_path, unsigned char *msg, int msg_len,
unsigned char *sig, unsigned int sig_len);

int
add_signature(unsigned char *out, char *private_key_path,
unsigned char *file, unsigned int fsize);

#endif
/** @} */
Loading

0 comments on commit a72c2c8

Please sign in to comment.