Module: OpenID::Nonce

### Home Classes Methods

### In Files

- lib/openid/store/nonce.rb

### Methods

- ::check_timestamp
- ::mk_nonce
- ::skew
- ::skew=
- ::split_nonce

### Files

- LICENSE

### Class/Module Index

Quicksearch

- OpenID
- OpenID::AX
- OpenID::AX::AXMessage
- OpenID::AX::AttrInfo
- OpenID::AX::Error
- OpenID::AX::FetchRequest
- OpenID::AX::FetchResponse
- OpenID::AX::KeyValueMessage
- OpenID::AX::StoreRequest
- OpenID::AX::StoreResponse
- OpenID::AssertionError
- OpenID::Association
- OpenID::AssociationNegotiator
- OpenID::Consumer
- OpenID::Consumer::AssociationManager
- OpenID::Consumer::CancelResponse
- OpenID::Consumer::CheckIDRequest
- OpenID::Consumer::DiffieHellmanSHA1Session
- OpenID::Consumer::DiffieHellmanSHA256Session
- OpenID::Consumer::DiffieHellmanSession
- OpenID::Consumer::DiscoveredServices
- OpenID::Consumer::DiscoveryManager
- OpenID::Consumer::FailureResponse
- OpenID::Consumer::IdResHandler
- OpenID::Consumer::NoEncryptionSession
- OpenID::Consumer::Response
- OpenID::Consumer::Session
- OpenID::Consumer::SetupNeededResponse
- OpenID::Consumer::SuccessResponse
- OpenID::CryptUtil
- OpenID::DiffieHellman
- OpenID::DiscoveryFailure
- OpenID::Extension
- OpenID::FetchingError
- OpenID::HTTPRedirectLimitReached
- OpenID::HTTPResponse
- OpenID::HTTPStatusError
- OpenID::InvalidOpenIDNamespace
- OpenID::KVFormError
- OpenID::KVPostNetworkError
- OpenID::Message
- OpenID::Message::KeyNotFound
- OpenID::NamespaceAliasRegistrationError
- OpenID::NamespaceMap
- OpenID::Nonce
- OpenID::OAuth
- OpenID::OAuth::Request
- OpenID::OAuth::Response
- OpenID::OpenIDError
- OpenID::OpenIDServiceEndpoint
- OpenID::PAPE
- OpenID::PAPE::Request
- OpenID::PAPE::Response
- OpenID::ProtocolError
- OpenID::RealmVerificationRedirected
- OpenID::SReg
- OpenID::SReg::NamespaceError
- OpenID::SReg::Request
- OpenID::SReg::Response
- OpenID::SSLFetchingError
- OpenID::Server
- OpenID::Server::AlreadySigned
- OpenID::Server::AssociateRequest
- OpenID::Server::BaseServerSession
- OpenID::Server::CheckAuthRequest
- OpenID::Server::CheckIDRequest
- OpenID::Server::Decoder
- OpenID::Server::DiffieHellmanSHA1ServerSession
- OpenID::Server::DiffieHellmanSHA256ServerSession
- OpenID::Server::Encoder
- OpenID::Server::EncodingError
- OpenID::Server::MalformedReturnURL
- OpenID::Server::MalformedTrustRoot
- OpenID::Server::NoReturnToError
- OpenID::Server::OpenIDRequest
- OpenID::Server::OpenIDResponse
- OpenID::Server::PlainTextServerSession
- OpenID::Server::ProtocolError
- OpenID::Server::Server
- OpenID::Server::Signatory
- OpenID::Server::SigningEncoder
- OpenID::Server::UntrustedReturnURL
- OpenID::Server::VersionError
- OpenID::Server::WebResponse
- OpenID::ServerError
- OpenID::StandardFetcher
- OpenID::Store
- OpenID::Store::Filesystem
- OpenID::Store::Interface
- OpenID::Store::Memcache
- OpenID::Store::Memory
- OpenID::TrustRoot
- OpenID::TrustRoot::TrustRoot
- OpenID::TypeURIMismatch
- OpenID::UI
- OpenID::UI::Request
- OpenID::URINorm
- OpenID::UndefinedOpenIDNamespace
- OpenID::Util
- OpenID::Yadis
- OpenID::Yadis::BasicServiceEndpoint
- OpenID::Yadis::CompoundFilter
- OpenID::Yadis::DiscoveryResult
- OpenID::Yadis::TransformFilterMaker
- OpenID::Yadis::XRDSError
- OpenID::Yadis::XRDSFraud
- OpenID::Yadis::XRI
- OpenID::Yadis::XRI::ProxyResolver
- OpenID::Yadis::XRI::XRIHTTPError
- HMAC
- HMAC::Base
- HMAC::SHA1
- HMAC::SHA256
- HMAC::SHA384
- HMAC::SHA512
- Net
- Net::HTTP
- HTMLComment
- HTMLTag
- HTMLText
- HTMLToken
- HTMLTokenizer
- HTMLTokenizerError
- Object

No matching classes.

# OpenID::Nonce

### Constants

DEFAULT_SKEW
TIME_FMT
TIME_STR_LEN
TIME_VALIDATOR

### Public Class Methods

check_timestamp(nonce_str, allowed_skew=nil, now=nil) click to toggle source

Is the timestamp that is part of the specified nonce string within the allowed clock-skew of the current time?

    # File lib/openid/store/nonce.rb, line 37
    def Nonce.check_timestamp(nonce_str, allowed_skew=nil, now=nil)
      allowed_skew = skew if allowed_skew.nil?
      begin
        stamp, _ = split_nonce(nonce_str)
      rescue ArgumentError # bad timestamp
        return false
      end
      now = Time.now.to_i unless now

      # times before this are too old
      past = now - allowed_skew

      # times newer than this are too far in the future
      future = now + allowed_skew

      return (past <= stamp and stamp <= future)
    end

mk_nonce(time = nil) click to toggle source

generate a nonce with the specified timestamp (defaults to now)

    # File lib/openid/store/nonce.rb, line 56
    def Nonce.mk_nonce(time = nil)
      salt = CryptUtil::random_string(6, @@NONCE_CHRS)
      if time.nil?
        t = Time.now.getutc
      else
        t = Time.at(time).getutc
      end
      time_str = t.strftime(TIME_FMT)
      return time_str + salt
    end

skew() click to toggle source

The allowed nonce time skew in seconds. Defaults to 5 hours. Used for checking nonce validity, and by stores' cleanup methods.

    # File lib/openid/store/nonce.rb, line 17
    def Nonce.skew
      @skew
    end

skew=(new_skew) click to toggle source

    # File lib/openid/store/nonce.rb, line 21
    def Nonce.skew=(new_skew)
      @skew = new_skew
    end

split_nonce(nonce_str) click to toggle source

Extract timestamp from a nonce string

    # File lib/openid/store/nonce.rb, line 26
    def Nonce.split_nonce(nonce_str)
      timestamp_str = nonce_str[0...TIME_STR_LEN]
      raise ArgumentError if timestamp_str.size < TIME_STR_LEN
      raise ArgumentError unless timestamp_str.match(TIME_VALIDATOR)
      ts = Time.parse(timestamp_str).to_i
      raise ArgumentError if ts < 0
      return ts, nonce_str[TIME_STR_LEN..-1]
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.