Permalink
Browse files

added certificate password field to configuration

git-svn-id: svn://rubyforge.org/var/svn/rubyhealthvault/trunk@8 5e59f7e3-561f-4167-93e6-46889eec4fca
  • Loading branch information...
1 parent a815505 commit ff157b5704d9e7981760dc50a922c966dfb6d1b0 dannycoates committed Jun 7, 2008
Showing with 12 additions and 9 deletions.
  1. +5 −4 lib/application.rb
  2. +3 −2 lib/config.rb
  3. +4 −3 lib/utils/crypto_utils.rb
View
@@ -14,19 +14,20 @@ module HealthVault
class Application
attr_reader :id, :uri
- def initialize(id, hv_uri, certificate_location)
+ def initialize(id, hv_uri, certificate_location, certificate_password)
@id = id
@uri = URI.parse(hv_uri)
- @key_file = certificate_location
+ @cert_file = certificate_location
+ @cert_pass = certificate_password
end
def key
- return CryptoKey.new(@key_file)
+ return CryptoKey.new(@cert_file, @cert_pass)
end
def self.default
config = Configuration.instance
- return Application.new(config.app_id, config.hv_url, config.cert_file)
+ return Application.new(config.app_id, config.hv_url, config.cert_file, config.cert_pass)
end
def create_connection
View
@@ -11,14 +11,15 @@
module HealthVault
class Configuration
include Singleton
- attr_accessor :app_id, :cert_file, :shell_url, :hv_url, :logger
+ attr_accessor :app_id, :cert_file, :cert_pass, :shell_url, :hv_url, :logger
- #default values to the HelloWorld sample
+ #default values to the HelloWorld sample.
#theses should be set by your application
#using HealthVault::Configuration.instance accessor methods
def initialize
@app_id = "05a059c9-c309-46af-9b86-b06d42510550"
@cert_file = File.dirname(__FILE__) + "/../bin/certs/helloWorld.pem"
+ @cert_pass = ""
@shell_url = "https://account.healthvault-ppe.com"
@hv_url = "https://platform.healthvault-ppe.com/platform/wildcat.ashx"
@logger = Logger.new("hv.log")
@@ -33,16 +33,17 @@ def self.digest(text)
end
class CryptoKey
- def initialize(pfx_or_pem_filename)
+ def initialize(pfx_or_pem_filename, password = nil)
begin
#INFO: I can't get OpenSSL::PKCS12 working on windows.
# This call fails with 'mac verify failed'
# To work around this I created a pem on the command line like:
# openssl pkcs12 -in xxx.pfx -out xxx.pem -nodes
- @pfx = OpenSSL::PKCS12::PKCS12.new(File.read(pfx_or_pem_filename))
+ @pfx = OpenSSL::PKCS12::PKCS12.new(File.read(pfx_or_pem_filename), password)
+ #TODO if pfx files are going to be a problem, maybe we just ought to remove
rescue
@pfx = nil
- @pkey = OpenSSL::PKey::RSA.new(File.read(pfx_or_pem_filename))
+ @pkey = OpenSSL::PKey::RSA.new(File.read(pfx_or_pem_filename),password)
@cert = OpenSSL::X509::Certificate.new(File.read(pfx_or_pem_filename))
end
end

0 comments on commit ff157b5

Please sign in to comment.