TPM sign
This commit is contained in:
parent
e9dfc7764f
commit
385e965c6f
|
|
@ -345,7 +345,7 @@ lightship_t* lightship_init() {
|
||||||
lightship->use_obd = 0;
|
lightship->use_obd = 0;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
lightship->use_obd = 1;
|
lightship->use_obd = 0; // TODO
|
||||||
close(shm_fd);
|
close(shm_fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -649,11 +649,11 @@ int main() {
|
||||||
memset(&facilities, 0x00, sizeof(facilities_t));
|
memset(&facilities, 0x00, sizeof(facilities_t));
|
||||||
|
|
||||||
facilities.zmq.ctx = zmq_ctx_new();
|
facilities.zmq.ctx = zmq_ctx_new();
|
||||||
facilities.lightship = lightship_init();
|
|
||||||
facilities.dissemination = dissemination_init();
|
|
||||||
facilities.tx_queue = queue_init();
|
facilities.tx_queue = queue_init();
|
||||||
|
facilities.lightship = lightship_init();
|
||||||
facilities.den = calloc(1, sizeof(den_t));
|
facilities.den = calloc(1, sizeof(den_t));
|
||||||
facilities.infrastructure = calloc(1, sizeof(infrastructure_t));
|
facilities.infrastructure = calloc(1, sizeof(infrastructure_t));
|
||||||
|
facilities.dissemination = dissemination_init();
|
||||||
bulletin_init(&facilities.bulletin);
|
bulletin_init(&facilities.bulletin);
|
||||||
|
|
||||||
time_t t;
|
time_t t;
|
||||||
|
|
@ -675,12 +675,15 @@ int main() {
|
||||||
// Infrastructure
|
// Infrastructure
|
||||||
pthread_create(&facilities.infrastructure_service, NULL, infrastructure_service, (void*) &facilities);
|
pthread_create(&facilities.infrastructure_service, NULL, infrastructure_service, (void*) &facilities);
|
||||||
|
|
||||||
// CPM
|
// CP
|
||||||
pthread_create(&facilities.cp_service, NULL, cp_service, (void*) &facilities);
|
pthread_create(&facilities.cp_service, NULL, cp_service, (void*) &facilities);
|
||||||
|
|
||||||
// SA
|
// SA
|
||||||
pthread_create(&facilities.sa_service, NULL, sa_service, (void*) &facilities);
|
pthread_create(&facilities.sa_service, NULL, sa_service, (void*) &facilities);
|
||||||
|
|
||||||
|
// Tolling
|
||||||
|
tolling_init(&facilities.tolling, facilities.zmq.ctx, facilities.zmq.security_address);
|
||||||
|
|
||||||
void* security_socket = zmq_socket(facilities.zmq.ctx, ZMQ_REQ);
|
void* security_socket = zmq_socket(facilities.zmq.ctx, ZMQ_REQ);
|
||||||
int wait_ms = 1000;
|
int wait_ms = 1000;
|
||||||
zmq_setsockopt(security_socket, ZMQ_RCVTIMEO, &wait_ms, sizeof(int));
|
zmq_setsockopt(security_socket, ZMQ_RCVTIMEO, &wait_ms, sizeof(int));
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,6 @@ SAEM_CODE_R saem_check(void* fc, bulletin_t* bulletin, SAEM_t* saem, uint8_t* ne
|
||||||
si->chOptions.extensions->list.array[e]->choice.applicationDataSAM.buf,
|
si->chOptions.extensions->list.array[e]->choice.applicationDataSAM.buf,
|
||||||
si->chOptions.extensions->list.array[e]->choice.applicationDataSAM.size
|
si->chOptions.extensions->list.array[e]->choice.applicationDataSAM.size
|
||||||
);
|
);
|
||||||
syslog_err("dec.code:: %d", dec.code);
|
|
||||||
if (!dec.code) {
|
if (!dec.code) {
|
||||||
bulletin->to_consume[bulletin->to_provide_len]->info.internal_p = facilities->tolling.infos.z[facilities->tolling.infos.length];
|
bulletin->to_consume[bulletin->to_provide_len]->info.internal_p = facilities->tolling.infos.z[facilities->tolling.infos.length];
|
||||||
++facilities->tolling.infos.length;
|
++facilities->tolling.infos.length;
|
||||||
|
|
@ -358,7 +357,7 @@ void *sa_service(void *fc) {
|
||||||
((TollingPaymentInfo_t*)bulletin->to_consume[a]->info.internal_p)->zone.a/10.0,
|
((TollingPaymentInfo_t*)bulletin->to_consume[a]->info.internal_p)->zone.a/10.0,
|
||||||
((TollingPaymentInfo_t*)bulletin->to_consume[a]->info.internal_p)->zone.b/10.0,
|
((TollingPaymentInfo_t*)bulletin->to_consume[a]->info.internal_p)->zone.b/10.0,
|
||||||
((TollingPaymentInfo_t*)bulletin->to_consume[a]->info.internal_p)->zone.angle/10.0,
|
((TollingPaymentInfo_t*)bulletin->to_consume[a]->info.internal_p)->zone.angle/10.0,
|
||||||
DCM_HAVERSINE
|
DCM_VINCENTY
|
||||||
)) {
|
)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
113
src/tpm.c
113
src/tpm.c
|
|
@ -1,6 +1,8 @@
|
||||||
#include "tpm.h"
|
#include "tpm.h"
|
||||||
#include "facilities.h"
|
#include "facilities.h"
|
||||||
|
|
||||||
|
#include <itss-security/SecurityRequest.h>
|
||||||
|
#include <itss-security/SecurityReply.h>
|
||||||
#include <it2s-tender/time.h>
|
#include <it2s-tender/time.h>
|
||||||
#include <itss-transport/TransportRequest.h>
|
#include <itss-transport/TransportRequest.h>
|
||||||
#include <it2s-tender/space.h>
|
#include <it2s-tender/space.h>
|
||||||
|
|
@ -16,6 +18,8 @@ int tpm_pay(void* fc, uint8_t* neighbour) {
|
||||||
tolling->tz = it2s_tender_get_clock(&facilities->epv) ;
|
tolling->tz = it2s_tender_get_clock(&facilities->epv) ;
|
||||||
|
|
||||||
TransportRequest_t* tr = NULL;
|
TransportRequest_t* tr = NULL;
|
||||||
|
SecurityRequest_t* sreq = NULL;
|
||||||
|
SecurityReply_t* srep = NULL;
|
||||||
TPM_t* tpm = NULL;
|
TPM_t* tpm = NULL;
|
||||||
|
|
||||||
const size_t buf_len = 2048;
|
const size_t buf_len = 2048;
|
||||||
|
|
@ -97,8 +101,53 @@ int tpm_pay(void* fc, uint8_t* neighbour) {
|
||||||
tpm->tpm.tollingFlow.choice.request.paymentMethod.choice.fiat.fiatId = FiatId_eur;
|
tpm->tpm.tollingFlow.choice.request.paymentMethod.choice.fiat.fiatId = FiatId_eur;
|
||||||
tpm->tpm.tollingFlow.choice.request.transactionNonce = tolling->nonce;
|
tpm->tpm.tollingFlow.choice.request.transactionNonce = tolling->nonce;
|
||||||
|
|
||||||
// encode TPM
|
// Encode TollingPaymentMessage
|
||||||
asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_TPM, NULL, tpm, buf, buf_len);
|
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_TollingPaymentMessage, NULL, &tpm->tpm, buf, buf_len);
|
||||||
|
if (enc.encoded == -1) {
|
||||||
|
syslog_err("[facilities] [tolling] error encoding TollingPaymentMessage (%s)", enc.failed_type->name);
|
||||||
|
rv = 1;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sign
|
||||||
|
sreq = calloc(1, sizeof(SecurityRequest_t));
|
||||||
|
sreq->present = SecurityRequest_PR_sign;
|
||||||
|
sreq->choice.sign.data.size = enc.encoded;
|
||||||
|
sreq->choice.sign.data.buf = malloc(enc.encoded);
|
||||||
|
memcpy(sreq->choice.sign.data.buf, buf, enc.encoded);
|
||||||
|
|
||||||
|
buf[0] = 4;
|
||||||
|
enc = oer_encode_to_buffer(&asn_DEF_SecurityRequest, NULL, sreq, buf+1, 2047);
|
||||||
|
syslog_debug("[facilities]->[security] SecurityRequest.sign (%ldB)", enc.encoded+1);
|
||||||
|
zmq_send(tolling->security_socket, buf, enc.encoded+1, 0);
|
||||||
|
int32_t rl = zmq_recv(tolling->security_socket, buf, buf_len, 0);
|
||||||
|
syslog_debug("[facilities]<-[security] SecurityReply.sign (%dB)", rl);
|
||||||
|
|
||||||
|
if (oer_decode(NULL, &asn_DEF_SecurityReply, (void**) &srep, buf, rl).code) {
|
||||||
|
syslog_err("[facilities] SecurityReply.sign decode failure");
|
||||||
|
rv = 1;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (srep->returnCode == SecurityReplyReturnCode_rejected) {
|
||||||
|
syslog_err("[facilities] SecurityReply.sign rejected");
|
||||||
|
rv = 1;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
tpm->signature.r.size = srep->data->choice.sign.r.size;
|
||||||
|
tpm->signature.r.buf = malloc(srep->data->choice.sign.r.size);
|
||||||
|
memcpy(tpm->signature.r.buf, srep->data->choice.sign.r.buf, srep->data->choice.sign.r.size);
|
||||||
|
tpm->signature.s.size = srep->data->choice.sign.s.size;
|
||||||
|
tpm->signature.s.buf = malloc(srep->data->choice.sign.s.size);
|
||||||
|
memcpy(tpm->signature.s.buf, srep->data->choice.sign.s.buf, srep->data->choice.sign.s.size);
|
||||||
|
tpm->signature.signer.size = srep->data->choice.sign.signer.size;
|
||||||
|
tpm->signature.signer.buf = malloc(srep->data->choice.sign.signer.size);
|
||||||
|
memcpy(tpm->signature.signer.buf, srep->data->choice.sign.signer.buf, srep->data->choice.sign.signer.size);
|
||||||
|
tpm->signature.type = srep->data->choice.sign.type;
|
||||||
|
|
||||||
|
// Encode TPM
|
||||||
|
enc = uper_encode_to_buffer(&asn_DEF_TPM, NULL, tpm, buf, buf_len);
|
||||||
if (enc.encoded == -1) {
|
if (enc.encoded == -1) {
|
||||||
syslog_err("[facilities] [tolling] error encoding TPM.request (%s)", enc.failed_type->name);
|
syslog_err("[facilities] [tolling] error encoding TPM.request (%s)", enc.failed_type->name);
|
||||||
rv = 1;
|
rv = 1;
|
||||||
|
|
@ -148,6 +197,8 @@ int tpm_pay(void* fc, uint8_t* neighbour) {
|
||||||
cleanup:
|
cleanup:
|
||||||
ASN_STRUCT_FREE(asn_DEF_TPM, tpm);
|
ASN_STRUCT_FREE(asn_DEF_TPM, tpm);
|
||||||
ASN_STRUCT_FREE(asn_DEF_TransportRequest, tr);
|
ASN_STRUCT_FREE(asn_DEF_TransportRequest, tr);
|
||||||
|
ASN_STRUCT_FREE(asn_DEF_SecurityRequest, sreq);
|
||||||
|
ASN_STRUCT_FREE(asn_DEF_SecurityReply, srep);
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
@ -166,6 +217,8 @@ static void rsu_handle_recv(facilities_t* facilities, TollRequest_t* req, uint8_
|
||||||
uint8_t buf[buf_len];
|
uint8_t buf[buf_len];
|
||||||
|
|
||||||
TransportRequest_t* tr = NULL;
|
TransportRequest_t* tr = NULL;
|
||||||
|
SecurityRequest_t* sreq = NULL;
|
||||||
|
SecurityReply_t* srep = NULL;
|
||||||
TPM_t* tpm = NULL;
|
TPM_t* tpm = NULL;
|
||||||
|
|
||||||
// TPM
|
// TPM
|
||||||
|
|
@ -203,8 +256,50 @@ static void rsu_handle_recv(facilities_t* facilities, TollRequest_t* req, uint8_
|
||||||
// TODO check clientId
|
// TODO check clientId
|
||||||
// TODO dlt: check transaction
|
// TODO dlt: check transaction
|
||||||
|
|
||||||
|
// Encode TollingPaymentMessage
|
||||||
|
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_TollingPaymentMessage, NULL, &tpm->tpm, buf, buf_len);
|
||||||
|
if (enc.encoded == -1) {
|
||||||
|
syslog_err("[facilities] [tolling] error encoding TollingPaymentMessage (%s)", enc.failed_type->name);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sign
|
||||||
|
sreq = calloc(1, sizeof(SecurityRequest_t));
|
||||||
|
sreq->present = SecurityRequest_PR_sign;
|
||||||
|
sreq->choice.sign.data.size = enc.encoded;
|
||||||
|
sreq->choice.sign.data.buf = malloc(enc.encoded);
|
||||||
|
memcpy(sreq->choice.sign.data.buf, buf, enc.encoded);
|
||||||
|
|
||||||
|
buf[0] = 4;
|
||||||
|
enc = oer_encode_to_buffer(&asn_DEF_SecurityRequest, NULL, sreq, buf+1, 2047);
|
||||||
|
syslog_debug("[facilities]->[security] SecurityRequest.sign (%ldB)", enc.encoded+1);
|
||||||
|
zmq_send(facilities->tolling.security_socket, buf, enc.encoded+1, 0);
|
||||||
|
int32_t rl = zmq_recv(facilities->tolling.security_socket, buf, buf_len, 0);
|
||||||
|
syslog_debug("[facilities]<-[security] SecurityReply.sign (%dB)", rl);
|
||||||
|
|
||||||
|
if (oer_decode(NULL, &asn_DEF_SecurityReply, (void**) &srep, buf, rl).code) {
|
||||||
|
syslog_err("[facilities] SecurityReply.sign decode failure");
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (srep->returnCode == SecurityReplyReturnCode_rejected) {
|
||||||
|
syslog_err("[facilities] SecurityReply.sign rejected");
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
tpm->signature.r.size = srep->data->choice.sign.r.size;
|
||||||
|
tpm->signature.r.buf = malloc(srep->data->choice.sign.r.size);
|
||||||
|
memcpy(tpm->signature.r.buf, srep->data->choice.sign.r.buf, srep->data->choice.sign.r.size);
|
||||||
|
tpm->signature.s.size = srep->data->choice.sign.s.size;
|
||||||
|
tpm->signature.s.buf = malloc(srep->data->choice.sign.s.size);
|
||||||
|
memcpy(tpm->signature.s.buf, srep->data->choice.sign.s.buf, srep->data->choice.sign.s.size);
|
||||||
|
tpm->signature.signer.size = srep->data->choice.sign.signer.size;
|
||||||
|
tpm->signature.signer.buf = malloc(srep->data->choice.sign.signer.size);
|
||||||
|
memcpy(tpm->signature.signer.buf, srep->data->choice.sign.signer.buf, srep->data->choice.sign.signer.size);
|
||||||
|
tpm->signature.type = srep->data->choice.sign.type;
|
||||||
|
|
||||||
// encode TPM
|
// encode TPM
|
||||||
asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_TPM, NULL, tpm, buf, buf_len);
|
enc = uper_encode_to_buffer(&asn_DEF_TPM, NULL, tpm, buf, buf_len);
|
||||||
if (enc.encoded == -1) {
|
if (enc.encoded == -1) {
|
||||||
syslog_err("[facilities] [tolling] error encoding TPM.reply (%s)", enc.failed_type->name);
|
syslog_err("[facilities] [tolling] error encoding TPM.reply (%s)", enc.failed_type->name);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
@ -254,6 +349,8 @@ static void rsu_handle_recv(facilities_t* facilities, TollRequest_t* req, uint8_
|
||||||
cleanup:
|
cleanup:
|
||||||
ASN_STRUCT_FREE(asn_DEF_TPM, tpm);
|
ASN_STRUCT_FREE(asn_DEF_TPM, tpm);
|
||||||
ASN_STRUCT_FREE(asn_DEF_TransportRequest, tr);
|
ASN_STRUCT_FREE(asn_DEF_TransportRequest, tr);
|
||||||
|
ASN_STRUCT_FREE(asn_DEF_SecurityRequest, sreq);
|
||||||
|
ASN_STRUCT_FREE(asn_DEF_SecurityReply, srep);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void veh_handle_recv(tolling_s* tolling, TollReply_t* rep, uint8_t* neighbour) {
|
static void veh_handle_recv(tolling_s* tolling, TollReply_t* rep, uint8_t* neighbour) {
|
||||||
|
|
@ -310,3 +407,13 @@ cleanup:
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int tolling_init(tolling_s* tolling, void* zmq_ctx, char* security_address) {
|
||||||
|
|
||||||
|
tolling->security_socket = zmq_socket(zmq_ctx, ZMQ_REQ);
|
||||||
|
int wait_ms = 1000;
|
||||||
|
zmq_setsockopt(tolling->security_socket, ZMQ_RCVTIMEO, &wait_ms, sizeof(int));
|
||||||
|
zmq_connect(tolling->security_socket, security_address);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,11 @@ typedef struct tolling {
|
||||||
uint8_t length;
|
uint8_t length;
|
||||||
} infos;
|
} infos;
|
||||||
|
|
||||||
|
// Security socket
|
||||||
|
void* security_socket;
|
||||||
|
|
||||||
} tolling_s;
|
} tolling_s;
|
||||||
|
|
||||||
|
int tolling_init(tolling_s* tolling, void* zmq_ctx, char* security_address);
|
||||||
int tpm_pay(void* fc, uint8_t* neighbour);
|
int tpm_pay(void* fc, uint8_t* neighbour);
|
||||||
int tpm_recv(void* fc, TPM_t* tpm_rx, uint8_t* neighbour);
|
int tpm_recv(void* fc, TPM_t* tpm_rx, uint8_t* neighbour);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue