Execute CURL command with private key in Alamofire - ios

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?

Related

Masking Basic Auth header when using CURL to trigger remote jenkins job

I want to trigger remote Jenkins job from my container(k8s).
Currently, I'm using:
curl -k -X POST -u $USER:$JENKINS_TOKEN "${JENKINS_URL}/job/{$JOB_NAME}/buildWithParameters?token=12345"
But this information($USER,$JENKINS_TOKEN) is displayed in ArgoUI, is there any secure/other way to save credentials for remote trigger?
You can try one of the following.
Save the password in a file called password-file and read from that
curl -k -X POST -u $USER:$(cat .password-file)"${JENKINS_URL}/job/{$JOB_NAME}/buildWithParameters?token=12345"
Accept credentials from the STDIN.
curl -k -X POST "${JENKINS_URL}/job/{$JOB_NAME}/buildWithParameters?token=12345" -K- <<< "--user $USER:$JENKINS_TOKEN"
You can also try using --netrc-file option with curl where you can store the username and password in a file itself.
file
machine JENKINS_HOST login USERNAME password PASSWORD
Curl Command
curl -k -X POST --netrc-file my-password-file "${JENKINS_URL}/job/{$JOB_NAME}/buildWithParameters?token=12345"

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

Simple and double quotes in cURL in groovy

I have a Jenkins pipeline where this command works and send me a notification through google chat :
script {
sh 'curl -k "https://chat.googleapis.com/v1/spaces/AAAABHT3HT0/messages?key=*****&token=******" -d "#chat_notification.json" -XPOST -H "Content-Type: application/json; charset=UTF-8"'
}
But if I enter the url in a variable, that does not work any more :
script {
url = "https://chat.googleapis.com/v1/spaces/AAAAfF9CGEQ/messages?key=******&token=******"
sh 'curl -k ${url} -d "#chat_notification.json" -XPOST -H "Content-Type: application/json; charset=UTF-8"'
}
With the error :
curl -k -d #chat_notification.json -XPOST -H 'Content-Type: application/json; charset=UTF-8'
curl: no URL specified!
curl: try 'curl --help' or 'curl --manual' for more information
It's probably a quote issue ?
Yes, if you are using single quotes in Groovy, that means you cannot interpolate the string with variables using the $ syntax.
See https://groovy-lang.org/syntax.html#_string_interpolation .
Same thing applies to shell code, by the way, or sh in this case.
But since you are not using any shell variables in your code, simply swapping the quotes, i.e. quoting your Groovy string with ", and using ' within the curl command would probably work.
Yes it is a quote issue try to use "" instead of '' to use the value of url variable in curl command. You should also seperate -X and POST (you have -XPOST in your script)
script {
url = "https://chat.googleapis.com/v1/spaces/AAAAfF9CGEQ/messages?key=******&token=******"
sh "curl -k ${url} -d #chat_notification.json -X POST -H Content-Type: application/json; charset=UTF-8"
}

Mask credentials in Jenkins script shell

I added credentials in Credentials Binding Plugin in Jenkins.
Then I send this credentials as text to company's chat in Execute shell section using curl with data parameter:
curl --silent $url -d "{ \"text\": \"$credentials\" }" -H "X-Auth-Token: $auth_token" -H "X-User-Id: $user_id" -H "Content-type:application/json"
And I receive unmasked credentials in chat. How can I mask credentials or modify Binding plugin which will mask secret text same as echo output

Restassured Authentication

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"))

Resources