|
|
|
@ -281,15 +281,18 @@ PEP_STATUS udp_sendto(PEP_SESSION session, message *msg, PEP_transport_status_co
|
|
|
|
|
stringlist_add(keylist, msg->from->fpr);
|
|
|
|
|
for (identity_list *loop_ident = msg->to; loop_ident && loop_ident->ident;
|
|
|
|
|
loop_ident = loop_ident->next) {
|
|
|
|
|
stringlist_add(keylist, loop_ident->ident->fpr);
|
|
|
|
|
if (loop_ident->ident->fpr)
|
|
|
|
|
stringlist_add(keylist, loop_ident->ident->fpr);
|
|
|
|
|
}
|
|
|
|
|
for (identity_list *loop_ident = msg->cc; loop_ident && loop_ident->ident;
|
|
|
|
|
loop_ident = loop_ident->next) {
|
|
|
|
|
stringlist_add(keylist, loop_ident->ident->fpr);
|
|
|
|
|
if (loop_ident->ident->fpr)
|
|
|
|
|
stringlist_add(keylist, loop_ident->ident->fpr);
|
|
|
|
|
}
|
|
|
|
|
for (identity_list *loop_ident = msg->bcc; loop_ident && loop_ident->ident;
|
|
|
|
|
loop_ident = loop_ident->next) {
|
|
|
|
|
stringlist_add(keylist, loop_ident->ident->fpr);
|
|
|
|
|
if (loop_ident->ident->fpr)
|
|
|
|
|
stringlist_add(keylist, loop_ident->ident->fpr);
|
|
|
|
|
}
|
|
|
|
|
pep_status = encrypt_and_sign(session, keylist, asn1text, asn1size, &ctext, &csize);
|
|
|
|
|
|
|
|
|
@ -304,62 +307,37 @@ PEP_STATUS udp_sendto(PEP_SESSION session, message *msg, PEP_transport_status_co
|
|
|
|
|
strncpy(uri_part, to_ident->ident->address, strlen(udp.uri_scheme));
|
|
|
|
|
|
|
|
|
|
if (strcmp(uri_part, udp.uri_scheme)) {
|
|
|
|
|
// URI scheme does not match
|
|
|
|
|
pep_status = PEP_ILLEGAL_VALUE;
|
|
|
|
|
*tsc = PEP_tsc_could_not_deliver_giving_up;
|
|
|
|
|
continue;
|
|
|
|
|
} else {
|
|
|
|
|
// correct URI scheme
|
|
|
|
|
*tsc = PEP_tsc_message_on_the_way;
|
|
|
|
|
pep_status = PEP_STATUS_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!strcmp(to_ident->ident->address, "udp://0.0.0.0")) {
|
|
|
|
|
// UDP unicast
|
|
|
|
|
to_addr = sin_s;
|
|
|
|
|
} else {
|
|
|
|
|
// broadcast
|
|
|
|
|
to_addr.sin_family = AF_INET;
|
|
|
|
|
to_addr.sin_port = htons(atoi(SERVERPORT)); // short, network byte order
|
|
|
|
|
to_addr.sin_addr.s_addr = inet_addr(&(to_ident->ident->address[strlen(udp.uri_scheme)]));
|
|
|
|
|
memset(to_addr.sin_zero, '\0', sizeof to_addr.sin_zero);
|
|
|
|
|
}
|
|
|
|
|
// write to socket
|
|
|
|
|
// ~~first we send longmsg~~
|
|
|
|
|
// send asn1text as an experiment
|
|
|
|
|
udp_status = sendto(socki_s, asn1text, asn1size, 0, (struct sockaddr *)&to_addr, size);
|
|
|
|
|
udp_status = sendto(socki_s, ctext, csize, 0, (struct sockaddr *)&to_addr, size);
|
|
|
|
|
|
|
|
|
|
fprintf(
|
|
|
|
|
stderr,
|
|
|
|
|
"pEpTransportUDP: Bytes sent for longmsg: %i of %lu\n",
|
|
|
|
|
udp_status,
|
|
|
|
|
strlen(msg->longmsg));
|
|
|
|
|
fprintf(stderr, "pEpTransportUDP: Bytes sent for asn.1.msg: %i of %lu\n", udp_status, csize);
|
|
|
|
|
if (udp_status == -1) {
|
|
|
|
|
perror("pEpTransportUDP: udp_sendto");
|
|
|
|
|
if (strlen(msg->longmsg) >= MAXBUFLEN)
|
|
|
|
|
if (csize >= MAXBUFLEN)
|
|
|
|
|
*tsc = PEP_tsc_udp_dgram_exceeds_mtu;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// in production, we will only send Sync attachments
|
|
|
|
|
// Or will we?
|
|
|
|
|
// Let's send everything for now and check later.
|
|
|
|
|
for (bloblist_t *a = msg->attachments; a && a->value; a = a->next) {
|
|
|
|
|
// if (a->mime_type && strcasecmp(a->mime_type, "application/pEp.sync") == 0) {
|
|
|
|
|
udp_status = sendto(socki_s, a->value, strlen(a->value), 0, (struct sockaddr *)&to_addr, size);
|
|
|
|
|
fprintf(
|
|
|
|
|
stderr,
|
|
|
|
|
"pEpTransportUDP: Bytes sent for attachment %s: %i of %lu\n",
|
|
|
|
|
a->filename,
|
|
|
|
|
udp_status,
|
|
|
|
|
strlen(a->value));
|
|
|
|
|
if (udp_status == -1) {
|
|
|
|
|
perror("pEpTransportUDP: udp_sendto");
|
|
|
|
|
if (strlen(a->value) >= MAXBUFLEN) {
|
|
|
|
|
*tsc = PEP_tsc_udp_dgram_exceeds_mtu;
|
|
|
|
|
} else {
|
|
|
|
|
*tsc = PEP_tsc_udp_unkown_error;
|
|
|
|
|
}
|
|
|
|
|
pep_status = PEP_TRANSPORT_ERROR;
|
|
|
|
|
}
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/////////////
|
|
|
|
|
return pep_status;
|
|
|
|
@ -383,7 +361,7 @@ PEP_STATUS udp_recvnext(PEP_SESSION session, message **msg, PEP_transport_status
|
|
|
|
|
// for future logs
|
|
|
|
|
char from_ip[INET_ADDRSTRLEN];
|
|
|
|
|
char from_address[strlen(udp.uri_scheme) + INET_ADDRSTRLEN];
|
|
|
|
|
// fprintf(stderr,"listener: waiting to recvfrom...\n"); //Not at all usefull with nonblocking socket
|
|
|
|
|
// fprintf(stderr,"pEpTransportUDP: waiting to recvfrom...\n"); //Not at all usefull with nonblocking socket
|
|
|
|
|
|
|
|
|
|
addr_len = sizeof their_addr;
|
|
|
|
|
if ((numbytes = recvfrom(socki_r, buf, MAXBUFLEN - 1, 0, (struct sockaddr *)&their_addr, &addr_len)) ==
|
|
|
|
@ -404,13 +382,23 @@ PEP_STATUS udp_recvnext(PEP_SESSION session, message **msg, PEP_transport_status
|
|
|
|
|
fprintf(stderr, "pEpTransportUDP: recvnext: got packet from %s\n", from_ip);
|
|
|
|
|
fprintf(stderr, "pEpTransportUDP: recvnext: packet is %d bytes long\n", numbytes);
|
|
|
|
|
buf[numbytes] = '\0';
|
|
|
|
|
//fprintf(stderr,"listener: packet contains \"%s\"\n", buf);
|
|
|
|
|
fprintf(
|
|
|
|
|
stderr,
|
|
|
|
|
"pEpTransportUDP: packet contains: \n------------------\n%s\n==================\n",
|
|
|
|
|
buf);
|
|
|
|
|
|
|
|
|
|
message *_msg = NULL;
|
|
|
|
|
ASN1Message_t *asn1msg;
|
|
|
|
|
char *asn1text;
|
|
|
|
|
size_t asn1size;
|
|
|
|
|
stringlist_t *keylist;
|
|
|
|
|
|
|
|
|
|
if (numbytes > 0) {
|
|
|
|
|
pep_status = decode_ASN1Message_message(buf, numbytes, &asn1msg);
|
|
|
|
|
// first decrypt
|
|
|
|
|
pep_status = decrypt_and_verify(session, buf, numbytes, NULL, 0, &asn1text, &asn1size, &keylist, NULL);
|
|
|
|
|
fprintf(stderr, "pEpTransportUDP: Decryption status %s\n", pEp_status_to_string(pep_status));
|
|
|
|
|
// then decode
|
|
|
|
|
pep_status = decode_ASN1Message_message(asn1text, asn1size, &asn1msg);
|
|
|
|
|
_msg = ASN1Message_to_message(asn1msg, NULL, 1, 0);
|
|
|
|
|
// _msg = new_message(PEP_dir_incoming);
|
|
|
|
|
char to_ip[INET_ADDRSTRLEN];
|
|
|
|
|