Ejemplo n.º 1
0
/**
 * Send the hello message over the channel.
 * @param was_ota_upgrade_successful {@code true} if the previous OTA update was successful.
 */
ProtocolError Protocol::hello(bool was_ota_upgrade_successful)
{
	Message message;
	channel.create(message);

	size_t len = build_hello(message, was_ota_upgrade_successful);
	message.set_length(len);
	message.set_confirm_received(true);
	last_message_millis = callbacks.millis();
	return channel.send(message);
}
Ejemplo n.º 2
0
int main(void)
{


    json_t *jwk;
    struct MemoryStruct res;
    struct timeval tval_before, tval_after, tval_result;

    lca_init();

    int fd = start();

    if (lca_load_signing_key ("test_keys/atmel.key", &signing_key))
        return -1;

    jwk = gcry_pubkey2jwk (&signing_key);

    assert (NULL != jwk);

    json_dumpf (jwk, stdout, 0);


    char *m1 = build_key_post (jwk);

    printf ("Post key: %s\n", m1);

    char *b = combine (postkey, m1);
    char *c = combine (getkey, m1);

    /* char *b = malloc (strlen(m1) + strlen(postkey) + 1); */
    /* memset (b, 0, strlen(m1) + strlen(postkey) + 1); */

    /* printf ("here"); */

    /* strcpy (b, postkey); */
    /* strcat (postkey, m1); */



  curl_global_init(CURL_GLOBAL_ALL);


  res = get (b);

  free (res.memory);

  res = get (c);

  json_t *dm_key = get_dm_key (res.memory);

  free (res.memory);

  char *hello = build_hello (sub);

  gettimeofday(&tval_before, NULL);

  char *d = combine (posthello, hello);

  res = get (d);

  json_t *hello_rsp = verify_hello (res.memory, dm_key);
  free (res.memory);

  char *done = build_hello_rsp (sub, hello_rsp);
  char *e = combine (postdone, done);

  res = get (e);

  json_t *done_rsp = verify_done (res.memory, dm_key);
  free (res.memory);

  gettimeofday(&tval_after, NULL);

  free (e);
  free (d);
  free (b);
  free (c);
  /* we're done with libcurl, so clean it up */
  curl_global_cleanup();

  timersub(&tval_after, &tval_before, &tval_result);

  printf("Time elapsed: %ld.%06ld\n", (long int)tval_result.tv_sec, (long int)tval_result.tv_usec);

  return 0;

}