Recv SAEM trigger TLS

This commit is contained in:
emanuel 2021-09-02 15:29:07 +01:00
parent c6d8be21f3
commit 4086995a15
1 changed files with 41 additions and 5 deletions

View File

@ -4,6 +4,8 @@
#include <it2s-tender/time.h> #include <it2s-tender/time.h>
#include <itss-transport/TransportRequest.h> #include <itss-transport/TransportRequest.h>
#include <itss-security/SecurityRequest.h>
#include <itss-security/SecurityReply.h>
#include <saem/SAEM.h> #include <saem/SAEM.h>
#include <syslog.h> #include <syslog.h>
@ -200,6 +202,9 @@ void *sa_service(void *fc) {
*bpr->gn.securityProfile = 1; *bpr->gn.securityProfile = 1;
} }
void* security_socket = zmq_socket(facilities->zmq.ctx, ZMQ_REQ);
zmq_connect(security_socket, facilities->zmq.security_address);
uint8_t tr_oer[1024]; uint8_t tr_oer[1024];
tr_oer[0] = 4; // Facilities tr_oer[0] = 4; // Facilities
@ -234,15 +239,46 @@ void *sa_service(void *fc) {
if (bulletin->to_consume[a]->its_aid == 0 && !bulletin->to_consume[a]->n_trigger) { if (bulletin->to_consume[a]->its_aid == 0 && !bulletin->to_consume[a]->n_trigger) {
SecurityRequest_t* sreq = calloc(1, sizeof(SecurityRequest_t));
sreq->present = SecurityRequest_PR_tlsSend;
sreq->choice.tlsSend.data.buf = malloc(7);
sreq->choice.tlsSend.data.size = 7;
char hello[] = "Hello!";
memcpy(sreq->choice.tlsSend.data.buf, hello, 7);
uint8_t buffer[1024];
buffer[0] = 4;
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_SecurityRequest, NULL, sreq, buffer+1, 1023);
ASN_STRUCT_FREE(asn_DEF_SecurityRequest, sreq);
syslog_debug("[facilities] [sa]-> SecurityRequest.tlsSend ->[security]");
zmq_send(security_socket, buffer, enc.encoded, 0);
zmq_recv(security_socket, buffer, 1024, 0);
syslog_debug("[facilities] [sa]<- SecurityReply <-[security]");
SecurityReply_t* srep = NULL;
asn_dec_rval_t dec = oer_decode(NULL, &asn_DEF_SecurityReply, (void**) &srep, buffer, 1024);
if (dec.code || srep->returnCode != SecurityReplyReturnCode_accepted) {
ASN_STRUCT_FREE(asn_DEF_SecurityReply, srep);
continue;
}
TransportRequest_t* tr_etc = calloc(1, sizeof(TransportRequest_t)); TransportRequest_t* tr_etc = calloc(1, sizeof(TransportRequest_t));
tr_etc->present = TransportRequest_PR_packet; tr_etc->present = TransportRequest_PR_packet;
TransportPacketRequest_t* tpr_etc = &tr_etc->choice.packet; TransportPacketRequest_t* tpr_etc = &tr_etc->choice.packet;
tpr_etc->present = TransportPacketRequest_PR_tcp; tpr_etc->present = TransportPacketRequest_PR_tcp;
tpr_etc->choice.tcp.data.buf = malloc(7); tpr_etc->choice.tcp.destinationAddress = calloc(1, sizeof(OCTET_STRING_t));
tpr_etc->choice.tcp.data.size = 7; tpr_etc->choice.tcp.destinationAddress->buf = malloc(16);
char hello[] = "Hello!"; tpr_etc->choice.tcp.destinationAddress->size = 16;
memcpy(tpr_etc->choice.tcp.data.buf, hello, 7); memcpy(tpr_etc->choice.tcp.destinationAddress->buf, bulletin->to_consume[a]->endpoint.ipv6_addr, 16);
tpr_etc->choice.tcp.data.buf = malloc(srep->data->choice.tlsSend.data.size);
tpr_etc->choice.tcp.data.size = srep->data->choice.tlsSend.data.size;
memcpy(tpr_etc->choice.tcp.data.buf, srep->data->choice.tlsSend.data.buf, srep->data->choice.tlsSend.data.size);
ASN_STRUCT_FREE(asn_DEF_SecurityReply, srep);
tpr_etc->choice.tcp.gn = calloc(1, sizeof(GeonetworkingOutboundOptions_t)); tpr_etc->choice.tcp.gn = calloc(1, sizeof(GeonetworkingOutboundOptions_t));
tpr_etc->choice.tcp.gn->packetTransportType = PacketTransportType_shb; tpr_etc->choice.tcp.gn->packetTransportType = PacketTransportType_shb;
@ -251,7 +287,7 @@ void *sa_service(void *fc) {
++bulletin->to_consume[a]->n_trigger; ++bulletin->to_consume[a]->n_trigger;
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr_etc, tr_oer+1, 1023); enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr_etc, tr_oer+1, 1023);
if (enc.encoded == -1) { if (enc.encoded == -1) {
syslog_err("[facilities] encoding TR for ETC-Req failed"); syslog_err("[facilities] encoding TR for ETC-Req failed");
continue; continue;