You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by cm...@apache.org on 2012/08/06 20:04:25 UTC

svn commit: r1369899 - in /subversion/branches/master-passphrase/subversion: include/svn_auth.h libsvn_auth_gnome_keyring/gnome_keyring.c libsvn_subr/cmdline.c libsvn_subr/masterpass_providers.c

Author: cmpilato
Date: Mon Aug  6 18:04:25 2012
New Revision: 1369899

URL: http://svn.apache.org/viewvc?rev=1369899&view=rev
Log:
On the 'master-passphrase' branch: Get the GNOME Keyring master
passphrase provider working, too.  At least, in theory.  Doesn't seem
to work in practice on my machine just yet ... something about symbol
names not resolving or somesuch.

* subversion/include/svn_auth.h
  svn_auth_get_gnome_keyring_master_passphrase_provider): New function.

* subversion/libsvn_auth_gnome_keyring/gnome_keyring.c
  (master_passphrase_gnome_keyring_first_creds,
   master_passphrase_gnome_keyring_save_creds,
   svn_auth_get_gnome_keyring_master_passphrase_provider): New functions.
  (gnome_keyring_master_passphrase_provider): New structure instance.

* subversion/libsvn_subr/cmdline.c
  (get_master_passphrase_auth_baton): New helper function, abstracted from...
  (open_auth_store): ...here.

* subversion/libsvn_subr/masterpass_providers.c
  (get_provider): Fix expected symbol name for gnome-keyring and kwallet
    master passphrase providers.
  (svn_auth_get_platform_specific_master_passphrase_providers): Enable
    GNOME Keyring master passphrase provider support.

Modified:
    subversion/branches/master-passphrase/subversion/include/svn_auth.h
    subversion/branches/master-passphrase/subversion/libsvn_auth_gnome_keyring/gnome_keyring.c
    subversion/branches/master-passphrase/subversion/libsvn_subr/cmdline.c
    subversion/branches/master-passphrase/subversion/libsvn_subr/masterpass_providers.c

Modified: subversion/branches/master-passphrase/subversion/include/svn_auth.h
URL: http://svn.apache.org/viewvc/subversion/branches/master-passphrase/subversion/include/svn_auth.h?rev=1369899&r1=1369898&r2=1369899&view=diff
==============================================================================
--- subversion/branches/master-passphrase/subversion/include/svn_auth.h (original)
+++ subversion/branches/master-passphrase/subversion/include/svn_auth.h Mon Aug  6 18:04:25 2012
@@ -1373,6 +1373,29 @@ svn_auth_get_gpg_agent_master_passphrase
   svn_auth_provider_object_t **provider,
   apr_pool_t *pool);
 #endif /* !defined(WIN32) || defined(DOXYGEN) */
+
+
+/** Set @a *provider to an authentication provider of type @c
+ * svn_auth_cred_master_passphrase_t, allocated in @a pool.
+ *
+ * @a *provider retrieves its credentials via GNOME Keyring.  The
+ * returned credentials are used to unlock Subversion's encrypted
+ * authentication credential store.
+ *
+ * If the GNOME Keyring is locked the provider calls
+ * @c *SVN_AUTH_PARAM_GNOME_KEYRING_UNLOCK_PROMPT_FUNC in order to unlock
+ * the keyring.
+ *
+ * @c SVN_AUTH_PARAM_GNOME_KEYRING_UNLOCK_PROMPT_BATON is passed to
+ * @c *SVN_AUTH_PARAM_GNOME_KEYRING_UNLOCK_PROMPT_FUNC.
+ *
+ * @since New in 1.8.
+ */
+void
+svn_auth_get_gnome_keyring_master_passphrase_provider(
+  svn_auth_provider_object_t **provider,
+  apr_pool_t *pool);
+
   
 #ifdef __cplusplus
 }

Modified: subversion/branches/master-passphrase/subversion/libsvn_auth_gnome_keyring/gnome_keyring.c
URL: http://svn.apache.org/viewvc/subversion/branches/master-passphrase/subversion/libsvn_auth_gnome_keyring/gnome_keyring.c?rev=1369899&r1=1369898&r2=1369899&view=diff
==============================================================================
--- subversion/branches/master-passphrase/subversion/libsvn_auth_gnome_keyring/gnome_keyring.c (original)
+++ subversion/branches/master-passphrase/subversion/libsvn_auth_gnome_keyring/gnome_keyring.c Mon Aug  6 18:04:25 2012
@@ -32,6 +32,7 @@
 #include "svn_config.h"
 #include "svn_error.h"
 #include "svn_pools.h"
+#include "svn_base64.h"
 
 #include "private/svn_auth_private.h"
 
@@ -531,3 +532,83 @@ svn_auth_get_gnome_keyring_ssl_client_ce
 
   init_gnome_keyring();
 }
+
+
+
+/*-----------------------------------------------------------------------*/
+/* GNOME Keyring master passphrase provider.                             */
+/*-----------------------------------------------------------------------*/
+
+/* An implementation of svn_auth_provider_t::first_credentials() */
+static svn_error_t *
+master_passphrase_gnome_keyring_first_creds(void **credentials,
+                                            void **iter_baton,
+                                            void *provider_baton,
+                                            apr_hash_t *parameters,
+                                            const char *realmstring,
+                                            apr_pool_t *pool)
+{ 
+  svn_boolean_t done;
+  const char *passphrase;
+  svn_boolean_t non_interactive = apr_hash_get(parameters,
+                                               SVN_AUTH_PARAM_NON_INTERACTIVE,
+                                               APR_HASH_KEY_STRING) != NULL;
+
+  *credentials = NULL;
+
+  SVN_ERR(password_get_gnome_keyring(&done, &passphrase, NULL, realmstring,
+                                     NULL, parameters, non_interactive, pool));
+  if (done && passphrase)
+    {
+      svn_auth_cred_master_passphrase_t *creds;
+      creds = apr_pcalloc(pool, sizeof(*creds));
+      creds->passphrase = 
+        svn_base64_decode_string(svn_string_create(passphrase, pool), pool);
+      *credentials = creds;
+    }
+
+  return SVN_NO_ERROR;
+}
+
+
+static svn_error_t *
+master_passphrase_gnome_keyring_save_creds(svn_boolean_t *saved,
+                                           void *credentials,
+                                           void *provider_baton,
+                                           apr_hash_t *parameters,
+                                           const char *realmstring,
+                                           apr_pool_t *pool)
+{
+  svn_auth_cred_master_passphrase_t *creds = credentials;
+  svn_boolean_t non_interactive = apr_hash_get(parameters,
+                                               SVN_AUTH_PARAM_NON_INTERACTIVE,
+                                               APR_HASH_KEY_STRING) != NULL;
+  const svn_string_t *encoded_passphrase =
+    svn_base64_encode_string2(creds->passphrase, FALSE, pool);
+
+  SVN_ERR(password_set_gnome_keyring(saved, NULL, realmstring, NULL,
+                                     encoded_passphrase->data,
+                                     parameters, non_interactive, pool));
+  return SVN_NO_ERROR;
+}
+
+
+static const svn_auth_provider_t gnome_keyring_master_passphrase_provider = {
+  SVN_AUTH_CRED_MASTER_PASSPHRASE,
+  master_passphrase_gnome_keyring_first_creds,
+  NULL,
+  master_passphrase_gnome_keyring_save_creds,
+};
+
+
+/* Public API */
+void
+svn_auth_get_gnome_keyring_master_passphrase_provider(
+  svn_auth_provider_object_t **provider,
+  apr_pool_t *pool)
+{
+  svn_auth_provider_object_t *po = apr_pcalloc(pool, sizeof(*po));
+
+  po->vtable = &gnome_keyring_master_passphrase_provider;
+  *provider = po;
+}

Modified: subversion/branches/master-passphrase/subversion/libsvn_subr/cmdline.c
URL: http://svn.apache.org/viewvc/subversion/branches/master-passphrase/subversion/libsvn_subr/cmdline.c?rev=1369899&r1=1369898&r2=1369899&view=diff
==============================================================================
--- subversion/branches/master-passphrase/subversion/libsvn_subr/cmdline.c (original)
+++ subversion/branches/master-passphrase/subversion/libsvn_subr/cmdline.c Mon Aug  6 18:04:25 2012
@@ -447,6 +447,50 @@ ssl_trust_unknown_server_cert
 }
 
 
+/* Build an authentication baton with the relevant master passphrase
+   providers. */
+static svn_error_t *
+get_master_passphrase_auth_baton(svn_auth_baton_t **mp_ab,
+                                 svn_config_t *cfg,
+                                 const char *config_dir,
+                                 svn_boolean_t no_auth_cache,
+                                 svn_boolean_t non_interactive,
+                                 svn_cmdline_prompt_baton2_t *pb,
+                                 apr_pool_t *pool)
+{
+  svn_auth_provider_object_t *provider;
+  apr_array_header_t *mp_providers;
+
+  /* First, we select our providers. */
+  if (! non_interactive)
+    {
+      SVN_ERR(svn_auth_get_platform_specific_master_passphrase_providers(
+          &mp_providers, cfg, pool));
+      svn_auth_get_master_passphrase_prompt_provider(
+          &provider, svn_cmdline_auth_master_passphrase_prompt,
+          pb, 3, pool);
+      APR_ARRAY_PUSH(mp_providers, svn_auth_provider_object_t *) = provider;
+    }
+
+  /* Then, we create the auth baton. */
+  svn_auth_open(mp_ab, mp_providers, pool);
+
+  /* Finally, we'll set some useful parameters on the baton. */
+  if (no_auth_cache)
+    svn_auth_set_parameter(*mp_ab, SVN_AUTH_PARAM_NO_AUTH_CACHE, "");
+  if (non_interactive)
+    svn_auth_set_parameter(*mp_ab, SVN_AUTH_PARAM_NON_INTERACTIVE, "");
+  if (config_dir)
+    svn_auth_set_parameter(*mp_ab, SVN_AUTH_PARAM_CONFIG_DIR, config_dir);
+#ifdef SVN_HAVE_GNOME_KEYRING
+  svn_auth_set_parameter(*mp_ab,
+                         SVN_AUTH_PARAM_GNOME_KEYRING_UNLOCK_PROMPT_FUNC,
+                         &svn_cmdline__auth_gnome_keyring_unlock_prompt);
+#endif /* SVN_HAVE_GNOME_KEYRING */
+
+  return SVN_NO_ERROR;
+}
+
 /* Instantiate and open an auth store. */
 static svn_error_t *
 open_auth_store(svn_auth__store_t **auth_store_p,
@@ -465,33 +509,13 @@ open_auth_store(svn_auth__store_t **auth
       svn_crypto__ctx_t *crypto_ctx;
       const char *auth_config_path, *auth_db_path;
       svn_auth_baton_t *mp_ab;
-      svn_auth_provider_object_t *provider;
-      apr_array_header_t *mp_providers;
 
       SVN_ERR(svn_config_get_user_config_path(&auth_config_path, config_dir,
                                               SVN_CONFIG__AUTH_SUBDIR, pool));
       auth_db_path = svn_path_join(auth_config_path, "pathetic.db", pool);
-
-      /* Build an authentication baton with the relevant master
-         passphrase providers. */
-      if (! non_interactive)
-        {
-          SVN_ERR(svn_auth_get_platform_specific_master_passphrase_providers(
-              &mp_providers, cfg, pool));
-          svn_auth_get_master_passphrase_prompt_provider(
-              &provider, svn_cmdline_auth_master_passphrase_prompt,
-              pb, 3, pool);
-          APR_ARRAY_PUSH(mp_providers, svn_auth_provider_object_t *) = provider;
-        }
-      svn_auth_open(&mp_ab, mp_providers, pool);
-
-      if (no_auth_cache)
-        svn_auth_set_parameter(mp_ab, SVN_AUTH_PARAM_NO_AUTH_CACHE, "");
-      if (non_interactive)
-        svn_auth_set_parameter(mp_ab, SVN_AUTH_PARAM_NON_INTERACTIVE, "");
-      if (config_dir)
-        svn_auth_set_parameter(mp_ab, SVN_AUTH_PARAM_CONFIG_DIR, config_dir);
-
+      SVN_ERR(get_master_passphrase_auth_baton(&mp_ab, cfg, config_dir,
+                                               no_auth_cache, non_interactive,
+                                               pb, pool));
       SVN_ERR(svn_config_get_user_config_path(&auth_config_path, config_dir,
                                               SVN_CONFIG__AUTH_SUBDIR, pool));
       SVN_ERR(svn_crypto__context_create(&crypto_ctx, pool));

Modified: subversion/branches/master-passphrase/subversion/libsvn_subr/masterpass_providers.c
URL: http://svn.apache.org/viewvc/subversion/branches/master-passphrase/subversion/libsvn_subr/masterpass_providers.c?rev=1369899&r1=1369898&r2=1369899&view=diff
==============================================================================
--- subversion/branches/master-passphrase/subversion/libsvn_subr/masterpass_providers.c (original)
+++ subversion/branches/master-passphrase/subversion/libsvn_subr/masterpass_providers.c Mon Aug  6 18:04:25 2012
@@ -182,7 +182,7 @@ get_provider(svn_auth_provider_object_t 
       library_label = apr_psprintf(pool, "svn_%s", provider_name);
       provider_func_name = 
         apr_psprintf(pool,
-                     "svn_auth__get_%s_master_passphrase_provider",
+                     "svn_auth_get_%s_master_passphrase_provider",
                      provider_name);
       version_func_name = 
         apr_psprintf(pool, "svn_auth_%s_version", provider_name);
@@ -263,10 +263,8 @@ svn_auth_get_platform_specific_master_pa
       /* GNOME Keyring */
       if (apr_strnatcmp(password_store, "gnome-keyring") == 0)
         {
-#if 0
           SVN_ERR(get_provider(&provider, "gnome_keyring", pool));
           SVN__MAYBE_ADD_PROVIDER(*providers, provider);
-#endif
           continue;
         }