2 * ssl_client_cert_pw_providers.c: providers for
3 * SVN_AUTH_CRED_SSL_CLIENT_CERT_PW
5 * ====================================================================
6 * Copyright (c) 2000-2004 CollabNet. All rights reserved.
8 * This software is licensed as described in the file COPYING, which
9 * you should have received as part of this distribution. The terms
10 * are also available at http://subversion.tigris.org/license-1.html.
11 * If newer versions of this license are posted there, you may use a
12 * newer version instead, at your option.
14 * This software consists of voluntary contributions made by many
15 * individuals. For exact contribution history, see the revision
16 * history and logs, available at http://subversion.tigris.org/.
17 * ====================================================================
20 /* ==================================================================== */
26 #include <apr_pools.h>
28 #include "svn_error.h"
29 #include "svn_config.h"
32 /*-----------------------------------------------------------------------*/
34 /*-----------------------------------------------------------------------*/
36 /* retrieve and load a password for a client certificate from servers file */
38 ssl_client_cert_pw_file_first_credentials(void **credentials_p
,
41 apr_hash_t
*parameters
,
42 const char *realmstring
,
45 svn_config_t
*cfg
= apr_hash_get(parameters
,
46 SVN_AUTH_PARAM_CONFIG
,
48 const char *server_group
= apr_hash_get(parameters
,
49 SVN_AUTH_PARAM_SERVER_GROUP
,
52 const char *password
=
53 svn_config_get_server_setting(cfg
, server_group
,
54 SVN_CONFIG_OPTION_SSL_CLIENT_CERT_PASSWORD
,
58 svn_auth_cred_ssl_client_cert_pw_t
*cred
59 = apr_palloc(pool
, sizeof(*cred
));
60 cred
->password
= password
;
61 cred
->may_save
= FALSE
;
62 *credentials_p
= cred
;
64 else *credentials_p
= NULL
;
70 static const svn_auth_provider_t ssl_client_cert_pw_file_provider
= {
71 SVN_AUTH_CRED_SSL_CLIENT_CERT_PW
,
72 ssl_client_cert_pw_file_first_credentials
,
78 /*** Public API to SSL file providers. ***/
79 void svn_auth_get_ssl_client_cert_pw_file_provider
80 (svn_auth_provider_object_t
**provider
, apr_pool_t
*pool
)
82 svn_auth_provider_object_t
*po
= apr_pcalloc(pool
, sizeof(*po
));
83 po
->vtable
= &ssl_client_cert_pw_file_provider
;
88 /*-----------------------------------------------------------------------*/
90 /*-----------------------------------------------------------------------*/
92 /* Baton type for client passphrase prompting.
93 There is no iteration baton type. */
96 svn_auth_ssl_client_cert_pw_prompt_func_t prompt_func
;
99 /* how many times to re-prompt after the first one fails */
101 } ssl_client_cert_pw_prompt_provider_baton_t
;
103 /* Iteration baton. */
106 /* The original provider baton */
107 ssl_client_cert_pw_prompt_provider_baton_t
*pb
;
109 /* The original realmstring */
110 const char *realmstring
;
112 /* how many times we've reprompted */
114 } ssl_client_cert_pw_prompt_iter_baton_t
;
118 ssl_client_cert_pw_prompt_first_cred(void **credentials_p
,
120 void *provider_baton
,
121 apr_hash_t
*parameters
,
122 const char *realmstring
,
125 ssl_client_cert_pw_prompt_provider_baton_t
*pb
= provider_baton
;
126 ssl_client_cert_pw_prompt_iter_baton_t
*ib
=
127 apr_pcalloc(pool
, sizeof(*ib
));
128 const char *no_auth_cache
= apr_hash_get(parameters
,
129 SVN_AUTH_PARAM_NO_AUTH_CACHE
,
130 APR_HASH_KEY_STRING
);
132 SVN_ERR(pb
->prompt_func((svn_auth_cred_ssl_client_cert_pw_t
**)
133 credentials_p
, pb
->prompt_baton
, realmstring
,
134 ! no_auth_cache
, pool
));
137 ib
->realmstring
= apr_pstrdup(pool
, realmstring
);
146 ssl_client_cert_pw_prompt_next_cred(void **credentials_p
,
148 void *provider_baton
,
149 apr_hash_t
*parameters
,
150 const char *realmstring
,
153 ssl_client_cert_pw_prompt_iter_baton_t
*ib
= iter_baton
;
154 const char *no_auth_cache
= apr_hash_get(parameters
,
155 SVN_AUTH_PARAM_NO_AUTH_CACHE
,
156 APR_HASH_KEY_STRING
);
158 if (ib
->retries
>= ib
->pb
->retry_limit
)
160 /* give up, go on to next provider. */
161 *credentials_p
= NULL
;
166 SVN_ERR(ib
->pb
->prompt_func((svn_auth_cred_ssl_client_cert_pw_t
**)
167 credentials_p
, ib
->pb
->prompt_baton
,
168 ib
->realmstring
, ! no_auth_cache
, pool
));
174 static const svn_auth_provider_t client_cert_pw_prompt_provider
= {
175 SVN_AUTH_CRED_SSL_CLIENT_CERT_PW
,
176 ssl_client_cert_pw_prompt_first_cred
,
177 ssl_client_cert_pw_prompt_next_cred
,
182 void svn_auth_get_ssl_client_cert_pw_prompt_provider
183 (svn_auth_provider_object_t
**provider
,
184 svn_auth_ssl_client_cert_pw_prompt_func_t prompt_func
,
189 svn_auth_provider_object_t
*po
= apr_pcalloc(pool
, sizeof(*po
));
190 ssl_client_cert_pw_prompt_provider_baton_t
*pb
=
191 apr_palloc(pool
, sizeof(*pb
));
193 pb
->prompt_func
= prompt_func
;
194 pb
->prompt_baton
= prompt_baton
;
195 pb
->retry_limit
= retry_limit
;
197 po
->vtable
= &client_cert_pw_prompt_provider
;
198 po
->provider_baton
= pb
;