Class: Aws::SNS::MessageVerifier
- Inherits:
 - 
      Object
      
        
- Object
 - Aws::SNS::MessageVerifier
 
 
- Defined in:
 - lib/aws-sdk-sns/message_verifier.rb
 
Overview
A utility class that can be used to verify the authenticity of messages sent by Amazon SNS.
verifier = Aws::SNS::MessageVerifier.new
# returns true/false
verifier.authentic?()
# raises a Aws::SNS::MessageVerifier::VerificationError on failure
verifier.authenticate!()
You can re-use a single MessageVerifier instance to authenticate multiple SNS messages.
Defined Under Namespace
Classes: VerificationError
Constant Summary collapse
- SIGNABLE_KEYS =
          
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
 [ 'Message', 'MessageId', 'Subject', 'SubscribeURL', 'Timestamp', 'Token', 'TopicArn', 'Type' ].freeze
- AWS_HOSTNAMES =
          
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
 [ /^sns\.[a-zA-Z0-9\-]{3,}\.amazonaws\.com(\.cn)?$/ ].freeze
Instance Method Summary collapse
- 
  
    
      #authentic?(message_body)  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
Returns ‘true` if the given message has been successfully verified.
 - 
  
    
      #authenticate!(message_body)  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
Returns ‘true` when the given message has been successfully verified.
 - 
  
    
      #initialize(http_options = {})  ⇒ MessageVerifier 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of MessageVerifier.
 
Constructor Details
#initialize(http_options = {}) ⇒ MessageVerifier
Returns a new instance of MessageVerifier.
      46 47 48 49  | 
    
      # File 'lib/aws-sdk-sns/message_verifier.rb', line 46 def initialize( = {}) @cached_pems = {} @http_proxy = [:http_proxy] end  | 
  
Instance Method Details
#authentic?(message_body) ⇒ Boolean
Returns ‘true` if the given message has been successfully verified. Returns `false` otherwise.
      54 55 56 57 58  | 
    
      # File 'lib/aws-sdk-sns/message_verifier.rb', line 54 def authentic?() authenticate!() rescue VerificationError false end  | 
  
#authenticate!(message_body) ⇒ Boolean
Returns ‘true` when the given message has been successfully verified.
      65 66 67 68 69 70 71 72 73 74 75 76 77 78  | 
    
      # File 'lib/aws-sdk-sns/message_verifier.rb', line 65 def authenticate!() msg = Json.load() msg = convert_lambda_msg(msg) if is_from_lambda(msg) case msg['SignatureVersion'] when '1' verify!(msg, sha1) when '2' verify!(msg, sha256) else error_msg = 'Invalid SignatureVersion' raise VerificationError, error_msg end end  |