Class: AadhaarAuth::DigitalSigner

Inherits:
Object
  • Object
show all
Defined in:
lib/aadhaar_auth/digital_signer.rb

Defined Under Namespace

Classes: InvalidSignature

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.pkcs12Object



17
18
19
# File 'lib/aadhaar_auth/digital_signer.rb', line 17

def pkcs12
  @pkcs12 ||= OpenSSL::PKCS12.new(File.read(Config.digital_signature_path), Config.digital_signature_pwd)
end

.private_keyObject



21
22
23
# File 'lib/aadhaar_auth/digital_signer.rb', line 21

def private_key
  @private_key ||= OpenSSL::PKey::RSA.new(pkcs12.key.to_s)
end

.private_key_certObject



25
26
27
# File 'lib/aadhaar_auth/digital_signer.rb', line 25

def private_key_cert
  @private_key_cert ||= OpenSSL::X509::Certificate.new(pkcs12.certificate.to_s)
end

.private_key_cert_valObject



29
30
31
# File 'lib/aadhaar_auth/digital_signer.rb', line 29

def private_key_cert_val
  @private_key_cert_val ||= private_key_cert.to_s.sub(/^-----BEGIN CERTIFICATE-----\n/, '').sub(/-----END CERTIFICATE-----\n$/, '')
end

Instance Method Details

#sign(xml) ⇒ Object



6
7
8
# File 'lib/aadhaar_auth/digital_signer.rb', line 6

def sign(xml)
  Xmldsig::SignedDocument.new(xml).sign(self.class.private_key)
end

#verify_signature(xml) ⇒ Object



10
11
12
13
14
# File 'lib/aadhaar_auth/digital_signer.rb', line 10

def verify_signature(xml)
  if !Xmldsig::SignedDocument.new(xml).validate(Encrypter.public_cert)
    raise InvalidSignature.new("Invalid response signature")
  end
end