#################### main pod documentation begin ################### =head1 NAME Zymonic::Form::KeyEntry; - Zymonic Workflow System Form 'KeyEntry' module =head1 SYNOPSIS This is a module to show the status of decryptor keys and allow entry of decryptor keys. =head1 DESCRIPTION This is a module to show the status of decryptor keys and allow entry of decryptor keys. =head1 USAGE This module should not be called directly. =head1 BUGS NONE =head1 SUPPORT As in the license, Zymonic is provided without warranty or support unless purchased separately, however... If you email zymonic-support@zednax.com your issue will be noted and may receive a response. For security issues, please contact zymonic-security@zednax.com and someone will respond within 8 working hours. =head1 AUTHOR Alex Masidlover et al. CPAN ID: MODAUTHOR Zednax Limited alex.masidlover@zednax.com http://www.zednax.com =head1 COPYRIGHT This program is free software licensed under the... Alfresco Public License 1.0 The full text of the license can be found in the LICENSE file included with this module. Other licenses may be acceptable if including parts of Zymonic in larger projects, please contact Zednax for details. =head1 SEE ALSO perl(1). =cut #################### main pod documentation end ################### package Zymonic::Form::KeyEntry; use strict; BEGIN { use Exporter (); use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); $VERSION = 'D1-r7186'; @ISA = qw(Exporter); #Give a hoot don't pollute, do not export more than needed by default @EXPORT = qw(); @EXPORT_OK = qw(); %EXPORT_TAGS = (); } use base "Zymonic::Form"; use Zymonic::Decryptor::Client; #################### subroutine header begin #################### =head2 init Usage : N/A Purpose : This is a stub for the init. Returns : nothing Argument : nothing Throws : see the 'See Also' Comment : nothing See Also : =cut #################### subroutine header end #################### sub init { my $self = shift; $self->{ident} = ( $self->{ident} || '' ) . ( $self->{zname} || '' ) . '_'; $self->get_records; } #################### subroutine header begin #################### =head2 get_records Usage : TO DO Purpose : TO DO Returns : nothing Argument : nothing Throws : TODO Comment : See Also : =cut #################### subroutine header end #################### sub get_records { my $self = shift; $self->{records} = [ { fields => $self->my_fields, id => 1, ident => $self->{ident} . "fake_rec", } ]; } #################### subroutine header begin #################### =head2 output_navigation Usage : $self->output_navigation; Purpose : This method returns the navigation ready for transformation to XML. Returns : a hashref containing navigation. Argument : nothing Throws : nothing Comment : This is a stub as the Login form has no navigation... See Also : =cut #################### subroutine header end #################### sub output_navigation { my $self = shift; return {}; } #################### subroutine header begin #################### =head2 save Usage : $form->save; Purpose : TODO Returns : nothing Argument : nothing Throws : TODO Comment : stub as this form has no table associated with it there is nothign to save on it. See Also : =cut #################### subroutine header end #################### sub save { my $self = shift; } #################### subroutine header begin #################### =head2 pre_save Usage : $form->pre_save; Purpose : TODO Returns : nothing Argument : nothing Throws : TODO Comment : stub as this form has no table associated with it there is nothign to save on it. See Also : =cut #################### subroutine header end #################### sub pre_save { my $self = shift; # update all fields on record foreach my $field ( map { $self->get_object($_) } values( %{ $self->{records}->[0]->{fields} } ) ) { $field->value( $field->raw_value ); } } #################### subroutine header begin #################### =head2 my_fields Usage : $form->my_fields; Purpose : TODO Returns : nothing Argument : nothing Throws : TODO Comment : See Also : =cut #################### subroutine header end #################### sub my_fields { my $self = shift; # Get the decryptor key statuses. my $decryptor_status = $self->decryptor_client()->call_decryptor( { messagetype => 'Status' }, '', 'nokey' ); Zymonic::Exception::Decryptor::KeyManagement->throw( error => 'Decryptor status returned error', extras => $decryptor_status, ) if $decryptor_status->{error}; # Work out which key group the user is in. my $keygroup = $self->{DB}->run_query( { string => 'SELECT keygroup FROM zz_keyholders WHERE username = ? AND (deleted IS NULL OR deleted != \'Y\')', params => [ $self->{auth}->{user} ], } ); # create fields. my %status_fields = (); my $sequence = 1; # Set the key entry field(s) up if ( ref($keygroup) eq 'ARRAY' and scalar( @{$keygroup} ) > 0 ) { foreach my $key ( map { substr( $_, -1 ) } grep { ref( $decryptor_status->{$_} ) and $decryptor_status->{$_}->{present} eq 'Y' } keys( %{$decryptor_status} ) ) { my $zname = 'kpc_' . $key . '_' . $keygroup->[0]->{keygroup}; $status_fields{$zname} = { parent => $self, xmldef => { ZName => { content => $zname }, sequence => $sequence++, DisplayName => { content => 'Part ' . $keygroup->[0]->{keygroup} . ' of Key ' . $key }, FieldGroup => { ZName => { content => 'zz_keyentry' }, }, MaximumLength => { content => '6' }, DisplaySize => { content => '6' }, HiddenContent => { content => 'true' }, }, ident => $self->{ident}, zname => $zname, on_form => 'Y', type => 'Field', }; } } # Status Fields my @field_descs = ( map { { key => $_, zname => 'present_' . $_, displayname => 'Key ' . $_ . ' Present', yesno => 1, }, { key => $_, zname => 'decoded_' . $_, displayname => 'Key ' . $_ . ' Decoded', yesno => 1, }, { key => $_, zname => 'primary_key_' . $_, displayname => 'Key ' . $_ . ' is Primary', yesno => 1, }, { key => $_, zname => 'kek_part_1_last_sent_' . $_, displayname => 'Key ' . $_ . ' Encrypting Key Part 1 Last Sent', }, { key => $_, zname => 'kek_part_2_last_sent_' . $_, displayname => 'Key ' . $_ . ' Encrypting Key Part 2 Last Sent', }, } (qw(a b)) ); foreach (@field_descs) { $status_fields{ $_->{zname} } = { parent => $self, xmldef => { ZName => { content => $_->{zname} }, sequence => $sequence++, DisplayName => { content => $_->{displayname} }, FieldGroup => { ZName => { content => 'zz_keyentry_' . $_->{key} }, }, ReadOnly => { content => 'true' }, ( ( $_->{yesno} ) ? ( class => 'Choice', MaximumLength => { content => '1' }, DisplaySize => { content => '1' }, ClassOptions => { 'Option' => [ { 'Value' => { 'content' => 'Y' }, 'DisplayName' => { 'content' => 'Yes' } }, { 'Value' => { 'content' => 'N' }, 'DisplayName' => { 'content' => 'No' } } ], 'DisplayAs' => { 'content' => 'Buttons' } }, ) : ( MaximumLength => { content => '50' }, DisplaySize => { content => '50' }, ) ), }, ident => $self->{ident}, zname => $_->{zname}, on_form => 'Y', type => 'Field', }; } # Set the values foreach my $zname ( keys(%status_fields) ) { # Skip key entry fields. next if $zname =~ /^kpc/; # Set from decryptor status my $key = substr( $zname, -1 ); my $name = substr( $zname, 0, -2 ); $self->get_object( $status_fields{$zname} )->value( $decryptor_status->{ 'key_' . $key }->{$name}, 'fromdb' ); } return \%status_fields; } #################### subroutine header begin #################### =head2 decyptor_client Usage : $form->decryptor_client; Purpose : TODO Returns : nothing Argument : nothing Throws : TODO Comment : See Also : =cut #################### subroutine header end #################### sub decryptor_client { my $self = shift; $self->{decryptor_client} = Zymonic::Decryptor::Client->new( parent => $self, config => $self->{config}, db => $self->{DB} ) unless ( defined( $self->{decryptor_client} ) ); return $self->{decryptor_client}; } 1;