How to override Kong Gateway default certificates in Kubernetes - ssl

I'm trying to set up an SSL certificate for Kong 2.7 installed in Kubernetes but I am not getting this to work as expected. I tried to follow this guide. Even looking for additional help in discussion .
curl -X POST http://kong-admin:8001/certificates -F "cert=kong.lan.pem" -F "key=kong.lan.key" -F "snis[0]=mydomain.net"
This is my response:
{
"fields": {
"cert": "invalid certificate: x509.new: asn1/a_d2i_fp.c:197:error:0D06B08E:asn1 encoding routines:asn1_d2i_read_bio:not enough data",
"key": "invalid key: pkey.new:load_key: asn1/a_d2i_fp.c:197:error:0D06B08E:asn1 encoding routines:asn1_d2i_read_bio:not enough data"
},
"message": "2 schema violations (cert: invalid certificate: x509.new: asn1/a_d2i_fp.c:197:error:0D06B08E:asn1 encoding routines:asn1_d2i_read_bio:not enough data; key: invalid key: pkey.new:load_key: asn1/a_d2i_fp.c:197:error:0D06B08E:asn1 encoding routines:asn1_d2i_read_bio:not enough data)",
"name": "schema violation",
"code": 2
}
Kong deployed with helm chart:
$ helm repo add kong https://charts.konghq.com
$ helm repo update
$ helm install kong/kong --generate-name --set ingressController.enabled=true --set admin.enabled=True --set admin.http.enabled=True --set ingress.enabled=True --set proxy.ingress.enabled=True --set admin.type=LoadBalancer --set proxy.type=LoadBalancer
Does any of you know how to make this working or how to add tls.crt and tls.key into Kong Deployment?

You just miss the # on the curl command to upload files
curl -X POST http://kong-admin:8001/certificates -F "cert=#kong.lan.pem" -F "key=#kong.lan.key" -F "snis[0]=mydomain.net"
curl -X POST http://localhost:8001/certificates -F "cert=kong.lan.pem" -F "key=kong.lan.key" -F "snis[0]=mydomain.net"
will send
POST /certificates HTTP/1.1
Host: localhost:8001
User-Agent: curl/7.68.0
Accept: */*
Content-Length: 363
Content-Type: multipart/form-data; boundary=------------------------d67ae21b533e5746
--------------------------d67ae21b533e5746
Content-Disposition: form-data; name="cert"
kong.lan.pem
--------------------------d67ae21b533e5746
Content-Disposition: form-data; name="key"
kong.lan.key
--------------------------d67ae21b533e5746
Content-Disposition: form-data; name="snis[0]"
mydomain.net
--------------------------d67ae21b533e5746--
echo "toto" >| kong.lan.pem
curl -X POST http://localhost:8001/certificates -F "cert=#kong.lan.pem" -F "key=kong.lan.key" -F "snis[0]=mydomain.net"
will send
POST /certificates HTTP/1.1
Host: localhost:8001
User-Agent: curl/7.68.0
Accept: */*
Content-Length: 421
Content-Type: multipart/form-data; boundary=------------------------973b3467e461334a
--------------------------973b3467e461334a
Content-Disposition: form-data; name="cert"; filename="kong.lan.pem"
Content-Type: application/octet-stream
toto
--------------------------973b3467e461334a
Content-Disposition: form-data; name="key"
kong.lan.key
--------------------------973b3467e461334a
Content-Disposition: form-data; name="snis[0]"
mydomain.net
--------------------------973b3467e461334a--

Related

Converge API : error 6042 - Invalid Request Format

Request Url:
https://api.convergepay.com/VirtualMerchant/processxml.do
Here is my Sample Xml Request:
xmldata=<txn>
<ssl_merchant_id>my_merchant_id</ssl_merchant_id>
<ssl_user_id>my_user_id</ssl_user_id>
<ssl_pin>my_pin</ssl_pin>
<ssl_transaction_type>ccsale</ssl_transaction_type><ssl_card_number>4000000000000002</ssl_card_number>
<ssl_exp_ date>1124</ssl_exp_date>
<ssl_amount>1.00</ssl_amount>
<ssl_cvv2cvc2_indicator>1</ssl_cvv2cvc2_indicator>
<ssl_cvv2cvc2>786</ssl_cvv2cvc2>
<ssl_first_name>adolfo</ssl_first_name></txn>
</txn>
My Result:
<?xml version="1.0" encoding="UTF-8"?>
<txn>
<errorCode>6042</errorCode>
<errorName>Invalid Request Format</errorName>
<errorMessage>XML request is not well-formed or request is incomplete.</errorMessage>
</txn>
Example request look like this:
curl -X POST -H 'Content-type: text/xml' -d 'xmldata=<txn><ssl_merchant_id>my_merchant_id</ssl_merchant_id><ssl_user_id>my_user_id</ssl_user_id><ssl_pin>my_pin</ssl_pin><ssl_transaction_type>ccsale</ssl_transaction_type><ssl_card_number>4000000000000002</ssl_card_number><ssl_exp_ date>1124</ssl_exp_date><ssl_amount>1.00</ssl_amount><ssl_cvv2cvc2_indicator>1</ssl_cvv2cvc2_indicator><ssl_cvv2cvc2>786</ssl_cvv2cvc2><ssl_first_name>adolfo</ssl_first_name></txn>' https://api.convergepay.com/VirtualMerchant/processxml.do
what the trouble with my request?
Change your HEADER fields:values to the following:
Content-Type: application/x-www-form-urlencoded
Accept: text/xml

my request failed when the post 'content-type' is application/x-www-form-urlencoded and * form field param= { <this is a json object>}

The request is failed when I post request an API whose header content-type is 'application/x-www-form-urlencoded; charset=UTF-8' and post body is ' param = { this is a json object} '
The curl request like this, it works.
curl 'http://localhost:7272/Acme/iEhr/PersonSample' -H 'Cookie: ACMETMP=fe35925f-a243-4be9-8e73-60c461ef9bd3; JSESSIONID=47A43F4988F232CC7B53F6CF30B954F6; SESSION=e580c2c7-bf4b-45e6-93fc-de6f79854346' -H 'Origin: http://localhost:7272' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: zh-CN,zh;q=0.9' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -H 'Accept: application/json, text/javascript, /; q=0.01' -H 'Referer: http://localhost:7272/route/sampleadd' -H 'X-Requested-With: XMLHttpRequest' -H 'Connection: keep-alive' --data 'param=%7B%22cityid%22%3A%222091afc3-bcd6-46d9-8033-3548ad10933b%22%2C%22areaid%22%3A%222d09f5e5-a07d-445c-9d8a-51eb436699a8%22%2C%22hosid%22%3A%220f226b63-58ad-44d7-bf23-25d0345276e1%22%2C%22deptid%22%3A%2291c176f5-63ca-4b95-87c4-9f311864ff9b%22%2C%22barcode%22%3A%221000000000%22%2C ......' --compressed
it also works with postman request but failed with Karate
Scenario: 样本登记
Given path 'iEhr/PersonSample'
And header Content-type = 'application/x-www-form-urlencoded; charset=UTF-8'
* cookies { JSESSIONID: '#(jsessionID)',SESSION: '#(sessionID)', ACMETMP: '#(acmetmpID)'}
And form fields param = {"cityid":"2091afc3-bcd6-46d9-8033-3548ad10933b","areaid":"2d09f5e5-a07d-445c-9d8a-51eb436699a8","hosid":"0f226b63-58ad-44d7-bf23-25d0345276e1","deptid":"91c176f5-63ca-4b95-87c4-9f311864ff9b","barcode":"1000000000","mothername":"manual-mother1","pregweek":"21", and so on}
When method post
Then status 200
* print response
'And form fields param = {this is a json object}'
this sentence should work but failed for us.
What is my means by karate failed ?
The response code is different compared with Karate, and it is expected result when working with postman.
Postman
the necessary param data
Karate:
18:14:09.437 request:
1 > POST http://localhost:7272/Acme/iEhr/PersonSample
1 > Accept-Encoding: gzip,deflate
1 > Connection: Keep-Alive
1 > Content-Length: 899
1 > Content-Type: application/x-www-form-urlencoded; charset=UTF-8
1 > Cookie: ACMETMP=d22c0d9a-b98b-4f6f-9e42-2f9bdffa22c8; JSESSIONID=09268B9F4CA0C15AE3FFB1A26BE424ED; SESSION=2baafdac-38d6-43d0-ac5c-d39e2b29fa48
1 > Host: localhost:7272
1 > User-Agent: Apache-HttpClient/4.5.5 (Java/1.8.0_211)
cityid=2091afc3-bcd6-46d9-8033-3548ad10933b&areaid=2d09f5e5-a07d-445c-9d8a-51eb436699a8&hosid=0f226b63-58ad-44d7-bf23-25d0345276e1&deptid=91c176f5-63ca-4b95-87c4-9f311864ff9b&barcode=1000000000&mothername=manual-mother1&pregweek=21&pregday=1&midentitycard=&birthday=2018-10-01+00%3A00&collectdate=2019-05-15+14%3A38&personsex=1&personweight=4000&address=manual-testaddress1&mobile=15397006044&collectperson=&samplequality=1&borntype=1&linkman=&fidentitycard=&labitem=PHE&sampletype=1&btn=&isfee=0&personremark=&telephone=&bednumber=&labstring=&collectnumber=&freecode=&dhosid=0f226b63-58ad-44d7-bf23-25d0345276e1&reviewtype=&diagnosticstatus=&centerid=bb717701-10de-47ee-b49e-693261c6df22&nowdeptid=07eeec75-079b-4fa9-93cf-c45ddc9a87b9&operator=%E9%BB%84%E5%86%88%E5%B8%82%E5%A6%87%E5%B9%BC%E4%BF%9D%E5%81%A5%E9%99%A2&labitems=PHE&pagecode=sampleadd&modifydetail=%E6%A0%B7%E6%9C%AC%E5%BD%95%E5%85%A5
18:14:09.557 response time in milliseconds: 120.12
1 < 200
1 < Accept-Charset: big5, big5-hkscs, cesu-8, euc-jp, euc-kr, gb18030, gb2312, gbk, ibm-thai ...... and so on
1 < Content-Length: 52
1 < Content-Type: text/plain;charset=UTF-8
1 < Date: Wed, 15 May 2019 10:14:09 GMT
1 < X-Application-Context: Acme.jc.test:dev:7272
[{"code":-90018,"result":"(错误-90018)失败!"}]
Can you try this,
Scenario: 样本登记
Given path 'iEhr/PersonSample'
* cookies { JSESSIONID: '#(jsessionID)',SESSION: '#(sessionID)', ACMETMP: '#(acmetmpID)'}
And def ffParams = {"param" : {"cityid":"2091afc3-bcd6-46d9-8033-3548ad10933b","areaid":"2d09f5e5-a07d-445c-9d8a-51eb436699a8","hosid":"0f226b63-58ad-44d7-bf23-25d0345276e1","deptid":"91c176f5-63ca-4b95-87c4-9f311864ff9b","barcode":"1000000000","mothername":"manual-mother1","pregweek":"21"}}
And form fields ffParams
When method post
Then status 200
* print response
Form fields are by default url-encoded only no need to explicitly mention it in header
And form field param = {"cityid":"2091afc3-bcd6-46d9-8033-3548ad10933b","areaid":"2d09f5e5-a07d-445c-9d8a-51eb436699a8","hosid":"0f226b63-58ad-44d7-bf23-25d0345276e1","deptid":"91c176f5-63ca-4b95-87c4-9f311864ff9b","barcode":"1000000000","mothername":"manual-mother1","pregweek":"21","pregday":"1","midentitycard":"","birthday":"2018-10-01 00:00" ...... and so on }
I changed to this, it works now.
I am misled by the keyword 'param' in karate and the keyword 'param' used by our product code.

Copy a file to source folder on OneDrive using OneDrive API

I tried to copy a file on OneDrive:
Request:
POST https://api.onedrive.com/v1.0/drive/root:/onedrive_test/foo/bar/a.txt:/action.copy
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Type: application/json
Content-Length: 84
Accept: */*
Authorization: Bearer Ew...
Prefer: respond-async
User-Agent: python-requests/2.7.0 CPython/3.4.4 Windows/7
b'{"parentReference": {"path": "/drive/root:/onedrive_test/foo/bar"}, "name": "b.txt"}'
Response: 202 Accepted
Request:
GET https://api.onedrive.com/v1.0/monitor/4sT2gLAWdXVK7EdkDM7k24ObcUFTzScBof3T80HbmKfVHPnUCDK4fWe01ttH9...
Accept-Encoding: gzip, deflate
Connection: keep-alive
Accept: */*
Authorization: Bearer Ew...
User-Agent: python-requests/2.7.0 CPython/3.4.4 Windows/7
None
Response: 500 Internal server error if copying to the same folder where source file is.
If I use
b'{"parentReference": {"path": "/drive/root:/onedrive_test/foo/bar2"}, "name": "b.txt"}'
or
b'{"parentReference": {"path": "/drive/root:/onedrive_test/foo"}, "name": "b.txt"}'
everything works fine.
This is an ongoing issue with OneDrive Consumer - I'll respond to this answer with a comment once it is resolved.

JHipster OAuth can't get token - 405 error

I am trying to get OAuth2 token for authorization on my local JHipster server.
Everything is setup correctly and working, I can login via Web GUI.
But when I try to get token via cURL I get POST method not allowed
My cURL request is as following:
curl -X POST -vu client:secret http://localhost:8080/oauth/token -H "Accept: application/json" -d "username=admin&password=admin&grant_type=password&scope=read&client_id=CLIENTID&client_secret=CLIENTSECRET"
Thanks to this post, I have tested JHipster UAA, alongside JHipster version 5 .
This command could be a working sample:
curl -X POST -v http://[server-ip]:9999/oauth/token -i
-H "Accept: application/json"
-H "Authorization: Basic aW50ZXJuYWw6aW50ZXJuYWw="
-d "username=admin&password=admin&grant_type=client_credentials&scope=web-app"
Important notice:
Username and password must be replaced with yours.
The BASE64 encoded value of your 'clientId + ":" + clientSecret' must be set in header.
In my case BASE64('internal:internal')='aW50ZXJuYWw6aW50ZXJuYWw='
https://www.base64encode.org/ can be used to encode your text.
Since you have put client Id and secret on message Header, no need to provide it on message body.
And this could be a sample output:
{
"access_token" : "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzY29wZSI6WyJ3ZWItYXBwIl0sImV4cCI6MTUzNTM2ODEyNiwiaWF0IjoxNTM1MzY2MzI2LCJqdGkiOiJiYjYwMWVkYS01NjUyLTQ5OTgtYWJkNS04YzYxZjA3Y2U1ODUiLCJjbGllbnRfaWQiOiJpbnRlcm5hbCJ9.lNqpfE7N6XJVFe9t7zPbwokU_zl4AFIAmQJZ_Hb2ok0vBpWrDMf3v6KgEEi5bN2iyRd0TQBelSIJothrsYHoTk0ZaeeK9BM97OJr4Uc8kLzn2Vp-xpBk8-n2PlwAKIRojoOxMnBp0nA2qjPieaPV2Fj1HETmK2gZ38lQcZ_KJLD-ug9AT9_N1E9SwRjt1yfZtd64IJZOQGqcZ05VCAj54jxH9lyvX-_1NY2Iq2aA5-cGbOftmv0sUjF15EiTGps6YtFUrJqKs8PmDofMImyqjAwB3yNObpg7c6PbeCXWYLAir5IOFdueTys3cLLyrhE78GJ3OiKSAA128nZSeUbiAg",
"token_type" : "bearer",
"expires_in" : 1799,
"scope" : "web-app",
"iat" : 1535366326,
"jti" : "bb601eda-5652-4998-abd5-8c61f07ce585"
* Connection #0 to host [server-ip] left intact
}
Using the default generated jhipster app (3.5.0), this is how you would curl a token for the admin user:
> curl -X POST -u jhipsterapp:my-secret-token-to-change-in-production -i -H 'Accept:application/json' http://localhost:8080/oauth/token -d "username=admin&password=admin&grant_type=password&scope=read%20write"
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
X-Application-Context: jhipster:swagger,dev:8080
Cache-Control: no-store
Pragma: no-cache
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
X-Frame-Options: DENY
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Fri, 22 Jul 2016 13:09:38 GMT
{
"access_token" : "4a1ae413-5cd7-46e9-8a33-31698218d43e",
"token_type" : "bearer",
"refresh_token" : "537f231c-e6e0-4499-bbd8-9580eee02f79",
"expires_in" : 1799,
"scope" : "read write"
}
Note: here is my .yo-rc.json:
{
"generator-jhipster": {
"jhipsterVersion": "3.5.0",
"baseName": "jhipster",
"packageName": "com.mycompany.myapp",
"packageFolder": "com/mycompany/myapp",
"serverPort": "8080",
"authenticationType": "oauth2",
"hibernateCache": "ehcache",
"clusteredHttpSession": "no",
"websocket": "no",
"databaseType": "sql",
"devDatabaseType": "h2Disk",
"prodDatabaseType": "mysql",
"searchEngine": "no",
"buildTool": "maven",
"useSass": false,
"applicationType": "monolith",
"testFrameworks": [
"gatling"
],
"jhiPrefix": "jhi",
"enableTranslation": true,
"nativeLanguage": "en",
"languages": [
"en"
]
}
}

Linkedin Share Api using simple curl

I do a simple request to share something on my linkedin profile
I try to just do it with curl but it doesn't work
I set the content-type to JSON in the header and I also set the authorization in the header
curl -v -H 'Authorization: OAuth oauth_consumer_key="V9uKPtEEB7JxQvYzbR2DuDfLe4qXjASgP5UhPJp8k13CYgSnN3BRFILxUJ6ApuCH",oauth_token="d6af5cda-b46e-4c38-b566-11428a9584fc",oauth_signature_method="HMAC-SHA1",oauth_signature="1PofnBExFc7pMB8b08fV34B5sTg%3D",oauth_timestamp="1323544645",oauth_nonce="516e0a1eadda4c24bfbcc4ca5e0cbedc",oauth_version="1.0"' -H 'Content-Type: application/json' -X POST -d '{"recipients":{"values": [{"person":{"_path": "/people/~"}}]}, "subject": "JSON POST test", "body": "You rule"}' http://api.linkedin.com/v1/people/~/shares
When I post this I get this result
About to connect() to api.linkedin.com port 80 (#0)
* Trying 216.52.242.83... connected
* Connected to api.linkedin.com (216.52.242.83) port 80 (#0)
> POST /v1/people/ICshCGDT79/shares HTTP/1.1
> User-Agent: curl/7.21.0 (x86_64-pc-linux-gnu) libcurl/7.21.0 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18
> Host: api.linkedin.com
> Accept: */*
> Authorization: OAuth oauth_consumer_key="V9uKPtEEB7JxQvYzbR2DuDfLe4qXjASgP5UhPJp8k13CYgSnN3BRFILxUJ6ApuCH",oauth_token="d6af5cda-b46e-4c38-b566-11428a9584fc",oauth_signature_method="HMAC-SHA1",oauth_signature="1PofnBExFc7pMB8b08fV34B5sTg%3D",oauth_timestamp="1323544645",oauth_nonce="516e0a1eadda4c24bfbcc4ca5e0cbedc",oauth_version="1.0"
> Content-Type: application/json
> Content-Length: 120
>
< HTTP/1.1 401 Unauthorized
< Server: Apache-Coyote/1.1
< Date: Sat, 10 Dec 2011 19:17:14 GMT
< Vary: *
< x-li-format: xml
< Content-Type: text/xml;charset=UTF-8
< Content-Length: 393
<
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<error>
<status>401</status>
<timestamp>1323544635447</timestamp>
<request-id>9UR4KT2T5Z</request-id>
<error-code>0</error-code>
<message>[unauthorized]. OAU:V9uKPtEEB7JxQvYzbR2DuDfLe4qXjASgP5UhPJp8k13CYgSnN3BRFILxUJ6ApuCH|d6af5cda-b46e-4c38-b566-11428a9584fc|*01|*01:1323544645:1PofnBExFc7pMB8b08fV34B5sTg=</message>
</error>
* Connection #0 to host api.linkedin.com left intact
* Closing connection #0
Anyone can tell me where am I wrong?
Thanks,