HOW-TO Use CURL and - s3-eu-west-1.amazonaws.com · Installing MC Client certificate in Windows...

12

Transcript of HOW-TO Use CURL and - s3-eu-west-1.amazonaws.com · Installing MC Client certificate in Windows...

Page 1: HOW-TO Use CURL and - s3-eu-west-1.amazonaws.com · Installing MC Client certificate in Windows Browser The client certificate will be used for authentication to the accessed service
Page 2: HOW-TO Use CURL and - s3-eu-west-1.amazonaws.com · Installing MC Client certificate in Windows Browser The client certificate will be used for authentication to the accessed service

HOW-TO Use CURL and SWAGGER

Version Date Sign Description

1.0 2019-03-26 MO

This HOW-TO explains how to use SWAGGER files and CURL for REST service call

Page 3: HOW-TO Use CURL and - s3-eu-west-1.amazonaws.com · Installing MC Client certificate in Windows Browser The client certificate will be used for authentication to the accessed service

HOW-TO use CURL and SWAGGER

• CURL

• SWAGGER

• Convert to pm12

Page 4: HOW-TO Use CURL and - s3-eu-west-1.amazonaws.com · Installing MC Client certificate in Windows Browser The client certificate will be used for authentication to the accessed service

API tests

This HOW-TO describes the use of swagger file to test REST interface

Page 5: HOW-TO Use CURL and - s3-eu-west-1.amazonaws.com · Installing MC Client certificate in Windows Browser The client certificate will be used for authentication to the accessed service

Windows browserInstalling MC Root certificate in Windows BrowserThe root certificate will tell the browser that the exchanged certificates for SSL is trusted

• Get the correct root certificate from MCP• (OBS! different root certificates for PRODUCTION and STAGING environment)

http://developers.maritimeconnectivity.net/identity/index.html#get-mcp-root-certificate• Download the Windows file• Install the Root Certificate (open the mc-ca-certs.cer file)

• Select Certificate store ”Trusted Root Certification Authorities”

Page 6: HOW-TO Use CURL and - s3-eu-west-1.amazonaws.com · Installing MC Client certificate in Windows Browser The client certificate will be used for authentication to the accessed service

Windows browserInstalling MC Client certificate in Windows BrowserThe client certificate will be used for authentication to the accessed service

• Issue a client certificate from MCP (service certificate with correct domain name)• Download the certificate including the private key (must be done immediately after issuing)

• Convert the files into .p12 files

• Install the Client Certificate (open the .p12 file)• Select default storage and finalise

Page 7: HOW-TO Use CURL and - s3-eu-west-1.amazonaws.com · Installing MC Client certificate in Windows Browser The client certificate will be used for authentication to the accessed service

API tests

SMA VIS instance can be tested with a browser

https://smavistest.stmvalidation.eu/swagger (public VIS SeaSWIM side)

Page 8: HOW-TO Use CURL and - s3-eu-west-1.amazonaws.com · Installing MC Client certificate in Windows Browser The client certificate will be used for authentication to the accessed service

On Windows

• Converting certificate from PEM to p12

• Download OpenSSL into local folderIssue a Certificate from the MC Portal and download the certificate

• Unpack the Certificate, there should be three (3) files• Run cmd and go to the OpenSSL folder• Run command ‘set RANDFILE=.rnd’• Run command ’openssl pkcs12 -export -in Your_Certificate_file.pem -inkey

Your_PrivateKey_file.pem -certfile mc-ca-chain.pem -name "Your_certificate_name" -out Your_certificate_output_filename.p12’

• Select password

You should know have a .p12 file that can be installed in a windows browser which allows you to be authenticated towards a SeaSWIM Connector.

Page 9: HOW-TO Use CURL and - s3-eu-west-1.amazonaws.com · Installing MC Client certificate in Windows Browser The client certificate will be used for authentication to the accessed service

curl

• Download curl– E.g. https://curl.haxx.se/download.html

– https://bintray.com/artifact/download/vszakats/generic/curl-7.53.1-win64-mingw.7z

• Download MC Root Certificate– http://developers.maritimecloud.net/identity/index.html

• Download Client Certificate– MC Portal

– Issue relevant certificate and download certificate

Page 10: HOW-TO Use CURL and - s3-eu-west-1.amazonaws.com · Installing MC Client certificate in Windows Browser The client certificate will be used for authentication to the accessed service

curlFor Windows; Adjust the client certificate

Convert the .pem certificate to .p12

• See HOW-TO Convert PEM to P12– set RANDFILE=.rnd

– openssl pkcs12 -export -in certificate.pem -inkey privkey.pem -certfile mc-ca-chain.pem -name "Your_certificate_name" -out key.p12

Convert the .p12 back to .pem

• openssl pkcs12 –in key.p12 –out key.pem -clcerts

Page 11: HOW-TO Use CURL and - s3-eu-west-1.amazonaws.com · Installing MC Client certificate in Windows Browser The client certificate will be used for authentication to the accessed service

curlExample of curls to VIS

curl --cert Mikael.pem --cacert mc-ca-chain.pem --header Accept:application/json --http1.1 -X GET "https://stmvistest.cloudapp.net/SMA009/V2/voyagePlans"

curl --cert Mikael.pem --cacert mc-ca-chain.pem --header Accept:application/json --header Content-Type:application/json --http1.1 -X GET https://stmvistest.cloudapp.net/SMA009/V2/voyagePlans --data “”

curl --cert Mikael.pem --cacert mc-ca-chain.pem --header Content-Type:text/xml --http1.1 -X POST https://stmvistest.cloudapp.net/SMA009/V2/voyagePlans" -T TestData/RTZ10.xml

Page 12: HOW-TO Use CURL and - s3-eu-west-1.amazonaws.com · Installing MC Client certificate in Windows Browser The client certificate will be used for authentication to the accessed service