| 1 | package MToken; # $Id: MToken.pm 76 2019-07-20 07:48:18Z minus $ | ||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 1 | ▶ | use utf8; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | =encoding utf-8 | ||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | =head1 NAME | ||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | MToken - Tokens processing system (Security) | ||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | =head1 VERSION | ||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | Version 1.03 | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | =head1 SYNOPSIS | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | mtoken init MyToken | ||||||||||||||||||||
| 18 | perl Makefile.PL | ||||||||||||||||||||
| 19 | make init | ||||||||||||||||||||
| 20 | make help | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | =head1 DESCRIPTION | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | Tokens processing system (Security) | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | =over 4 | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | =item STEP1 | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | Create a token device | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | cd /my/token/dir | ||||||||||||||||||||
| 33 | mtoken init MyToken | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | =item STEP2 | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | Initialize the MyToken device | ||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | perl Makefile.PL | ||||||||||||||||||||
| 40 | make init | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | Get help page | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | make help | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | Test the device | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | make test | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | =item STEP3 | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | Generate GPG key pair | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | make gengpgkey | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | =item STEP4 | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | Add file to device | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | make add | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | Update file on device | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | make update | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | Delete file from device | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | make delete | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | Show file list on device | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | make show | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | =item STEP5 | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | Backup current token device to server | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | make backup | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | Show list of all available backups on server | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | make list | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | Show information about last backup stored on server | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | make info | ||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | =item STEP6 | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | Restore token device from server backup | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | make restore | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | =item STEP7 | ||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | Cleaning the device (delete all temporary files) | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | make clean | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | =back | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | =head1 HISTORY | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | See C<Changes> file | ||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | =head1 DEPENDENCIES | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | L<LWP>, L<CTK>, C<openssl>, C<gnupg> | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | =head1 TO DO | ||||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | See C<TODO> file | ||||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | =head1 BUGS | ||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | * none noted | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | =head1 SEE ALSO | ||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | L<CTK> | ||||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | =head1 AUTHOR | ||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | Serż Minus (Sergey Lepenkov) L<http://www.serzik.com> E<lt>abalama@cpan.orgE<gt> | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | =head1 COPYRIGHT | ||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | Copyright (C) 1998-2019 D&D Corporation. All Rights Reserved | ||||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | =head1 LICENSE | ||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | This program is free software; you can redistribute it and/or | ||||||||||||||||||||
| 133 | modify it under the same terms as Perl itself. | ||||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | See C<LICENSE> file and L<https://dev.perl.org/licenses/> | ||||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | =cut | ||||||||||||||||||||
| 138 | |||||||||||||||||||||
| 139 | 1 | ▶ | use vars qw/ $VERSION /; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 140 | 1 | $VERSION = "1.03"; | |||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | 1 | ▶ | use feature qw/say/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 143 | 1 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 144 | 1 | ▶ | use Cwd qw/getcwd/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 145 | 1 | ▶ | use CTK::Skel; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 146 | 1 | ▶ | use MToken::Const; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 147 | 1 | ▶ | use MToken::Util qw/explain red yellow /; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 148 | 1 | ▶ | use MToken::Config; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 149 | |||||||||||||||||||||
| 150 | 1 | ▶ | use base qw/ CTK::App /; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 151 | |||||||||||||||||||||
| 152 | __PACKAGE__->register_handler( | ||||||||||||||||||||
| 153 | handler => "test", | ||||||||||||||||||||
| 154 | description => "MToken testing (internal use only)", | ||||||||||||||||||||
| 155 | code => sub { | ||||||||||||||||||||
| 156 | ### CODE: | ||||||||||||||||||||
| 157 | 0 | ▶ | my ($self, $meta, @arguments) = @_; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 158 | |||||||||||||||||||||
| 159 | 0 | ▶ | if ($self->verbosemode) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 160 | 0 | ▶ | say("CLI arguments: ", join("; ",@arguments) || yellow('none') ); | ||||||||||||||||||
|
Condition0%0/3
join('; ', @arguments) || yellow('none')
MC/DC0%0/2
join('; ', @arguments) || yellow('none')
join('; ', @arguments)
yellow('none')
Truth table0%0/3
A || B
A= join('; ', @arguments)B= yellow('none')
| |||||||||||||||||||||
| 161 | 0 | say("Meta: ", explain($meta)); | |||||||||||||||||||
| 162 | 0 | say("CTK object: ", explain($self)); | |||||||||||||||||||
| 163 | 0 | say("App handlers: ", join(", ", $self->list_handlers)); | |||||||||||||||||||
| 164 | } else { | ||||||||||||||||||||
| 165 | 0 | say STDERR red("Incorrect arguments!"); | |||||||||||||||||||
| 166 | 0 | say STDERR "Usage:"; | |||||||||||||||||||
| 167 | 0 | say STDERR " mtoken test -v -- for show app information"; | |||||||||||||||||||
| 168 | 0 | return 0; | |||||||||||||||||||
| 169 | } | ||||||||||||||||||||
| 170 | |||||||||||||||||||||
| 171 | 0 | return 1; | |||||||||||||||||||
| 172 | 1 | }); | |||||||||||||||||||
| 173 | |||||||||||||||||||||
| 174 | __PACKAGE__->register_handler( | ||||||||||||||||||||
| 175 | handler => "init", | ||||||||||||||||||||
| 176 | description => "Initialize token device", | ||||||||||||||||||||
| 177 | code => sub { | ||||||||||||||||||||
| 178 | ### CODE: | ||||||||||||||||||||
| 179 | 0 | ▶ | my ($self, $meta, @arguments) = @_; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=7 SCAR=40.3
| |||||||||||||||||||||
| 180 | 0 | my $prj = shift(@arguments); | |||||||||||||||||||
| 181 | 0 | ▶ | my $dir = $self->option("directory") || getcwd(); | ||||||||||||||||||
|
Condition0%0/3
$self->option('directory') || getcwd()
MC/DC0%0/2
$self->option('directory') || getcwd()
$self->option('directory')
getcwd()
Truth table0%0/3
A || B
A= $self->option('directory')B= getcwd()
| |||||||||||||||||||||
| 182 | |||||||||||||||||||||
| 183 | # Project name | ||||||||||||||||||||
| 184 | 0 | ▶ | $prj //= $self->project; | ||||||||||||||||||
|
Condition0%0/3
$prj //= $self->project
MC/DC0%0/2
$prj //= $self->project
$prj
$self->project
Truth table0%0/3
A //= B
A= $prjB= $self->project
| |||||||||||||||||||||
| 185 | 0 | $prj = lc($prj); | |||||||||||||||||||
| 186 | 0 | $prj =~ s/\s+//g; | |||||||||||||||||||
| 187 | 0 | $prj =~ s/[^a-z0-9]//g; | |||||||||||||||||||
| 188 | 0 | ▶ | $prj ||= $self->project; | ||||||||||||||||||
|
Condition0%0/3
$prj ||= $self->project
MC/DC0%0/2
$prj ||= $self->project
$prj
$self->project
Truth table0%0/3
A ||= B
A= $prjB= $self->project
| |||||||||||||||||||||
| 189 | 0 | ▶ | if ($prj =~ /^\d/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 190 | 0 | $self->error("The project name must not begin with numbers. Choose another name consisting mainly of letters of the Latin alphabet"); | |||||||||||||||||||
| 191 | 0 | return 0; | |||||||||||||||||||
| 192 | } | ||||||||||||||||||||
| 193 | |||||||||||||||||||||
| 194 | 0 | ▶ | my $skel = new CTK::Skel ( | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 195 | -name => $prj, | ||||||||||||||||||||
| 196 | -root => $dir, | ||||||||||||||||||||
| 197 | -skels => { | ||||||||||||||||||||
| 198 | device => 'MToken::DeviceSkel', | ||||||||||||||||||||
| 199 | }, | ||||||||||||||||||||
| 200 | -vars => { | ||||||||||||||||||||
| 201 | PROJECT => $prj, | ||||||||||||||||||||
| 202 | PROJECTNAME => $prj, | ||||||||||||||||||||
| 203 | NAME => ($prj eq $self->project) ? "MToken::Device" : sprintf("%s::Device", ucfirst($prj)), | ||||||||||||||||||||
| 204 | DISTNAME => $prj, | ||||||||||||||||||||
| 205 | GPGBIN => GPGBIN, | ||||||||||||||||||||
| 206 | OPENSSLBIN => OPENSSLBIN, | ||||||||||||||||||||
| 207 | MTOKEN_VERSION => $VERSION, | ||||||||||||||||||||
| 208 | CONFFILEONLY => MToken::Config::GLOBAL_CONF_FILE(), | ||||||||||||||||||||
| 209 | }, | ||||||||||||||||||||
| 210 | -debug => $self->debugmode, | ||||||||||||||||||||
| 211 | ); | ||||||||||||||||||||
| 212 | #say("Skel object: ", explain($skel)); | ||||||||||||||||||||
| 213 | 0 | printf("Initializing device \"%s\"...\n", $prj); | |||||||||||||||||||
| 214 | 0 | my %vars = ( | |||||||||||||||||||
| 215 | PACKAGE => __PACKAGE__, | ||||||||||||||||||||
| 216 | VERSION => $VERSION, | ||||||||||||||||||||
| 217 | ); | ||||||||||||||||||||
| 218 | 0 | ▶ | if ($skel->build("device", $dir, {%vars})) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 219 | 0 | say "Done."; | |||||||||||||||||||
| 220 | } else { | ||||||||||||||||||||
| 221 | 0 | say "Fail."; | |||||||||||||||||||
| 222 | 0 | $self->error(sprintf("Can't build the device to \"%s\" directory", $dir)); | |||||||||||||||||||
| 223 | 0 | return 0; | |||||||||||||||||||
| 224 | } | ||||||||||||||||||||
| 225 | 0 | return 1; | |||||||||||||||||||
| 226 | 1 | }); | |||||||||||||||||||
| 227 | |||||||||||||||||||||
| 228 | 1 | 1; | |||||||||||||||||||
| 229 | |||||||||||||||||||||
| 230 | __END__ | ||||||||||||||||||||