int silc_packet_decrypt(SilcCipher cipher, SilcHmac hmac,
SilcBuffer buffer, SilcPacketContext *packet)
{
-#if 0
- SILC_LOG_DEBUG(("Decrypting packet, cipher %s, len %d (%d)",
- cipher->cipher->name, len, len - 2));
-#endif
/* Decrypt start of the packet header */
if (cipher)
} else {
/* Packet requires special handling, decrypt rest of the header.
This only decrypts. */
- silc_packet_decrypt_rest_special(cipher, hmac, buffer);
+ if (!silc_packet_decrypt_rest_special(cipher, hmac, buffer))
+ return -1;
/* Check MAC */
if (!silc_packet_check_mac(hmac, buffer))
SilcPacketType silc_packet_parse(SilcPacketContext *ctx)
{
SilcBuffer buffer = ctx->buffer;
- int len;
+ int len, ret;
SILC_LOG_DEBUG(("Parsing incoming packet"));
SILC_STR_UI_SHORT(&ctx->dst_id_len),
SILC_STR_UI_CHAR(&ctx->src_id_type),
SILC_STR_END);
+ if (len == -1)
+ return SILC_PACKET_NONE;
if (ctx->src_id_len > SILC_PACKET_MAX_ID_LEN ||
ctx->dst_id_len > SILC_PACKET_MAX_ID_LEN) {
ctx->padlen = SILC_PACKET_PADLEN(ctx->truelen);
silc_buffer_pull(buffer, len);
- silc_buffer_unformat(buffer,
- SILC_STR_UI_XNSTRING_ALLOC(&ctx->src_id,
- ctx->src_id_len),
- SILC_STR_UI_CHAR(&ctx->dst_id_type),
- SILC_STR_UI_XNSTRING_ALLOC(&ctx->dst_id,
- ctx->dst_id_len),
- SILC_STR_UI_XNSTRING(NULL, ctx->padlen),
- SILC_STR_END);
+ ret = silc_buffer_unformat(buffer,
+ SILC_STR_UI_XNSTRING_ALLOC(&ctx->src_id,
+ ctx->src_id_len),
+ SILC_STR_UI_CHAR(&ctx->dst_id_type),
+ SILC_STR_UI_XNSTRING_ALLOC(&ctx->dst_id,
+ ctx->dst_id_len),
+ SILC_STR_UI_XNSTRING(NULL, ctx->padlen),
+ SILC_STR_END);
+ if (ret == -1)
+ return SILC_PACKET_NONE;
+
silc_buffer_push(buffer, len);
SILC_LOG_HEXDUMP(("parsed packet, len %d", ctx->buffer->len),
SilcPacketType silc_packet_parse_special(SilcPacketContext *ctx)
{
SilcBuffer buffer = ctx->buffer;
- int len, tmplen;
+ int len, tmplen, ret;
SILC_LOG_DEBUG(("Parsing incoming packet"));
SILC_STR_UI_SHORT(&ctx->dst_id_len),
SILC_STR_UI_CHAR(&ctx->src_id_type),
SILC_STR_END);
+ if (len == -1)
+ return SILC_PACKET_NONE;
if (ctx->src_id_len > SILC_PACKET_MAX_ID_LEN ||
ctx->dst_id_len > SILC_PACKET_MAX_ID_LEN) {
ctx->padlen = SILC_PACKET_PADLEN(tmplen);
silc_buffer_pull(buffer, len);
- silc_buffer_unformat(buffer,
- SILC_STR_UI_XNSTRING_ALLOC(&ctx->src_id,
- ctx->src_id_len),
- SILC_STR_UI_CHAR(&ctx->dst_id_type),
- SILC_STR_UI_XNSTRING_ALLOC(&ctx->dst_id,
- ctx->dst_id_len),
- SILC_STR_UI_XNSTRING(NULL, ctx->padlen),
- SILC_STR_END);
+ ret = silc_buffer_unformat(buffer,
+ SILC_STR_UI_XNSTRING_ALLOC(&ctx->src_id,
+ ctx->src_id_len),
+ SILC_STR_UI_CHAR(&ctx->dst_id_type),
+ SILC_STR_UI_XNSTRING_ALLOC(&ctx->dst_id,
+ ctx->dst_id_len),
+ SILC_STR_UI_XNSTRING(NULL, ctx->padlen),
+ SILC_STR_END);
+ if (ret == -1)
+ return SILC_PACKET_NONE;
+
silc_buffer_push(buffer, len);
SILC_LOG_HEXDUMP(("parsed packet, len %d", ctx->buffer->len),