SilcMessagePayload message;
SilcBuffer buf;
const char *msg = "FOOBAR MESSAGE";
- unsigned char *data, tmp[1023];
+ unsigned char *data, tmp[1023], *tmp2;
SilcUInt32 data_len;
SilcUInt16 flags;
- int i;
- SilcMessageSignedPayload sig;
+ int i, n;
if (argc > 1 && !strcmp(argv[1], "-d")) {
silc_log_debug(TRUE);
SILC_LOG_DEBUG(("Parsing private messsage (static key)"));
message = silc_message_payload_parse(silc_buffer_data(buf),
silc_buffer_len(buf), TRUE, TRUE,
- key, hmac);
+ key, hmac, NULL, FALSE, NULL);
if (!message)
goto err;
flags = silc_message_get_flags(message);
silc_message_payload_free(message);
/* Simple private message */
- SILC_LOG_DEBUG(("Encoding private message len %d (static key)", 10));
+ n = 10;
+ SILC_LOG_DEBUG(("Encoding private message len %d (static key)", n));
buf = silc_message_payload_encode(SILC_MESSAGE_FLAG_ACTION |
SILC_MESSAGE_FLAG_UTF8 |
SILC_MESSAGE_FLAG_ACK,
- msg, 10, TRUE, TRUE,
+ msg, n, TRUE, TRUE,
key, hmac, rng, NULL, NULL, NULL, buf);
if (!buf)
goto err;
SILC_LOG_DEBUG(("Parsing private messsage (static key)"));
message = silc_message_payload_parse(silc_buffer_data(buf),
silc_buffer_len(buf), TRUE, TRUE,
- key, hmac);
+ key, hmac, NULL, FALSE, NULL);
if (!message)
goto err;
flags = silc_message_get_flags(message);
goto err;
data = silc_message_get_data(message, &data_len);
SILC_LOG_HEXDUMP(("Data"), data, data_len);
- if (data_len != 10 || memcmp(data, msg, 10))
+ if (data_len != n || memcmp(data, msg, n))
goto err;
SILC_LOG_HEXDUMP(("MAC"), silc_message_get_mac(message),
silc_hmac_len(hmac));
silc_message_payload_free(message);
/* Simple private message */
- SILC_LOG_DEBUG(("Encoding private message len %d (static key)", 1));
+ n = 1;
+ SILC_LOG_DEBUG(("Encoding private message len %d (static key)", n));
buf = silc_message_payload_encode(SILC_MESSAGE_FLAG_ACTION |
SILC_MESSAGE_FLAG_UTF8 |
SILC_MESSAGE_FLAG_ACK,
- msg, 1, TRUE, TRUE,
+ msg, n, TRUE, TRUE,
key, hmac, rng, NULL, NULL, NULL, buf);
if (!buf)
goto err;
SILC_LOG_DEBUG(("Parsing private messsage (static key)"));
message = silc_message_payload_parse(silc_buffer_data(buf),
silc_buffer_len(buf), TRUE, TRUE,
- key, hmac);
+ key, hmac, NULL, FALSE, NULL);
if (!message)
goto err;
flags = silc_message_get_flags(message);
goto err;
data = silc_message_get_data(message, &data_len);
SILC_LOG_HEXDUMP(("Data"), data, data_len);
- if (data_len != 1 || memcmp(data, msg, 1))
+ if (data_len != n || memcmp(data, msg, n))
goto err;
SILC_LOG_HEXDUMP(("MAC"), silc_message_get_mac(message),
silc_hmac_len(hmac));
SILC_LOG_DEBUG(("Parsing private messsage (static key)"));
message = silc_message_payload_parse(silc_buffer_data(buf),
silc_buffer_len(buf), TRUE, TRUE,
- key, hmac);
+ key, hmac, NULL, FALSE, NULL);
if (!message)
goto err;
flags = silc_message_get_flags(message);
SILC_LOG_DEBUG(("Parsing private messsage (static key)"));
message = silc_message_payload_parse(silc_buffer_data(buf),
silc_buffer_len(buf), TRUE, TRUE,
- key, hmac);
+ key, hmac, NULL, FALSE, NULL);
if (!message)
goto err;
flags = silc_message_get_flags(message);
goto err;
SILC_LOG_HEXDUMP(("MAC"), silc_message_get_mac(message),
silc_hmac_len(hmac));
- SILC_LOG_DEBUG(("Get signature"));
- sig = silc_message_get_signature(message);
- if (!sig)
- goto err;
SILC_LOG_DEBUG(("Verifying signature"));
- if (silc_message_signed_verify(sig, message, public_key, hash) !=
+ if (silc_message_signed_verify(message, public_key, hash) !=
SILC_AUTH_OK)
goto err;
SILC_LOG_DEBUG(("Signature Ok"));
SILC_LOG_DEBUG(("Get public key"));
- pk2 = silc_message_signed_get_public_key(sig, NULL, NULL);
+ pk2 = silc_message_signed_get_public_key(message, NULL, NULL);
if (!pk2)
goto err;
SILC_LOG_DEBUG(("Verify public key"));
SILC_LOG_DEBUG(("Parsing channel messsage (static key)"));
message = silc_message_payload_parse(silc_buffer_data(buf),
silc_buffer_len(buf), FALSE, TRUE,
- key, hmac);
+ key, hmac, NULL, FALSE, NULL);
if (!message)
goto err;
flags = silc_message_get_flags(message);
goto err;
SILC_LOG_HEXDUMP(("MAC"), silc_message_get_mac(message),
silc_hmac_len(hmac));
- SILC_LOG_DEBUG(("Get signature"));
- sig = silc_message_get_signature(message);
- if (!sig)
- goto err;
SILC_LOG_DEBUG(("Verifying signature"));
- if (silc_message_signed_verify(sig, message, public_key, hash) !=
+ if (silc_message_signed_verify(message, public_key, hash) !=
SILC_AUTH_OK)
goto err;
SILC_LOG_DEBUG(("Signature Ok"));
SILC_LOG_DEBUG(("Get public key"));
- pk2 = silc_message_signed_get_public_key(sig, NULL, NULL);
+ pk2 = silc_message_signed_get_public_key(message, NULL, NULL);
if (!pk2)
goto err;
SILC_LOG_DEBUG(("Verify public key"));
SILC_LOG_DEBUG(("Parsing private messsage (static key)"));
message = silc_message_payload_parse(silc_buffer_data(buf),
silc_buffer_len(buf), TRUE, FALSE,
- NULL, NULL);
+ NULL, NULL, NULL, FALSE, NULL);
if (!message)
goto err;
flags = silc_message_get_flags(message);
SILC_LOG_HEXDUMP(("Data"), data, data_len);
if (data_len != sizeof(tmp) / 2 || memcmp(data, tmp, sizeof(tmp) / 2))
goto err;
- SILC_LOG_DEBUG(("Get signature"));
- sig = silc_message_get_signature(message);
- if (!sig)
+ SILC_LOG_DEBUG(("Verifying signature"));
+ if (silc_message_signed_verify(message, public_key, hash) !=
+ SILC_AUTH_OK)
+ goto err;
+ SILC_LOG_DEBUG(("Signature Ok"));
+ SILC_LOG_DEBUG(("Get public key"));
+ pk2 = silc_message_signed_get_public_key(message, NULL, NULL);
+ if (!pk2)
+ goto err;
+ SILC_LOG_DEBUG(("Verify public key"));
+ if (!silc_pkcs_public_key_compare(public_key, pk2))
+ goto err;
+ SILC_LOG_DEBUG(("Public key Ok"));
+ silc_pkcs_public_key_free(pk2);
+ silc_message_payload_free(message);
+
+ /* Digitally signed channel message (LARGE) */
+ n = 65550;
+ tmp2 = silc_malloc(n);
+ if (!tmp2)
+ goto err;
+ SILC_LOG_DEBUG(("Encoding channel message len %d (static key) SIGNED LARGE",
+ n));
+ buf = silc_message_payload_encode(SILC_MESSAGE_FLAG_ACTION |
+ SILC_MESSAGE_FLAG_UTF8 |
+ SILC_MESSAGE_FLAG_ACK |
+ SILC_MESSAGE_FLAG_SIGNED,
+ tmp2, n, TRUE, FALSE,
+ key, hmac, rng,
+ public_key, private_key, hash, buf);
+ if (!buf)
+ goto err;
+ SILC_LOG_DEBUG(("Message length: %d", silc_buffer_len(buf)));
+ if (silc_buffer_len(buf) > SILC_PACKET_MAX_LEN)
+ goto err;
+ SILC_LOG_DEBUG(("Parsing channel messsage (static key)"));
+ message = silc_message_payload_parse(silc_buffer_data(buf),
+ silc_buffer_len(buf), FALSE, TRUE,
+ key, hmac, NULL, FALSE, NULL);
+ if (!message)
+ goto err;
+ flags = silc_message_get_flags(message);
+ SILC_LOG_DEBUG(("Flags: %x", flags));
+ if (!(flags & SILC_MESSAGE_FLAG_ACTION))
+ goto err;
+ if (!(flags & SILC_MESSAGE_FLAG_UTF8))
+ goto err;
+ if (!(flags & SILC_MESSAGE_FLAG_ACK))
goto err;
+ if (!(flags & SILC_MESSAGE_FLAG_SIGNED))
+ goto err;
+ data = silc_message_get_data(message, &data_len);
+ SILC_LOG_DEBUG(("Data len: %d", data_len));
+ if (silc_buffer_len(buf) > SILC_PACKET_MAX_LEN)
+ goto err;
+ SILC_LOG_HEXDUMP(("MAC"), silc_message_get_mac(message),
+ silc_hmac_len(hmac));
SILC_LOG_DEBUG(("Verifying signature"));
- if (silc_message_signed_verify(sig, message, public_key, hash) !=
+ if (silc_message_signed_verify(message, public_key, hash) !=
SILC_AUTH_OK)
goto err;
SILC_LOG_DEBUG(("Signature Ok"));
SILC_LOG_DEBUG(("Get public key"));
- pk2 = silc_message_signed_get_public_key(sig, NULL, NULL);
+ pk2 = silc_message_signed_get_public_key(message, NULL, NULL);
if (!pk2)
goto err;
SILC_LOG_DEBUG(("Verify public key"));
SILC_LOG_DEBUG(("Public key Ok"));
silc_pkcs_public_key_free(pk2);
silc_message_payload_free(message);
+ silc_free(tmp2);
success = TRUE;