IsSigned 0.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.
- data/lib/Sign.rb +88 -0
- metadata +45 -0
data/lib/Sign.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
# require 'origami'
|
3
|
+
|
4
|
+
module Checksign
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'origami'
|
8
|
+
rescue LoadError
|
9
|
+
ORIGAMIDIR = "C:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\origami-1.2.4\lib"
|
10
|
+
$: << ORIGAMIDIR
|
11
|
+
require 'origami'
|
12
|
+
end
|
13
|
+
|
14
|
+
include Origami
|
15
|
+
|
16
|
+
# Code below is based on documentation available on
|
17
|
+
# http://www.ruby-doc.org/stdlib-1.9.3/libdoc/openssl/rdoc/OpenSSL.html
|
18
|
+
OUTPUTFILE = "test.pdf"
|
19
|
+
|
20
|
+
# for PDF Sign
|
21
|
+
def self.Signpdf
|
22
|
+
|
23
|
+
key = OpenSSL::PKey::RSA.new 2048
|
24
|
+
|
25
|
+
open 'private_key.pem', 'w' do |io| io.write key.to_pem end
|
26
|
+
open 'public_key.pem', 'w' do |io| io.write key.public_key.to_pem end
|
27
|
+
|
28
|
+
cipher = OpenSSL::Cipher::Cipher.new 'AES-128-CBC'
|
29
|
+
pass_phrase = 'Origami rocks'
|
30
|
+
|
31
|
+
key_secure = key.export cipher, pass_phrase
|
32
|
+
|
33
|
+
open 'private_key.pem', 'w' do |io|
|
34
|
+
io.write key_secure
|
35
|
+
end
|
36
|
+
|
37
|
+
#Create the certificate
|
38
|
+
|
39
|
+
name = OpenSSL::X509::Name.parse 'CN=nobody/DC=example'
|
40
|
+
|
41
|
+
cert = OpenSSL::X509::Certificate.new
|
42
|
+
cert.version = 2
|
43
|
+
cert.serial = 0
|
44
|
+
cert.not_before = Time.now
|
45
|
+
cert.not_after = Time.now + 3600
|
46
|
+
|
47
|
+
cert.public_key = key.public_key
|
48
|
+
cert.subject = name
|
49
|
+
|
50
|
+
|
51
|
+
contents = ContentStream.new.setFilter(:FlateDecode)
|
52
|
+
contents.write OUTPUTFILE,:x => 350, :y => 750, :rendering => Text::Rendering::STROKE, :size => 30
|
53
|
+
|
54
|
+
pdf = PDF.read('kimbo.pdf')
|
55
|
+
|
56
|
+
|
57
|
+
# Open certificate files
|
58
|
+
|
59
|
+
sigannot = Annotation::Widget::Signature.new
|
60
|
+
sigannot.Rect = Rectangle[:llx => 89.0, :lly => 386.0, :urx => 190.0, :ury => 353.0]
|
61
|
+
|
62
|
+
#page.add_annot(sigannot)
|
63
|
+
|
64
|
+
# Sign the PDF with the specified keys
|
65
|
+
pdf.sign(cert, key,
|
66
|
+
:method => 'adbe.pkcs7.sha1',
|
67
|
+
:annotation => sigannot,
|
68
|
+
:location => 'India',
|
69
|
+
# :contact => nil,
|
70
|
+
:reason => 'Proof of Concept'
|
71
|
+
)
|
72
|
+
|
73
|
+
# puts pdf
|
74
|
+
|
75
|
+
# Save the resulting file
|
76
|
+
pdf.save(OUTPUTFILE)
|
77
|
+
|
78
|
+
|
79
|
+
end #end sign
|
80
|
+
|
81
|
+
# for PDF verification
|
82
|
+
|
83
|
+
def self.Verifypdf
|
84
|
+
|
85
|
+
end #end verify
|
86
|
+
|
87
|
+
|
88
|
+
end #end Module
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: IsSigned
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- SK
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-12-15 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: A simple gem
|
15
|
+
email: skpranesh2009@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/Sign.rb
|
21
|
+
homepage: http://rubygems.org/gems/Issigned
|
22
|
+
licenses: []
|
23
|
+
post_install_message:
|
24
|
+
rdoc_options: []
|
25
|
+
require_paths:
|
26
|
+
- lib
|
27
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 1.8.24
|
42
|
+
signing_key:
|
43
|
+
specification_version: 3
|
44
|
+
summary: Test to see if a pdf is signed or not!
|
45
|
+
test_files: []
|