#################### main pod documentation begin ################### =head1 NAME Zymonic::Decryptor::Message::SendKEKPart - Zymonic Decryptor Status Message. =head1 SYNOPSIS This is a Message class that allows setting of the keys. =head1 DESCRIPTION This is a Message class that allows setting of the keys. =head1 USAGE The message should simply be: { messagetype => 'SendKEKPart', username => 'username', kek_part_number => 1 or 2, kek_parts => { a => 'kek part', b => 'kek part', } } The response will be: { ok => 1, } =head1 BUGS None we're aware of... =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... Zymonic 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::Decryptor::Message::SendKEKPart; use strict; use warnings; BEGIN { use Exporter (); use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); $VERSION = '0.01'; @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::Decryptor::Message'; use Zymonic::Utils qw(death_handler); #################### subroutine header begin #################### =head2 respond Usage : my $response = $mh->repsond($in) Purpose : This is the response handler method for decryptor messages. Returns : a response hashref Argument : a message hashref Throws : nothing Comment : The 'base' response is just a ping... See Also : =cut #################### subroutine header end #################### sub respond { my $self = shift; my $in = shift; $self->{decryptor_server}->connection_log( 'KEK Part sent by user: ' . $in->{username} ); # Check system is loaded return { error => 'Requested system not loaded.' } unless ref( $self->{decryptor_server}->{systems}->{ $in->{system} } ); my $system = $self->{decryptor_server}->{systems}->{ $in->{system} }; my @messages = (); # Set the key part and last updated foreach my $keyversion ( keys( %{ $in->{kek_parts} } ) ) { next unless $in->{kek_parts}->{$keyversion}; # Log it. $self->{decryptor_server}->connection_log( 'KEK part ' . $in->{kek_part_number} . ' for Key ' . $keyversion ); # If all parts are present try a complete system load. if ( $self->{decryptor_server} ->set_kek( $in->{system}, $keyversion, $in->{kek_part_number}, $in->{kek_parts}->{$keyversion} ) ) { # Check if key being sent is 'new' if so re-do key load. my $nkv = $system->{config}->sys_opt('new_keyversion'); eval { $self->{decryptor_server} ->get_decrsa( $in->{system}, $keyversion, ( ( $nkv || '' ) eq $keyversion ) ? 1 : 0 ); 1; } or do { my $exception = $@; if ( $exception and $exception =~ /no start line/ ) { push( @messages, 'One of the key parts was incorrect.' ); } else { my $err = death_handler( $exception, '', 'return' ); eval { push( @messages, $err->{message}->{content} ); }; } }; } } my $response = {}; if (@messages) { $response = { error => join( ",", map { "System Load Failed: " . $_ } @messages ) }; } else { $response = { ok => 1 }; } return $response; } 1;