Forward incoming TLS messages to [security]
This commit is contained in:
parent
866eb427f5
commit
dea7a685ac
|
|
@ -16,6 +16,8 @@
|
||||||
#include <itss-security/SecurityResponse.h>
|
#include <itss-security/SecurityResponse.h>
|
||||||
#include <itss-management/ManagementIndication.h>
|
#include <itss-management/ManagementIndication.h>
|
||||||
#include <itss-management/ManagementRequest.h>
|
#include <itss-management/ManagementRequest.h>
|
||||||
|
#include <itss-security/SecurityRequest.h>
|
||||||
|
#include <itss-security/SecurityReply.h>
|
||||||
|
|
||||||
#include <camv2/CAM.h>
|
#include <camv2/CAM.h>
|
||||||
#include <denmv2/DENM.h>
|
#include <denmv2/DENM.h>
|
||||||
|
|
@ -43,10 +45,12 @@
|
||||||
#define syslog_debug(msg, ...)
|
#define syslog_debug(msg, ...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int transport_indication(facilities_t *facilities, void* responder, uint8_t *msg, uint32_t msg_len) {
|
static int transport_indication(facilities_t *facilities, void* responder, void* security_socket, uint8_t *msg, uint32_t msg_len) {
|
||||||
int rv = 0, code = 0;
|
int rv = 0, code = 0;
|
||||||
bool handled_msg = false;
|
bool handled_msg = false;
|
||||||
FacilitiesIndication_t *fi = NULL;
|
FacilitiesIndication_t *fi = NULL;
|
||||||
|
SecurityRequest_t* sreq = NULL;
|
||||||
|
SecurityReply_t* srep = NULL;
|
||||||
|
|
||||||
TransportIndication_t* ti = calloc(1, sizeof(TransportIndication_t));
|
TransportIndication_t* ti = calloc(1, sizeof(TransportIndication_t));
|
||||||
|
|
||||||
|
|
@ -74,7 +78,6 @@ static int transport_indication(facilities_t *facilities, void* responder, uint8
|
||||||
;
|
;
|
||||||
|
|
||||||
// Parse message
|
// Parse message
|
||||||
|
|
||||||
switch (tpi->choice.btp.destinationPort) {
|
switch (tpi->choice.btp.destinationPort) {
|
||||||
case Port_cam:
|
case Port_cam:
|
||||||
its_msg_descriptor = &asn_DEF_CAM;
|
its_msg_descriptor = &asn_DEF_CAM;
|
||||||
|
|
@ -192,6 +195,31 @@ static int transport_indication(facilities_t *facilities, void* responder, uint8
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TransportPacketIndication_PR_tcp:
|
case TransportPacketIndication_PR_tcp:
|
||||||
|
|
||||||
|
sreq = calloc(1, sizeof(SecurityRequest_t));
|
||||||
|
sreq->present = SecurityRequest_PR_tlsRecv;
|
||||||
|
sreq->choice.tlsRecv.data.size = tpi->choice.tcp.data.size;
|
||||||
|
sreq->choice.tlsRecv.data.buf = malloc(tpi->choice.tcp.data.size);
|
||||||
|
memcpy(sreq->choice.tlsRecv.data.buf, tpi->choice.tcp.data.buf, tpi->choice.tcp.data.size);
|
||||||
|
|
||||||
|
uint8_t b_sdu[1024];
|
||||||
|
b_sdu[0] = 4;
|
||||||
|
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_SecurityRequest, NULL, sreq, b_sdu+1, 1023);
|
||||||
|
|
||||||
|
syslog_debug("[facilities]-> SecurityRequest.tlsRecv ->[security]");
|
||||||
|
zmq_send(security_socket, b_sdu, enc.encoded+1, 0);
|
||||||
|
int32_t rl = zmq_recv(security_socket, b_sdu, enc.encoded, 0);
|
||||||
|
syslog_debug("[facilities]<- SecurityReply.tlsRecv <-[security]");
|
||||||
|
|
||||||
|
asn_dec_rval_t dec = oer_decode(NULL, &asn_DEF_SecurityReply, (void**) &srep, b_sdu, rl);
|
||||||
|
printf("recv %d\n", rl); fflush(stdout);
|
||||||
|
|
||||||
|
for (int m = 0; m < srep->data->choice.tlsRecv.data.size; ++m) {
|
||||||
|
printf("%02x", srep->data->choice.tlsRecv.data.buf[m]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
fflush(stdout);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case TransportPacketIndication_PR_udp:
|
case TransportPacketIndication_PR_udp:
|
||||||
break;
|
break;
|
||||||
|
|
@ -226,6 +254,8 @@ cleanup:
|
||||||
}
|
}
|
||||||
ASN_STRUCT_FREE(asn_DEF_TransportIndication, ti);
|
ASN_STRUCT_FREE(asn_DEF_TransportIndication, ti);
|
||||||
ASN_STRUCT_FREE(asn_DEF_FacilitiesIndication, fi);
|
ASN_STRUCT_FREE(asn_DEF_FacilitiesIndication, fi);
|
||||||
|
ASN_STRUCT_FREE(asn_DEF_SecurityRequest, sreq);
|
||||||
|
ASN_STRUCT_FREE(asn_DEF_SecurityReply, srep);
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
@ -545,6 +575,11 @@ int main() {
|
||||||
// SA
|
// SA
|
||||||
pthread_create(&facilities.sa_service, NULL, sa_service, (void*) &facilities);
|
pthread_create(&facilities.sa_service, NULL, sa_service, (void*) &facilities);
|
||||||
|
|
||||||
|
void* security_socket = zmq_socket(facilities.zmq.ctx, ZMQ_REQ);
|
||||||
|
int wait_ms = 1000;
|
||||||
|
zmq_setsockopt(security_socket, ZMQ_RCVTIMEO, &wait_ms, sizeof(int));
|
||||||
|
zmq_connect(security_socket, facilities.zmq.security_address);
|
||||||
|
|
||||||
uint8_t buffer[PACKET_MAX_LEN];
|
uint8_t buffer[PACKET_MAX_LEN];
|
||||||
syslog_info("[facilities] listening");
|
syslog_info("[facilities] listening");
|
||||||
uint8_t code;
|
uint8_t code;
|
||||||
|
|
@ -570,7 +605,7 @@ int main() {
|
||||||
pthread_mutex_unlock(&facilities.id.change.lock);
|
pthread_mutex_unlock(&facilities.id.change.lock);
|
||||||
|
|
||||||
if (!in_idchange) {
|
if (!in_idchange) {
|
||||||
transport_indication(&facilities, facilities.zmq.responders[i].socket, buffer+1, rl);
|
transport_indication(&facilities, facilities.zmq.responders[i].socket, security_socket, buffer+1, rl);
|
||||||
|
|
||||||
pthread_mutex_lock(&facilities.id.change.lock);
|
pthread_mutex_lock(&facilities.id.change.lock);
|
||||||
facilities.id.change.stage = ID_CHANGE_INACTIVE;
|
facilities.id.change.stage = ID_CHANGE_INACTIVE;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue