| Class | Origami::Adobe::AddressBook |
| In: |
sources/parser/adobe/addressbook.rb
sources/parser/adobe/header.rb |
| Parent: | Object |
Class representing an Adobe Reader certificate store.
| Size | = | rev.body.size + 1 |
| Cert | = | OpenSSL::X509::Certificate.new(certfile).to_der |
| ID | = | self.Catalog.PPK.AddressBook.NextID |
| Trust | = | attributes |
| Viewable | = | viewable |
| Editable | = | editable |
| Size | = | @revisions.first.body.size + 1 |
| filename | [RW] | |
| header | [RW] | |
| revisions | [RW] |
# File sources/parser/adobe/addressbook.rb, line 108
108: def <<(object)
109:
110: object.set_indirect(true)
111:
112: if object.no.zero?
113: maxno = 1
114: while get_object(maxno) do maxno = maxno.succ end
115:
116: object.generation = 0
117: object.no = maxno
118: end
119:
120: @revisions.first.body[object.reference] = object
121:
122: object.reference
123: end
124:
125: def Catalog
126: get_object(@trailer.Root)
127: end
128:
129: def saveas(filename)
130:
131: bin = ""
132: bin << @header.to_s
133:
134: lastno, brange = 0, 0
135:
136: xrefs = [ XRef.new(0, XRef::LASTFREE, XRef::FREE) ]
137: xrefsection = XRef::Section.new
138:
139: @revisions.first.body.values.sort.each { |obj|
140: if (obj.no - lastno).abs > 1
141: xrefsection << XRef::Subsection.new(brange, xrefs)
142: brange = obj.no
143: xrefs.clear
144: end
145:
146: xrefs << XRef.new(bin.size, obj.generation, XRef::USED)
147: lastno = obj.no
148:
149: bin << obj.to_s
150: }
151:
152: xrefsection << XRef::Subsection.new(brange, xrefs)
153:
154: @xreftable = xrefsection
155: @trailer ||= Trailer.new
156: @trailer.Size = rev.body.size + 1
157: @trailer.startxref = bin.size
158:
159: bin << @xreftable.to_s
160: bin << @trailer.to_s
161:
162: fd = File.open(filename, "w").binmode
163: fd << bin
164: fd.close
165:
166: show_entries
167: end
168:
169: #
170: # Prints registered users in the address book
171: #
172: def show_users
173:
174: puts "----------"
175: puts "Users list"
176: puts "----------"
177:
178: @revisions.first.body.values.each { |obj| if obj.is_a?(User) then obj.show; puts end }
179:
180: nil
181: end
182:
183: #
184: # Prints registered certificates in the addressbook
185: #
186: def show_certs
187: puts "-----------------"
188: puts "Certificates list"
189: puts "-----------------"
190:
191: @revisions.first.body.values.each { |obj| if obj.is_a?(Certificate) then obj.show; puts end }
192:
193: nil
194: end
195:
196: #
197: # Prints certificate with the specified id
198: #
199: def show_cert(id)
200: certs = @revisions.first.body.values.find_all { |obj| obj.is_a?(Certificate) and obj.ID == id }
201:
202: certs.each { |cert| cert.show; puts }
203:
204: nil
205: end
206:
207: #
208: # Returns a Certificate dictionary corresponding to the specified id
209: #
210: def get_cert(id)
211:
212: @revisions.first.body.values.find { |obj| obj.is_a?(Certificate) and obj.ID == id }
213:
214: end
215:
216: def show_user(id)
217: users = @revisions.first.body.values.find_all { |obj| obj.is_a?(User) and obj.ID == id }
218:
219: users.each { |user| cert.show; puts }
220:
221: nil
222: end
223:
224: #
225: # Prints users and certificates registered in the address book
226: #
227: def show_entries
228: show_users
229: show_certs
230:
231: puts "End of address book."
232: end
233:
234: #
235: # Add a certificate into the address book
236: #
237: def add_certificate(certfile, attributes, viewable = false, editable = false)
238:
239: cert = Certificate.new
240: cert.Cert = OpenSSL::X509::Certificate.new(certfile).to_der
241: cert.ID = self.Catalog.PPK.AddressBook.NextID
242: self.Catalog.PPK.AddressBook.NextID += 1
243: cert.Trust = attributes
244: cert.Viewable = viewable
245: cert.Editable = editable
246:
247: self.Catalog.PPK.AddressBook.Entries.push(self << cert)
248:
249: show_certs
250: end
251:
252: alias to_s show_entries
253: alias to_str show_entries
254:
255: class Catalog < Dictionary
256:
257: include Configurable
258:
259: field :Type, :Type => Name, :Default => :Catalog, :Required => true
260: field :PPK, :Type => Dictionary, :Required => true
261:
262: def initialize(hash = {}) #:nodoc:
263: super(hash, true)
264: end
265:
266: end
267:
268: class PPK < Dictionary
269:
270: include Configurable
271:
272: field :Type, :Type => Name, :Default => :PPK, :Required => true
273: field :User, :Type => Dictionary, :Required => true
274: field :AddressBook, :Type => Dictionary, :Required => true
275: field :V, :Type => Integer, :Default => 0x10001, :Required => true
276:
277: def initialize(hash = {}) #:nodoc:
278: super(hash, false)
279: end
280:
281: end
282:
283: class UserList < Dictionary
284:
285: include Configurable
286:
287: field :Type, :Type => Name, :Default => :User, :Required => true
288:
289: def initialize(hash = {})
290: super(hash, false)
291: end
292:
293: end
294:
295: class AddressList < Dictionary
296:
297: include Configurable
298:
299: field :Type, :Type => Name, :Default => :AddressBook, :Required => true
300: field :NextID, :Type => Integer
301: field :Entries, :Type => Array, :Default => [], :Required => true
302:
303: def initialize(hash = {}) #:nodoc:
304: super(hash, false)
305: end
306:
307: end
308:
309: module Descriptor
310:
311: CERTIFICATE = 1
312: USER = 2
313:
314: def self.included(receiver) #:nodoc:
315: receiver.field :ID, :Type => Integer, :Required => true
316: receiver.field :ABEType, :Type => Integer, :Default => Descriptor::CERTIFICATE, :Required => true
317: end
318:
319: def initialize(hash = {}) #:nodoc:
320: super(hash, true)
321: end
322:
323: end
324:
325: class User < Dictionary
326:
327: include Configurable
328: include Descriptor
329:
330: field :ABEType, :Type => Integer, :Default => Descriptor::USER, :Required => true
331: field :Name, :Type => String, :Required => true
332: field :Encrypt, :Type => Integer
333: field :Certs, :Type => Array, :Default => [], :Required => true
334:
335: def show
336: puts "ID: #{self.ID}"
337: puts "Name: #{self.Name}"
338: puts "Certificates: " + self.Certs.join(", ")
339: end
340:
341: end
342:
343: class Certificate < Dictionary
344:
345: include Configurable
346: include Descriptor
347:
348: module Flags
349:
350: CAN_CERTIFY = 1 << 1
351: ALLOW_DYNAMIC_CONTENT = 1 << 2
352: UNKNOWN_1 = 1 << 3
353: ALLOW_HIGH_PRIV_JS = 1 << 4
354: UNKNOWN_2 = 1 << 5
355: IS_ROOT_CA = 1 << 6
356:
357: #~ FULL_TRUST = 1 << 1 | 1 << 2 | 1 << 3 | 1 << 4 | 1 << 5 | 1 << 6
358: FULL_TRUST = 8190
359: end
360:
361: field :ABEType, :Type => Integer, :Default => Descriptor::CERTIFICATE, :Required => true
362: field :Usage, :Type => Integer, :Default => 1, :Required => true
363: field :Viewable, :Type => Boolean, :Default => true
364: field :Editable, :Type => Boolean, :Default => true
365: field :Cert, :Type => String, :Required => true
366: field :Trust, :Type => Integer, :Default => Flags::UNKNOWN_2, :Required => true
367:
368: def show
369: puts "ID: #{self.ID}"
370: puts "Viewable: #{self.Viewable}"
371: puts "Editable: #{self.Editable}"
372: puts "Trust attributes: #{self.Trust}"
373: end
374:
375: end
376:
377: def get_object(no, generation = 0) #:nodoc:
378:
379: case no
380: when Reference
381: target = no
382: when ::Integer
383: target = Reference.new(no, generation)
384: when Origami::Object
385: return no
386: end
387:
388: @revisions.first.body[target]
389: end
390:
391: private
392:
393: def rebuildxrefs #:nodoc:
394:
395: startxref = @header.to_s.size
396:
397: @revisions.first.body.values.each { |object|
398: startxref += object.to_s.size
399: }
400:
401: @xreftable = buildxrefs(@revisions.first.body)
402:
403: @trailer ||= Trailer.new
404: @trailer.Size = @revisions.first.body.size + 1
405: @trailer.startxref = startxref
406:
407: self
408: end
409:
410: def buildxrefs(objects) #:nodoc:
411:
412: lastno = 0
413: brange = 0
414:
415: xrefs = [ XRef.new(0, XRef::LASTFREE, XRef::FREE) ]
416:
417: xrefsection = XRef::Section.new
418: objects.sort.each { |object|
419: if (object.no - lastno).abs > 1
420: xrefsection << XRef::Subsection.new(brange, xrefs)
421: brange = object.no
422: xrefs.clear
423: end
424:
425: xrefs << XRef.new(get_object_offset(object.no, object.generation), object.generation, XRef::USED)
426:
427: lastno = object.no
428: }
429:
430: xrefsection << XRef::Subsection.new(brange, xrefs)
431:
432: xrefsection
433: end
434:
435: def get_object_offset(no,generation) #:nodoc:
436:
437: bodyoffset = @header.to_s.size
438:
439: objectoffset = bodyoffset
440:
441: @revisions.first.body.values.each { |object|
442: if object.no == no and object.generation == generation then return objectoffset
443: else
444: objectoffset += object.to_s.size
445: end
446: }
447:
448: nil
449: end
450:
451: end
# File sources/parser/adobe/addressbook.rb, line 125
125: def Catalog
126: get_object(@trailer.Root)
127: end
Add a certificate into the address book
# File sources/parser/adobe/addressbook.rb, line 237
237: def add_certificate(certfile, attributes, viewable = false, editable = false)
238:
239: cert = Certificate.new
240: cert.Cert = OpenSSL::X509::Certificate.new(certfile).to_der
241: cert.ID = self.Catalog.PPK.AddressBook.NextID
242: self.Catalog.PPK.AddressBook.NextID += 1
243: cert.Trust = attributes
244: cert.Viewable = viewable
245: cert.Editable = editable
246:
247: self.Catalog.PPK.AddressBook.Entries.push(self << cert)
248:
249: show_certs
250: end
# File sources/parser/adobe/addressbook.rb, line 84
84: def append_subobj(root, objset)
85:
86: if objset.find{ |o| o.object_id == root.object_id }.nil?
87:
88: objset << root
89:
90: if root.is_a?(Array) or root.is_a?(Dictionary)
91: root.each { |subobj| append_subobj(subobj, objset) unless subobj.is_a?(Reference) }
92: end
93:
94: end
95:
96: end
Returns a Certificate dictionary corresponding to the specified id
# File sources/parser/adobe/addressbook.rb, line 210
210: def get_cert(id)
211:
212: @revisions.first.body.values.find { |obj| obj.is_a?(Certificate) and obj.ID == id }
213:
214: end
# File sources/parser/adobe/addressbook.rb, line 82
82: def objects
83:
84: def append_subobj(root, objset)
85:
86: if objset.find{ |o| o.object_id == root.object_id }.nil?
87:
88: objset << root
89:
90: if root.is_a?(Array) or root.is_a?(Dictionary)
91: root.each { |subobj| append_subobj(subobj, objset) unless subobj.is_a?(Reference) }
92: end
93:
94: end
95:
96: end
97:
98: objset = []
99: @revisions.first.body.values.each { |object|
100: unless object.is_a?(Reference)
101: append_subobj(object, objset)
102: end
103: }
104:
105: objset
106: end
# File sources/parser/adobe/addressbook.rb, line 129
129: def saveas(filename)
130:
131: bin = ""
132: bin << @header.to_s
133:
134: lastno, brange = 0, 0
135:
136: xrefs = [ XRef.new(0, XRef::LASTFREE, XRef::FREE) ]
137: xrefsection = XRef::Section.new
138:
139: @revisions.first.body.values.sort.each { |obj|
140: if (obj.no - lastno).abs > 1
141: xrefsection << XRef::Subsection.new(brange, xrefs)
142: brange = obj.no
143: xrefs.clear
144: end
145:
146: xrefs << XRef.new(bin.size, obj.generation, XRef::USED)
147: lastno = obj.no
148:
149: bin << obj.to_s
150: }
151:
152: xrefsection << XRef::Subsection.new(brange, xrefs)
153:
154: @xreftable = xrefsection
155: @trailer ||= Trailer.new
156: @trailer.Size = rev.body.size + 1
157: @trailer.startxref = bin.size
158:
159: bin << @xreftable.to_s
160: bin << @trailer.to_s
161:
162: fd = File.open(filename, "w").binmode
163: fd << bin
164: fd.close
165:
166: show_entries
167: end
Prints certificate with the specified id
# File sources/parser/adobe/addressbook.rb, line 199
199: def show_cert(id)
200: certs = @revisions.first.body.values.find_all { |obj| obj.is_a?(Certificate) and obj.ID == id }
201:
202: certs.each { |cert| cert.show; puts }
203:
204: nil
205: end
Prints registered certificates in the addressbook
# File sources/parser/adobe/addressbook.rb, line 186
186: def show_certs
187: puts "-----------------"
188: puts "Certificates list"
189: puts "-----------------"
190:
191: @revisions.first.body.values.each { |obj| if obj.is_a?(Certificate) then obj.show; puts end }
192:
193: nil
194: end
Prints users and certificates registered in the address book
# File sources/parser/adobe/addressbook.rb, line 227
227: def show_entries
228: show_users
229: show_certs
230:
231: puts "End of address book."
232: end
# File sources/parser/adobe/addressbook.rb, line 216
216: def show_user(id)
217: users = @revisions.first.body.values.find_all { |obj| obj.is_a?(User) and obj.ID == id }
218:
219: users.each { |user| cert.show; puts }
220:
221: nil
222: end
Prints registered users in the address book
# File sources/parser/adobe/addressbook.rb, line 172
172: def show_users
173:
174: puts "----------"
175: puts "Users list"
176: puts "----------"
177:
178: @revisions.first.body.values.each { |obj| if obj.is_a?(User) then obj.show; puts end }
179:
180: nil
181: end