lib/origami/signature.rb in origami-1.2.5 vs lib/origami/signature.rb in origami-1.2.6
- old
+ new
@@ -21,11 +21,16 @@
You should have received a copy of the GNU Lesser General Public License
along with Origami. If not, see <http://www.gnu.org/licenses/>.
=end
-require 'openssl'
+begin
+ require 'openssl' if Origami::OPTIONS[:use_openssl]
+rescue LoadError
+ Origami::OPTIONS[:use_openssl] = false
+end
+
require 'digest/sha1'
module Origami
class PDF
@@ -38,10 +43,15 @@
# Options:
# _:trusted_: an array of trusted X509 certificates.
# If no argument is passed, embedded certificates are treated as trusted.
#
def verify(options = {})
+
+ unless Origami::OPTIONS[:use_openssl]
+ fail "OpenSSL is not present or has been disabled."
+ end
+
params =
{
:trusted => []
}.update(options)
@@ -259,28 +269,32 @@
#
# Returns whether the document contains a digital signature.
#
def is_signed?
- not self.Catalog.AcroForm.nil? and
- self.Catalog.AcroForm.has_key?(:SigFlags) and
- (self.Catalog.AcroForm.SigFlags & InteractiveForm::SigFlags::SIGNATURESEXIST != 0)
+ begin
+ self.Catalog.AcroForm.is_a?(Dictionary) and
+ self.Catalog.AcroForm.has_key?(:SigFlags) and
+ (self.Catalog.AcroForm.SigFlags & InteractiveForm::SigFlags::SIGNATURESEXIST != 0)
+ rescue InvalidReferenceError
+ false
+ end
end
#
# Enable the document Usage Rights.
# _rights_:: list of rights defined in UsageRights::Rights
#
def enable_usage_rights(cert, pkey, *rights)
+ unless Origami::OPTIONS[:use_openssl]
+ fail "OpenSSL is not present or has been disabled."
+ end
+
signfield_size = lambda{|crt, key, ca|
datatest = "abcdefghijklmnopqrstuvwxyz"
OpenSSL::PKCS7.sign(crt, key, datatest, ca, OpenSSL::PKCS7::DETACHED | OpenSSL::PKCS7::BINARY).to_der.size + 128
}
-
- unless Origami::OPTIONS[:use_openssl]
- fail "OpenSSL is not present or has been disabled."
- end
#
# Load key pair
#
key = pkey.is_a?(OpenSSL::PKey::RSA) ? pkey : OpenSSL::PKey::RSA.new(pkey)