Restassured Authentication - rest-assured

I have a curl command
curl --header "IDS-SESSION-ID:000000000000" -k --key ./file.key.pem --cert ./file.crt.pem -X POST -v https://localhost:9086/api/v11.0/search
How can i pass certificate and key file in rest assured .
I have sample code below which work forother parameter in curl command
RESTBase restClient = new RESTBase(URL + "/search");
restClient.skipSSLCertificateValidation();
restClient.setHeader("IDS-SESSION-ID", sessionId);

First of all import your certificate to Java keystore
$ keytool -importcert -alias "some-ca" -file SomeBusinessCA-1.crt -keystore truststore_java.jks -storepass test1234
Then use following code:
given().config(newConfig().sslConfig(new SSLConfig("/truststore_java.jks", "test1234"))

Related

Cookies don't work in dart but curl generated by CurlLoggerDioInterceptor works in shell

I have in my Flutter project APIs that use cookies and they don't work. I have enabled the interceptor that generates the curl:
CurlLoggerDioInterceptor (printOnSuccess: true)
with the following result:
curl -i \
-H "Accept: application / json" \
-H "Connection: keep-alive" \
-H "cookie: ci_session = uv0hts7fb8us0r7m5vvaa64p4o89u9he" \
-H "Authorization: 1652292531" \
"http://xxxxx.it"
And this works on shell. I don't understand, why the curl generated by Dart code works and the code itself doesn't work?
Regarding the code I've used all the solutions in this link (dio_cookie_manager, NetworkService, HTTP request instead of dio...) How do I make an http request using cookies on flutter?
With Dio is not possible, but with the following library yes:
flutter_curl: ^0.1.1

Spring cloud skipper Cannot upload a package via REST API

I am following a doc to upload a package into Skipper Server at https://docs.spring.io/spring-cloud-skipper/docs/current-SNAPSHOT/reference/htmlsingle/#resources-package
Here is a package: Helloworld
This is curl command as
$ curl 'http://localhost:7577/api/package/upload' -i -X POST \
-H 'Content-Type: application/json;charset=UTF-8' \
-H 'Accept: application/json' \
-F 'data=/home/user1/helloworld-1.0.0.zip'
But still cannot upload a package. Please help me what's correct to upload a package to Skipper via REST API.
P.s: By using a POSTMAN but It's also impossible.
I found it how to do on old doc from spring team.
Post here if someone is needed.
https://docs.spring.io/spring-cloud-skipper/docs/1.0.0.BUILD-SNAPSHOT/reference/html/api-guide-resources.html#resources-package

Execute CURL command with private key in Alamofire

Execute it in Alamofire on Swift language
curl -k --cert client.crt --key clientprivate.key -X GET 'https://example.com:8443/test
I assume that I need to configure in this place
session = Session(
serverTrustManager: ServerTrustManager(evaluators: evaluators)
)
It is possible?

How to convert pcks12 certificate string, which was taken from azure key vault in docker container, to pem format?

I use for taking a certificate in a docker container via managed identity like described in Microsoft docs here (Example 1): https://learn.microsoft.com/en-us/azure/container-instances/container-instances-managed-identity#example-1-use-a-user-assigned-identity-to-access-azure-key-vault
When it was a certificate in pem format output of the command:
curl https://mykeyvault.vault.azure.net/secrets/SampleSecret/?api-version=2016-10-01 -H "Authorization: Bearer $token"
Was like:
{"value":"-----BEGIN PRIVATE
KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDBkelEEzvwXiaW\nX4sPt052w/5tahn6OAy+lasH4Lq1xvU/G+z9Ra0rBs2NGhPr7smu8iAxACfr74I5\nCHENM4kvmM{too
many symbols}KkrjDMmf5Om\n-----END PRIVATE KEY-----\n-----BEGIN
CERTIFICATE-----\nMIIDMDCCAhigAw{too many symbols}4GMgUQ==\n-----END
CERTIFICATE-----\n","contentType":"application/x-pem-file","id":"myid","managed":true,"attributes":{"enabled":true,"nbf":1600276258,"exp":1631812858,"created":1600276858,"updated":1600276858,"recoveryLevel":"Recoverable+Purgeable"},"kid":"https://cert_url"}
And parse it to cert.pem and private_key.pem files is easy.
But if it is pcks12 format output is just like one string:
{"value":"MIIKPAIBAzCCCfwGCSqGSIb3DQEHAaCCCe0EggnpMIIJ5TCCBhYGCSqGSIb3DQEHA{only
many
symbols}8O3VaP5TOUaZMQ=","contentType":"application/x-pkcs12","id":"myid","managed":true,"attributes":{"enabled":true,"nbf":1600275456,"exp":1631812056,"created":1600276056,"updated":1600276056,"recoveryLevel":"Recoverable+Purgeable"},"kid":"https://cert_url"}
So I can't convert that string to cert.pem and private_key.pem files like was explained above.
I put in file cert.cer value via:
curl https://testigorcert.vault.azure.net/secrets/SampleSecret/?api-version=2016-10-01 -H "Authorization: Bearer $token" | jq '.value' > cert.cer
And tried command like:
openssl pkcs12 -in cert.cer -out cert.pem -nodes
Error:
139876006393152:error:0D0680A8:asn1 encoding
routines:asn1_check_tlen:wrong tag:../crypto/asn1/tasn_dec.c:1130:
139876006393152:error:0D07803A:asn1 encoding
routines:asn1_item_embed_d2i:nested asn1
error:../crypto/asn1/tasn_dec.c:290:Type=PKCS12
Tried:
openssl pkcs12 -in cert.cer -nocerts -nodes -out key.pem
Error:
140021099644224:error:0D0680A8:asn1 encoding
routines:asn1_check_tlen:wrong tag:../crypto/asn1/tasn_dec.c:1130:
140021099644224:error:0D07803A:asn1 encoding
routines:asn1_item_embed_d2i:nested asn1
error:../crypto/asn1/tasn_dec.c:290:Type=PKCS12
Tried:
openssl x509 -in cert.cer -text
Error:
139665046693184:error:0909006C:PEM routines:get_name:no start
line:../crypto/pem/pem_lib.c:745:Expecting: TRUSTED CERTIFICATE
So. How can I convert this value of pkcs12 certificate format to two files cert.pem and private_key.pem?
The problem was in encoding of downloaded string, because curl get a .pfx string, BUT in ascii coding (should be in base64). So I just use another way (Example 2):
https://learn.microsoft.com/en-us/azure/container-instances/container-instances-managed-identity#example-2-use-a-system-assigned-identity-to-access-azure-key-vault
Where I just download certificate .pfx via command:
az keyvault secret download --file cert.pfx --name {cert_name} --vault-name {vault_name} -e base64
And then convert to two needed files by:
openssl pkcs12 -in cert.pfx -nocerts -out key.rsa -nodes -passin pass:
openssl pkcs12 -in cert.pfx -clcerts -nokeys -out cert.crt -passin pass:
That another (best) option to convert cert to base 64 format by an appropriate command like:
token=$(curl 'http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https%3A%2F%2Fvault.azure.net' -H Metadata:true | jq -r '.access_token')
curl https://myvault.vault.azure.net/secrets/mycert/?api-version=2016-10-01 -H "Authorization: Bearer $token" |
jq -r ".value" | base64 -d | openssl pkcs12 -nocerts -out /etc/ssl/private-key.pem -nodes -passin pass:
curl https://myvault.vault.azure.net/secrets/mycert/?api-version=2016-10-01 -H "Authorization: Bearer $token" |
jq -r ".value" | base64 -d | openssl pkcs12 -clcerts -nokeys -out /etc/ssl/cert.pem -passin pass:

Wget to download excel from Jira automatically

I have tried the below commands to get the excel file automatically from jira but I'm getting different data other than the filter data.
wget --user username--password pass -O test.xls --ignore-length=on http://esjirq62.emea.nsn-net.net:8080/sr/jira.issueviews:searchrequest-excel-all-fields/70920/SearchRequest-70920.xls?tempMax=1000;
curl -D my-output.xml -u upgrade:hjjKl801 -X GET -H "Content-Type: application/json" http://esjirq62.emea.nsn-net.net:8080/sr/jira.issueviews:searchrequest-excel-all-fields/70920/SearchRequest-70920.xls?tempMax=1000
Please help me here.
You have to set correct encoding header gzip :
curl -D my-output.xml -u upgrade:secret -X GET -H "Content-Type: application/json" -H "Accept-Encoding: gzip" "http://esjirq62.emea.nsn-net.net:8080/sr/jira.issueviews:searchrequest-excel-all-fields/70920/SearchRequest-70920.xls?tempMax=1000"
Some notes:
Remove password from your example
-D flag for curl dumps headers, not output. Did you mean -o maybe?
Content-Type header can be skipped
To be on the safe side, put the url in double quotes
You can copy request from Google Chrome using developer tools
I can't get Wget work in my environment (permission denied error; maybe because of SSO?) but following curl command .
"D:\DSUsers\uid41890\Tools\curl.exe" -o C:\Users\uid41890\Documents\JIRA\search.csv -u uid41890:password -X GET "http://jiraurl:port/sr/jira.issueviews:searchrequest-csv-current-fields/17899/SearchRequest-17899.csv"
No need for Header options as mentioned in #grundic's answer.
Replace -D by -o in your original command and change the output file format from xml to csv for example.
You must use -O flag as:
curl -o excel.xls -O -u upgrade:hjjKl801 -X GET -H "Content-Type: application/json" http://esjirq62.emea.nsn-net.net:8080/sr/jira.issueviews:searchrequest-excel-all-fields/70920/SearchRequest-70920.xls?tempMax=1000

Resources