OPJ_BOOL process_JPIPrequest( server_record_t *rec, QR_t *qr) { target_param_t *target = NULL; session_param_t *cursession = NULL; channel_param_t *curchannel = NULL; if( qr->query->target || qr->query->tid){ if( !identify_target( *(qr->query), rec->targetlist, &target)) return OPJ_FALSE; } if( qr->query->cid){ if( !associate_channel( *(qr->query), rec->sessionlist, &cursession, &curchannel)) return OPJ_FALSE; qr->channel = curchannel; } if( qr->query->cnew != non){ if( !open_channel( *(qr->query), rec->sessionlist, rec->auxtrans, target, &cursession, &curchannel)) return OPJ_FALSE; qr->channel = curchannel; } if( qr->query->cclose) if( !close_channel( *(qr->query), rec->sessionlist, &cursession, &curchannel)) return OPJ_FALSE; if( (qr->query->fx > 0 && qr->query->fy > 0) || qr->query->box_type[0][0] != 0 || qr->query->len > 0) if( !gene_JPIPstream( *(qr->query), target, cursession, curchannel, &qr->msgqueue)) return OPJ_FALSE; return OPJ_TRUE; }
static void add_channel(char *cname) { Channel *c; int fd; char *name = striplower(cname); for(c = channels; c; c = c->next) if(!strcmp(name, c->name)) return; /* already handled */ fd = open_channel(name); if(fd == -1) { printf("ii: exiting, cannot create in channel: %s\n", name); exit(EXIT_FAILURE); } c = calloc(1, sizeof(Channel)); if(!c) { perror("ii: cannot allocate memory"); exit(EXIT_FAILURE); } if(!channels) channels = c; else { c->next = channels; channels = c; } c->fd = fd; c->name = strdup(name); }
static int np_open_channels(void){ /* * Returns: * 0 => no errors * -1 => system error from open_channel() * 1 => all channels were disabled */ int i; int status = 0; FD_ZERO(&grdset); gmaxfd = -1; for(i = 0; i < NPCAST_NUM_CHANNELS; ++i){ if(get_npcast_channel_enable(i) == 0) continue; status = open_channel(i); if(status != 0) break; if(gnpcast.channel[i].sfd > gmaxfd) gmaxfd = gnpcast.channel[i].sfd; } if((status == 0) && (gmaxfd == -1)) status = 1; return(status); }
int control_tracing(void) { packet_add_filter(PACKET_FILTER_SHOW_INDEX); if (server_fd >= 0) return 0; if (open_channel(HCI_CHANNEL_MONITOR) < 0) { if (!hcidump_fallback) return -1; if (hcidump_tracing() < 0) return -1; return 0; } open_channel(HCI_CHANNEL_CONTROL); return 0; }
int open_fifo(const char * pathname) { /* Recreate the FIFO in pathname */ unlink(pathname); if (mkfifo(pathname,0600) < 0) { perror("mkfifo()"); exit(1); } /* Open the channel */ return (open_channel(pathname)); }
/************************************************************************** * WsOpenServiceProxy [webservices.@] */ HRESULT WINAPI WsOpenServiceProxy( WS_SERVICE_PROXY *handle, const WS_ENDPOINT_ADDRESS *endpoint, const WS_ASYNC_CONTEXT *ctx, WS_ERROR *error ) { struct proxy *proxy = (struct proxy *)handle; TRACE( "%p %p %p %p\n", handle, endpoint, ctx, error ); if (error) FIXME( "ignoring error parameter\n" ); if (ctx) FIXME( "ignoring ctx parameter\n" ); return open_channel( proxy->channel, endpoint ); }
static gboolean get_descriptions (MuScriptInfo *msi, const char *prefix) { GIOStatus io_status; GIOChannel *script_io; GError *err; char *line, *descr, *oneline; if (!prefix) return TRUE; /* not an error */ if (!(script_io = open_channel (msi->_path))) return FALSE; err = NULL; line = descr = oneline = NULL; do { g_free (line); io_status = g_io_channel_read_line (script_io, &line, NULL, NULL, &err); if (io_status != G_IO_STATUS_NORMAL) break; if (!g_str_has_prefix (line, prefix)) continue; if (!oneline) oneline = g_strdup (line + strlen (prefix)); else { char *tmp; tmp = descr; descr = g_strdup_printf ("%s%s", descr ? descr : "", line + strlen(prefix)); g_free (tmp); } } while (TRUE); if (io_status != G_IO_STATUS_EOF) { g_warning ("error reading %s: %s", msi->_path, err ? err->message : "something went wrong"); g_clear_error (&err); } end_channel (script_io); msi->_oneline = oneline; msi->_descr = descr; return TRUE; }
static void handle_channels_input(Channel *c) { static char buf[PIPE_BUF]; if(read_line(c->fd, PIPE_BUF, buf, 0) == -1) { close(c->fd); int fd = open_channel(c->name); if(fd != -1) c->fd = fd; else rm_channel(c); return; } proc_channels_input(c, buf); }
static void server_callback(int fd, uint32_t events, void *user_data) { union { struct sockaddr common; struct sockaddr_un sun; struct sockaddr_in sin; } addr; socklen_t len; int host_fd, dev_fd; if (events & (EPOLLERR | EPOLLHUP)) { mainloop_quit(); return; } memset(&addr, 0, sizeof(addr)); len = sizeof(addr); if (getsockname(fd, &addr.common, &len) < 0) { perror("Failed to get socket name"); return; } host_fd = accept(fd, &addr.common, &len); if (host_fd < 0) { perror("Failed to accept client socket"); return; } if (client_active) { fprintf(stderr, "Active client already present\n"); close(host_fd); return; } dev_fd = open_channel(hci_index); if (dev_fd < 0) { close(host_fd); return; } printf("New client connected\n"); if (!setup_proxy(host_fd, true, dev_fd, false)) { close(dev_fd); close(host_fd); return; } client_active = true; }
/************************************************************************** * WsOpenChannel [webservices.@] */ HRESULT WINAPI WsOpenChannel( WS_CHANNEL *handle, const WS_ENDPOINT_ADDRESS *endpoint, const WS_ASYNC_CONTEXT *ctx, WS_ERROR *error ) { struct channel *channel = (struct channel *)handle; TRACE( "%p %p %p %p\n", handle, endpoint, ctx, error ); if (error) FIXME( "ignoring error parameter\n" ); if (ctx) FIXME( "ignoring ctx parameter\n" ); if (!endpoint) return E_INVALIDARG; if (channel->state != WS_CHANNEL_STATE_CREATED) return WS_E_INVALID_OPERATION; return open_channel( channel, endpoint ); }
void ant_config(void) { uint8_t data[6]; if (_config.master == TRUE) { assign_channel_id(0x30); // Channel type (0x30 == shared transmit channel } else { assign_channel_id(0x20); // Channel type (0x20 == shared receive channel } ant_handle_msg(); set_channel_id(); ant_handle_msg(); set_channel_period(_config.period); ant_handle_msg(); set_frequency(_config.frequency); ant_handle_msg(); open_channel(); ant_handle_msg(); // If we're not a master, tell the ANT radio what our address is if (_config.master == FALSE) { data[0] = 1; data[1] = 1; data[2] = 1; data[3] = 1; data[4] = 1; data[5] = 1; ant_send_broadcast_data(_config.address, data); } }
int main(int argc, char *argv[]) { struct socket *sock; struct sockaddr_in addr; socklen_t addr_len; char line[LINE_LENGTH + 1]; unsigned int unordered, policy, value, id, seconds; unsigned int i; struct channel *channel; const int on = 1; struct sctp_assoc_value av; struct sctp_event event; struct sctp_udpencaps encaps; struct sctp_initmsg initmsg; uint16_t event_types[] = {SCTP_ASSOC_CHANGE, SCTP_PEER_ADDR_CHANGE, SCTP_REMOTE_ERROR, SCTP_SHUTDOWN_EVENT, SCTP_ADAPTATION_INDICATION, SCTP_SEND_FAILED_EVENT, SCTP_STREAM_RESET_EVENT, SCTP_STREAM_CHANGE_EVENT}; if (argc > 1) { usrsctp_init(atoi(argv[1]), NULL, debug_printf); } else { usrsctp_init(9899, NULL, debug_printf); } #ifdef SCTP_DEBUG usrsctp_sysctl_set_sctp_debug_on(SCTP_DEBUG_NONE); #endif usrsctp_sysctl_set_sctp_blackhole(2); if ((sock = usrsctp_socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP, receive_cb, NULL, 0, &peer_connection)) == NULL) { perror("socket"); } init_peer_connection(&peer_connection); if (argc > 2) { memset(&encaps, 0, sizeof(struct sctp_udpencaps)); encaps.sue_address.ss_family = AF_INET6; encaps.sue_port = htons(atoi(argv[2])); if (usrsctp_setsockopt(sock, IPPROTO_SCTP, SCTP_REMOTE_UDP_ENCAPS_PORT, (const void*)&encaps, (socklen_t)sizeof(struct sctp_udpencaps)) < 0) { perror("setsockopt"); } } if (usrsctp_setsockopt(sock, IPPROTO_SCTP, SCTP_RECVRCVINFO, &on, sizeof(int)) < 0) { perror("setsockopt SCTP_RECVRCVINFO"); } if (usrsctp_setsockopt(sock, IPPROTO_SCTP, SCTP_EXPLICIT_EOR, &on, sizeof(int)) < 0) { perror("setsockopt SCTP_EXPLICIT_EOR"); } /* Allow resetting streams. */ av.assoc_id = SCTP_ALL_ASSOC; av.assoc_value = SCTP_ENABLE_RESET_STREAM_REQ | SCTP_ENABLE_CHANGE_ASSOC_REQ; if (usrsctp_setsockopt(sock, IPPROTO_SCTP, SCTP_ENABLE_STREAM_RESET, &av, sizeof(struct sctp_assoc_value)) < 0) { perror("setsockopt SCTP_ENABLE_STREAM_RESET"); } /* Enable the events of interest. */ memset(&event, 0, sizeof(event)); event.se_assoc_id = SCTP_ALL_ASSOC; event.se_on = 1; for (i = 0; i < sizeof(event_types)/sizeof(uint16_t); i++) { event.se_type = event_types[i]; if (usrsctp_setsockopt(sock, IPPROTO_SCTP, SCTP_EVENT, &event, sizeof(event)) < 0) { perror("setsockopt SCTP_EVENT"); } } memset(&initmsg, 0, sizeof(struct sctp_initmsg)); initmsg.sinit_num_ostreams = 5; initmsg.sinit_max_instreams = 65535; if (usrsctp_setsockopt(sock, IPPROTO_SCTP, SCTP_INITMSG, &initmsg, sizeof(struct sctp_initmsg)) < 0) { perror("setsockopt SCTP_INITMSG"); } if (argc == 5) { /* operating as client */ memset(&addr, 0, sizeof(struct sockaddr_in)); addr.sin_family = AF_INET; #ifdef HAVE_SIN_LEN addr.sin_len = sizeof(struct sockaddr_in); #endif addr.sin_addr.s_addr = inet_addr(argv[3]); addr.sin_port = htons(atoi(argv[4])); if (usrsctp_connect(sock, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)) < 0) { perror("connect"); } printf("Connected to %s:%d.\n", inet_ntoa(addr.sin_addr), ntohs(addr.sin_port)); } else if (argc == 4) { struct socket *conn_sock; /* operating as server */ memset(&addr, 0, sizeof(struct sockaddr_in)); addr.sin_family = AF_INET; #ifdef HAVE_SIN_LEN addr.sin_len = sizeof(struct sockaddr_in); #endif addr.sin_addr.s_addr = INADDR_ANY; addr.sin_port = htons(atoi(argv[3])); if (usrsctp_bind(sock, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)) < 0) { perror("bind"); } if (usrsctp_listen(sock, 1) < 0) { perror("listen"); } addr_len = (socklen_t)sizeof(struct sockaddr_in); memset(&addr, 0, sizeof(struct sockaddr_in)); if ((conn_sock = usrsctp_accept(sock, (struct sockaddr *)&addr, &addr_len)) == NULL) { perror("accept"); } usrsctp_close(sock); sock = conn_sock; printf("Connected to %s:%d.\n", inet_ntoa(addr.sin_addr), ntohs(addr.sin_port)); } else { printf("Usage: %s local_udp_port remote_udp_port local_port when operating as server\n" " %s local_udp_port remote_udp_port remote_addr remote_port when operating as client\n", argv[0], argv[0]); return (0); } lock_peer_connection(&peer_connection); peer_connection.sock = sock; unlock_peer_connection(&peer_connection); for (;;) { #ifdef _WIN32 if (gets_s(line, LINE_LENGTH) == NULL) { #else if (fgets(line, LINE_LENGTH, stdin) == NULL) { #endif if (usrsctp_shutdown(sock, SHUT_WR) < 0) { perror("usrsctp_shutdown"); } while (usrsctp_finish() != 0) { #ifdef _WIN32 Sleep(1000); #else sleep(1); #endif } break; } if (strncmp(line, "?", strlen("?")) == 0 || strncmp(line, "help", strlen("help")) == 0) { printf("Commands:\n" "open unordered pr_policy pr_value - opens a channel\n" "close channel - closes the channel\n" "send channel:string - sends string using channel\n" "status - prints the status\n" "sleep n - sleep for n seconds\n" "help - this message\n"); } else if (strncmp(line, "status", strlen("status")) == 0) { lock_peer_connection(&peer_connection); print_status(&peer_connection); unlock_peer_connection(&peer_connection); } else if (strncmp(line, "quit", strlen("quit")) == 0) { if (usrsctp_shutdown(sock, SHUT_WR) < 0) { perror("usrsctp_shutdown"); } while (usrsctp_finish() != 0) { #ifdef _WIN32 Sleep(1000); #else sleep(1); #endif } break; } else if (sscanf(line, "open %u %u %u", &unordered, &policy, &value) == 3) { lock_peer_connection(&peer_connection); channel = open_channel(&peer_connection, (uint8_t)unordered, (uint16_t)policy, (uint32_t)value); unlock_peer_connection(&peer_connection); if (channel == NULL) { printf("Creating channel failed.\n"); } else { printf("Channel with id %u created.\n", channel->id); } } else if (sscanf(line, "close %u", &id) == 1) { if (id < NUMBER_OF_CHANNELS) { lock_peer_connection(&peer_connection); close_channel(&peer_connection, &peer_connection.channels[id]); unlock_peer_connection(&peer_connection); } } else if (sscanf(line, "send %u", &id) == 1) { if (id < NUMBER_OF_CHANNELS) { char *msg; msg = strstr(line, ":"); if (msg) { msg++; lock_peer_connection(&peer_connection); #ifdef _WIN32 if (send_user_message(&peer_connection, &peer_connection.channels[id], msg, strlen(msg))) { #else if (send_user_message(&peer_connection, &peer_connection.channels[id], msg, strlen(msg) - 1)) { #endif printf("Message sent.\n"); } else { printf("Message sending failed.\n"); } unlock_peer_connection(&peer_connection); } } } else if (sscanf(line, "sleep %u", &seconds) == 1) { #ifdef _WIN32 Sleep(seconds * 1000); #else sleep(seconds); #endif } else { printf("Unknown command: %s", line); } } return (0); }
/* during init, we setup two channels for both xmit and recv: * (a) a public address announcement channel. There are two variants * of this: * (1) system processes - e.g., daemons, tools. This channel * is reserved solely for their use in performing admin * functions * (2) application processes. This channel is used to announce * their existence and contact info for auto-wireup * (b) our own group's channel, which is where our own output * will be sent. At this time, we assume that we always * want to hear our peers, so this channels is also * bidirectional * * In addition, the HNP opens a third channel which is used solely * for cmd-control purposes. This is where a tool, for example, might * send a cmd to the HNP to take some action - there is no point in * having that cmd echo around to every daemon and/or other tool * in the system. */ static int init(void) { int rc; if (init_completed) { return ORTE_SUCCESS; } OPAL_OUTPUT_VERBOSE((2, orte_rmcast_base.rmcast_output, "%s rmcast:udp: init called", ORTE_NAME_PRINT(ORTE_PROC_MY_NAME))); /* setup local ctl */ OBJ_CONSTRUCT(&ctl, orte_thread_ctl_t); /* flag that we are unreliable and need help */ orte_rmcast_base.unreliable_xport = true; if (ORTE_PROC_IS_HNP || ORTE_PROC_IS_DAEMON || ORTE_PROC_IS_SCHEDULER) { /* open the system channel - it will be our input/output channel as well */ if (ORTE_SUCCESS != (rc = open_channel(ORTE_RMCAST_SYS_CHANNEL, "SYSTEM", NULL, -1, NULL, ORTE_RMCAST_BIDIR))) { ORTE_ERROR_LOG(rc); return rc; } orte_rmcast_base.my_input_channel = (rmcast_base_channel_t*)opal_list_get_last(&orte_rmcast_base.channels); orte_rmcast_base.my_output_channel = orte_rmcast_base.my_input_channel; /* open the heartbeat channel */ if (ORTE_SUCCESS != (rc = open_channel(ORTE_RMCAST_HEARTBEAT_CHANNEL, "heartbeat", NULL, -1, NULL, ORTE_RMCAST_BIDIR))) { ORTE_ERROR_LOG(rc); return rc; } } else if (ORTE_PROC_IS_APP) { /* setup our grp xmit/recv channels, if given */ if (NULL != orte_rmcast_base.my_group_name) { if (ORTE_SUCCESS != (rc = open_channel(orte_rmcast_base.my_group_number, "recv", NULL, -1, NULL, ORTE_RMCAST_BIDIR))) { ORTE_ERROR_LOG(rc); return rc; } orte_rmcast_base.my_input_channel = (rmcast_base_channel_t*)opal_list_get_last(&orte_rmcast_base.channels); if (ORTE_SUCCESS != (rc = open_channel(orte_rmcast_base.my_group_number+1, "xmit", NULL, -1, NULL, ORTE_RMCAST_BIDIR))) { ORTE_ERROR_LOG(rc); return rc; } orte_rmcast_base.my_output_channel = (rmcast_base_channel_t*)opal_list_get_last(&orte_rmcast_base.channels); } } /* setup the recv for missed message replacement */ if (ORTE_SUCCESS != (rc = orte_rml.recv_buffer_nb(ORTE_NAME_WILDCARD, ORTE_RML_TAG_MISSED_MSG, ORTE_RML_PERSISTENT, resend_data, NULL))) { ORTE_ERROR_LOG(rc); return rc; } if (ORTE_SUCCESS != (rc = orte_rml.recv_buffer_nb(ORTE_NAME_WILDCARD, ORTE_RML_TAG_MULTICAST, ORTE_RML_PERSISTENT, missed_msg, NULL))) { ORTE_ERROR_LOG(rc); return rc; } /* start the recv threads */ if (ORTE_SUCCESS != (rc = orte_rmcast_base_start_threads())) { ORTE_ERROR_LOG(rc); return rc; } init_completed = true; comm_enabled = true; return ORTE_SUCCESS; }
int main(int argc, char ** argv) { int ec_fifo, ce_fifo, es_fifo, se_fifo; FILE* fp; ssize_t msg_size; uint8_t *buff; char client_nm[NM_LENGTH], client_nm_tmp[NM_LENGTH]; uint8_t rsa_tmp[RSA_LENGTH], rsa_tmp2[RSA_LENGTH]; BIGNUM /**bn_n, *bn_d,*/ *bn_client_e, *bn_client_n, *bn_r; char client_cipher_suite; uint8_t sym_id, hash_id, public_id; uint8_t k[K_SIZE] = {0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1}; int i, done; int k_len, c_hex_len, c_len; uint8_t g[HASH_LENGTH], g1[HASH_LENGTH]; uint8_t c[MSG_SIZE_MAX]; unsigned int tmp; assert(K_SIZE == 8); bn_client_e = BN_new(); bn_client_n = BN_new(); bn_r = BN_new(); /* Mandatory arguments */ if (!argv[1] || !argv[2] || !argv[3] || !argv[4] || !argv[1] || !argv[2] || !argv[3] || !argv[4]) { fprintf(stderr, "%s [server->eve fifo] [eve->server fifo] [eve->client fifo] [client->eve fifo]\n", argv[0]); exit(1); } se_fifo = open_channel(argv[1]); es_fifo = open_channel(argv[2]); ec_fifo = open_fifo(argv[3]); ce_fifo = open_fifo(argv[4]); /* wait real client to connect */ fprintf(stderr,"(E) Waiting connection...\n"); if (wait_connection(ce_fifo) < 0) { fprintf(stderr,"(E) Communication error...\n"); goto next; } /* connect to server */ write_msg(es_fifo, (const u_int8_t *)CONNECTION_STRING, strlen(CONNECTION_STRING)); forward_string(se_fifo, ec_fifo, OK_STRING); /* Server authentication */ /* client challange */ forward_msg(ce_fifo, es_fifo); /* server response to challange */ forward_msg(se_fifo, ec_fifo); /* Client authentication */ /* Client name */ msg_size = forward_msg_read(ce_fifo, es_fifo, &buff); /* vvvv copy-paste from server vvvv */ buff[msg_size] = '\0'; strncpy((char *)client_nm, (const char *) buff, NM_LENGTH); /* EXTRACT from (names[],c_puk[],n[]) the pair (c_puk[i],n[i]) where names[i] = nm */ if ((fp = fopen("server_folder/clients_rsa64_public_keys.txt", "r")) == NULL) { fprintf(stderr, "Error while getting clients RSA public keys...\n"); goto next; } done = 0; while (!feof(fp)) { fscanf(fp, "%129s %129s %129s", client_nm_tmp, rsa_tmp, rsa_tmp2); if (strcmp(client_nm_tmp, client_nm) == 0) { done = 1; break; } } if (done == 0) { fprintf(stderr, "Error: unrecognized client\n"); goto next; } fclose(fp); BN_hex2bn(&bn_client_n, (const char *) rsa_tmp); BN_hex2bn(&bn_client_e, (const char *) rsa_tmp2); /* ^^^^ copy-paste from server ^^^^ */ /* now I know client name and pub key */ /* server challange */ forward_msg(se_fifo, ec_fifo); /* client response */ forward_msg(ce_fifo, es_fifo); /* Negotiation of the cipher suite */ /* cipher suite c -> s */ forward_msg_read(ce_fifo, es_fifo, &buff); /* vvvv copy-paste from server vvvv */ client_cipher_suite = buff[0]; cipher_suite_table(client_cipher_suite, &sym_id, &hash_id, &public_id); /* ^^^^ copy-paste from server ^^^^ */ /* Negotiation of the private key */ /* k already set as an arbitrary key */ /* vvvv copy-paste from server vvvv */ if (sym_id == 1) { k_len = 3; } else { k_len = K_SIZE; } BN_bin2bn(k, k_len, bn_r); /* If we're using RSA512 read the correct key (we have the 64bit one) */ if (public_id == 6) { if ((fp = fopen("server_folder/clients_rsa512_public_keys.txt", "r")) == NULL) { fprintf(stderr, "Error while getting clients RSA public keys...\n"); goto next; } done = 0; while (!feof(fp)) { fscanf(fp, "%129s %129s %129s", client_nm_tmp, rsa_tmp, rsa_tmp2); if (strcmp(client_nm_tmp, client_nm) == 0) { done = 1; break; } } if (done == 0) { fprintf(stderr, "Error: unrecognized client\n"); goto next; } fclose(fp); BN_hex2bn(&bn_client_n, (const char *) rsa_tmp); BN_hex2bn(&bn_client_e, (const char *) rsa_tmp2); } /* ENCRYPT key */ rsa_encrypt(bn_r, bn_client_e, bn_client_n); /* WRITE encrypted k to C */ buff = (uint8_t *) BN_bn2hex(bn_r); if ((write_msg(ec_fifo, buff, strlen((char *) buff))) < 0) { fprintf(stderr, "Error while sending C to the client...\n"); goto next; } OPENSSL_free(buff); /* Encrypted communication */ if ((msg_size = read_msg(ce_fifo,&buff)) < 0) { fprintf(stderr, "Error while reading message from the client...\n"); goto next; } c_hex_len = msg_size - HASH_LENGTH * 2; if (c_hex_len <= 0) { fprintf(stderr, "Error, malformed message...\n"); goto next; } c_len = c_hex_len / 2; for (i=0; i<msg_size; i+=2) { if (i < c_hex_len) { sscanf((char *) (buff+i), "%02x", &tmp); c[i/2] = (uint8_t) tmp; } else { sscanf((char *) (buff+i), "%02x", &tmp); g[(i - c_hex_len) / 2] = (uint8_t) tmp; } } /* Decrypt C */ decrypt(sym_id, c, c_len, k); /* COMPUTE G' = H(M) */ sponge_hash(c, c_len, g1); c[c_len] = '\0'; /* CHECK G' = G */ done = 1; for (i=0; i<HASH_LENGTH; i++) { if (g[i] != g1[i]) { done = 0; } } /* If the check fails print error message */ if (done == 0) { if ((write_msg(ec_fifo, (uint8_t *) CORRUPTED_STRING, strlen(CORRUPTED_STRING))) < 0) { fprintf(stderr, "Error while writing to the client...\n"); goto next; } } /* PUT M' on a file */ if ((fp = fopen("eve_folder/received_messages.txt", "a+")) == NULL) { fprintf(stderr, "Error while saving message...\n"); fclose(fp); goto next; } fprintf(fp, "%s", c); fflush(stdout); fprintf(stdout, "MESSAGGIO SEGRETO >>>%s<<< FINE MESSAGGIO SEGRETO\n", c); fflush(stdout); fclose(fp); /* WRITE ok message to C */ if ((write_msg(ec_fifo, (uint8_t *) DECRYPTED_STRING, strlen(DECRYPTED_STRING))) < 0) { fprintf(stderr, "Error while writing C to the client...\n"); goto next; } /* ^^^^ copy-paste from server ^^^^ */ next: /*close_channels ...!*/ BN_free(bn_client_n); BN_free(bn_client_e); BN_free(bn_r); exit(0); }
int main(int argc, char *argv[]) { int c; int errs; int ncpus; int nthreads; cpu_set_t cpus; extern int opterr; extern int optind; extern char *optarg; unsigned long long pci_mem_addr = 0; if ((program = strrchr(argv[0], '/')) != NULL) ++program; else program = argv[0]; set_program_name(program); /* * default to checking all cpus */ for (c = 0; c < CPU_SETSIZE; c++) { CPU_SET(c, &cpus); } opterr = 0; errs = 0; while ((c = getopt_long(argc, argv, optstring, options, NULL)) != EOF) { switch (c) { case 'a': ascii = 1; break; case 't': transmitter = 1; break; case 'c': if (parse_cpu_set(optarg, &cpus) != 0) ++errs; break; case 'm': pci_mem_addr = strtoul(optarg, NULL, 16); break; default: ERROR(0, "unknown option '%c'", c); ++errs; break; } } open_channel(pci_mem_addr); if (errs) { usage(); exit(1); } /* * limit the set of CPUs to the ones that are currently available * (Note that on some kernel versions sched_setaffinity() will fail * if you specify CPUs that are not currently online so we ignore * the return value and hope for the best) */ sched_setaffinity(0, sizeof cpus, &cpus); if (sched_getaffinity(0, sizeof cpus, &cpus) < 0) { ERROR(errno, "sched_getaffinity() failed"); exit(1); } /* * create the threads */ ncpus = count_cpus(&cpus); nthreads = create_per_cpu_threads(&cpus, worker_thread, NULL); if (nthreads != ncpus) { ERROR(0, "failed to create threads: expected %d, got %d", ncpus, nthreads); if (nthreads) { join_threads(); } return 1; } join_threads(); }
int main(int argc, char ** argv) { int sc_fifo_fd, cs_fifo_fd; /* Mandatory arguments */ if( !argv[1] || !argv[2] || !argv[3] || !argv[4] ) { fprintf(stderr,"client [server->client fifo] [client->server fifo] [password file] [username]\n"); exit(1); } /* Create connection with the server */ fprintf(stderr,"Create connection...\n"); sc_fifo_fd = open_channel(argv[1]); cs_fifo_fd = open_channel(argv[2]); write_msg(cs_fifo_fd,(const u_int8_t *)CONNECTION_STRING,strlen(CONNECTION_STRING)); /* Read OK */ if( read_string(sc_fifo_fd,OK_STRING) < 0 ) { fprintf(stderr,"Communication error\n"); goto next1; } /* Server authentication */ write_msg(cs_fifo_fd,(const u_int8_t *)"A",1); // GET public rsa key of S, (s_puk,n), from "client_folder/server_rsa_public_key.txt" /* ... */ // CREATE a random number r /* ... */ // ENCRYPT r using (s_puk,n) -> c = r^s_puk mod n /* ... */ // WRITE c to S /* ... */ // READ r' from C /* ... */ // CHECK if r = r' /* ... */ /* Client authentication */ // SEND client_name to S /* ... */ // GET private rsa key of C, (s_prk,n) from "client_folder/client_rsa_private_key.txt" /* ... */ // READ c from S /* ... */ // DECRYPT c using (c_prk,n) -> r' = c^c_prk mod n /* ... */ // WRITE r' to S /* ... */ // GET private rsa key of C, c_prk from "client_folder/client_rsa_private_key.txt" /* ... */ /* Negotiation of the cipher suite */ /* ... */ /* Negotiation of the private key */ /* ... */ /* Encrypt communication */ /* ... */ /* Disconnection */ /* ... */ next1: // to be used when server writes the BYE string /* Close connection with the server */ fprintf(stderr,"Closing connection...\n"); /* Expect BYE */ if( read_string(sc_fifo_fd,CLOSE_CONNECTION_STRING) < 0 ) { fprintf(stderr,"Communication error\n"); goto next1; } close_channel(cs_fifo_fd); close_channel(sc_fifo_fd); exit(0) ; next2: // to be used when client writes the BYE string /* Close current connection */ fprintf(stderr,"Closing connection...\n"); write_BYE(cs_fifo_fd); close_channel(cs_fifo_fd); close_channel(sc_fifo_fd); exit(0); }