Wednesday, August 8, 2012

Check signature and version info on Mac and Windows


Mac:


Following command are very useful: codesign, defauls.


#!/bin/bash
files=(
"/Library/Services/AdobeDrive4.service" "/Volumes/AdobeDrive4-mul/Install.app"
"/Library/Application Support/Adobe/Adobe Drive 4/Adobe Drive.app"
)
echo "-----------------------------------------------------------------codesign -v -ddd -----------------------------------------------------------------"
for file in "${files[@]}"
do
echo "codesign -v -vvv " "$file"
codesign -v -vvv "$file"
done

echo "-----------------------------------------------------------------codesign -d -ddd -----------------------------------------------------------------"

for file in "${files[@]}"
do
echo "codesign -d -vvv " "$file"
codesign -d -vvv "$file"
done

echo "-----------------------------------------------------------------spctl --assess -v -----------------------------------------------------------------"

files=(
"/Volumes/AdobeDrive4-mul/Install.app"
)

for file in "${files[@]}"
do
echo "spctl --assess -v " "$file"
spctl --assess -v "$file"
done

#!/bin/bash

echo "-----------------------------------------------------------------get version -----------------------------------------------------------------"

files=(
"/Library/Application Support/Adobe/Adobe Drive 4/Adobe Drive.app"
)

for file in "${files[@]}"
do
VERSION=`defaults read "$file/Contents/Info" CFBundleShortVersionString`
echo "get file version " "$file" "$VERSION"
done



Win:

Useful commands : powershell -command , and wmic datafile 


import subprocess
import os

ADx86Folder = "C:\\'Program Files (x86)'\\'Common Files'\\Adobe\\'Adobe Drive 4'";
ADx64Folder = "C:\\'Program Files'\\'Common Files'\\Adobe\\'Adobe Drive 4'";
ExpectBuildNumber = "4.0.1.16";


W64BIT = "win64bit";
W32BIT = "win32bit";
Mac    = "osx";

platform = W32BIT;
if os.path.exists("C:\\Program Files (x86)\\"):
    platform = W64BIT;
if os.path.exists("/Volumes/"):
    platform = Mac;

files =[];    
if platform == W32BIT:
    files=["%s\\ADConnect.exe"%(ADx64Folder),
       "%s\\ADFSMenu.dll"%(ADx64Folder),];
    pass
def getSigNatureCommand(filename):
    sCmd = "powershell -command (get-authenticodesignature \"%s\").status -eq 'valid'"%(filename);
    return sCmd;
    pass
def getFileVersionCommand(filename):
    #sCmd = "powershell -command (get-childitem \"%s\").VersionInfo.FileVersion "%(filename);
    sCmd = "wmic datafile where name=\"%s\" get version "%(filename);
    sCmd = sCmd.replace("'","").replace("\\","/").replace("/","\\\\");
    return sCmd;
    pass

def runValidation():
    
    try:
        vResult = False;
        sResult = False;
        result  = True;
        for f in files:
            print f;
            vResult = False;
            callcmd = getFileVersionCommand(f);
            #print callcmd;
            process = subprocess.Popen(callcmd,shell=True,stdin=subprocess.PIPE,stdout=subprocess.PIPE, stderr=subprocess.PIPE);
            line = "";
            while process.poll() == None:
                t = process.stdout.readline().strip();
                if t != "":
                    line = t;
                if line == ExpectBuildNumber:
                    vResult = True;
                    print "Version is right,Expect is %s"%(ExpectBuildNumber);
                    break;
                    pass
            if vResult == False:
                print "~~~~~~~~~~~~~~~~~~~~~~:Version is wrong,Expect is %s, Result is %s.~~~~~~~~~~~~~~~~~~~~~~"%(ExpectBuildNumber,line);
                result = False;
                pass
            sResult = False;
            callcmd = getSigNatureCommand(f);
            #print callcmd;
            process = subprocess.Popen(callcmd,shell=True,stdin=subprocess.PIPE,stdout=subprocess.PIPE, stderr=subprocess.PIPE);
            [out,error] =process.communicate();
            line = out.strip();
            if line == "True":
                print "Signature is right"
                sResult = True;
                pass
            if sResult == False:
                print "~~~~~~~~~~~~~~~~~~~~~~:Signature is Wrong.~~~~~~~~~~~~~~~~~~~~~~"
                print callcmd;
                print line + str(error);
                result = False;
                pass            
        print "##########################################################";
        if result:
            print "Check result is PASS"
        else:
            print "Check result is Failure"
        print "##########################################################";
    except Exception,e:
        print str(e);
        pass
runValidation();

No comments:

Post a Comment