[epiphany/wip/ephy-sync: 117/126] sync-crypto: Discard some of the structs



commit bd401372d19846e97fa359cfe04060077e1ac092
Author: Gabriel Ivascu <ivascu gabriel59 gmail com>
Date:   Sat Aug 13 16:49:58 2016 +0300

    sync-crypto: Discard some of the structs

 src/ephy-sync-crypto.c  |  195 +++++++++++------------------------------------
 src/ephy-sync-crypto.h  |  150 ++++++++++++++++--------------------
 src/ephy-sync-service.c |   80 ++++++++++++--------
 3 files changed, 159 insertions(+), 266 deletions(-)
---
diff --git a/src/ephy-sync-crypto.c b/src/ephy-sync-crypto.c
index 43e9644..d928880 100644
--- a/src/ephy-sync-crypto.c
+++ b/src/ephy-sync-crypto.c
@@ -102,53 +102,6 @@ ephy_sync_crypto_hawk_header_new (gchar                       *header,
   return hawk_header;
 }
 
-static EphySyncCryptoProcessedKFT *
-ephy_sync_crypto_processed_kft_new (guint8 *tokenID,
-                                    guint8 *reqHMACkey,
-                                    guint8 *respHMACkey,
-                                    guint8 *respXORkey)
-{
-  EphySyncCryptoProcessedKFT *processed_kft;
-
-  processed_kft = g_slice_new (EphySyncCryptoProcessedKFT);
-  processed_kft->tokenID = tokenID;
-  processed_kft->reqHMACkey = reqHMACkey;
-  processed_kft->respHMACkey = respHMACkey;
-  processed_kft->respXORkey = respXORkey;
-
-  return processed_kft;
-}
-
-static EphySyncCryptoProcessedST *
-ephy_sync_crypto_processed_st_new (guint8 *tokenID,
-                                   guint8 *reqHMACkey,
-                                   guint8 *requestKey)
-{
-  EphySyncCryptoProcessedST *processed_st;
-
-  processed_st = g_slice_new (EphySyncCryptoProcessedST);
-  processed_st->tokenID = tokenID;
-  processed_st->reqHMACkey = reqHMACkey;
-  processed_st->requestKey = requestKey;
-
-  return processed_st;
-}
-
-static EphySyncCryptoSyncKeys *
-ephy_sync_crypto_sync_keys_new (guint8 *kA,
-                                guint8 *kB,
-                                guint8 *wrapKB)
-{
-  EphySyncCryptoSyncKeys *sync_keys;
-
-  sync_keys = g_slice_new (EphySyncCryptoSyncKeys);
-  sync_keys->kA = kA;
-  sync_keys->kB = kB;
-  sync_keys->wrapKB = wrapKB;
-
-  return sync_keys;
-}
-
 static EphySyncCryptoRSAKeyPair *
 ephy_sync_crypto_rsa_key_pair_new (struct rsa_public_key  public,
                                    struct rsa_private_key private)
@@ -211,43 +164,6 @@ ephy_sync_crypto_hawk_header_free (EphySyncCryptoHawkHeader *hawk_header)
 }
 
 void
-ephy_sync_crypto_processed_kft_free (EphySyncCryptoProcessedKFT *processed_kft)
-{
-  g_return_if_fail (processed_kft != NULL);
-
-  g_free (processed_kft->tokenID);
-  g_free (processed_kft->reqHMACkey);
-  g_free (processed_kft->respHMACkey);
-  g_free (processed_kft->respXORkey);
-
-  g_slice_free (EphySyncCryptoProcessedKFT, processed_kft);
-}
-
-void
-ephy_sync_crypto_processed_st_free (EphySyncCryptoProcessedST *processed_st)
-{
-  g_return_if_fail (processed_st != NULL);
-
-  g_free (processed_st->tokenID);
-  g_free (processed_st->reqHMACkey);
-  g_free (processed_st->requestKey);
-
-  g_slice_free (EphySyncCryptoProcessedST, processed_st);
-}
-
-void
-ephy_sync_crypto_sync_keys_free (EphySyncCryptoSyncKeys *sync_keys)
-{
-  g_return_if_fail (sync_keys != NULL);
-
-  g_free (sync_keys->kA);
-  g_free (sync_keys->kB);
-  g_free (sync_keys->wrapKB);
-
-  g_slice_free (EphySyncCryptoSyncKeys, sync_keys);
-}
-
-void
 ephy_sync_crypto_rsa_key_pair_free (EphySyncCryptoRSAKeyPair *keypair)
 {
   g_return_if_fail (keypair != NULL);
@@ -280,20 +196,14 @@ xor (guint8 *a,
 
 static gboolean
 are_equal (guint8 *a,
-           guint8 *b)
+           guint8 *b,
+           gsize   length)
 {
-  gchar *a_hex;
-  gchar *b_hex;
-  gboolean retval;
-
-  a_hex = ephy_sync_crypto_encode_hex (a, 0);
-  b_hex = ephy_sync_crypto_encode_hex (b, 0);
-  retval = g_str_equal (a_hex, b_hex);
-
-  g_free (a_hex);
-  g_free (b_hex);
+  for (gsize i = 0; i < length; i++)
+    if (a[i] != b[i])
+      return FALSE;
 
-  return retval;
+  return TRUE;
 }
 
 static gchar *
@@ -601,16 +511,16 @@ base64_urlsafe_to_base64 (gchar *text)
   g_strcanon (text, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789=+", '/');
 }
 
-EphySyncCryptoProcessedKFT *
-ephy_sync_crypto_process_key_fetch_token (const gchar *keyFetchToken)
+void
+ephy_sync_crypto_process_key_fetch_token (const gchar  *keyFetchToken,
+                                          guint8      **tokenID,
+                                          guint8      **reqHMACkey,
+                                          guint8      **respHMACkey,
+                                          guint8      **respXORkey)
 {
   guint8 *kft;
   guint8 *out1;
   guint8 *out2;
-  guint8 *tokenID;
-  guint8 *reqHMACkey;
-  guint8 *respHMACkey;
-  guint8 *respXORkey;
   guint8 *keyRequestKey;
   gchar *info_kft;
   gchar *info_keys;
@@ -626,11 +536,11 @@ ephy_sync_crypto_process_key_fetch_token (const gchar *keyFetchToken)
         (guint8 *) info_kft, strlen (info_kft),
         out1, 3 * EPHY_SYNC_TOKEN_LENGTH);
 
-  tokenID = g_malloc (EPHY_SYNC_TOKEN_LENGTH);
-  reqHMACkey = g_malloc (EPHY_SYNC_TOKEN_LENGTH);
+  *tokenID = g_malloc (EPHY_SYNC_TOKEN_LENGTH);
+  *reqHMACkey = g_malloc (EPHY_SYNC_TOKEN_LENGTH);
   keyRequestKey = g_malloc (EPHY_SYNC_TOKEN_LENGTH);
-  memcpy (tokenID, out1, EPHY_SYNC_TOKEN_LENGTH);
-  memcpy (reqHMACkey, out1 + EPHY_SYNC_TOKEN_LENGTH, EPHY_SYNC_TOKEN_LENGTH);
+  memcpy (*tokenID, out1, EPHY_SYNC_TOKEN_LENGTH);
+  memcpy (*reqHMACkey, out1 + EPHY_SYNC_TOKEN_LENGTH, EPHY_SYNC_TOKEN_LENGTH);
   memcpy (keyRequestKey, out1 + 2 * EPHY_SYNC_TOKEN_LENGTH, EPHY_SYNC_TOKEN_LENGTH);
 
   hkdf (keyRequestKey, EPHY_SYNC_TOKEN_LENGTH,
@@ -638,10 +548,10 @@ ephy_sync_crypto_process_key_fetch_token (const gchar *keyFetchToken)
         (guint8 *) info_keys, strlen (info_keys),
         out2, 3 * EPHY_SYNC_TOKEN_LENGTH);
 
-  respHMACkey = g_malloc (EPHY_SYNC_TOKEN_LENGTH);
-  respXORkey = g_malloc (2 * EPHY_SYNC_TOKEN_LENGTH);
-  memcpy (respHMACkey, out2, EPHY_SYNC_TOKEN_LENGTH);
-  memcpy (respXORkey, out2 + EPHY_SYNC_TOKEN_LENGTH, 2 * EPHY_SYNC_TOKEN_LENGTH);
+  *respHMACkey = g_malloc (EPHY_SYNC_TOKEN_LENGTH);
+  *respXORkey = g_malloc (2 * EPHY_SYNC_TOKEN_LENGTH);
+  memcpy (*respHMACkey, out2, EPHY_SYNC_TOKEN_LENGTH);
+  memcpy (*respXORkey, out2 + EPHY_SYNC_TOKEN_LENGTH, 2 * EPHY_SYNC_TOKEN_LENGTH);
 
   g_free (kft);
   g_free (out1);
@@ -649,21 +559,16 @@ ephy_sync_crypto_process_key_fetch_token (const gchar *keyFetchToken)
   g_free (info_kft);
   g_free (info_keys);
   g_free (keyRequestKey);
-
-  return ephy_sync_crypto_processed_kft_new (tokenID,
-                                             reqHMACkey,
-                                             respHMACkey,
-                                             respXORkey);
 }
 
-EphySyncCryptoProcessedST *
-ephy_sync_crypto_process_session_token (const gchar *sessionToken)
+void
+ephy_sync_crypto_process_session_token (const gchar  *sessionToken,
+                                        guint8      **tokenID,
+                                        guint8      **reqHMACkey,
+                                        guint8      **requestKey)
 {
   guint8 *st;
   guint8 *out;
-  guint8 *tokenID;
-  guint8 *reqHMACkey;
-  guint8 *requestKey;
   gchar *info;
 
   st = ephy_sync_crypto_decode_hex (sessionToken);
@@ -675,27 +580,25 @@ ephy_sync_crypto_process_session_token (const gchar *sessionToken)
         (guint8 *) info, strlen (info),
         out, 3 * EPHY_SYNC_TOKEN_LENGTH);
 
-  tokenID = g_malloc (EPHY_SYNC_TOKEN_LENGTH);
-  reqHMACkey = g_malloc (EPHY_SYNC_TOKEN_LENGTH);
-  requestKey = g_malloc (EPHY_SYNC_TOKEN_LENGTH);
-  memcpy (tokenID, out, EPHY_SYNC_TOKEN_LENGTH);
-  memcpy (reqHMACkey, out + EPHY_SYNC_TOKEN_LENGTH, EPHY_SYNC_TOKEN_LENGTH);
-  memcpy (requestKey, out + 2 * EPHY_SYNC_TOKEN_LENGTH, EPHY_SYNC_TOKEN_LENGTH);
+  *tokenID = g_malloc (EPHY_SYNC_TOKEN_LENGTH);
+  *reqHMACkey = g_malloc (EPHY_SYNC_TOKEN_LENGTH);
+  *requestKey = g_malloc (EPHY_SYNC_TOKEN_LENGTH);
+  memcpy (*tokenID, out, EPHY_SYNC_TOKEN_LENGTH);
+  memcpy (*reqHMACkey, out + EPHY_SYNC_TOKEN_LENGTH, EPHY_SYNC_TOKEN_LENGTH);
+  memcpy (*requestKey, out + 2 * EPHY_SYNC_TOKEN_LENGTH, EPHY_SYNC_TOKEN_LENGTH);
 
   g_free (st);
   g_free (out);
   g_free (info);
-
-  return ephy_sync_crypto_processed_st_new (tokenID,
-                                            reqHMACkey,
-                                            requestKey);
 }
 
-EphySyncCryptoSyncKeys *
-ephy_sync_crypto_retrieve_sync_keys (const gchar *bundle,
-                                     guint8      *respHMACkey,
-                                     guint8      *respXORkey,
-                                     guint8      *unwrapBKey)
+void
+ephy_sync_crypto_retrieve_sync_keys (const gchar  *bundle,
+                                     guint8       *respHMACkey,
+                                     guint8       *respXORkey,
+                                     guint8       *unwrapBKey,
+                                     guint8      **kA,
+                                     guint8      **kB)
 {
   guint8 *bdl;
   guint8 *ciphertext;
@@ -703,16 +606,13 @@ ephy_sync_crypto_retrieve_sync_keys (const gchar *bundle,
   guint8 *respMAC2;
   guint8 *xored;
   guint8 *wrapKB;
-  guint8 *kA;
-  guint8 *kB;
   gchar *respMAC2_hex;
-  EphySyncCryptoSyncKeys *retval = NULL;
 
   bdl = ephy_sync_crypto_decode_hex (bundle);
   ciphertext = g_malloc (2 * EPHY_SYNC_TOKEN_LENGTH);
   respMAC = g_malloc (EPHY_SYNC_TOKEN_LENGTH);
   wrapKB = g_malloc (EPHY_SYNC_TOKEN_LENGTH);
-  kA = g_malloc (EPHY_SYNC_TOKEN_LENGTH);
+  *kA = g_malloc (EPHY_SYNC_TOKEN_LENGTH);
 
   memcpy (ciphertext, bdl, 2 * EPHY_SYNC_TOKEN_LENGTH);
   memcpy (respMAC, bdl + 2 * EPHY_SYNC_TOKEN_LENGTH, EPHY_SYNC_TOKEN_LENGTH);
@@ -720,27 +620,20 @@ ephy_sync_crypto_retrieve_sync_keys (const gchar *bundle,
                                           respHMACkey, EPHY_SYNC_TOKEN_LENGTH,
                                           ciphertext, 2 * EPHY_SYNC_TOKEN_LENGTH);
   respMAC2 = ephy_sync_crypto_decode_hex (respMAC2_hex);
-
-  if (are_equal (respMAC, respMAC2) == FALSE) {
-    g_warning ("respMAC and respMAC2 differ");
-    goto out;
-  }
+  g_assert (are_equal (respMAC, respMAC2, EPHY_SYNC_TOKEN_LENGTH) == TRUE);
 
   xored = xor (ciphertext, respXORkey, 2 * EPHY_SYNC_TOKEN_LENGTH);
-  memcpy (kA, xored, EPHY_SYNC_TOKEN_LENGTH);
+  memcpy (*kA, xored, EPHY_SYNC_TOKEN_LENGTH);
   memcpy (wrapKB, xored + EPHY_SYNC_TOKEN_LENGTH, EPHY_SYNC_TOKEN_LENGTH);
-  kB = xor (unwrapBKey, wrapKB, EPHY_SYNC_TOKEN_LENGTH);
-  retval = ephy_sync_crypto_sync_keys_new (kA, kB, wrapKB);
+  *kB = xor (unwrapBKey, wrapKB, EPHY_SYNC_TOKEN_LENGTH);
 
-out:
   g_free (bdl);
   g_free (ciphertext);
   g_free (respMAC);
   g_free (respMAC2);
-  g_free (respMAC2_hex);
   g_free (xored);
-
-  return retval;
+  g_free (wrapKB);
+  g_free (respMAC2_hex);
 }
 
 EphySyncCryptoHawkHeader *
diff --git a/src/ephy-sync-crypto.h b/src/ephy-sync-crypto.h
index 814b14a..480726b 100644
--- a/src/ephy-sync-crypto.h
+++ b/src/ephy-sync-crypto.h
@@ -62,93 +62,77 @@ typedef struct {
 } EphySyncCryptoHawkHeader;
 
 typedef struct {
-  guint8 *tokenID;
-  guint8 *reqHMACkey;
-  guint8 *respHMACkey;
-  guint8 *respXORkey;
-} EphySyncCryptoProcessedKFT;
-
-typedef struct {
-  guint8 *tokenID;
-  guint8 *reqHMACkey;
-  guint8 *requestKey;
-} EphySyncCryptoProcessedST;
-
-typedef struct {
-  guint8 *kA;
-  guint8 *kB;
-  guint8 *wrapKB;
-} EphySyncCryptoSyncKeys;
-
-typedef struct {
   struct rsa_public_key public;
   struct rsa_private_key private;
 } EphySyncCryptoRSAKeyPair;
 
-EphySyncCryptoHawkOptions   *ephy_sync_crypto_hawk_options_new       (gchar *app,
-                                                                      gchar *dlg,
-                                                                      gchar *ext,
-                                                                      gchar *content_type,
-                                                                      gchar *hash,
-                                                                      gchar *local_time_offset,
-                                                                      gchar *nonce,
-                                                                      gchar *payload,
-                                                                      gchar *timestamp);
-
-void                        ephy_sync_crypto_hawk_options_free       (EphySyncCryptoHawkOptions 
*hawk_options);
-
-void                        ephy_sync_crypto_hawk_header_free        (EphySyncCryptoHawkHeader *hawk_header);
-
-void                        ephy_sync_crypto_processed_kft_free      (EphySyncCryptoProcessedKFT 
*processed_kft);
-
-void                        ephy_sync_crypto_processed_st_free       (EphySyncCryptoProcessedST 
*processed_st);
-
-void                        ephy_sync_crypto_sync_keys_free          (EphySyncCryptoSyncKeys *sync_keys);
-
-void                        ephy_sync_crypto_rsa_key_pair_free       (EphySyncCryptoRSAKeyPair *keypair);
-
-EphySyncCryptoProcessedKFT *ephy_sync_crypto_process_key_fetch_token (const gchar *keyFetchToken);
-
-EphySyncCryptoProcessedST  *ephy_sync_crypto_process_session_token   (const gchar *sessionToken);
-
-EphySyncCryptoSyncKeys     *ephy_sync_crypto_retrieve_sync_keys      (const gchar *bundle,
-                                                                      guint8      *respHMACkey,
-                                                                      guint8      *respXORkey,
-                                                                      guint8      *unwrapBKey);
-
-EphySyncCryptoHawkHeader   *ephy_sync_crypto_compute_hawk_header     (const gchar               *url,
-                                                                      const gchar               *method,
-                                                                      const gchar               *id,
-                                                                      guint8                    *key,
-                                                                      gsize                      key_length,
-                                                                      EphySyncCryptoHawkOptions *options);
-
-EphySyncCryptoRSAKeyPair   *ephy_sync_crypto_generate_rsa_key_pair   (void);
-
-gchar                      *ephy_sync_crypto_create_assertion        (const gchar              *certificate,
-                                                                      const gchar              *audience,
-                                                                      guint64                   duration,
-                                                                      EphySyncCryptoRSAKeyPair *keypair);
-
-gchar                      *ephy_sync_crypto_generate_random_string  (gsize length);
-
-gchar                      *ephy_sync_crypto_base64_urlsafe_encode   (guint8   *data,
-                                                                      gsize     data_length,
-                                                                      gboolean  strip);
-
-guint8                     *ephy_sync_crypto_base64_urlsafe_decode   (const gchar *text,
-                                                                      gsize       *out_length);
-
-guint8                     *ephy_sync_crypto_aes_256                 (EphySyncCryptoAES256Mode  mode,
-                                                                      const guint8             *key,
-                                                                      const guint8             *data,
-                                                                      gsize                     data_length,
-                                                                      gsize                    *out_length);
-
-gchar                      *ephy_sync_crypto_encode_hex              (guint8 *data,
-                                                                      gsize   data_length);
-
-guint8                     *ephy_sync_crypto_decode_hex              (const gchar *hex_string);
+EphySyncCryptoHawkOptions *ephy_sync_crypto_hawk_options_new       (gchar *app,
+                                                                    gchar *dlg,
+                                                                    gchar *ext,
+                                                                    gchar *content_type,
+                                                                    gchar *hash,
+                                                                    gchar *local_time_offset,
+                                                                    gchar *nonce,
+                                                                    gchar *payload,
+                                                                    gchar *timestamp);
+
+void                      ephy_sync_crypto_hawk_options_free       (EphySyncCryptoHawkOptions *hawk_options);
+
+void                      ephy_sync_crypto_hawk_header_free        (EphySyncCryptoHawkHeader *hawk_header);
+
+void                      ephy_sync_crypto_rsa_key_pair_free       (EphySyncCryptoRSAKeyPair *keypair);
+
+void                      ephy_sync_crypto_process_key_fetch_token (const gchar  *keyFetchToken,
+                                                                    guint8      **tokenID,
+                                                                    guint8      **reqHMACkey,
+                                                                    guint8      **respHMACkey,
+                                                                    guint8      **respXORkey);
+
+void                      ephy_sync_crypto_process_session_token   (const gchar  *sessionToken,
+                                                                    guint8      **tokenID,
+                                                                    guint8      **reqHMACkey,
+                                                                    guint8      **requestKey);
+
+void                      ephy_sync_crypto_retrieve_sync_keys      (const gchar  *bundle,
+                                                                    guint8       *respHMACkey,
+                                                                    guint8       *respXORkey,
+                                                                    guint8       *unwrapBKey,
+                                                                    guint8      **kA,
+                                                                    guint8      **kB);
+
+EphySyncCryptoHawkHeader *ephy_sync_crypto_compute_hawk_header     (const gchar               *url,
+                                                                    const gchar               *method,
+                                                                    const gchar               *id,
+                                                                    guint8                    *key,
+                                                                    gsize                      key_length,
+                                                                    EphySyncCryptoHawkOptions *options);
+
+EphySyncCryptoRSAKeyPair *ephy_sync_crypto_generate_rsa_key_pair   (void);
+
+gchar                    *ephy_sync_crypto_create_assertion        (const gchar              *certificate,
+                                                                    const gchar              *audience,
+                                                                    guint64                   duration,
+                                                                    EphySyncCryptoRSAKeyPair *keypair);
+
+gchar                    *ephy_sync_crypto_generate_random_string  (gsize length);
+
+gchar                    *ephy_sync_crypto_base64_urlsafe_encode   (guint8   *data,
+                                                                    gsize     data_length,
+                                                                    gboolean  strip);
+
+guint8                   *ephy_sync_crypto_base64_urlsafe_decode   (const gchar *text,
+                                                                    gsize       *out_length);
+
+guint8                   *ephy_sync_crypto_aes_256                 (EphySyncCryptoAES256Mode  mode,
+                                                                    const guint8             *key,
+                                                                    const guint8             *data,
+                                                                    gsize                     data_length,
+                                                                    gsize                    *out_length);
+
+gchar                    *ephy_sync_crypto_encode_hex              (guint8 *data,
+                                                                    gsize   data_length);
+
+guint8                   *ephy_sync_crypto_decode_hex              (const gchar *hex_string);
 
 G_END_DECLS
 
diff --git a/src/ephy-sync-service.c b/src/ephy-sync-service.c
index 5336040..179b1b6 100644
--- a/src/ephy-sync-service.c
+++ b/src/ephy-sync-service.c
@@ -568,8 +568,10 @@ static void
 ephy_sync_service_obtain_signed_certificate (EphySyncService *self,
                                              gpointer         user_data)
 {
-  EphySyncCryptoProcessedST *processed_st;
-  gchar *tokenID;
+  guint8 *tokenID;
+  guint8 *reqHMACkey;
+  guint8 *requestKey;
+  gchar *tokenID_h;
   gchar *public_key_json;
   gchar *request_body;
   gchar *n_str;
@@ -583,8 +585,9 @@ ephy_sync_service_obtain_signed_certificate (EphySyncService *self,
   self->keypair = ephy_sync_crypto_generate_rsa_key_pair ();
   g_return_if_fail (self->keypair != NULL);
 
-  processed_st = ephy_sync_crypto_process_session_token (self->sessionToken);
-  tokenID = ephy_sync_crypto_encode_hex (processed_st->tokenID, 0);
+  ephy_sync_crypto_process_session_token (self->sessionToken,
+                                          &tokenID, &reqHMACkey, &requestKey);
+  tokenID_h = ephy_sync_crypto_encode_hex (tokenID, 0);
 
   n_str = mpz_get_str (NULL, 10, self->keypair->public.n);
   e_str = mpz_get_str (NULL, 10, self->keypair->public.e);
@@ -600,15 +603,17 @@ ephy_sync_service_obtain_signed_certificate (EphySyncService *self,
                                   public_key_json, 30 * 60 * 1000);
   ephy_sync_service_fxa_hawk_post_async (self,
                                          "certificate/sign",
-                                         tokenID,
-                                         processed_st->reqHMACkey,
+                                         tokenID_h,
+                                         reqHMACkey,
                                          EPHY_SYNC_TOKEN_LENGTH,
                                          request_body,
                                          obtain_signed_certificate_response_cb,
                                          user_data);
 
-  ephy_sync_crypto_processed_st_free (processed_st);
   g_free (tokenID);
+  g_free (reqHMACkey);
+  g_free (requestKey);
+  g_free (tokenID_h);
   g_free (public_key_json);
   g_free (request_body);
   g_free (n_str);
@@ -835,11 +840,13 @@ void
 ephy_sync_service_destroy_session (EphySyncService *self,
                                    const gchar     *sessionToken)
 {
-  EphySyncCryptoProcessedST *processed_st;
   EphySyncCryptoHawkOptions *hawk_options;
   EphySyncCryptoHawkHeader *hawk_header;
   SoupMessage *message;
-  gchar *tokenID;
+  guint8 *tokenID;
+  guint8 *reqHMACkey;
+  guint8 *requestKey;
+  gchar *tokenID_h;
   gchar *url;
   const gchar *content_type = "application/json";
   const gchar *endpoint = "session/destroy";
@@ -851,8 +858,9 @@ ephy_sync_service_destroy_session (EphySyncService *self,
                          MOZILLA_FIREFOX_ACCOUNTS_BASE_URL,
                          MOZILLA_FIREFOX_ACCOUNTS_VERSION,
                          endpoint);
-  processed_st = ephy_sync_crypto_process_session_token (sessionToken);
-  tokenID = ephy_sync_crypto_encode_hex (processed_st->tokenID, 0);
+  ephy_sync_crypto_process_session_token (sessionToken,
+                                          &tokenID, &reqHMACkey, &requestKey);
+  tokenID_h = ephy_sync_crypto_encode_hex (tokenID, 0);
 
   message = soup_message_new (SOUP_METHOD_POST, url);
   soup_message_set_request (message, content_type,
@@ -864,8 +872,8 @@ ephy_sync_service_destroy_session (EphySyncService *self,
                                                     g_strdup (request_body),
                                                     NULL);
   hawk_header = ephy_sync_crypto_compute_hawk_header (url, "POST",
-                                                      tokenID,
-                                                      processed_st->reqHMACkey,
+                                                      tokenID_h,
+                                                      reqHMACkey,
                                                       EPHY_SYNC_TOKEN_LENGTH,
                                                       hawk_options);
   soup_message_headers_append (message->request_headers,
@@ -877,8 +885,10 @@ ephy_sync_service_destroy_session (EphySyncService *self,
 
   ephy_sync_crypto_hawk_options_free (hawk_options);
   ephy_sync_crypto_hawk_header_free (hawk_header);
-  ephy_sync_crypto_processed_st_free (processed_st);
+  g_free (tokenID_h);
   g_free (tokenID);
+  g_free (reqHMACkey);
+  g_free (requestKey);
   g_free (url);
 }
 
@@ -888,22 +898,28 @@ ephy_sync_service_fetch_sync_keys (EphySyncService *self,
                                    const gchar     *keyFetchToken,
                                    const gchar     *unwrapBKey)
 {
-  EphySyncCryptoProcessedKFT *processed_kft = NULL;
-  EphySyncCryptoSyncKeys *sync_keys = NULL;
   JsonNode *node;
   JsonObject *json;
   guint8 *unwrapKB;
-  gchar *tokenID;
+  guint8 *tokenID;
+  guint8 *reqHMACkey;
+  guint8 *respHMACkey;
+  guint8 *respXORkey;
+  guint8 *kA;
+  guint8 *kB;
+  gchar *tokenID_h;
   guint status_code;
   gboolean retval = FALSE;
 
   unwrapKB = ephy_sync_crypto_decode_hex (unwrapBKey);
-  processed_kft = ephy_sync_crypto_process_key_fetch_token (keyFetchToken);
-  tokenID = ephy_sync_crypto_encode_hex (processed_kft->tokenID, 0);
+  ephy_sync_crypto_process_key_fetch_token (keyFetchToken,
+                                            &tokenID, &reqHMACkey,
+                                            &respHMACkey, &respXORkey);
+  tokenID_h = ephy_sync_crypto_encode_hex (tokenID, 0);
   status_code = ephy_sync_service_fxa_hawk_get_sync (self,
                                                      "account/keys",
-                                                     tokenID,
-                                                     processed_kft->reqHMACkey,
+                                                     tokenID_h,
+                                                     reqHMACkey,
                                                      EPHY_SYNC_TOKEN_LENGTH,
                                                      &node);
   json = json_node_get_object (node);
@@ -915,29 +931,29 @@ ephy_sync_service_fetch_sync_keys (EphySyncService *self,
     goto out;
   }
 
-  sync_keys = ephy_sync_crypto_retrieve_sync_keys (json_object_get_string_member (json, "bundle"),
-                                                   processed_kft->respHMACkey,
-                                                   processed_kft->respXORkey,
-                                                   unwrapKB);
-
-  if (sync_keys == NULL)
-    goto out;
+  ephy_sync_crypto_retrieve_sync_keys (json_object_get_string_member (json, "bundle"),
+                                       respHMACkey, respXORkey, unwrapKB,
+                                       &kA, &kB);
 
   /* Everything is okay, save the tokens. */
   ephy_sync_service_set_user_email (self, email);
   ephy_sync_service_set_and_store_tokens (self,
                                           g_strdup (keyFetchToken), TOKEN_KEYFETCHTOKEN,
                                           g_strdup (unwrapBKey), TOKEN_UNWRAPBKEY,
-                                          ephy_sync_crypto_encode_hex (sync_keys->kA, 0), TOKEN_KA,
-                                          ephy_sync_crypto_encode_hex (sync_keys->kB, 0), TOKEN_KB,
+                                          ephy_sync_crypto_encode_hex (kA, 0), TOKEN_KA,
+                                          ephy_sync_crypto_encode_hex (kB, 0), TOKEN_KB,
                                           NULL);
+  g_free (kA);
+  g_free (kB);
   retval = TRUE;
 
 out:
-  ephy_sync_crypto_processed_kft_free (processed_kft);
-  ephy_sync_crypto_sync_keys_free (sync_keys);
   json_node_free (node);
   g_free (tokenID);
+  g_free (reqHMACkey);
+  g_free (respHMACkey);
+  g_free (respXORkey);
+  g_free (tokenID_h);
   g_free (unwrapKB);
 
   return retval;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]