wtls_state-decl.h
字号:
NULL_STATE)/* Exception Request */ROW(CREATED, SEC_Exception_Req, 1, { /* Send off a T_Unitdata_Req containing an exception as specified */ send_alert(event->u.SEC_Exception_Req.alert_level, event->u.SEC_Exception_Req.alert_desc, wtls_machine); }, CREATED)/* Exchange State *//* Unitdata arrival - identical ClientHello record */ROW(EXCHANGE, T_Unitdata_Ind, clienthellos_are_identical(event->u.T_Unitdata_Ind.pdu_list, wtls_machine->last_received_packet) == 1, { /* It appears as though someone has sent us an identical ClientHello to the last one */ /* Make ourselves a T_Unitdata_Req with the last_transmitted_packet */ /* And send it on it's merry */ }, EXCHANGE)/* Unitdata arrival - non-identical ClientHello record *///ROW(EXCHANGE,// T_Unitdata_Ind,// clienthellos_are_identical(event->u.T_Unitdata_Ind.pdu_list, wtls_machine->last_received_packet) != 1,// {/* So, this one's different. They must have changed their mind about something, so try a CREATING again *//* Do the necessary SEC_Create_Ind stuff */// },// CREATING)/* Unitdata arrival - good packet */ROW(EXCHANGE, T_Unitdata_Ind, 1, { RSAPublicKey *public_key = NULL; Octstr* key_block; Octstr* final_client_write_enc_key = NULL; Octstr* final_server_write_enc_key = NULL; Octstr* final_client_write_IV = NULL; Octstr* final_server_write_IV = NULL; Octstr* emptySecret = NULL; Octstr* checking_data = NULL; // packet_contains_changecipherspec (event->u.T_Unitdata_Ind.pdu_list) == 1 && // packet_contains_finished (event->u.T_Unitdata_Ind.pdu_list) == 1 && // packet_contains_optional_stuff (event->u.T_Unitdata_Ind.pdu_list) == 1, /* The Wap PDUs we have to dispatch */ wtls_PDU* changeCipherSpecPDU; wtls_PDU* finishedPDU; /* The PDUs we have to process */ wtls_Payload* tempPayload; wtls_PDU* clientKeyXchgPDU; wtls_PDU* changeCipherSpec_incoming_PDU; wtls_PDU* finished_incoming_PDU; /* For decrypting/encrypting data */ Octstr* concatenatedRandoms=0; Octstr* encryptedData=0; Octstr* decryptedData=0; Octstr* labelVerify=0; Octstr* labelMaster=0; /* Process the incoming event : ClientKeyExchange*/ tempPayload = (wtls_Payload*) list_search (event->u.T_Unitdata_Ind.pdu_list, (void*) client_key_exchange, match_handshake_type); /* Keep the data so we can send it back */ octstr_insert(wtls_machine->handshake_data, tempPayload->data, octstr_len(wtls_machine->handshake_data)); clientKeyXchgPDU = wtls_pdu_unpack(tempPayload,wtls_machine); wtls_pdu_dump(clientKeyXchgPDU,0); /* Decrypt the client key exchange PDU */ encryptedData = clientKeyXchgPDU->u.handshake.client_key_exchange->rsa_params->encrypted_secret; decryptedData = wtls_decrypt_rsa(encryptedData); public_key = wtls_get_rsapublickey(); pack_int16(decryptedData, octstr_len(decryptedData), octstr_len(public_key->rsa_exponent)); octstr_insert(decryptedData, public_key->rsa_exponent, octstr_len(decryptedData)); pack_int16(decryptedData, octstr_len(decryptedData), octstr_len(public_key->rsa_modulus)); octstr_insert(decryptedData, public_key->rsa_modulus, octstr_len(decryptedData)); /* Concatenate our random data */ concatenatedRandoms = octstr_cat(wtls_machine->client_random, wtls_machine->server_random); /* Generate our master secret */ labelMaster = octstr_create("master secret"); wtls_machine->master_secret = wtls_calculate_prf(decryptedData, labelMaster, concatenatedRandoms,20, wtls_machine ); octstr_destroy(labelMaster); labelMaster = NULL; /* calculate the key blocks */ calculate_server_key_block(wtls_machine); calculate_client_key_block(wtls_machine); /* Process the incoming event : ChangeCipherSpec*/ tempPayload = (wtls_Payload*) list_search (event->u.T_Unitdata_Ind.pdu_list, (void*) ChangeCipher_PDU, match_pdu_type); changeCipherSpec_incoming_PDU = wtls_pdu_unpack(tempPayload, wtls_machine); if(changeCipherSpec_incoming_PDU->u.cc.change == 1) { debug("wtls", 0,"Need to decrypt the PDUs from now on..."); wtls_machine->encrypted = 1; wtls_decrypt_pdu_list(wtls_machine, event->u.T_Unitdata_Ind.pdu_list); } octstr_dump(wtls_machine->client_write_MAC_secret,0); wtls_pdu_dump(changeCipherSpec_incoming_PDU,0); /* Process the incoming event : Finished*/ tempPayload = (wtls_Payload*) list_search (event->u.T_Unitdata_Ind.pdu_list, (void*) finished, match_handshake_type); if(tempPayload == NULL) debug("wtls", 0, "null finished !!!"); finished_incoming_PDU = wtls_pdu_unpack(tempPayload,wtls_machine); debug("wtls", 0, "Client Finished PDU:"); wtls_pdu_dump(finished_incoming_PDU,0); /* Check the verify_data */ labelVerify = octstr_create("client finished"); checking_data = wtls_calculate_prf(wtls_machine->master_secret, labelVerify, (Octstr *)wtls_hash(wtls_machine->handshake_data, wtls_machine), 12, wtls_machine); octstr_destroy(labelVerify); labelVerify = NULL; if(octstr_compare(finished_incoming_PDU->u.handshake.finished->verify_data, checking_data)==0) { debug("wtls", 0, "DATA VERIFICATION OK"); } /* Keep the data so we can send it back in the next message */ /*octstr_insert(wtls_machine->handshake_data, tempPayload->data, octstr_len(wtls_machine->handshake_data)); */ // temporary fix octstr_truncate(tempPayload->data, 15); octstr_insert(wtls_machine->handshake_data, tempPayload->data, octstr_len(wtls_machine->handshake_data)); /* Create a new PDU List containing a ChangeCipherSpec and a Finished */ changeCipherSpecPDU = wtls_pdu_create(ChangeCipher_PDU); changeCipherSpecPDU->u.cc.change = 1; /* Generate our verify data */ finishedPDU = wtls_pdu_create(Handshake_PDU); finishedPDU->u.handshake.msg_type = finished; finishedPDU->cipher = 1; finishedPDU->u.handshake.finished = gw_malloc(sizeof(Finished)); labelVerify = octstr_create("server finished"); finishedPDU->u.handshake.finished->verify_data = wtls_calculate_prf(wtls_machine->master_secret, labelVerify,(Octstr *)wtls_hash(wtls_machine->handshake_data, wtls_machine), 12,wtls_machine); /* Reset the accumulated Handshake data */ octstr_destroy(wtls_machine->handshake_data); wtls_machine->handshake_data = octstr_create(""); octstr_destroy(labelVerify); labelVerify = NULL; /* Add the pdus to our list */ add_pdu(wtls_machine, changeCipherSpecPDU); add_pdu(wtls_machine, finishedPDU); /* Send it off */ send_queuedpdus(wtls_machine); /* reset the seq_num */ wtls_machine->server_seq_num = 0; }, OPENING)/* Unitdata arrival - critical/fatal alert */ROW(EXCHANGE, T_Unitdata_Ind, is_critical_alert(event->u.T_Unitdata_Ind.pdu_list) == 1, {/* Do the necessary SEC_Terminate_Ind stuff *//* And we're dead :-< */}, NULL_STATE)/* Unitdata arrival - warning alert */ROW(EXCHANGE, T_Unitdata_Ind, is_warning_alert(event->u.T_Unitdata_Ind.pdu_list) == 1, {/* Do the necessary SEC_Exception_Ind stuff */}, EXCHANGE)/* Terminate */ROW(EXCHANGE, SEC_Terminate_Req, 1, {/* Send off a T_Unitdata_Req containing an alert as specified */send_alert(event->u.SEC_Terminate_Req.alert_level, event->u.SEC_Terminate_Req.alert_desc, wtls_machine);}, NULL_STATE)/* Exception */ROW(EXCHANGE, SEC_Exception_Req, 1, {/* Send off a T_Unitdata_Req containing an exception as specified */send_alert(event->u.SEC_Exception_Req.alert_level, event->u.SEC_Exception_Req.alert_desc, wtls_machine);}, EXCHANGE)/* Commit State *//* Unitdata arrival - identical ClientHello record */ROW(COMMIT, T_Unitdata_Ind, clienthellos_are_identical(event->u.T_Unitdata_Ind.pdu_list, wtls_machine->last_received_packet) == 1, {/* It appears as though someone has sent us an identical ClientHello to the last one *//* Make ourselves a T_Unitdata_Req with the last_transmitted_packet *//* And send it on it's merry way */}, COMMIT)/* Unitdata arrival - non-identical ClientHello record */ROW(COMMIT, T_Unitdata_Ind, clienthellos_are_identical(event->u.T_Unitdata_Ind.pdu_list, wtls_machine->last_received_packet) != 1, {/* So, this one's different. They must have changed their mind about something, so try a CREATING again *//* Do the necessary SEC_Create_Ind stuff */}, CREATING)/* Unitdata arrival - good packet with ChangeCipherSpec and Finished */ROW(COMMIT, T_Unitdata_Ind, packet_contains_changecipherspec (event->u.T_Unitdata_Ind.pdu_list) == 1 &&packet_contains_finished (event->u.T_Unitdata_Ind.pdu_list) == 1 &&packet_contains_userdata (event->u.T_Unitdata_Ind.pdu_list) != 1, {/* Create ourselves a SEC_Commit_Cnf packet to send off *//* Send it off */}, OPEN)/* Unitdata arrival - good packet with ChangeCipherSpec, Finished and UD */ROW(COMMIT, T_Unitdata_Ind, packet_contains_changecipherspec (event->u.T_Unitdata_Ind.pdu_list) == 1 &&packet_contains_finished (event->u.T_Unitdata_Ind.pdu_list) == 1 &&packet_contains_userdata (event->u.T_Unitdata_Ind.pdu_list) == 1, {/* Create a SEC_Commit_Cnf packet to send off *//* Send it off *//* Relay the contents of the packets up to the WTP or WSP layers, depending on the destination port */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -