"Fossies" - the Fresh Open Source Software Archive

Member "LinOTP-release-2.10.5.3/linotpd/src/tools/linotp-convert-token" (24 Jun 2019, 3782 Bytes) of package /linux/misc/LinOTP-release-2.10.5.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/usr/bin/perl -w
    2 #
    3 #    LinOTP - the open source solution for two factor authentication
    4 #    Copyright (C) 2010 - 2019 KeyIdentity GmbH
    5 #
    6 #    This file is part of LinOTP server.
    7 #
    8 #    This program is free software: you can redistribute it and/or
    9 #    modify it under the terms of the GNU Affero General Public
   10 #    License, version 3, as published by the Free Software Foundation.
   11 #
   12 #    This program is distributed in the hope that it will be useful,
   13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
   14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   15 #    GNU Affero General Public License for more details.
   16 #
   17 #    You should have received a copy of the
   18 #               GNU Affero General Public License
   19 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
   20 #
   21 #
   22 #    E-mail: linotp@keyidentity.com
   23 #    Contact: www.linotp.org
   24 #    Support: www.keyidentity.com
   25 #
   26 
   27 # This program converts the Safeword Alpine import Data to the Aladdin XML file format
   28 
   29 use strict;
   30 use Getopt::Std;
   31 
   32 my %options;
   33 my @tokens;
   34 
   35 my %token_db;
   36 my $file;
   37 my $showdb=0;
   38 
   39 my $token_template= <<EOF;
   40 <Token serial="SERIAL">
   41 <CaseModel>5</CaseModel>
   42 <Model>101</Model>
   43 <ProductionDate>02/19/2009</ProductionDate>
   44 <ProductName>Safeword Alpine</ProductName>
   45 <ProductVersion>2</ProductVersion>
   46 <Applications>
   47 <Application ConnectorID="{a61c4073-2fc8-4170-99d1-9f5b70a2cec6}">
   48 <Seed>SEED</Seed>
   49 <MovingFactor>1</MovingFactor>
   50 </Application>
   51 </Applications>
   52 </Token>
   53 EOF
   54 
   55 sub help() {
   56     print STDERR "Usage: $0 [-h] \n";
   57     print STDERR "  This program converts the Safeword Alpine import Data to the Aladdin XML file format\n";
   58     print STDERR " -h : this help message\n";
   59     print STDERR " -f : this is the input file with the safeword data. You can also use stdin\n";
   60     print STDERR " -d : show the contents of the hash of the parsed input. Don't output the conversion.\n\n";
   61 
   62     exit 1;
   63 }
   64 
   65 
   66 sub getoptions() {
   67         my $ok=0;
   68         getopts("hf:d", \%options);
   69         if ( $options{h} ) { help(); $ok=1; }
   70     if ( $options{f} ) { $file=$options{f}; $ok=1; }
   71     if ( $options{d} ) { $showdb=1; }
   72         if ( $ok==0 ) {
   73                 help();
   74         }
   75 }
   76 
   77 sub read_tokens() {
   78     if ($file) {
   79     @tokens=`cat "$file"`;
   80     }else{
   81     @tokens=<>;
   82     }
   83 }
   84 
   85 
   86 sub read_db() {
   87     my $i=0;
   88     my $found=0;
   89     my $line;
   90     my $previous_line;
   91     my $summary;
   92     my $record_sum=0;
   93     my $record_app=0;
   94 
   95 #dn: sccAuthenticatorId=F722425
   96 #objectclass: sccCompatibleToken
   97 #sccAuthenticatorId: F722425
   98 #sccTokenType: SafeWord-Alpine-ES
   99 #sccTokenData: sccKey=C8842DADF04F17FD3E5C87039DA39D841DC06C7C;sccMode=E;sccPwLen=6;sccVer=1.1;
  100 #sccSignature: MC4CFQD1myMBcOQ8voA9xu0DrKedEMr4rAIVAOch+nTAd6Sxgcqw3fLdNhEznCTE
  101 
  102     my $found_token='0';
  103     foreach $line (@tokens) {
  104     # cko: Achtung: Das sind DOS-Files. Da gibt es ein lf und nl. Verwirrt die Regexp
  105     if ($line=~/^sccAuthenticatorId:\s*(\w*)/ ){
  106         # if there is a line, starting with ccAuthenticatorId we have found a token and remember its serial number
  107         $found_token=$1;
  108     }
  109     if ($line=~/^sccTokenData:\s*sccKey=(.*);sccMode=E/){
  110         # We found a token with a Key! :)
  111         $token_db{ $found_token }=$1;
  112         $i++;
  113     }
  114     }
  115     return $i;
  116 }
  117 
  118 sub show_db() {
  119     my $k;
  120     my $v;
  121     while ( ($k,$v) = each( %token_db )) {
  122     print "----------------------------\n";
  123     print "$k => $v\n";
  124     }
  125 }
  126 
  127 sub convert_tokens() {
  128     my $k;
  129     my $v;
  130     my $line;
  131 
  132     print '<?xml version="1.0" encoding="utf-8" ?>';
  133     print "<Tokens>\n";
  134     while  ( ($k,$v) = each %token_db ) {
  135         $line = $token_template;
  136         $line =~ s/SERIAL/$k/g; 
  137         $line =~ s/SEED/$v/g;
  138         print $line."\n";
  139     }
  140     print "</Tokens>";
  141 }
  142 
  143 
  144 #
  145 # M A I N
  146 #
  147 getoptions();
  148 
  149 read_tokens();
  150 read_db();
  151 
  152 if ( $showdb ) { 
  153     show_db(); 
  154 }else{
  155     convert_tokens();
  156 }
  157 exit 0;