pdf-reader 2.0.0.beta1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +3 -0
- data/lib/pdf/reader.rb +2 -0
- data/lib/pdf/reader/null_security_handler.rb +16 -0
- data/lib/pdf/reader/object_hash.rb +18 -10
- data/lib/pdf/reader/standard_security_handler.rb +30 -24
- data/lib/pdf/reader/unimplemented_security_handler.rb +16 -0
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d34a3033638fcf4f78ce2d71dd5f5aebc2ea7d68
|
4
|
+
data.tar.gz: 912ed3986ab7e7eefce8f987cffc0d0357bcd675
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a24c874cae12838cf122c92338e6da1639d15187be9ef5c1f149eedd0167cc21b53544c3148efd37992535efe2d0ec4487a02fc3a668992295cecc7aa5529f2a
|
7
|
+
data.tar.gz: c88b9daa21de84eb2a841cc024c499ecc7c5d4b5908ad6618494fa3e7f5d694d291ae87ceb72f5ff9f4d2db66b3bc781e1ff499485ba50290710c6e1061a76db
|
data/CHANGELOG
CHANGED
data/lib/pdf/reader.rb
CHANGED
@@ -275,7 +275,9 @@ require 'pdf/reader/parser'
|
|
275
275
|
require 'pdf/reader/print_receiver'
|
276
276
|
require 'pdf/reader/reference'
|
277
277
|
require 'pdf/reader/register_receiver'
|
278
|
+
require 'pdf/reader/null_security_handler'
|
278
279
|
require 'pdf/reader/standard_security_handler'
|
280
|
+
require 'pdf/reader/unimplemented_security_handler'
|
279
281
|
require 'pdf/reader/stream'
|
280
282
|
require 'pdf/reader/text_run'
|
281
283
|
require 'pdf/reader/page_state'
|
@@ -45,6 +45,7 @@ class PDF::Reader
|
|
45
45
|
@pdf_version = read_version
|
46
46
|
@trailer = @xref.trailer
|
47
47
|
@cache = opts[:cache] || PDF::Reader::ObjectCache.new
|
48
|
+
@sec_handler = NullSecurityHandler.new
|
48
49
|
@sec_handler = build_security_handler(opts)
|
49
50
|
end
|
50
51
|
|
@@ -286,20 +287,27 @@ class PDF::Reader
|
|
286
287
|
end
|
287
288
|
|
288
289
|
def build_security_handler(opts = {})
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
StandardSecurityHandler.new(
|
290
|
+
encrypt = deref(trailer[:Encrypt])
|
291
|
+
if NullSecurityHandler.supports?(encrypt)
|
292
|
+
NullSecurityHandler.new
|
293
|
+
elsif StandardSecurityHandler.supports?(encrypt)
|
294
|
+
encmeta = !encrypt.has_key?(:EncryptMetadata) || encrypt[:EncryptMetadata].to_s == "true"
|
295
|
+
StandardSecurityHandler.new(
|
296
|
+
key_length: (encrypt[:Length] || 40).to_i,
|
297
|
+
revision: encrypt[:R],
|
298
|
+
owner_key: encrypt[:O],
|
299
|
+
user_key: encrypt[:U],
|
300
|
+
permissions: encrypt[:P].to_i,
|
301
|
+
encrypted_metadata: encmeta,
|
302
|
+
file_id: (deref(trailer[:ID]) || []).first,
|
303
|
+
password: opts[:password]
|
304
|
+
)
|
295
305
|
else
|
296
|
-
|
306
|
+
UnimplementedSecurityHandler.new
|
297
307
|
end
|
298
308
|
end
|
299
309
|
|
300
310
|
def decrypt(ref, obj)
|
301
|
-
return obj unless sec_handler?
|
302
|
-
|
303
311
|
case obj
|
304
312
|
when PDF::Reader::Stream then
|
305
313
|
obj.data = sec_handler.decrypt(obj.data, ref)
|
@@ -331,7 +339,7 @@ class PDF::Reader
|
|
331
339
|
# returns a nested array of object references for all pages in this object store.
|
332
340
|
#
|
333
341
|
def get_page_objects(ref)
|
334
|
-
obj =
|
342
|
+
obj = deref(ref)
|
335
343
|
|
336
344
|
if obj[:Type] == :Page
|
337
345
|
ref
|
@@ -42,30 +42,36 @@ class PDF::Reader
|
|
42
42
|
0x2e, 0x2e, 0x00, 0xb6, 0xd0, 0x68, 0x3e, 0x80,
|
43
43
|
0x2f, 0x0c, 0xa9, 0xfe, 0x64, 0x53, 0x69, 0x7a ]
|
44
44
|
|
45
|
-
attr_reader :
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
@
|
52
|
-
@
|
53
|
-
@
|
54
|
-
@
|
55
|
-
@
|
56
|
-
@
|
57
|
-
|
58
|
-
@
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
45
|
+
attr_reader :key_length, :revision, :encrypt_key
|
46
|
+
attr_reader :owner_key, :user_key, :permissions, :file_id, :password
|
47
|
+
|
48
|
+
def initialize(opts = {})
|
49
|
+
@key_length = opts[:key_length].to_i/8
|
50
|
+
@revision = opts[:revision].to_i
|
51
|
+
@owner_key = opts[:owner_key]
|
52
|
+
@user_key = opts[:user_key]
|
53
|
+
@permissions = opts[:permissions].to_i
|
54
|
+
@encryptMeta = opts.fetch(:encrypted_metadata, true)
|
55
|
+
@file_id = opts[:file_id] || ""
|
56
|
+
@encrypt_key = build_standard_key(opts[:password] || "")
|
57
|
+
|
58
|
+
if @key_length != 5 && @key_length != 16
|
59
|
+
msg = "StandardSecurityHandler only supports 40 and 128 bit\
|
60
|
+
encryption (#{@key_length * 8}bit)"
|
61
|
+
raise ArgumentError, msg
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# This handler supports all RC4 encryption that follows the PDF spec. It does not support
|
66
|
+
# AES encryption that was added in later versions of the spec.
|
67
|
+
def self.supports?(encrypt)
|
68
|
+
return false if encrypt.nil?
|
69
|
+
|
70
|
+
filter = encrypt.fetch(:Filter, :Standard)
|
71
|
+
version = encrypt.fetch(:V, 0)
|
72
|
+
algorithm = encrypt.fetch(:CF, {}).fetch(encrypt[:StmF], {}).fetch(:CFM, nil)
|
73
|
+
filter == :Standard &&
|
74
|
+
(version <= 3 || (version == 4 && algorithm != :AESV2))
|
69
75
|
end
|
70
76
|
|
71
77
|
##7.6.2 General Encryption Algorithm
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
class PDF::Reader
|
4
|
+
|
5
|
+
# Security handler for when we don't support the flavour of encryption
|
6
|
+
# used in a PDF.
|
7
|
+
class UnimplementedSecurityHandler
|
8
|
+
def self.supports?(encrypt)
|
9
|
+
true
|
10
|
+
end
|
11
|
+
|
12
|
+
def decrypt(buf, ref)
|
13
|
+
raise PDF::Reader::EncryptedPDFError, "Unsupported encryption style"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pdf-reader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Healy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02-
|
11
|
+
date: 2017-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -241,6 +241,7 @@ files:
|
|
241
241
|
- lib/pdf/reader/glyph_hash.rb
|
242
242
|
- lib/pdf/reader/glyphlist.txt
|
243
243
|
- lib/pdf/reader/lzw.rb
|
244
|
+
- lib/pdf/reader/null_security_handler.rb
|
244
245
|
- lib/pdf/reader/object_cache.rb
|
245
246
|
- lib/pdf/reader/object_hash.rb
|
246
247
|
- lib/pdf/reader/object_stream.rb
|
@@ -261,6 +262,7 @@ files:
|
|
261
262
|
- lib/pdf/reader/text_run.rb
|
262
263
|
- lib/pdf/reader/token.rb
|
263
264
|
- lib/pdf/reader/transformation_matrix.rb
|
265
|
+
- lib/pdf/reader/unimplemented_security_handler.rb
|
264
266
|
- lib/pdf/reader/width_calculator.rb
|
265
267
|
- lib/pdf/reader/width_calculator/built_in.rb
|
266
268
|
- lib/pdf/reader/width_calculator/composite.rb
|
@@ -288,12 +290,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
288
290
|
version: 1.9.3
|
289
291
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
290
292
|
requirements:
|
291
|
-
- - "
|
293
|
+
- - ">="
|
292
294
|
- !ruby/object:Gem::Version
|
293
|
-
version:
|
295
|
+
version: '0'
|
294
296
|
requirements: []
|
295
297
|
rubyforge_project:
|
296
|
-
rubygems_version: 2.
|
298
|
+
rubygems_version: 2.6.8
|
297
299
|
signing_key:
|
298
300
|
specification_version: 4
|
299
301
|
summary: A library for accessing the content of PDF files
|