Class: WSS4R::Tokenresolver::CertificateDirectoryResolver

Inherits:
Resolver
  • Object
show all
Defined in:
lib/wss4r/tokenresolver/certificateresolver.rb

Instance Method Summary collapse

Methods inherited from Resolver

#authenticate_user

Constructor Details

#initialize(directory) ⇒ CertificateDirectoryResolver

Returns a new instance of CertificateDirectoryResolver.



8
9
10
11
# File 'lib/wss4r/tokenresolver/certificateresolver.rb', line 8

def initialize(directory)
  File.stat(directory).directory?
  @directory = directory
end

Instance Method Details

#certificate_by_key_identifier(key_identifier) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/wss4r/tokenresolver/certificateresolver.rb', line 13

def certificate_by_key_identifier(key_identifier)
  files = Dir[@directory + "/*.cer"]
  files.each{|f|
    certificate = Certificate.new(File.read(f))
    if (key_identifier == certificate.key_identifier())
      certificate.filename=(f)
      return certificate
    end
  }
  nil
end

#certificate_by_subject(subject) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/wss4r/tokenresolver/certificateresolver.rb', line 43

def certificate_by_subject(subject)
  files = Dir[@directory + "/*.cer"]
  files.each{|f|
    certificate = Certificate.new(File.read(f))
    if (certificate.subject().to_s() == subject)
      certificate.filename=(f)
      return certificate
    end
  }
  nil
end

#private_key(certificate, passphrase = nil) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/wss4r/tokenresolver/certificateresolver.rb', line 25

def private_key(certificate, passphrase=nil)
  if (certificate.filename() != nil)
    if passphrase
      return (RSA.new(File.read(certificate.filename()), passphrase))
    else
      return (RSA.new(File.read(certificate.filename() + ".key")))
    end
  end
  files = Dir[@directory + "/*.key"]
  files.each{|f|
    pkey = RSA.new(File.read(f))
    if (certificate.check_private_key(pkey))
      return pkey
    end
  }
  return nil
end