class PDFWalker::Walker::SignWizard

Constants

INTRO_PAGE
KEYPAIR_IMPORT_PAGE
KEY_SELECT_PAGE
PKCS12_IMPORT_PAGE
SIGNATURE_INFO_PAGE
SIGNATURE_RESULT_PAGE

Public Class Methods

new(parent, pdf) click to toggle source
Calls superclass method
# File lib/pdfwalker/signing.rb, line 399
def initialize(parent, pdf)
    super()

    @parent = parent

    @pkey, @cert, @ca = nil, nil, []

    create_intro_page
    create_key_selection_page
    create_pkcs12_import_page
    create_keypair_import_page
    create_signature_info_page
    create_termination_page

    set_forward_page_func { |current_page|
        case current_page
        when KEY_SELECT_PAGE
            if @p12button.active? then PKCS12_IMPORT_PAGE else KEYPAIR_IMPORT_PAGE end

        when PKCS12_IMPORT_PAGE, KEYPAIR_IMPORT_PAGE
            SIGNATURE_INFO_PAGE

        else current_page.succ
        end
    }

    signal_connect('delete_event') { self.destroy }
    signal_connect('cancel') { self.destroy }
    signal_connect('close') { self.destroy }

    signal_connect('apply') {
        location = @location.text.empty? ? nil : @location.text
        contact = @email.text.empty? ? nil : @email.text
        reason = @reason.text.empty? ? nil : @reason.text

        begin
            pdf.sign(@cert, @pkey,
                     ca: @ca,
                     location: location,
                     contact: contact,
                     reason: reason)

            set_page_title(@lastpage, "Document has been signed")
            @msg_status.text = "The document has been signed.\n You should consider saving it now."

            @parent.reload
        rescue
            @parent.error("#{$!}: #{$!.backtrace.join($/)}")

            set_page_title(@lastpage, "Document has not been signed")
            @msg_status.text = "An error occured during the signature process."
        end
    }

    set_modal(true)

    show_all
end

Private Instance Methods

create_intro_page() click to toggle source
# File lib/pdfwalker/signing.rb, line 460
            def create_intro_page
                intro = <<-INTRO.gsub(/^\s+/, '')
                    You are about to sign the current PDF document.
                    Once the document will be signed, no further modification will be allowed.

                    The signature process is based on assymetric cryptography, so you will basically need a public/private RSA key pair (between 1024 and 4096 bits).
                INTRO

                vbox = VBox.new(false, 5)
                vbox.set_border_width(5)

                lbl = Label.new(intro).set_justify(Gtk::JUSTIFY_LEFT).set_wrap(true)

                vbox.pack_start(lbl, true, true, 0)

                append_page(vbox)
                set_page_title(vbox, "Signature Wizard")
                set_page_type(vbox, Assistant::PAGE_INTRO)
                set_page_complete(vbox, true)
            end
create_key_selection_page() click to toggle source
# File lib/pdfwalker/signing.rb, line 481
def create_key_selection_page
    vbox = VBox.new(false, 5)

    @rawbutton = RadioButton.new("Import keys from separate PEM/DER encoded files")
    @p12button = RadioButton.new(@rawbutton, "Import keys from a PKCS12 container")

    vbox.pack_start(@rawbutton, true, true, 0)
    vbox.pack_start(@p12button, true, true, 0)

    append_page(vbox)
    set_page_title(vbox, "Choose a key importation method")
    set_page_type(vbox, Assistant::PAGE_CONTENT)
    set_page_complete(vbox, true)
end
create_pkcs12_import_page() click to toggle source
# File lib/pdfwalker/signing.rb, line 496
def create_pkcs12_import_page
    vbox = VBox.new(false, 5)

    hbox = HBox.new(false, 5)
    vbox.pack_start(hbox, true, false, 10)

    @p12filename = Entry.new.set_editable(false).set_sensitive(false)
    choosebtn = Button.new(Gtk::Stock::OPEN)

    choosebtn.signal_connect('clicked') { open_pkcs12_file_dialog(vbox) }

    hbox.pack_start(@p12filename, true, true, 5)
    hbox.pack_start(choosebtn, false, false, 5)

    append_page(vbox)
    set_page_title(vbox, "Import a PKCS12 container")
    set_page_type(vbox, Assistant::PAGE_CONTENT)
end
create_signature_info_page() click to toggle source
# File lib/pdfwalker/signing.rb, line 515
def create_signature_info_page
    vbox = VBox.new(false, 5)

    lbl = Label.new("Here are a few optional information you can add with your signature.")
    vbox.pack_start(lbl, true, true, 0)

    labels =
    [
        [ "Location:", @location = Entry.new ],
        [ "Contact:", @email = Entry.new ],
        [ "Reason:", @reason = Entry.new ]
    ]

    row = 0
    table = Table.new(4, 3)
    labels.each do |label|
        table.attach(Label.new(label[0]).set_alignment(1,0), 0, 1, row, row + 1, Gtk::EXPAND | Gtk::FILL, Gtk::SHRINK, 4, 4)
        table.attach(label[1], 1, 2, row, row + 1, Gtk::EXPAND | Gtk::FILL, Gtk::SHRINK, 4, 4)

        row = row.succ
    end

    vbox.pack_start(table, true, true, 0)

    append_page(vbox)
    set_page_title(vbox, "Fill in signature details")
    set_page_type(vbox, Assistant::PAGE_CONFIRM)
    set_page_complete(vbox, true)
end
create_termination_page() click to toggle source
# File lib/pdfwalker/signing.rb, line 545
def create_termination_page
    @lastpage = VBox.new(false, 5)

    @msg_status = Label.new
    @lastpage.pack_start(@msg_status, true, true, 0)

    append_page(@lastpage)
    set_page_title(@lastpage, "Document has not been signed")
    set_page_type(@lastpage, Assistant::PAGE_SUMMARY)
end