gcr: Check that secret exchanged data has correct protocol prefix
authorStef Walter <stefw@collabora.co.uk>
Sat, 1 Oct 2011 11:27:03 +0000 (13:27 +0200)
committerStef Walter <stefw@collabora.co.uk>
Sat, 1 Oct 2011 11:27:03 +0000 (13:27 +0200)
 * This is for future backward compatibility, so when we have more
   than one protocol, we can be sure we can identify the old one.

gcr/gcr-secret-exchange.c

index 492fde5..92899ad 100644 (file)
@@ -82,6 +82,8 @@ EGG_SECURE_DECLARE (secret_exchange);
  * transport encryption is done with 128 bit AES.
  */
 
+#define SECRET_EXCHANGE_PROTOCOL_1_PREFIX "[" GCR_SECRET_EXCHANGE_PROTOCOL_1 "]\n"
+
 enum {
        PROP_0,
        PROP_PROTOCOL
@@ -290,6 +292,11 @@ gcr_secret_exchange_begin (GcrSecretExchange *self)
        result = g_key_file_to_data (output, NULL, NULL);
        g_return_val_if_fail (result != NULL, NULL);
 
+       g_strchomp (result);
+
+       if (g_str_has_prefix (result, SECRET_EXCHANGE_PROTOCOL_1_PREFIX))
+               g_warning ("the prepared data does not have the correct protocol prefix");
+
        g_key_file_free (output);
 
        return result;
@@ -531,6 +538,12 @@ gcr_secret_exchange_send (GcrSecretExchange *self,
 
        result = g_key_file_to_data (output, NULL, NULL);
        g_return_val_if_fail (result != NULL, NULL);
+
+       g_strchomp (result);
+
+       if (g_str_has_prefix (result, SECRET_EXCHANGE_PROTOCOL_1_PREFIX))
+               g_warning ("the prepared data does not have the correct protocol prefix");
+
        g_key_file_free (output);
        return result;
 }