68 #ifdef HAVE_WTLS_OPENSSL 81 int wtls_payload_guess_length(
Octstr * data);
87 pdu = gw_malloc(
sizeof(*pdu));
112 warning(0,
"Cannot create unknown WTLS PDU type %d", pdu->
type);
205 switch (client_key_exchange_algo) {
227 switch (client_key_exchange_algo) {
269 Octstr *returnData = 0, *tempData1 = 0, *tempData2 = 0;
288 tempData1 = returnData;
291 returnData =
octstr_cat(tempData1, tempData2);
316 List *payloadlist = NULL;
329 while (offset < dataLength) {
331 debug(
"wtls:wtls_unpack_payloadlist", 0,
"Offset is now : %d",
334 tempPayload = wtls_payload_unpack_from_offset(data, &offset);
337 if (tempPayload != NULL) {
343 debug(
"wtls:wtls_unpack_payloadlist", 0,
"Finished, found %ld PDUs",
360 int wtls_payload_guess_length(
Octstr * data)
363 int type = 0, lengthFlag = 0, lengthSize = 0, pdu_length = 0;
364 long lengthOffset = 1;
381 if (lengthFlag == 1) {
408 if (pdu_length == -1) {
413 return (pdu_length + lengthOffset);
424 int guessedPayloadLength = 0;
426 Octstr *dataFromOffset = 0;
427 Octstr *dataFromOffsetToLength = 0;
440 dataFromOffset =
octstr_copy(data, *offset, dataLength);
441 guessedPayloadLength = wtls_payload_guess_length(dataFromOffset);
444 if (guessedPayloadLength == -1) {
446 *offset = dataLength;
455 if ((*offset + guessedPayloadLength) > dataLength) {
457 *offset = dataLength;
462 *offset += guessedPayloadLength;
466 dataFromOffsetToLength =
467 octstr_copy(dataFromOffset, 0, guessedPayloadLength);
473 return returnPayload;
479 long bitpos = 0, charpos = 0;
645 while (charpos <= len) {
685 switch (client_key_exchange_algo) {
713 switch (client_key_exchange_algo) {
763 debug(
"wap.wtls", 0,
"%*sPDU: ", 0,
"");
765 panic(0,
"Unpacking unknown WTLS PDU type %ld",
776 long bitpos, charpos;
818 Octstr *buffer, *encryptedbuffer;
820 long bitpos, charpos;
821 long messageSizePos, sizepos;
823 int size, recordType;
856 messageSizePos = charpos;
950 int pos = charpos, len;
996 len = charpos - pos - 2;
998 (len & 0xFF00) >> 8);
1003 debug(
"wtls: ", 0,
"Packing ServerKeyExchange");
1010 switch (client_key_exchange_algo) {
1037 switch (client_key_exchange_algo) {
1074 debug(
"wtls", 0,
"verify_data (in pack)");
1080 debug(
"wtls_msg.c:length", 0,
"Setting msg size to : %d",
size);
1082 messageSizePos += 1;
1097 panic(0,
"Packing unknown WTLS PDU type %ld", (
long)pdu->
type);
1103 recordType = 1 << 7;
1104 recordType |= pdu->
snMode << 6;
1105 recordType |= pdu->
cipher << 5;
1107 recordType |= pdu->
type;
1108 if (!(encryptedbuffer =
wtls_encrypt(buffer, wtls_machine,
1117 debug(
"wtls", 0,
"Packed PDU Length: %d",
payload->rlen);
1124 char *dbg =
"wap.wtls",
type[20], *data;
1131 debug(dbg, 0,
"%*sPayload type: %s", level,
"",
type);
1134 debug(dbg, 0,
"%*sHandshake type: %s", level + 1,
"",
type);
1137 debug(dbg, 0,
"%*sAlert type: %s", level + 1,
"",
type);
1140 debug(dbg, 0,
"%*sReserved bit: %d", level,
"",
payload->reserved);
1142 debug(dbg, 0,
"%*sCipher in use: %d", level,
"",
payload->cipher);
1144 debug(dbg, 0,
"%*sSequence number in use: %d", level,
"",
1147 debug(dbg, 0,
"%*sRecord field length present: %d", level,
"",
1155 char *dbg =
"wap.wtls",
type[20];
1159 debug(dbg, 0,
"%*sPDU type: %s", level,
"",
type);
1162 debug(dbg, 0,
"%*sHandshake type: %s", level + 1,
"",
type);
1165 debug(dbg, 0,
"%*sReserved bit: %d", level,
"", pdu->
reserved);
1167 debug(dbg, 0,
"%*sCipher in use: %d", level,
"", pdu->
cipher);
1169 debug(dbg, 0,
"%*sSequence number in use: %d", level,
"", pdu->
seqNum);
1171 debug(dbg, 0,
"%*sRecord field length present: %d", level,
"",
1174 switch (pdu->
type) {
1176 debug(dbg, 0,
"%*sChangeCipher:", level,
"");
1181 debug(dbg, 0,
"%*sAlert:", level,
"");
1182 debug(dbg, 0,
"%*sLevel: %d", level + 1,
"",
1184 debug(dbg, 0,
"%*sDescription: %d", level + 1,
"",
1186 debug(dbg, 0,
"%*sChecksum: %s", level + 1,
"",
1191 debug(dbg, 0,
"%*sHandshake:", level,
"");
1192 debug(dbg, 0,
"%*sMessage Type: %d", level + 1,
"",
1194 debug(dbg, 0,
"%*sLength: %d", level + 1,
"",
1198 debug(dbg, 0,
"%*sHelloRequest.", level,
"");
1202 debug(dbg, 0,
"%*sClientHello:", level,
"");
1203 debug(dbg, 0,
"%*sClient version: %d", level + 1,
"",
1205 debug(dbg, 0,
"%*sRandom:", level + 1,
"");
1208 debug(dbg, 0,
"%*sSessionId: ", level,
"");
1212 debug(dbg, 0,
"%*sClient Key IDs: ", level + 1,
"");
1216 debug(dbg, 0,
"%*sTrusted Key IDs: ", level + 1,
"");
1221 debug(dbg, 0,
"%*sCipherSuite List: ", level + 1,
"");
1226 debug(dbg, 0,
"%*sCompression Method List: ", level + 1,
1232 debug(dbg, 0,
"%*sSeq Number Mode: %d", level + 1,
"",
1234 debug(dbg, 0,
"%*sKey Refresh: %d", level + 1,
"",
1239 debug(dbg, 0,
"%*sServerHello:", level,
"");
1240 debug(dbg, 0,
"%*sServer version: %d", level + 1,
"",
1242 debug(dbg, 0,
"%*sRandom:", level + 1,
"");
1245 debug(dbg, 0,
"%*sSession ID: %s", level + 1,
"",
1248 debug(dbg, 0,
"%*sClient Key ID: %d", level + 1,
"",
1251 debug(dbg, 0,
"%*sBulk Cipher Algo: %d", level + 1,
"",
1253 ciphersuite->bulk_cipher_algo);
1254 debug(dbg, 0,
"%*sMAC Algo: %d", level + 1,
"",
1258 debug(dbg, 0,
"%*sCompression Method: %d", level + 1,
1260 debug(dbg, 0,
"%*sSeq Number Mode: %d", level + 1,
"",
1262 debug(dbg, 0,
"%*sKey Refresh: %d", level + 1,
"",
1267 debug(dbg, 0,
"%*sCertificate:", level,
"");
1274 for (; i < len; i++) {
1278 "%*sCertificate Format: %d",
1284 "%*sWTLS Certificate:",
1294 "%*sX509 Certificate:",
1303 "%*sX968 Certificate:",
1315 debug(dbg, 0,
"%*sServerKeyExchange: ", level,
"");
1317 debug(dbg, 0,
"%*sParameter Index: %d", level + 1,
"",
1323 debug(dbg, 0,
"%*sParameter Set: %p", level + 1,
1328 switch (client_key_exchange_algo) {
1355 debug(dbg, 0,
"%*sClientKeyExchange:", level,
"");
1356 switch (client_key_exchange_algo) {
1386 debug(dbg, 0,
"%*sClientHelloDone.", level,
"");
1391 debug(dbg, 0,
"%*sFinished:", level,
"");
1392 debug(dbg, 0,
"%*sverify_data :", level + 1,
"");
1403 debug(dbg, 0,
"%*sApplication:", level,
"");
1409 debug(dbg, 0,
"%*sWTLS PDU at %p:", level,
"", (
void *)pdu);
1410 debug(dbg, 0,
"%*s unknown type %u", level,
"", pdu->
type);
void destroy_compression_method_list(List *compmethod_list)
void dump_compression_method_list(char *dbg, int level, List *compmethod_list)
Certificates * certificates
ServerHello * server_hello
wtls_Payload * wtls_pdu_pack(wtls_PDU *pdu, WTLSMachine *wtls_machine)
wtls_PDU * wtls_pdu_create(int type)
ClientKeyExchange * client_key_exchange
enum pubkey_algo PublicKeyAlgorithm
void dump_rsa_pubkey(char *dbg, int level, RSAPublicKey *key)
void wtls_payload_destroy(wtls_Payload *payload)
gw_assert(wtls_machine->packet_to_send !=NULL)
void gwlist_append(List *list, void *item)
void hsName(char *name, int handshake)
void octstr_append(Octstr *ostr1, const Octstr *ostr2)
long gwlist_len(List *list)
void wtls_payload_dump(wtls_Payload *msg, int level)
void * gwlist_get(List *list, long pos)
void octstr_set_bits(Octstr *ostr, long bitpos, int numbits, unsigned long value)
int pack_dh_pubkey(Octstr *data, long charpos, DHPublicKey *key)
ECPublicKey * unpack_ec_pubkey(Octstr *data, long *charpos)
void octstr_append_char(Octstr *ostr, int ch)
CertificateFormat certificateformat
WTLSCertificate * unpack_wtls_certificate(Octstr *data, long *charpos)
void alertName(char *name, int alert)
int pack_octstr16(Octstr *data, long charpos, Octstr *opaque)
Octstr * wtls_payload_pack(wtls_Payload *payload, int seqnum)
int pack_key_list(Octstr *data, long charpos, List *key_list)
enum keyex_suite KeyExchangeSuite
void pduName(char *name, int pdu)
List * unpack_compression_method_list(Octstr *data, long *charpos)
Octstr * unpack_octstr16(Octstr *data, long *charpos)
void destroy_ec_pubkey(ECPublicKey *key)
int pack_random(Octstr *data, long charpos, Random *random)
int pack_int16(Octstr *data, long charpos, int i)
#define octstr_get_cstr(ostr)
void dump_ec_pubkey(char *dbg, int level, ECPublicKey *key)
#define octstr_copy(ostr, from, len)
void wtls_pldList_destroy(List *pldList)
int pack_rsa_pubkey(Octstr *data, long charpos, RSAPublicKey *key)
void wtls_pdu_dump(wtls_PDU *msg, int level)
int pack_wtls_certificate(Octstr *data, long charpos, WTLSCertificate *cert)
ParameterSpecifier * param_spec
void destroy_rsa_encrypted_secret(RSAEncryptedSecret *secret)
void destroy_param_spec(ParameterSpecifier *pspec)
Octstr * wtls_pack_payloadlist(List *payloadlist, int seqnum)
void octstr_insert(Octstr *ostr1, const Octstr *ostr2, long pos)
ParameterSpecifier * unpack_param_spec(Octstr *data, long *charpos)
long octstr_get_bits(Octstr *ostr, long bitpos, int numbits)
void dump_dh_pubkey(char *dbg, int level, DHPublicKey *key)
void * gwlist_extract_first(List *list)
Octstr * x968_certificate
void dump_random(char *dbg, int level, Random *random)
void wtls_pdu_destroy(wtls_PDU *msg)
int pack_ciphersuite_list(Octstr *data, long charpos, List *ciphersuites)
void octstr_delete(Octstr *ostr1, long pos, long len)
void dump_wtls_certificate(char *dbg, int level, WTLSCertificate *cert)
Octstr * x509_certificate
ServerKeyExchange * server_key_exchange
wtls_Payload * wtls_payload_unpack(Octstr *data)
#define octstr_duplicate(ostr)
#define octstr_dump(ostr, level,...)
void warning(int err, const char *fmt,...)
int unpack_int16(Octstr *data, long *charpos)
Random * unpack_random(Octstr *data, long *charpos)
WTLSCertificate * wtls_certificate
void octstr_destroy(Octstr *ostr)
#define octstr_create(cstr)
CipherSuite * ciphersuite
enum sig_algo SignatureAlgorithm
Octstr * unpack_octstr(Octstr *data, long *charpos)
void dump_key_list(char *dbg, int level, List *key_list)
List * unpack_key_list(Octstr *data, long *charpos)
void destroy_dh_pubkey(DHPublicKey *key)
RSAEncryptedSecret * unpack_rsa_encrypted_secret(Octstr *data, long *charpos)
int pack_rsa_encrypted_secret(Octstr *data, long charpos, RSAEncryptedSecret *secret)
long octstr_len(const Octstr *ostr)
int pack_compression_method_list(Octstr *data, long charpos, List *compmethod_list)
void * gwlist_consume(List *list)
void destroy_key_list(List *key_list)
DHPublicKey * unpack_dh_pubkey(Octstr *data, long *charpos)
void debug(const char *place, int err, const char *fmt,...)
int pack_octstr_fixed(Octstr *data, long charpos, Octstr *opaque)
serverKeyXchgPDU u handshake server_key_exchange param_spec
void destroy_rsa_pubkey(RSAPublicKey *key)
void dump_rsa_encrypted_secret(char *dbg, int level, RSAEncryptedSecret *secret)
Octstr * octstr_cat(Octstr *ostr1, Octstr *ostr2)
CompressionMethod comp_method
List * unpack_ciphersuite_list(Octstr *data, long *charpos)
void destroy_random(Random *random)
void destroy_wtls_certificate(WTLSCertificate *cert)
ClientHello * client_hello
int pack_octstr(Octstr *data, long charpos, Octstr *opaque)
int pack_param_spec(Octstr *data, long charpos, ParameterSpecifier *pspec)
RSAPublicKey * unpack_rsa_pubkey(Octstr *data, long *charpos)
Octstr * wtls_encrypt(Octstr *buffer, WTLSMachine *wtls_machine, int recordType)
serverKeyXchgPDU u handshake server_key_exchange rsa_params
List * wtls_unpack_payloadlist(Octstr *data)
int octstr_get_char(const Octstr *ostr, long pos)
void octstr_set_char(Octstr *ostr, long pos, int ch)
Octstr * unpack_octstr_fixed(Octstr *data, long *charpos, long length)
int pack_ec_pubkey(Octstr *data, long charpos, ECPublicKey *key)
void dump_ciphersuite_list(char *dbg, int level, List *ciphersuites)
wtls_PDU * wtls_pdu_unpack(wtls_Payload *payload, WTLSMachine *wtls_machine)
void destroy_ciphersuite_list(List *ciphersuites)
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)