PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, July 11, 2022

[FIXED] How Do I Authenticate a AWS SNS Message Using C#?

 July 11, 2022     amazon-sns, authentication, message     No comments   

Issue

I am sending SNS messages to a HTTP endpoint. I can pick up the message information from the JSON data but how do I authenticate the message and validate the message signature?

This is one of the messages:

{
  "Type": "Notification",
  "MessageId": "a1825ceb-aa86-531a-9712-09b49bb60b32",
  "TopicArn": "arn:aws:sns:us-west-2:xxxx:Test_Topic",
  "Message": "This is the message body",
  "Timestamp": "2019-05-22T11:13:52.513Z",
  "SignatureVersion": "1",
  "Signature": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc",
  "SigningCertURL": "https://sns.us-west-2.amazonaws.com/SimpleNotificationService-abcabcabc.pem",
  "UnsubscribeURL": "https://sns.us-west-2.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-west-2:yyy",
  "MessageAttributes": {
    "String2": {
      "Type": "String",
      "Value": "This is the second string"
    },
    "String1": {
      "Type": "String",
      "Value": "This is the first string"
    }
  }
}

How do I check that the Message Signature is valid?


Solution

I'm using the Message class from the AWSSDK Utils, here is the code.

var msg = await ReadBody();

var message = Message.ParseMessage(msg);

if (!message.IsMessageSignatureValid())

this is the package Amazon.SimpleNotificationService.Util.Message.

Hope this helps.



Answered By - Nicolas Rubiano
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing