1. VISHALAKSHI RAO
  2. PowerBuilder
  3. Sunday, 3 July 2022 19:59 PM UTC

Hi,

I would need help on consuming AWS SQS in PowerBuilder 2019 version. I was trying in Postman & able call it successfully. But I'm finding it difficult to call from PowerBuilder. I get following error message. I have verified on Access Key & its valid and working fine from Postman

<?xml version="1.0"?><ErrorResponse xmlns="http://queue.amazonaws.com/doc/2012-11-05/"><Error><Type>Sender</Type><Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.

This is the HTTP Code snippet got it from Postman. 

GET /964043123456/maven-notification-maven-8?Action=ReceiveMessage HTTP/1.1
Host: sqs.ap-south-1.amazonaws.com
X-Amz-Date: 20220703T165602Z
Authorization: AWS4-HMAC-SHA256 Credential=ABCDEFG/20220703/ap-south-1/sqs/aws4_request, SignedHeaders=host;x-amz-date, Signature=848ddaf8a216cc6e824d6199aa4f2c90412189462bbd51c66a844afb6ba8e6b9

This is the AWS documentation page on the signature calculation => https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-header-based-auth.html

I would really appreciate if some help in sharing the request code for PowerBuilder?   Thanks in Advance.

 

Regards,

Vishalakshi

 

 

VISHALAKSHI RAO Accepted Answer Pending Moderation
  1. Tuesday, 5 July 2022 05:20 AM UTC
  2. PowerBuilder
  3. # 1

Hi,

I have updated my code a bit & Now I get following error message. I have updated my PowerBuilder code as well below. Pls help!

 

<?xml version="1.0"?><ErrorResponse xmlns="http://queue.amazonaws.com/doc/2010-05-08
/"><Error><Type>Sender</Type><Code>MalformedVersion</Code><Message>Version not well formed: 2010-05-08
. Must be in YYYY-MM-DD format.</Message><Detail/></Error><RequestId>e96ee9d8-f694-5229-98a6-b2e5e20b8c5b</RequestId></ErrorResponse>

 

Regards,

Vishalakshi

Integer li_rc
RestClient lnv_RestClient
ResourceResponse lrr_response
String ls_url, ls_response, ls_auth, ls_secret_key, ls_host, ls_signing_key, ls_access_key, ls_string_to_sign
Blob lblb_signing_key, lblb_string_to_sign
String ls_utcdate


httpclient lhttp_client  
lhttp_client = CREATE httpclient 

CoderObject lnv_CoderObject
lnv_CoderObject = Create CoderObject

CrypterObject lnv_CrypterObject
lnv_CrypterObject = Create CrypterObject


ls_access_key = 'XXXXXX'
ls_secret_key = 'XXXXX'
ls_host = 'sqs.ap-south-1.amazonaws.com'

SELECT CURRENT UTC TIMESTAMP INTO :ls_utcdate FROM DUMMY;    //SQL ANYWHERE DB
ls_utcdate = String(ls_utcdate, "YYYYMMDD") + "T" + String(ls_utcdate, "HHMMSS") + "Z"


ls_string_to_sign = "AWS4-HMAC-SHA256"+Left(ls_utcdate, 8)+"/ap-south-1/sqs/aws4_request"
lblb_string_to_sign = lnv_CrypterObject.SHA(SHA256!, Blob(ls_string_to_sign,EncodingANSI!))

lblb_signing_key = lnv_CrypterObject.HMAC(HMACSHA256!, Blob("AWS4" + ls_secret_key, EncodingANSI!),Blob(Left(ls_utcdate, 8),EncodingANSI!))
lblb_signing_key = lnv_CrypterObject.HMAC(HMACSHA256!, lblb_signing_key, Blob("ap-south-1", EncodingANSI!))
lblb_signing_key = lnv_CrypterObject.HMAC(HMACSHA256!, lblb_signing_key, Blob("sqs", EncodingANSI!))
lblb_signing_key = lnv_CrypterObject.HMAC(HMACSHA256!, lblb_signing_key, Blob("aws4_request", EncodingANSI!))

ls_signing_key = lnv_CoderObject.HexEncode(lnv_CrypterObject.HMAC(HMACSHA256!, lblb_signing_key, lblb_string_to_sign))

ls_auth = "AWS4-HMAC-SHA256 Credential=" + ls_access_key + "/"+Left(ls_utcdate, 8)+"/ap-south-1/sqs/aws4_request,SignedHeaders=host;x-amz-date,Signature="+ls_signing_key
lhttp_client.SetRequestHeader( "content-type","application/x-www-form-urlencoded"+"~n")
lhttp_client.SetRequestHeader("x-amz-date", ls_utcdate+"~n")
lhttp_client.SetRequestHeader("host", ls_host+"~n")
lhttp_client.SetRequestHeader("authorization", ls_auth+"~n")

ls_url = "https://sqs.ap-south-1.amazonaws.com/123456653804/maven-notification-maven-8?Action=ReceiveMessage&Version=2012-11-05"+"~n"

li_rc = lhttp_client.SendRequest("GET", ls_url)

ls_response = lhttp_client.GetResponseStatusText()
//if li_rc = 1 and lhttp_client.GetResponseStatusCode() = 200 then
	lhttp_client.GetResponseBody(ls_response)
//end if

DESTROY lhttp_client
DESTROY lnv_CoderObject
DESTROY lnv_CrypterObject

RETURN ls_response
Comment
  1. Miguel Leeuwe
  2. Tuesday, 5 July 2022 05:42 AM UTC
Maybe this is the problem?

The error message is telling you to use a date format including - (dashes), You are using a format without dashes "String(ls_utcdate, "YYYYMMDD")".

  1. Helpful 1
  1. VISHALAKSHI RAO
  2. Tuesday, 5 July 2022 16:46 PM UTC
No, I think, its looking for the Version format in URL section.



ls_url = "https://sqs.ap-south-1.amazonaws.com/123456653804/maven-notification-maven-8?Action=ReceiveMessage&Version=2012-11-05";+"~n"

  1. Helpful
There are no comments made yet.
mike S Accepted Answer Pending Moderation
  1. Monday, 4 July 2022 14:47 PM UTC
  2. PowerBuilder
  3. # 2

"does not match the signature"

 

most likely your signature calculation is not correct.  you may have missed some steps.  Azure has similar requirements, and it was pretty in-depth and not well described - mainly because the assumption is that libraries will be used to calculate it. 

 

There are multiple signature versions apparently:  AWS Signature Version 4 is the most current.  which did you use?

 

Also, there is often a time component, and you have to allow for clock skew.  typically, that is GMT.  

 

As a shortcut, you could check to see if a .net library exists for it and use the .net importer in PB to use it.

Comment
  1. VISHALAKSHI RAO
  2. Tuesday, 5 July 2022 16:48 PM UTC
Thank you. I have used Version 4. But after some modifications of my code,. I don't see the error on signature. But I see the error on the version date.
  1. Helpful
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Monday, 4 July 2022 10:50 AM UTC
  2. PowerBuilder
  3. # 3

Hi,

Maybe you can get more help if you paste your powerbuilder code by using the "inser/edit code sample" icon on the toolbar:

 

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.