Commit 1cf0a07a authored by johan's avatar johan

Fix compilation error when polarssl version in 1.2

parent f7e51cd7
......@@ -62,6 +62,14 @@ struct belle_sip_signing_key {
/**
* Retrieve key or certificate in a string(PEM format)
*/
#if POLARSSL_VERSION_NUMBER < 0x01030000
unsigned char *belle_sip_get_certificates_pem(belle_sip_certificates_chain_t *cert) {
return NULL;
}
unsigned char *belle_sip_get_key_pem(belle_sip_signing_key_t *key) {
return NULL;
}
#else /* POLARSSL_VERSION_NUMBER >= 0x01030000 */
unsigned char *belle_sip_get_certificates_pem(belle_sip_certificates_chain_t *cert) {
unsigned char *pem_certificate = NULL;
size_t olen=0;
......@@ -79,6 +87,7 @@ unsigned char *belle_sip_get_key_pem(belle_sip_signing_key_t *key) {
pk_write_key_pem( &(key->key), (unsigned char *)pem_key, 4096);
return pem_key;
}
#endif /* POLARSSL_VERSION_NUMBER >= 0x01030000 */
/*************tls********/
......@@ -592,6 +601,9 @@ int belle_sip_get_certificate_and_pkey_in_dir(const char *path, const char *subj
int belle_sip_generate_self_signed_certificate(const char* path, const char *subject, belle_sip_certificates_chain_t **certificate, belle_sip_signing_key_t **pkey) {
#ifdef HAVE_POLARSSL
#if POLARSSL_VERSION_NUMBER < 0x01030000
return -1;
#else /* POLARSSL_VERSION_NUMBER < 0x01030000 */
entropy_context entropy;
ctr_drbg_context ctr_drbg;
int ret;
......@@ -721,6 +733,7 @@ int belle_sip_generate_self_signed_certificate(const char* path, const char *sub
}
return 0;
#endif /* else POLARSSL_VERSION_NUMBER < 0x01030000 */
#else /* ! HAVE_POLARSSL */
return -1;
#endif
......@@ -729,6 +742,9 @@ int belle_sip_generate_self_signed_certificate(const char* path, const char *sub
/* Note : this code is duplicated in mediastreamer2/src/voip/dtls_srtp.c but get directly a x509_crt as input parameter */
unsigned char *belle_sip_generate_certificate_fingerprint(belle_sip_certificates_chain_t *certificate) {
#ifdef HAVE_POLARSSL
#if POLARSSL_VERSION_NUMBER < 0x01030000
return NULL;
#else /* POLARSSL_VERSION_NUMBER < 0x01030000 */
unsigned char buffer[64]; /* buffer is max length of returned hash, which is 64 in case we use sha-512 */
size_t hash_length = 0;
char hash_alg_string[8]; /* buffer to store the string description of the algo, longest is SHA-512(7 chars + null termination) */
......@@ -764,6 +780,7 @@ unsigned char *belle_sip_generate_certificate_fingerprint(belle_sip_certificates
}
return fingerprint;
#endif /* else POLARSSL_VERSION_NUMBER < 0x01030000 */
#else /* ! HAVE_POLARSSL */
return NULL;
#endif
......
......@@ -16,11 +16,20 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "belle-sip/auth-helper.h"
#include "belle_sip_tester.h"
#include <stdio.h>
#include "CUnit/Basic.h"
#ifdef HAVE_POLARSSL
#include <polarssl/version.h>
#endif
static void test_authentication(void) {
const char* l_raw_header = "WWW-Authenticate: Digest "
......@@ -77,6 +86,8 @@ static void test_proxy_authentication(void) {
#define TEMPORARY_CERTIFICATE_DIR "/belle_sip_tester_crt"
static void test_generate_and_parse_certificates(void) {
#ifdef HAVE_POLARSSL
#if POLARSSL_VERSION_NUMBER >= 0x01030000
/* function not available on windows yet - need to add the create and parse directory */
#ifndef WIN32
belle_sip_certificates_chain_t *certificate, *parsed_certificate;
......@@ -121,19 +132,26 @@ static void test_generate_and_parse_certificates(void) {
belle_sip_object_unref(key);
belle_sip_object_unref(parsed_key);
#endif /* WIN32 */
#endif /* POLARSSL_VERSION_NUMBER >= 0x01030000 */
#endif /* HAVE_POLARSSL */
}
static void test_certificate_fingerprint(void) {
#ifdef HAVE_POLARSSL
#if POLARSSL_VERSION_NUMBER >= 0x01030000
unsigned char *fingerprint;
/* parse certificate defined in belle_sip_register_tester.c */
belle_sip_certificates_chain_t* cert = belle_sip_certificates_chain_parse(belle_sip_tester_client_cert,strlen(belle_sip_tester_client_cert),BELLE_SIP_CERTIFICATE_RAW_FORMAT_PEM);
/* generate fingerprint */
fingerprint = belle_sip_generate_certificate_fingerprint(cert);
CU_ASSERT_TRUE_FATAL(fingerprint!=NULL);
CU_ASSERT_STRING_EQUAL(fingerprint, belle_sip_tester_client_cert_fingerprint);
free(fingerprint);
belle_sip_object_unref(cert);
#endif /* POLARSSL_VERSION_NUMBER >= 0x01030000 */
#endif /* HAVE_POLARSSL */
}
test_t authentication_helper_tests[] = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment