origamindee 3.1.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +4 -2
- data/lib/origami/graphics/instruction.rb +1 -1
- data/lib/origami/signature.rb +11 -10
- data/lib/origami/version.rb +1 -1
- data/lib/origami.rb +1 -0
- data/test/test_actions.rb +1 -1
- data/test/test_pdf_sign.rb +44 -19
- data/test/test_xrefs.rb +1 -1
- metadata +25 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45413662e5fb14c50c4dd206522be8e187950c6119b3f8a3a1c2632f363d797d
|
4
|
+
data.tar.gz: 6a016143c0898b649e1b386af4daf117e3c023f7acb414f7a48dbc578ec0afdc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3612b2edae8776c43acb2715a38e16e47a0416d83b11568136b053ad4f9137f1d827b371d26a25861dfdd12fcd92af871ae02c8ba714ce915fcd0191f6134bf2
|
7
|
+
data.tar.gz: 8bacd88b9cb1020e1986aaafe75520f1ec993d299b3dbfb98e70f0041609e57c954a8ca8a14752e3cd6b2091507282570c15f263c9edfe590509846288774bff
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -27,7 +27,9 @@ Origami is able to parse PDF, FDF and PPKLite (Adobe certificate store) files.
|
|
27
27
|
|
28
28
|
Requirements
|
29
29
|
------------
|
30
|
-
The following Ruby versions are tested and supported:
|
30
|
+
The following Ruby versions are tested and supported: 3.0, 3.1, 3.2, 3.3, 3.4
|
31
|
+
|
32
|
+
(It could maybe, possibly, in some cases run on Ruby 2.7, but no guarantees. Update your stack.)
|
31
33
|
|
32
34
|
Some optional features require additional gems:
|
33
35
|
|
@@ -114,7 +116,7 @@ It was therefore replaced by `Rainbow` which has similar functionality, and is l
|
|
114
116
|
|
115
117
|
Furthermore, we are now in a better position to fix any problems related to PDF parsing that are encountered by our users.
|
116
118
|
|
117
|
-
As such it is our intention to support functionalities within the scope of our client library.
|
119
|
+
As such it is our intention to support functionalities within the scope of our Ruby client library.
|
118
120
|
|
119
121
|
**We do not claim to be an official successor to Origami.**
|
120
122
|
|
data/lib/origami/signature.rb
CHANGED
@@ -70,7 +70,7 @@ module Origami
|
|
70
70
|
#
|
71
71
|
# Sign the document with the given key and x509 certificate.
|
72
72
|
# _certificate_:: The X509 certificate containing the public key.
|
73
|
-
# _key_:: The private key associated with the certificate.
|
73
|
+
# _key_:: The RSA or EC private key associated with the certificate.
|
74
74
|
# _method_:: The PDF signature identifier.
|
75
75
|
# _ca_:: Optional CA certificates used to sign the user certificate.
|
76
76
|
# _annotation_:: Annotation associated with the signature.
|
@@ -89,19 +89,19 @@ module Origami
|
|
89
89
|
reason: nil)
|
90
90
|
|
91
91
|
unless certificate.is_a?(OpenSSL::X509::Certificate)
|
92
|
-
raise TypeError,
|
92
|
+
raise TypeError, 'A OpenSSL::X509::Certificate object must be passed.'
|
93
93
|
end
|
94
94
|
|
95
|
-
unless key.is_a?(OpenSSL::PKey::RSA)
|
96
|
-
raise TypeError,
|
95
|
+
unless (key.is_a?(OpenSSL::PKey::RSA) || key.is_a?(OpenSSL::PKey::EC))
|
96
|
+
raise TypeError, 'An OpenSSL::PKey::RSA or OpenSSL::PKey::EC object must be passed.'
|
97
97
|
end
|
98
98
|
|
99
99
|
unless ca.is_a?(::Array)
|
100
|
-
raise TypeError,
|
100
|
+
raise TypeError, 'Expected an Array of CA certificates.'
|
101
101
|
end
|
102
102
|
|
103
103
|
unless annotation.nil? or annotation.is_a?(Annotation::Widget::Signature)
|
104
|
-
raise TypeError,
|
104
|
+
raise TypeError, 'Expected a Annotation::Widget::Signature object.'
|
105
105
|
end
|
106
106
|
|
107
107
|
#
|
@@ -125,7 +125,8 @@ module Origami
|
|
125
125
|
InteractiveForm::SigFlags::SIGNATURES_EXIST | InteractiveForm::SigFlags::APPEND_ONLY
|
126
126
|
|
127
127
|
digsig.Type = :Sig
|
128
|
-
|
128
|
+
placeholder_size = Signature::required_size(method, certificate, key, ca) + 128
|
129
|
+
digsig.Contents = HexaString.new("\x00" * placeholder_size)
|
129
130
|
digsig.Filter = :"Adobe.PPKLite"
|
130
131
|
digsig.SubFilter = Name.new(method)
|
131
132
|
digsig.ByteRange = [0, 0, 0, 0]
|
@@ -327,7 +328,7 @@ module Origami
|
|
327
328
|
r1.end != start_sig or
|
328
329
|
r2.begin != end_sig
|
329
330
|
|
330
|
-
raise SignatureError,
|
331
|
+
raise SignatureError, 'Invalid signature byte range'
|
331
332
|
end
|
332
333
|
|
333
334
|
self.original_data[r1] + self.original_data[r2]
|
@@ -589,7 +590,7 @@ module Origami
|
|
589
590
|
byte_range = self.ByteRange
|
590
591
|
|
591
592
|
unless byte_range.is_a?(Array) and byte_range.length == 4 and byte_range.all? {|i| i.is_a?(Integer) }
|
592
|
-
raise SignatureError,
|
593
|
+
raise SignatureError, 'Invalid ByteRange field value'
|
593
594
|
end
|
594
595
|
|
595
596
|
byte_range.map(&:to_i).each_slice(2).map do |start, length|
|
@@ -608,7 +609,7 @@ module Origami
|
|
608
609
|
|
609
610
|
chain = self.Cert
|
610
611
|
unless chain.is_a?(String) or (chain.is_a?(Array) and chain.all?{|cert| cert.is_a?(String)})
|
611
|
-
return SignatureError,
|
612
|
+
return SignatureError, 'Invalid embedded certificate chain'
|
612
613
|
end
|
613
614
|
|
614
615
|
[ chain ].flatten.map! {|str| OpenSSL::X509::Certificate.new(str) }
|
data/lib/origami/version.rb
CHANGED
data/lib/origami.rb
CHANGED
data/test/test_actions.rb
CHANGED
data/test/test_pdf_sign.rb
CHANGED
@@ -4,9 +4,7 @@ require 'openssl'
|
|
4
4
|
|
5
5
|
class TestSign < Minitest::Test
|
6
6
|
|
7
|
-
def create_self_signed_ca_certificate(
|
8
|
-
key = OpenSSL::PKey::RSA.new key_size
|
9
|
-
|
7
|
+
def create_self_signed_ca_certificate(key, expires)
|
10
8
|
name = OpenSSL::X509::Name.parse 'CN=origami/DC=example'
|
11
9
|
|
12
10
|
cert = OpenSSL::X509::Certificate.new
|
@@ -14,8 +12,7 @@ class TestSign < Minitest::Test
|
|
14
12
|
cert.serial = 0
|
15
13
|
cert.not_before = Time.now
|
16
14
|
cert.not_after = Time.now + expires
|
17
|
-
|
18
|
-
cert.public_key = key.public_key
|
15
|
+
cert.public_key = key
|
19
16
|
cert.subject = name
|
20
17
|
|
21
18
|
extension_factory = OpenSSL::X509::ExtensionFactory.new
|
@@ -29,12 +26,28 @@ class TestSign < Minitest::Test
|
|
29
26
|
cert.issuer = name
|
30
27
|
cert.sign key, OpenSSL::Digest::SHA256.new
|
31
28
|
|
32
|
-
|
29
|
+
cert
|
30
|
+
end
|
31
|
+
|
32
|
+
def ec_test_data(curve_name)
|
33
|
+
key = OpenSSL::PKey::EC.generate(curve_name)
|
34
|
+
other_key = OpenSSL::PKey::EC.generate(curve_name)
|
35
|
+
cert = create_self_signed_ca_certificate(key, 3600)
|
36
|
+
other_cert = create_self_signed_ca_certificate(other_key, 3600)
|
37
|
+
[ cert, key, other_cert ]
|
38
|
+
end
|
39
|
+
|
40
|
+
def rsa_test_data(key_size)
|
41
|
+
key = OpenSSL::PKey::RSA.new(key_size)
|
42
|
+
other_key = OpenSSL::PKey::RSA.new(key_size)
|
43
|
+
cert = create_self_signed_ca_certificate(key, 3600)
|
44
|
+
other_cert = create_self_signed_ca_certificate(other_key, 3600)
|
45
|
+
[ cert, key, other_cert ]
|
33
46
|
end
|
34
47
|
|
35
48
|
def setup
|
36
|
-
@
|
37
|
-
@
|
49
|
+
@rsa_1024_data = rsa_test_data(1024)
|
50
|
+
@ec_prime256v1_data = ec_test_data('prime256v1')
|
38
51
|
end
|
39
52
|
|
40
53
|
def setup_document_with_annotation
|
@@ -51,10 +64,10 @@ class TestSign < Minitest::Test
|
|
51
64
|
[ document, annotation ]
|
52
65
|
end
|
53
66
|
|
54
|
-
def sign_document_with_method(method)
|
67
|
+
def sign_document_with_method(method, cert, key, other_cert)
|
55
68
|
document, annotation = setup_document_with_annotation
|
56
69
|
|
57
|
-
document.sign(
|
70
|
+
document.sign(cert, key,
|
58
71
|
method: method,
|
59
72
|
annotation: annotation,
|
60
73
|
issuer: "Guillaume Delugré",
|
@@ -73,25 +86,37 @@ class TestSign < Minitest::Test
|
|
73
86
|
|
74
87
|
refute document.verify
|
75
88
|
assert document.verify(allow_self_signed: true)
|
76
|
-
assert document.verify(trusted_certs: [
|
77
|
-
refute document.verify(trusted_certs: [
|
89
|
+
assert document.verify(trusted_certs: [cert])
|
90
|
+
refute document.verify(trusted_certs: [other_cert])
|
78
91
|
|
79
92
|
result = document.verify do |ctx|
|
80
|
-
ctx.error == OpenSSL::X509::V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT and ctx.current_cert.to_pem ==
|
93
|
+
ctx.error == OpenSSL::X509::V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT and ctx.current_cert.to_pem == cert.to_pem
|
81
94
|
end
|
82
95
|
|
83
96
|
assert result
|
84
97
|
end
|
85
98
|
|
86
|
-
def
|
87
|
-
sign_document_with_method(Signature::PKCS7_SHA1)
|
99
|
+
def test_rsa_sign_pkcs7_sha1
|
100
|
+
sign_document_with_method(Signature::PKCS7_SHA1, *@rsa_1024_data)
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_rsa_sign_pkcs7_detached
|
104
|
+
sign_document_with_method(Signature::PKCS7_DETACHED, *@rsa_1024_data)
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_rsa_sign_x509_sha1
|
108
|
+
sign_document_with_method(Signature::PKCS1_RSA_SHA1, *@rsa_1024_data)
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_ec_sign_pkcs7_sha1
|
112
|
+
sign_document_with_method(Signature::PKCS7_SHA1, *@ec_prime256v1_data)
|
88
113
|
end
|
89
114
|
|
90
|
-
def
|
91
|
-
sign_document_with_method(Signature::PKCS7_DETACHED)
|
115
|
+
def test_ec_sign_pkcs7_detached
|
116
|
+
sign_document_with_method(Signature::PKCS7_DETACHED, *@ec_prime256v1_data)
|
92
117
|
end
|
93
118
|
|
94
|
-
def
|
95
|
-
sign_document_with_method(Signature::PKCS1_RSA_SHA1)
|
119
|
+
def test_ec_sign_x509_sha1
|
120
|
+
sign_document_with_method(Signature::PKCS1_RSA_SHA1, *@ec_prime256v1_data)
|
96
121
|
end
|
97
122
|
end
|
data/test/test_xrefs.rb
CHANGED
metadata
CHANGED
@@ -1,16 +1,30 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: origamindee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guillaume Delugré
|
8
8
|
- Mindee, SA
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2025-02-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: base64
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 0.1.0
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 0.1.0
|
14
28
|
- !ruby/object:Gem::Dependency
|
15
29
|
name: rainbow
|
16
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,23 +96,23 @@ dependencies:
|
|
82
96
|
- !ruby/object:Gem::Version
|
83
97
|
version: '12.3'
|
84
98
|
- !ruby/object:Gem::Dependency
|
85
|
-
name:
|
99
|
+
name: yard
|
86
100
|
requirement: !ruby/object:Gem::Requirement
|
87
101
|
requirements:
|
88
102
|
- - "~>"
|
89
103
|
- !ruby/object:Gem::Version
|
90
|
-
version: '
|
104
|
+
version: '0.9'
|
91
105
|
type: :development
|
92
106
|
prerelease: false
|
93
107
|
version_requirements: !ruby/object:Gem::Requirement
|
94
108
|
requirements:
|
95
109
|
- - "~>"
|
96
110
|
- !ruby/object:Gem::Version
|
97
|
-
version: '
|
111
|
+
version: '0.9'
|
98
112
|
description: Mindee's fork of Origami, a pure Ruby library to parse, modify and generate
|
99
113
|
PDF documents.
|
100
114
|
email:
|
101
|
-
-
|
115
|
+
- opensource@mindee.co
|
102
116
|
executables:
|
103
117
|
- pdfsh
|
104
118
|
- pdf2pdfa
|
@@ -260,7 +274,7 @@ metadata:
|
|
260
274
|
source_code_uri: https://github.com/mindee/origamindee
|
261
275
|
changelog_uri: https://github.com/mindee/origamindee/blob/main/CHANGELOG.md
|
262
276
|
rubygems_mfa_required: 'true'
|
263
|
-
post_install_message:
|
277
|
+
post_install_message:
|
264
278
|
rdoc_options: []
|
265
279
|
require_paths:
|
266
280
|
- lib
|
@@ -268,15 +282,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
268
282
|
requirements:
|
269
283
|
- - ">="
|
270
284
|
- !ruby/object:Gem::Version
|
271
|
-
version: '2.
|
285
|
+
version: '2.7'
|
272
286
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
273
287
|
requirements:
|
274
288
|
- - ">="
|
275
289
|
- !ruby/object:Gem::Version
|
276
290
|
version: '0'
|
277
291
|
requirements: []
|
278
|
-
rubygems_version: 3.
|
279
|
-
signing_key:
|
292
|
+
rubygems_version: 3.2.33
|
293
|
+
signing_key:
|
280
294
|
specification_version: 4
|
281
295
|
summary: Ruby framework to manipulate PDF documents
|
282
296
|
test_files:
|