Remove duplicated code in authentication plugin (#442)

* Remove duplicated code in authentication plugin

Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>

* Fix build warnings

Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>

* Fix memory leak and call create_validate_asymmetrical_signature directly from create_validate_signature_impl

Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>

* Fix refcount issue (assert in openssl) for identity cert in hs remote info

Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>

* Refactoring of validate_handshake_token function

Co-authored-by: Erik Boasson <eb@ilities.com>
Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>
This commit is contained in:
Dennis Potman 2020-03-20 13:44:27 +01:00 committed by GitHub
parent ab5f51eada
commit 0768ad59ed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 348 additions and 627 deletions

View file

@ -14,6 +14,7 @@
#define DSCMN_SECURITY_UTILS_H_
#include <stddef.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdbool.h>
#include "dds/export.h"
@ -261,6 +262,15 @@ DDS_EXPORT void
DDS_Security_HandleSeq_deinit(
DDS_Security_HandleSeq *seq);
DDS_EXPORT void
DDS_Security_Exception_vset(
DDS_Security_SecurityException *ex,
const char *context,
int code,
int minor_code,
const char *fmt,
va_list ap);
DDS_EXPORT void
DDS_Security_Exception_set(
DDS_Security_SecurityException *ex,
@ -268,7 +278,7 @@ DDS_Security_Exception_set(
int code,
int minor_code,
const char *fmt,
...);
...);
#ifdef DDSI_INCLUDE_SSL

View file

@ -760,50 +760,49 @@ DDS_Security_HandleSeq_deinit(
DDS_Security_HandleSeq_freebuf(seq);
}
void
DDS_Security_Exception_set(
DDS_Security_SecurityException *ex,
const char *context,
int code,
int minor_code,
const char *fmt,
...)
void DDS_Security_Exception_vset (DDS_Security_SecurityException *ex, const char *context, int code, int minor_code, const char *fmt, va_list args1)
{
int32_t ret;
size_t len;
char buf[1] = { '\0' };
char *str = NULL;
va_list args1, args2;
int32_t ret;
size_t len;
char buf[1] = { '\0' };
char *str = NULL;
va_list args2;
assert(context);
assert(fmt);
assert(ex);
DDSRT_UNUSED_ARG( context );
assert(context);
assert(fmt);
assert(ex);
DDSRT_UNUSED_ARG( context );
va_start(args1, fmt);
va_copy(args2, args1);
va_copy(args2, args1);
if ((ret = vsnprintf(buf, sizeof(buf), fmt, args1)) >= 0) {
len = (size_t)ret; /* +1 for null byte */
if ((str = ddsrt_malloc(len + 1)) == NULL) {
assert(false);
} else if ((ret = vsnprintf(str, len + 1, fmt, args2)) >= 0) {
assert((size_t) ret == len);
} else {
ddsrt_free(str);
str = NULL;
}
if ((ret = vsnprintf(buf, sizeof(buf), fmt, args1)) >= 0) {
len = (size_t)ret; /* +1 for null byte */
if ((str = ddsrt_malloc(len + 1)) == NULL) {
assert(false);
} else if ((ret = vsnprintf(str, len + 1, fmt, args2)) >= 0) {
assert((size_t) ret == len);
} else {
ddsrt_free(str);
str = NULL;
}
}
va_end(args1);
va_end(args2);
va_end(args1);
ex->message = str;
ex->code = code;
ex->minor_code = minor_code;
ex->message = str;
ex->code = code;
ex->minor_code = minor_code;
}
void DDS_Security_Exception_set (DDS_Security_SecurityException *ex, const char *context, int code, int minor_code, const char *fmt, ...)
{
va_list args1;
assert(context);
assert(fmt);
assert(ex);
va_start(args1, fmt);
DDS_Security_Exception_vset (ex, context, code, minor_code, fmt, args1);
va_end(args1);
}
#ifdef DDSI_INCLUDE_SSL