Class: Rack::Blinkbox::Zuul::FileKeyFinder
- Inherits:
-
Object
- Object
- Rack::Blinkbox::Zuul::FileKeyFinder
- Defined in:
- lib/rack/blinkbox/zuul/tokens/file_key_finder.rb
Overview
A simple key finder which uses the key identifier to locate keys on the file system.
Instance Method Summary collapse
-
#initialize(key_dir = "./keys") ⇒ FileKeyFinder
constructor
Initialises a new file key finder.
-
#key_with_id(key_id, type) ⇒ String
Loads a key with a specified identifier.
Constructor Details
#initialize(key_dir = "./keys") ⇒ FileKeyFinder
Initialises a new file key finder.
13 14 15 |
# File 'lib/rack/blinkbox/zuul/tokens/file_key_finder.rb', line 13 def initialize(key_dir = "./keys") @key_dir = key_dir end |
Instance Method Details
#key_with_id(key_id, type) ⇒ String
Loads a key with a specified identifier.
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rack/blinkbox/zuul/tokens/file_key_finder.rb', line 22 def key_with_id(key_id, type) raise Sandal::InvalidTokenError.new("Unspecified key.") if key_id.nil? key_dir = ::File.join(@key_dir, ::File.(key_id, "/")) # mitigate directory expansion attacks key_file = "#{key_dir}/#{type}.pem" begin ::File.read(key_file) # TODO: Binary read rescue raise Sandal::InvalidTokenError.new("Unknown key.") end end |