Class: Wsaa::CmsSigner
- Inherits:
-
Object
- Object
- Wsaa::CmsSigner
- Defined in:
- lib/wsaa/cms_signer.rb
Overview
Signs data using CMS/PKCS#7 format.
Creates cryptographic signatures compatible with WSAA requirements.
Instance Attribute Summary collapse
-
#certificate ⇒ OpenSSL::X509::Certificate
readonly
The signing certificate.
-
#private_key ⇒ OpenSSL::PKey::RSA
readonly
The private key for signing.
Instance Method Summary collapse
-
#initialize(cert_path:, pkey_path:) ⇒ CmsSigner
constructor
Creates a new CmsSigner.
-
#sign(data) ⇒ String
Signs data and returns the base64-encoded CMS signature.
Constructor Details
#initialize(cert_path:, pkey_path:) ⇒ CmsSigner
Creates a new CmsSigner.
21 22 23 24 |
# File 'lib/wsaa/cms_signer.rb', line 21 def initialize(cert_path:, pkey_path:) @certificate = load_certificate(cert_path) @private_key = load_private_key(pkey_path) end |
Instance Attribute Details
#certificate ⇒ OpenSSL::X509::Certificate (readonly)
The signing certificate.
12 13 14 |
# File 'lib/wsaa/cms_signer.rb', line 12 def certificate @certificate end |
#private_key ⇒ OpenSSL::PKey::RSA (readonly)
The private key for signing.
12 13 14 |
# File 'lib/wsaa/cms_signer.rb', line 12 def private_key @private_key end |
Instance Method Details
#sign(data) ⇒ String
Signs data and returns the base64-encoded CMS signature.
32 33 34 35 36 37 38 |
# File 'lib/wsaa/cms_signer.rb', line 32 def sign(data) flags = OpenSSL::PKCS7::BINARY | OpenSSL::PKCS7::NOSMIMECAP pkcs7 = OpenSSL::PKCS7.sign(certificate, private_key, data, [], flags) Base64.strict_encode64(pkcs7.to_der) rescue OpenSSL::PKCS7::PKCS7Error => e raise SigningError, "Failed to sign data: #{e.}" end |