11netCDF Authorization Support
2- ============================
2+ ======================================
33<!-- double header is needed to workaround doxygen bug -->
44
55# netCDF Authorization Support {#Header}
@@ -37,29 +37,92 @@ directly insert the username and the password into a url in this form.
3737This username and password will be used if the server asks for
3838authentication. Note that only simple password authentication
3939is supported in this format.
40+
4041Specifically note that [ redirection-based] ( #REDIR )
41- authorization will not work with this because the username and password
42- will only be used on the initial request, not the redirection
42+ authorization may work with this but it is a security risk.
43+ This is because the username and password
44+ may be sent to each server in the redirection chain.
45+
46+ Note also that the ` user:password ` form may contain characters that must be
47+ escaped. See the <a href =" #USERPWDESCAPE " >password escaping</a > section to see
48+ how to properly escape the user and password.
4349
4450## RC File Authentication {#DODSRC}
4551The netcdf library supports an _ rc_ file mechanism to allow the passing
4652of a number of parameters to libnetcdf and libcurl.
53+ Locating the _ rc_ file is a multi-step process.
54+
55+ ### Search Order
4756
4857The file must be called one of the following names:
4958".daprc" or ".dodsrc".
5059If both ".daprc" and ".dodsrc" exist, then
5160the ".daprc" file will take precedence.
5261
53- The rc file is searched for first in the current directory
54- and then in the home directory (as defined by the HOME environment
55- variable).
62+ It is strongly suggested that you pick one of the two names
63+ and use it always. Otherwise you may observe unexpected results
64+ when the netcdf-c library finds one that you did not intend.
65+
66+ The search for an _ rc_ file looks in the following places in this order.
67+
68+ 1 . Check for the environment variable named _ DAPRCFILE_ .
69+ This will specify the full path for the _ rc_ file
70+ (not just the containing directory).
71+ 2 . Search the current working directory (` ./ ` ) looking
72+ for (in order) .daprc or .dodsrc.
73+ 3 . Search the HOME directory (` $HOME ` ) looking
74+ for (in order) .daprc or .dodsrc. The HOME environment
75+ variable is used to define the directory in which to search.
76+
77+ It is strongly suggested that you pick a uniform location
78+ and use it always. Otherwise you may observe unexpected results
79+ when the netcdf-c library get an rc file you did not expect.
80+
81+ ### RC File Format
5682
5783The rc file format is a series of lines of the general form:
5884
5985 [<host:port>]<key>=<value>
6086
61- where the bracket-enclosed host: port is optional and will be discussed
62- subsequently.
87+ where the bracket-enclosed host: port is optional.
88+
89+ ### URL Constrained RC File Entries
90+
91+ Each line of the rc file can begin with
92+ a host+port enclosed in square brackets.
93+ The form is "host: port ".
94+ If the port is not specified
95+ then the form is just "host".
96+ The reason that more of the url is not used is that
97+ libcurl's authorization grain is not any finer than host level.
98+
99+ Examples.
100+
101+ [remotetest.unidata.ucar.edu]HTTP.VERBOSE=1
102+
103+ or
104+
105+ [fake.ucar.edu:9090]HTTP.VERBOSE=0
106+
107+ If the url request from, say, the _ netcdf_open_ method
108+ has a host+port matching one of the prefixes in the rc file, then
109+ the corresponding entry will be used, otherwise ignored.
110+ This means that an entry with a matching host+port will take
111+ precedence over an entry without a host+port.
112+
113+ For example, the URL
114+
115+ http://remotetest.unidata.ucar.edu/thredds/dodsC/testdata/testData.nc
116+
117+ will have HTTP.VERBOSE set to 1 because its host matches the example above.
118+
119+ Similarly,
120+
121+ http://fake.ucar.edu:9090/dts/test.01
122+
123+ will have HTTP.VERBOSE set to 0 because its host+port matches the example above.
124+
125+ ## Authorization-Related Keys {#AUTHKEYS}
63126
64127The currently defined set of authorization-related keys are as follows.
65128The second column is the affected curl_easy_setopt option(s), if any.
@@ -71,12 +134,12 @@ The second column is the affected curl_easy_setopt option(s), if any.
71134<tr ><td >HTTP.SSL.CERTIFICATE</td ><td >CURLOPT_SSLCERT</td >
72135<tr ><td >HTTP.SSL.KEY</td ><td >CURLOPT_SSLKEY</td >
73136<tr ><td >HTTP.SSL.KEYPASSWORD</td ><td >CURLOPT_KEYPASSWORD</td >
74- <tr ><td >HTTP.SSL.CAINFO</td ><td >CURLOPT_SSLCAINFO </td >
75- <tr ><td >HTTP.SSL.CAPATH</td ><td >CURLOPT_SSLCAPATH </td >
137+ <tr ><td >HTTP.SSL.CAINFO</td ><td >CURLOPT_CAINFO </td >
138+ <tr ><td >HTTP.SSL.CAPATH</td ><td >CURLOPT_CAPATH </td >
76139<tr ><td >HTTP.SSL.VERIFYPEER</td ><td >CURLOPT_SSL_VERIFYPEER</td >
77140<tr ><td >HTTP.SSL.VALIDATE</td ><td >CURLOPT_SSL_VERIFYPEER, CURLOPT_SSL_VERIFYHOST</td >
78141<tr ><td >HTTP.CREDENTIALS.USERPASSWORD</td ><td >CURLOPT_USERPASSWORD</td >
79- <tr ><td >HTTP.NETRC</td ><td >N.A.</ td >< td >Specify path of the .netrc file </td >
142+ <tr ><td >HTTP.NETRC</td ><td >CURLOPT_NETRC,CURLOPT_NETRC_FILE </td >
80143</table >
81144
82145### Password Authentication
@@ -86,7 +149,9 @@ HTTP.CREDENTIALS.USERPASSWORD
86149can be used to set the simple password authentication.
87150This is an alternative to setting it in the url.
88151The value must be of the form "username: password ".
89- See <a href =" #REDIR " >redirection authorization</a >
152+ See the <a href =" #USERPWDESCAPE " >password escaping</a > section
153+ to see how this value must escape certain characters.
154+ Also see <a href =" #REDIR " >redirection authorization</a >
90155for important additional information.
91156
92157### Cookie Jar
@@ -129,6 +194,29 @@ specifies the absolute path of the .netrc file.
129194See [ redirection authorization] ( #REDIR )
130195for information about using .netrc.
131196
197+ ## Password Escaping {#USERPWDESCAPE}
198+
199+ With current password rules, it is is not unlikely that the password
200+ will contain characters that need to be escaped. Similarly, the user
201+ may contain characters such as '@' that need to be escaped. To support this,
202+ it is assumed that all occurrences of ` user:password ` use URL (i.e. %%XX)
203+ escaping for at least the characters in the table below.
204+
205+ The minimum set of characters that must be escaped depends on the location.
206+ If the user+pwd is embedded in the URL, then '@' and ':' __ must__ be escaped.
207+ If the user+pwd is the value for
208+ the HTTP.CREDENTIALS.USERPASSWORD key in the _ rc_ file, then
209+ ':' __ must__ be escaped.
210+ Escaping should __ not__ be used in the ` .netrc ` file.
211+
212+ The relevant escape codes are as follows.
213+ <table >
214+ <tr ><th >Character</th ><th >Escaped Form</th >
215+ <tr ><td >'@'</td ><td >%40</td >
216+ <tr ><td >':'</td ><td >%3a</td >
217+ </table >
218+ Additional characters can be escaped if desired.
219+
132220## Redirection-Based Authentication {#REDIR}
133221
134222Some sites provide authentication by using a third party site
@@ -145,16 +233,18 @@ using the _https_ protocol (note the use of _https_ instead of _http_).
1452334 . URS sends a redirect (with authorization information) to send
146234the client back to the SOI to actually obtain the data.
147235
148- It turns out that libcurl uses the password in the ` .daprc `
149- file (or from the url)
150- only for the initial connection. This causes problems because
151- the redirected connection is the one that actually requires the password.
152- This is where the ` .netrc ` file comes in. Libcurl will use ` .netrc ` for
153- the redirected connection. It is possible to cause libcurl to use
154- the ` .daprc ` password always, but this introduces a security hole
155- because it may send the initial user+pwd to the redirection site.
156- In summary, if you are using redirection, then you must create a ` .netrc `
157- file to hold the password for the site to which the redirection is sent.
236+ It turns out that libcurl, by default, uses the password in the
237+ ` .daprc ` file (or from the url) for all connections that request
238+ a password. This causes problems because only the the specific
239+ redirected connection is the one that actually requires the password.
240+ This is where the ` .netrc ` file comes in. Libcurl will use ` .netrc `
241+ for the redirected connection. It is possible to cause libcurl
242+ to use the ` .daprc ` password always, but this introduces a
243+ security hole because it may send the initial user+pwd to every
244+ server in the redirection chain.
245+ In summary, if you are using redirection, then you are
246+ ''strongly'' encouraged to create a ` .netrc ` file to hold the
247+ password for the site to which the redirection is sent.
158248
159249The format of this ` .netrc ` file will contain lines that
160250typically look like this.
@@ -165,52 +255,19 @@ where the machine, mmmmmm, is the hostname of the machine to
165255which the client is redirected for authorization, and the
166256login and password are those needed to authenticate on that machine.
167257
168- The ` .netrc ` file can be specified by
258+ The location of the ` .netrc ` file can be specified by
169259putting the following line in your ` .daprc ` /` .dodsrc ` file.
170260
171261 HTTP.NETRC=<path to netrc file>
172262
263+ If not specified, then libcurl will look first in the current
264+ directory, and then in the HOME directory.
265+
173266One final note. In using this, you MUST
174267to specify a real file in the file system to act as the
175268cookie jar file (HTTP.COOKIEJAR) so that the
176269redirect site can properly pass back authorization information.
177270
178- ## URL Constrained RC File Entries {#URLCONS}
179-
180- Each line of the rc file can begin with
181- a host+port enclosed in square brackets.
182- The form is "host: port ".
183- If the port is not specified
184- then the form is just "host".
185- The reason that more of the url is not used is that
186- libcurl's authorization grain is not any finer than host level.
187-
188- Examples.
189-
190- [remotetest.unidata.ucar.edu]HTTP.VERBOSE=1
191-
192- or
193-
194- [fake.ucar.edu:9090]HTTP.VERBOSE=0
195-
196- If the url request from, say, the _ netcdf_open_ method
197- has a host+port matching one of the prefixes in the rc file, then
198- the corresponding entry will be used, otherwise ignored.
199- This means that an entry with a matching host+port will take
200- precedence over an entry without a host+port.
201-
202- For example, the URL
203-
204- http://remotetest.unidata.ucar.edu/thredds/dodsC/testdata/testData.nc
205-
206- will have HTTP.VERBOSE set to 1 because its host matches the example above.
207-
208- Similarly,
209-
210- http://fake.ucar.edu:9090/dts/test.01
211-
212- will have HTTP.VERBOSE set to 0 because its host+port matches the example above.
213-
214271## Client-Side Certificates {#CLIENTCERTS}
215272
216273Some systems, notably ESG (Earth System Grid), requires
@@ -244,8 +301,8 @@ the code is definitive.
244301<tr ><td >HTTP.SSL.CERTIFICATE</td ><td >CUROPT_SSLCERT</td >
245302<tr ><td >HTTP.SSL.KEY</td ><td >CUROPT_SSLKEY</td >
246303<tr ><td >HTTP.SSL.KEYPASSWORD</td ><td >CUROPT_KEYPASSWORD</td >
247- <tr ><td >HTTP.SSL.CAINFO</td ><td >CUROPT_SSLCAINFO </td >
248- <tr ><td >HTTP.SSL.CAPATH</td ><td >CUROPT_SSLCAPATH </td >
304+ <tr ><td >HTTP.SSL.CAINFO</td ><td >CUROPT_CAINFO </td >
305+ <tr ><td >HTTP.SSL.CAPATH</td ><td >CUROPT_CAPATH </td >
249306<tr ><td >HTTP.SSL.VERIFYPEER</td ><td >CUROPT_SSL_VERIFYPEER</td >
250307<tr ><td >HTTP.CREDENTIALS.USERPASSWORD</td ><td >CUROPT_USERPASSWORD</td >
251308<tr ><td >HTTP.NETRC</td ><td >CURLOPT_NETRC,CURLOPT_NETRC_FILE</td >
0 commit comments