Subversion Repositories DevTools

Rev

Rev 6943 | Rev 6978 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6943 Rev 6962
Line 304... Line 304...
304
our $pkgBase;                       # Where the package is being sourced from
304
our $pkgBase;                       # Where the package is being sourced from
305
our $noSigs = 1;                    # Control signature generation (Force noSigs. could use use undef)
305
our $noSigs = 1;                    # Control signature generation (Force noSigs. could use use undef)
306
 
306
 
307
#
307
#
308
#   Internal
308
#   Internal
-
 
309
#   Used while generating a manifest
309
#
310
#
310
my $certName;                       # Signing Cert Name
311
my $certName;                       # Signing Cert Name
311
my $certFile;                       # Path to the certificate
312
my $certFile;                       # Path to the certificate
312
my $keyFile;                        # Path to the keyfile
313
my $keyFile;                        # Path to the keyfile
313
my $opensslProg;                    # Path to openssl program
314
my $opensslProg;                    # Path to openssl program
314
my $opensslConf;                    # Path to openssl config
315
my $opensslConf;                    # Path to openssl config
-
 
316
my $manifestName;                   # Name of the current manifest file
315
 
317
 
316
BEGIN {
318
BEGIN {
317
    my $path = rel2abs( __FILE__ );
319
    my $path = rel2abs( __FILE__ );
318
    $pkgBase = dirname( $path );
320
    $pkgBase = dirname( $path );
319
}
321
}
Line 864... Line 866...
864
 
866
 
865
    #
867
    #
866
    #   Determine the target packaging directory
868
    #   Determine the target packaging directory
867
    #   Default is .../mug
869
    #   Default is .../mug
868
    #
870
    #
869
    my $pkgdir = 'mug';
871
    $pkg_subdir = 'mug';
870
    if ( exists $Manifests[0]->{pkgsubdir} && defined $Manifests[0]->{pkgsubdir} )
872
    if ( exists $Manifests[0]->{pkgsubdir} && defined $Manifests[0]->{pkgsubdir} )
871
    {
873
    {
872
        my $subdir = $Manifests[0]->{pkgsubdir};
874
        my $subdir = $Manifests[0]->{pkgsubdir};
873
        $pkgdir .= '/' . $subdir;
875
        $pkg_subdir .= '/' . $subdir;
874
        $pkgdir =~ s~^mug/mug~mug~;
876
        $pkg_subdir =~ s~^mug/mug~mug~;
875
    }
877
    }
876
 
878
 
877
    #
879
    #
878
    #   Create the Manifest File as we process the lists
880
    #   Create the Manifest File as we process the lists
879
    #   Place this in the 'lib' directory:
881
    #   Place this in the 'lib' directory:
Line 884... Line 886...
884
    Error ("ManifestFiles: Needs local directory specified in build.pl") unless ( $::ScmLocal );
886
    Error ("ManifestFiles: Needs local directory specified in build.pl") unless ( $::ScmLocal );
885
 
887
 
886
    my $manifest_dir = "$::ScmPlatform.LIB";
888
    my $manifest_dir = "$::ScmPlatform.LIB";
887
    System( "$::GBE_BIN/mkdir -p $manifest_dir" );
889
    System( "$::GBE_BIN/mkdir -p $manifest_dir" );
888
 
890
 
889
    my $manifest_file = $manifest_dir . '/Manifest';
891
    $manifestName = $manifest_dir . '/Manifest';
890
    $manifest_file .= '_' . $::ScmBuildVersion if ( $Manifest_has_version );
892
    $manifestName .= '_' . $::ScmBuildVersion if ( $Manifest_has_version );
891
    ::ToolsetGenerate( $manifest_file );
893
    ::PackageFile ('*', $manifestName, '--Subdir=' . $pkg_subdir, '--Strip' );
892
    Verbose ("Generate: File: $manifest_file");
894
    ::ToolsetGenerate( $manifestName );
893
 
895
 
894
    PackageManifestFile ($manifest_file, $pkgdir);
896
    Verbose ("Generate: File: $manifestName");
895
    open (MF, '>', $manifest_file ) || Error ("Cannot create the Manifest file: $manifest_file");
-
 
896
 
897
 
-
 
898
    open (MF, '>', $manifestName ) || Error ("Cannot create the Manifest file: $manifestName");
897
    binmode (MF);
899
    binmode (MF);
898
 
900
 
899
    if ($Manifests[0]->{is_sub_manifest} == 1) {
901
    if ($Manifests[0]->{is_sub_manifest} == 1) {
900
        print_mf ("# Package $::ScmBuildPackage $::ScmBuildVersion built: $::CurrentTime");
902
        print_mf ("# Package $::ScmBuildPackage $::ScmBuildVersion built: $::CurrentTime");
901
    } else {
903
    } else {
Line 918... Line 920...
918
        print_mf ("");
920
        print_mf ("");
919
        print_mf ("#");
921
        print_mf ("#");
920
        print_mf ("# Signing Certificate");
922
        print_mf ("# Signing Certificate");
921
        print_mf ("[Certificate],$certName");
923
        print_mf ("[Certificate],$certName");
922
 
924
 
923
        ::PackageFile ('*', $certFile, '--Subdir=' . $pkgdir, '--Strip' );
925
        ::PackageFile ('*', $certFile, '--Subdir=' . $pkg_subdir, '--Strip' );
924
    }
926
    }
925
        
927
        
926
    #
928
    #
927
    #   Process each tier in the order presented in the source file
929
    #   Process each tier in the order presented in the source file
928
    #
930
    #
Line 971... Line 973...
971
                }
973
                }
972
                if (exists $entry->{fileVersions} && exists $entry->{fileVersions}{$file} ) {
974
                if (exists $entry->{fileVersions} && exists $entry->{fileVersions}{$file} ) {
973
                    push @items, "VERSION=" . $entry->{fileVersions}{$file};
975
                    push @items, "VERSION=" . $entry->{fileVersions}{$file};
974
                }
976
                }
975
                print_mf (join (',', @items));
977
                print_mf (join (',', @items));
976
                PackageManifestFile ($file, $pkgdir);
978
                PackageManifestFile ($name, $tier, $file );
977
                $last_was_comment = 0;
979
                $last_was_comment = 0;
978
            }
980
            }
979
 
981
 
980
            if ( my $file = $fentry->{'filenocopy'} )
982
            if ( my $file = $fentry->{'filenocopy'} )
981
            {
983
            {
Line 1010... Line 1012...
1010
                            if ($include_md5 && $md5_added == 0) { # add md5 if requested and not already added from submanifest
1012
                            if ($include_md5 && $md5_added == 0) { # add md5 if requested and not already added from submanifest
1011
                                my $md5 = digest_file_hex($emf->{'file_base'} . '/' . $item->{'file_name'}, 'MD5');
1013
                                my $md5 = digest_file_hex($emf->{'file_base'} . '/' . $item->{'file_name'}, 'MD5');
1012
                                push @items, "MD5=$md5";
1014
                                push @items, "MD5=$md5";
1013
                            }
1015
                            }
1014
                            print_mf (join (',', @items));
1016
                            print_mf (join (',', @items));
1015
                            PackageManifestFile ( $emf->{'file_base'} . '/' . $item->{'file_name'}, $pkgdir);
1017
                            PackageManifestFile ( $name, $tier, $emf->{'file_base'} . '/' . $item->{'file_name'} );
1016
                        }
1018
                        }
1017
                        elsif (defined($item->{'comment'})) {
1019
                        elsif (defined($item->{'comment'})) {
1018
                            print_mf($item->{'comment'});
1020
                            print_mf($item->{'comment'});
1019
                        }
1021
                        }
1020
                    }
1022
                    }
Line 1022... Line 1024...
1022
                }
1024
                }
1023
                else {
1025
                else {
1024
                    print_mf ($_) foreach  ( @{$emf->{'contents'}} );
1026
                    print_mf ($_) foreach  ( @{$emf->{'contents'}} );
1025
                    foreach my $item ( @{$emf->{'items'}}) {
1027
                    foreach my $item ( @{$emf->{'items'}}) {
1026
                        if (defined($item->{'file_name'})) {
1028
                        if (defined($item->{'file_name'})) {
1027
                            PackageManifestFile ( $emf->{'file_base'} . '/' . $item->{'file_name'}, $pkgdir);
1029
                            PackageManifestFile ( $name, $tier, $emf->{'file_base'} . '/' . $item->{'file_name'} );
1028
                        }
1030
                        }
1029
                    }
1031
                    }
1030
                    print_mf('#');
1032
                    print_mf('#');
1031
                }
1033
                }
1032
            }
1034
            }
Line 1050... Line 1052...
1050
                if ($include_md5) {
1052
                if ($include_md5) {
1051
                    my $md5 = digest_file_hex($file, 'MD5');
1053
                    my $md5 = digest_file_hex($file, 'MD5');
1052
                    push @items, "MD5=$md5" ;
1054
                    push @items, "MD5=$md5" ;
1053
                }
1055
                }
1054
                print_mf (join (',', @items));
1056
                print_mf (join (',', @items));
1055
                PackageManifestFile ($file, 'mug');
1057
                PackageManifestFile ($name, $tier, $file );
1056
            }
1058
            }
1057
        }
1059
        }
1058
    }
1060
    }
1059
 
1061
 
1060
    #
1062
    #
Line 1120... Line 1122...
1120
# Description     : Process and package a manifest file
1122
# Description     : Process and package a manifest file
1121
#                       Reatin a list of files in the mnifest to allow postprocessing
1123
#                       Reatin a list of files in the mnifest to allow postprocessing
1122
#                       such as signature generation
1124
#                       such as signature generation
1123
#                   
1125
#                   
1124
#
1126
#
1125
# Inputs          : $srcFile        - Full path to the source file
1127
# Inputs          : $name           - Target platform name
-
 
1128
#                   $tier           - Target tier
1126
#                   $pkgPath        - Target path within the package    
1129
#                   $srcFile        - Full path to the source file
1127
#
1130
#
1128
# Returns         : Nothing
1131
# Returns         : Nothing
1129
#
1132
#
1130
sub PackageManifestFile {
1133
sub PackageManifestFile {
1131
    my ($srcFile, $pkgPath) = @_;
1134
    my ($name, $tier, $srcFile ) = @_;
1132
    push @{$ManifestFiles}, ({srcFile => $srcFile, pkgPath => $pkgPath});
1135
    push @{$ManifestFiles}, ({srcFile => $srcFile, name =>$name, tier => $tier});
1133
 
1136
 
1134
    ::PackageFile ('*', $srcFile, '--Subdir=' . $pkgPath, '--Strip' );
1137
    ::PackageFile ('*', $srcFile, '--Subdir=' . $pkg_subdir, '--Strip' );
1135
}
1138
}
1136
 
1139
 
1137
#-------------------------------------------------------------------------------
1140
#-------------------------------------------------------------------------------
1138
# Function        : GenSigInit 
1141
# Function        : GenSigInit 
1139
#
1142
#
Line 1236... Line 1239...
1236
sub GenSignatures
1239
sub GenSignatures
1237
{
1240
{
1238
    Debug("GenSignatures:", $noSigs);
1241
    Debug("GenSignatures:", $noSigs);
1239
    return if $noSigs;
1242
    return if $noSigs;
1240
 
1243
 
-
 
1244
    my %sigManifest;
-
 
1245
 
1241
    foreach my $entry ( @{$ManifestFiles}) {
1246
    foreach my $entry ( @{$ManifestFiles}) {
1242
        Verbose("PostProcess: $entry->{srcFile}, $entry->{pkgPath}");
1247
        Verbose("PostProcess: $entry->{srcFile}");
1243
 
1248
 
1244
        #
1249
        #
1245
        #   Generate the name of the signature file
1250
        #   Generate the name of the signature file
1246
        #   Generate Packaging directives for the signature
1251
        #   Generate Packaging directives for the signature
1247
        #   
1252
        #   
1248
        my $sigFileName = CatPaths( "$::ScmPlatform.LIB", StripDir($entry->{srcFile}) . '.sig' );
1253
        my $sigFileName = CatPaths( "$::ScmPlatform.LIB", StripDir($entry->{srcFile}) . '.sig' );
1249
        ::PackageFile ('*', $sigFileName, '--Subdir=' . $entry->{pkgPath}, '--Strip' );
1254
        ::PackageFile ('*', $sigFileName, '--Subdir=' . $pkg_subdir, '--Strip' );
1250
        ::ToolsetGenerate($sigFileName);
1255
        ::ToolsetGenerate($sigFileName);
1251
 
1256
 
1252
        #
1257
        #
1253
        #   Generate package signature
1258
        #   Generate the name/tier for the manifest signature
1254
        #   The required custom(vix) 'sig' file has the format:
1259
        #       ie: Manifest_<name>_<tier>.sig
1255
        #       line-1 : name of the certificate to decode
1260
        #   Generate the name for the manifest signature
1256
        #                Assume its the keyname with .key -> .crt - with no path elements
-
 
1257
        #       line-2 : Text representation of the signature
1261
        #       ie: Manifest_<name>.sig
1258
        #                The openssl dgst command generates a binary output by default
-
 
1259
        #                This is then converted into base64 with -A option
1262
        #   Will generate signature of signatures
1260
        #
1263
        #
1261
        my $tmp1 = CatPaths( "$::ScmPlatform.LIB", 'temp1');
1264
        my $sigManifest =  join('_', $entry->{name}, $entry->{tier});
1262
        my $tmp2 = CatPaths( "$::ScmPlatform.LIB", 'temp2');
1265
        push @{$sigManifest{$sigManifest}}, $sigFileName;
1263
        ::ToolsetGenerate($tmp1, $tmp2);
1266
        push @{$sigManifest{$entry->{name}}}, $sigFileName;
-
 
1267
 
1264
 
1268
 
1265
        Verbose("Signing: " . StripDir($entry->{srcFile}));
1269
        # Generate the signature over the file
1266
        System( '--Exit', '--NoShell', $opensslProg, 'dgst', '-sha256', '-sign', $keyFile, '-out', $tmp1, $entry->{srcFile} );
-
 
1267
        System( '--Exit', '--NoShell', $opensslProg, 'base64', '-A', '-in', $tmp1, '-out', $tmp2 );
-
 
1268
        my $base64 = TagFileRead($tmp2);
1270
        genSigForFile($entry->{srcFile}, $sigFileName);
-
 
1271
    }
1269
 
1272
 
1270
        #
1273
    #
1271
        #   In a development environment we don't want to create the signature file
1274
    #   Create a file of signatures
1272
        #   every time we run. Its noisy. Solution:
1275
    #   Create one for each platform/tier
-
 
1276
    #
1273
        #       Only generate a signature file if:
1277
    foreach my $nameTier ( keys %sigManifest)
-
 
1278
    {
1274
        #           It doesn't exist
1279
        Verbose("PostProcessSig: $nameTier");
1275
        #           A copy of the signed digest doesn't exist (.fpp)
1280
        my $sigSigTemp = $manifestName . '_' . $nameTier . '.sig';
1276
        #           The signed digest has changed
1281
        my $sigSigTempCat = $sigSigTemp . '.content';
-
 
1282
        ::ToolsetGenerate($sigSigTemp, $sigSigTempCat);
-
 
1283
        ::PackageFile ('*', $sigSigTemp, '--Subdir=' . $pkg_subdir, '--Strip' );
-
 
1284
 
1277
        #   
1285
        #
1278
        my $fppFileName = CatPaths( "$::ScmPlatform.LIB", StripDir($entry->{srcFile}) . '.fpp' );
1286
        #   Concatenate the contents of the required .sig files
1279
        ::ToolsetGenerate($fppFileName);
1287
        #   Treat them as binary files. 
-
 
1288
        #
-
 
1289
        open  (my $ofh, '>', $sigSigTempCat ) || Error( "Cannot create file: $sigSigTempCat", "Reason: $!" );
1280
        my $genSig = 0;
1290
        binmode ($ofh);
1281
        $genSig = 1 unless ( -e $sigFileName &&  -e $fppFileName);
1291
        foreach my $entry (@{$sigManifest{$nameTier}}) {
1282
        unless ($genSig) {
1292
            Verbose("PostProcessSig: $entry");
-
 
1293
            open( my $file, '<', $entry ) || Error("Cannot open '$entry'. $!");
1283
            my $ffp = TagFileRead($fppFileName);
1294
            binmode ($file);
1284
            $genSig = ($ffp ne $base64);
1295
            my @lines = <$file>;
1285
        }
1296
            close $file;
1286
 
1297
 
1287
        if ($genSig) {
1298
            foreach my $entry ( @lines ) {
1288
            FileCreate($sigFileName, $certName, $base64);
1299
                print $ofh $entry;
1289
            rename $tmp2, $fppFileName ;
1300
            }
1290
        }
1301
        }
-
 
1302
        close $ofh;
1291
 
1303
 
-
 
1304
        #
-
 
1305
        #   Generate a signature over the file
1292
        unlink $tmp1;
1306
        #
-
 
1307
        genSigForFile($sigSigTempCat, $sigSigTemp);
1293
        unlink $tmp2;
1308
        #unlink $sigSigTempCat;
1294
    }
1309
    }
-
 
1310
    
1295
    unlink $opensslConf;
1311
    unlink $opensslConf;
1296
}
1312
}
1297
 
1313
 
-
 
1314
#-------------------------------------------------------------------------------
-
 
1315
# Function        : genSigForFile 
-
 
1316
#
-
 
1317
# Description     : Generate a .sig file for a named file (internal)
-
 
1318
#                   Will be smart and only 'touch' the output file if the input has chnaged
-
 
1319
#                       It will maintain a fingerprint file to do this.
-
 
1320
#                   
-
 
1321
#                   Generate package signature
-
 
1322
#                   The required custom(vix) 'sig' file has the format:
-
 
1323
#                       line-1 : name of the certificate to decode
-
 
1324
#                                Assume its the keyname with .key -> .crt - with no path elements
-
 
1325
#                       line-2 : Text representation of the signature (base64)
-
 
1326
#                                The openssl dgst command generates a binary output by default
-
 
1327
#                                This is then converted into base64 with -A option
-
 
1328
#                   
-
 
1329
# Inputs          : $srcFile        - Source file to process
-
 
1330
#                   $tgtFile        - Output file name
-
 
1331
#
-
 
1332
# Returns         : 
-
 
1333
#
-
 
1334
sub genSigForFile
-
 
1335
{
-
 
1336
    my ($srcFile, $tgtFile) = @_;
-
 
1337
 
-
 
1338
    my $tmp1 = CatPaths( "$::ScmPlatform.LIB", 'temp1');
-
 
1339
    my $tmp2 = CatPaths( "$::ScmPlatform.LIB", 'temp2');
-
 
1340
    ::ToolsetGenerate($tmp1, $tmp2);
-
 
1341
 
-
 
1342
    Verbose("Signing: " . StripDir($srcFile));
-
 
1343
    System( '--Exit', '--NoShell', $opensslProg, 'dgst', '-sha256', '-sign', $keyFile, '-out', $tmp1, $srcFile );
-
 
1344
    System( '--Exit', '--NoShell', $opensslProg, 'base64', '-A', '-in', $tmp1, '-out', $tmp2 );
-
 
1345
    my $base64 = TagFileRead($tmp2);
-
 
1346
 
-
 
1347
    #
-
 
1348
    #   In a development environment we don't want to create the signature file every time we run. Its noisy. 
-
 
1349
    #   Solution: Only generate a signature file if:
-
 
1350
    #               It doesn't exist
-
 
1351
    #               A copy of the signed digest doesn't exist (.fpp)
-
 
1352
    #               The signed digest has changed
-
 
1353
    #   
-
 
1354
    my $fppFileName = CatPaths( "$::ScmPlatform.LIB", StripDir($srcFile) . '.fpp' );
-
 
1355
    ::ToolsetGenerate($fppFileName);
-
 
1356
    my $genSig = 0;
-
 
1357
    $genSig = 1 unless ( -e $tgtFile &&  -e $fppFileName);
-
 
1358
    unless ($genSig) {
-
 
1359
        my $ffp = TagFileRead($fppFileName);
-
 
1360
        $genSig = ($ffp ne $base64);
-
 
1361
    }
-
 
1362
 
-
 
1363
    if ($genSig) {
-
 
1364
        FileCreate($tgtFile, $certName, $base64);
-
 
1365
        rename $tmp2, $fppFileName ;
-
 
1366
    }
-
 
1367
 
-
 
1368
    unlink $tmp1;
-
 
1369
    unlink $tmp2;
-
 
1370
}
1298
 
1371
 
1299
#-------------------------------------------------------------------------------
1372
#-------------------------------------------------------------------------------
1300
# Function        : DmfGenerate
1373
# Function        : DmfGenerate
1301
#
1374
#
1302
# Description     : Import an existing manifest
1375
# Description     : Import an existing manifest