Adding certificate to request using MSXML in TD5.2?

Discussion forum about all things Team Developer 5.x and 6.x
User avatar
benedikz
Czech Republic
Posts: 14
Joined: 04 Nov 2021, 06:03
Location: Šumperk, Czech Republic

Adding certificate to request using MSXML in TD5.2?

Post by benedikz » 09 Dec 2021, 08:40

Hello there,

I've recently looked at https://wiki.tdcommunity.net/index.php/WebServices and I tried Dave Rabelink's sample. I need to send SOAP action request to an URL which needs client certificate to secure the request. However I have not found any hints on how to add certificates into this solution. If this could work out well, it would be a huge improvement for my future tasks, my solutions need to communicate via HTTPS requests including client certificate with third-party APIs.

I am actually searching for something like this in Gupta:

Code: Select all

C# analogy:
X509Certificate Cert = X509Certificate.CreateFromCertFile("path");
HttpWebRequest Request = (HttpWebRequest)WebRequest.Create("url");
Request.ClientCertificates.Add(Cert);
Code snippet:

Code: Select all

!!CB!! 70
If uHTTP.Create( )
	! Set synchronous call
	Call uVariantAsync.SetBoolean( FALSE )
	! No user/password needed, so make optional
	Call uVariantUser.MakeOptional(  )
	Call uVariantPassword.MakeOptional(  )
	!
	If uHTTP.open( 'POST', dfURL, uVariantAsync, uVariantUser, uVariantPassword )
		! Create the XML document object to put the XML string in
		If uMSXMLDocSoapRequest.Create(  )
			! Load the XML string in to document. It will check for valid XML
			If uMSXMLDocSoapRequest.loadXML( mlRequest, bLoaded ) AND bLoaded
				! Now set the document in the body
				Call uVariantBody.SetObject( uMSXMLDocSoapRequest )
				!
				! Set the HTTP header properties
				Call uHTTP.setRequestHeader( 'Content-Type', 'text/xml' )
				Call uHTTP.setRequestHeader( "SOAPAction", dfSoapAction )
				Call uHTTP.setRequestHeader( "Content-Length", SalNumberToStrX(SalStrLength( mlRequest ), 0) )
				! Do execute the service
				If uHTTP.send( uVariantBody )
					! Get the status of the call
					Call uHTTP.PropGetstatus( nStatus )
					Call uHTTP.PropGetstatusText( sStatus )
					Set dfStatus = sStatus || " (" || SalNumberToStrX( nStatus, 0 ) || ")"
					!
					! Get the header info
					Call uHTTP.getAllResponseHeaders( sHeaders )
					!
					! Get the response document
					Call uHTTP.PropGetresponseXML( uMSXMLDocSoapResponse )
					!
					! Get the response as XML text
					Call uMSXMLDocSoapResponse.PropGetxml( sResponseXML )
					!
					! Display on GUI
					Set mlResponse = sHeaders || "
							" || sResponseXML
					Call uMSXMLDocSoapResponse.Release( )
				Else
					Set dfStatus = "Error send"
			Else
				Set dfStatus = "Error loadXML"
			!
			Call uMSXMLDocSoapRequest.Release( )
		Else
			Set dfStatus = "Error create DocSoapRequest"
	Else
		Set dfStatus = "Error opening"
	!
	Call uHTTP.Release( )
If there's any library, or functionality to help me with this, I would really appreciate it!

Kind regards to all and thank you in advance for any help :)

Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 3384
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

Re: Adding certificate to request using MSXML in TD5.2?

Post by Dave Rabelink » 09 Dec 2021, 09:30

There are some topics here on the forum. Did you check those?

search.php?keywords=certificate&terms=a ... mit=Search
Regards,
Dave Rabelink

Image
Articles and information on Team Developer Tips & Tricks Wiki
Download samples, documents and resources from TD Sample Vault
Videos on TDWiki YouTube Channel

User avatar
benedikz
Czech Republic
Posts: 14
Joined: 04 Nov 2021, 06:03
Location: Šumperk, Czech Republic

Re: Adding certificate to request using MSXML in TD5.2?

Post by benedikz » 09 Dec 2021, 11:30

Hello, I did. I actually did everything clearly as mentioned in one of the topics and I am stuck at OleError (or HTTPError) saying, that a certificate is required by the server, even though that I included it in my code below:

My MSXML2_ServerXMLHTTP60 HTTPRequest code snippet:
Image

Here I included the Certificate in the code:
Image

However it seems like the request cannot find the certificate I want to use, because it is searching for it in Local Machine certificates, but it is single user-only certificate.

Any help, I appreciate.

Igor Ivanovic
Site Admin
Site Admin
Croatia
Posts: 1462
Joined: 05 Mar 2017, 12:37
Location: Zagreb, Croatia

Re: Adding certificate to request using MSXML in TD5.2?

Post by Igor Ivanovic » 09 Dec 2021, 11:40

You are trying to load Local Computer\Personal certificate, try Current User\Personal instead.
Igor Ivanovic
Image

User avatar
benedikz
Czech Republic
Posts: 14
Joined: 04 Nov 2021, 06:03
Location: Šumperk, Czech Republic

Re: Adding certificate to request using MSXML in TD5.2?

Post by benedikz » 09 Dec 2021, 11:57

I tried to change it, however error still persists. I'd like to point out, that the certificate is secured by passphrase, do I need to take care of that when making this request or is it enough when it's installed and I don't have to think about the password at all?

Image

Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 3384
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

Re: Adding certificate to request using MSXML in TD5.2?

Post by Dave Rabelink » 09 Dec 2021, 12:10

I think you need double backslashes in your path , so

Code: Select all

"Current User\\Personal\\Certificate\\cp_komercni"
(or single forward slashes, I always get confused about the correct use of the slashes)
Regards,
Dave Rabelink

Image
Articles and information on Team Developer Tips & Tricks Wiki
Download samples, documents and resources from TD Sample Vault
Videos on TDWiki YouTube Channel

User avatar
benedikz
Czech Republic
Posts: 14
Joined: 04 Nov 2021, 06:03
Location: Šumperk, Czech Republic

Re: Adding certificate to request using MSXML in TD5.2?

Post by benedikz » 09 Dec 2021, 12:26

I did add them, however now the error changed from the previous one into:
SEC_E_UNTRUSTED_ROOT (0x80090325). Wonder why that is, I tried with the same certificate with the same request in Postman (API/WebRequest testing tool) and it came through OK


...

Actually, I found out, that this error occurs every time, does not correspond to the correct string in certificate path option. It basically appears if I let it be blank quotes and even if I fill in the correct path to certificate.

Both of these cause the SEC_E_UNTRUSTED_ROOT error. I seriously don't know why :(
Image

Image

Return to “General Discussion”

Who is online

Users browsing this forum: [Ccbot] and 1 guest