包含冒号的cURL和密码

时间:2017-03-22 07:50:22

标签: curl passwords dashdb

我正在开发OpenSuse,并尝试通过cURL实用程序向dashDB Local环境进行数据上传。当我使用带有简单密码的用户/密码(没有'特殊字符)时,它运行良好,但是当密码包含冒号时,它始终会失败,无论指定夫妻用户名/密码的方式如何。

任务工作:

curl -X POST -H "Content-Type: multipart/form-data" -u "myuser:mypassword" "https://my_url" -F loadFile1=@"inputfile"

{"result":{...,"resultCode":"SUCCESS","errorMessageCode":"NONE","message":"LOAD started successfully."}

任务无效:

curl -X POST -H "Content-Type: multipart/form-data" -u "myuser:my:password" "https://my_url" -F loadFile1=@"inputfile"

Error 401: Basic authorization - bad header

我尝试了一些事情,比如逃避冒号,用%3A替换它,将它放在.netrc文件中,直接放在网址(https://myuser:my:password@my_url)等等。 ,但是对于每种情况都失败了......

我非常确定它不是cURL失败的原因,因为当我通过cURL对Cloudant环境执行类似的任务并使用冒号输入密码时,它运行良好:

[i1058@lat111 ~]$ curl -X POST -H "Content-Type: application/json" -u "myuser:my:password" http://myuser.cloudant.com/mydb/_bulk_docs -d "@inputfile"
[{"ok":true,"id":"125ac5859f1e6f0de25e0ed33abd3198","rev":"1-c7e75ed33e6efae85d053acc1008c2c6"},...]

如何指定这样的密码?

修改:

以下是两个执行的标题:

工作执行:

[i1058@lat111 ~]$ curl -X POST -H "Content-Type: multipart/form-data" "https://user1:infotel0@192.168.42.219:8443/dashdb-api/load/local/del/USER1.EMPLOYEE?hasHeaderRow=false&delimiter=','&codePage=1208&hasDateTypes=true&dateFormat="YYYY-MM-DD"" -F loadFile1=@"outfile" -v
* About to connect() to proxy 192.168.42.219 port 3128 (#0)
*   Trying 192.168.42.219...
* Connected to 192.168.42.219 (192.168.42.219) port 3128 (#0)
* Establish HTTP proxy tunnel to 192.168.42.219:8443
* Server auth using Basic with user 'user1'
> CONNECT 192.168.42.219:8443 HTTP/1.1
> Host: 192.168.42.219:8443
> User-Agent: curl/7.29.0
> Proxy-Connection: Keep-Alive
> 
< HTTP/1.1 200 Connection established
< Date: Wed, 22 Mar 2017 13:24:05 GMT
< Content-Type: text/html
< Proxy-Connection: Keep-Alive
< Via: 1.1 TO-PROXY.****
< Connection: close
< 
* Proxy replied OK to CONNECT request
* Initializing NSS with certpath: sql:/etc/pki/nssdb
* skipping SSL peer certificate verification
* SSL connection using TLS_RSA_WITH_AES_128_CBC_SHA
* Server certificate:
*       subject: CN=localhost,OU=dsweb,O=ibm,C=us
*       start date: Sep 08 17:37:29 2016 GMT
*       expire date: Sep 08 17:37:29 2017 GMT
*       common name: localhost
*       issuer: CN=localhost,OU=dsweb,O=ibm,C=us
* Server auth using Basic with user 'user1'
> POST /dashdb-api/load/local/del/USER1.EMPLOYEE?hasHeaderRow=false&delimiter=','&codePage=1208&hasDateTypes=true&dateFormat=YYYY-MM-DD HTTP/1.1
> Authorization: Basic dXNlcjE6aW5mb3RlbDA=
> User-Agent: curl/7.29.0
> Host: 192.168.42.219:8443
> Accept: */*
> Content-Length: 5260
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=----------------------------cbd0c10a30ab
> 
< HTTP/1.1 100 Continue
< Content-Length: 0
< Date: Wed, 22 Mar 2017 13:24:06 GMT
< HTTP/1.1 200 OK
< Date: Wed, 22 Mar 2017 13:24:06 GMT
< X-Powered-By: Servlet/3.0
< Content-Type: application/json
< Content-Length: 423
< Set-Cookie: dsweb9302=00008jj9QpxOaIwwbWcGZddJ9V8:91d35242-6b49-4d90-9c18-5543188442ec; Path=/; HttpOnly
< Expires: Thu, 01 Dec 1994 16:00:00 GMT
< Cache-Control: no-cache="set-cookie, set-cookie2"
< 
{"result":{"ROWS_COMMITTED":"","LOAD_LOGFILE":"loadlogs\/load_1982878712_USER1_EMPLOYEE_20170322-132406-UTC.txt","START_TIME":"20170322 13:24:06 UTC","LOAD_STATUS":"RUNNING","LOAD_ID":1982878712,"ROWS_LOADED":"","TABLE":"EMPLOYEE","ROWS_SKIPPED":"","END_TIME":"","SCHEMA":"USER1","ROWS_READ":"","ROWS_DELETED":"","ROWS_REJECTED":""},"resultCode":"SUCCESS","errorMessageCode":"NONE","message":"LOAD started successfully."}
* Connection #0 to host 192.168.42.219 left intact

然后失败者:

[i1058@lat111 ~]$ curl -X POST -H "Content-Type: multipart/form-data" "https://user5:infotel%3A0@192.168.42.219:8443/dashdb-api/load/local/del/USER1.EMPLOYEE?hasHeaderRow=false&delimiter=','&codePage=1208&hasDateTypes=true&dateFormat="YYYY-MM-DD"" -F loadFile1=@"outfile" -v       
* About to connect() to proxy 192.168.42.219 port 3128 (#0)
*   Trying 192.168.42.219...
* Connected to 192.168.42.219 (192.168.42.219) port 3128 (#0)
* Establish HTTP proxy tunnel to 192.168.42.219:8443
* Server auth using Basic with user 'user5'
> CONNECT 192.168.42.219:8443 HTTP/1.1
> Host: 192.168.42.219:8443
> User-Agent: curl/7.29.0
> Proxy-Connection: Keep-Alive
> 
< HTTP/1.1 200 Connection established
< Date: Wed, 22 Mar 2017 13:22:23 GMT
< Content-Type: text/html
< Proxy-Connection: Keep-Alive
< Via: 1.1 TO-PROXY.****
< Connection: close
< 
* Proxy replied OK to CONNECT request
* Initializing NSS with certpath: sql:/etc/pki/nssdb
* skipping SSL peer certificate verification
* SSL connection using TLS_RSA_WITH_AES_128_CBC_SHA
* Server certificate:
*       subject: CN=localhost,OU=dsweb,O=ibm,C=us
*       start date: Sep 08 17:37:29 2016 GMT
*       expire date: Sep 08 17:37:29 2017 GMT
*       common name: localhost
*       issuer: CN=localhost,OU=dsweb,O=ibm,C=us
* Server auth using Basic with user 'user5'
> POST /dashdb-api/load/local/del/USER1.EMPLOYEE?hasHeaderRow=false&delimiter=','&codePage=1208&hasDateTypes=true&dateFormat=YYYY-MM-DD HTTP/1.1
> Authorization: Basic dXNlcjU6aW5mb3RlbDow
> User-Agent: curl/7.29.0
> Host: 192.168.42.219:8443
> Accept: */*
> Content-Length: 5260
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=----------------------------69215f2ae3da
> 
< HTTP/1.1 100 Continue
< Content-Length: 0
< Date: Wed, 22 Mar 2017 13:22:24 GMT
< HTTP/1.1 401 Unauthorized
< Date: Wed, 22 Mar 2017 13:22:24 GMT
< X-Powered-By: Servlet/3.0
< Content-Type: text/html;charset=UTF-8
< $WSEP:                  <-- Here there is something strange??
< Content-Language: en-US
< Set-Cookie: dsweb9302=0000ihijrP8WYwpQW8TCOzRB-gv:91d35242-6b49-4d90-9c18-5543188442ec; Path=/; HttpOnly
< Transfer-Encoding: chunked
< Expires: Thu, 01 Dec 1994 16:00:00 GMT
< Cache-Control: no-cache="set-cookie, set-cookie2"
* HTTP error before end of send, stop sending
< 
Error 401: Basic authorization - bad header
* Closing connection 0
[i1058@lat111 ~]$ curl -X POST -H "Content-Type: multipart/form-data" "https://user5:infotel%3A0@192.168.42.219:8443/dashdb-api/load/local/del/USER1.EMPLOYEE?hasHeaderRow=false&delimiter=','&codePage=1208&hasDateTypes=true&dateFormat="YYYY-MM-DD"" -F loadFile1=@"outfile" 
Error 401: Basic authorization - bad header

1 个答案:

答案 0 :(得分:1)

最近在使用需要用户名传递的API进行身份验证时遇到了类似的问题:用户组作为用户名传递,中间使用冒号。在用户名:用户组周围加上双引号对我有用。

这不起作用:

-u "username:usergroup:password"

这确实有效:

-u ""username:usergroup":password"

因此,这应该适用于包含冒号的密码:

-u "username:"password""