HP fortify scan in Ios getting error - fortify

Hi I am trying to generate reaport but I am getting warning as below and not generating report.Could you please help me out?
[warning]: NST file: /Users/xxxx/.fortify/sca6.2/build/yyyyy/Classes/AFNetworking/AFHTTPClient.m.nst does not exist or removed.
I am using below steps for scanning code. I am getting warning in third step during scanning code apart from step 1 & 2 are working for me.
sourceanalyzer-4.21 -b ${project} -clean
sourceanalyzer-4.21 -Xmx3G -debug -b ${project} -logfile ${project}-trans.log xcodebuild -project ${project}.xcodeproj -sdk iphonesimulator7.1
sourceanalyzer-4.21 -Xmx3G -b ${project} -scan -f ${project}.fpr
ReportGenerator -format pdf -f ${project}.pdf -source ${project}.fpr

Fortify generates NST files during compilation, these NST files together generate one combined FPR file.
If NST files are not generated, then you may not get an appropriate fpr.
sourceanalyzer-4.21 -Xmx3G -debug -b ${project} -logfile ${project}-trans.log xcodebuild -project ${project}.xcodeproj -sdk iphonesimulator
If you want to use iphoneos sdk, you must make sure that "i386" is listed in the Valid Architectures setting.

Related

Turn Package.swift file into binary XCFramework

Someone in my company created a Swift package SDK and now I was tasked to publish it for the customer in a binary way so that the end customers that will use the SDK will not be able to see the source code of it. This is how the SDK is built:
the SDK in xcode (p.s. the build folder is empty)
From my reading on the subject I understand that I need to export the files into an XCFramework file. However, the vast majority of guides I've encountered explain how to make this progress from a framework, and not from a package like in my case..
The only guide I found that seems exactly like what I need is this one, however I get an error right on the first relevant terminal command of xcodebuild -scheme [my scheme name] -sdk iphoneos -configuration Release ARCHS="arm64" BUILD_DIR="./Build". This is the main error line I get: xcodebuild: error: Building a Swift package requires that a destination is provided using the "-destination" option. The "-showdestinations" option can be used to list the available destinations.. Why would I need to specify a destination? I want the SDK to work for all the devices (ios 13+). Non of the forums I searched in online helped me solve this.
I also read Apple's instructions here but got very confused about how the terminal command in step 2 is supposed to look like in my case. Are some of the fields mandatory and some are not?
Any help would be much appreciated!!
Assuming you are working with iOS only and you need an xcframework for both device and simulator architectures, in order to generate an XCFramework from a swift package you need to:
Mark your Package as .dynamic (i.e. .library(name: "Foo", type: .dynamic, targets: ["Foo"]))
Archive the project for both simulator and device. This will generate a .framework file for each architecture.
Copy Modules folders (if any) into the .xcarchive files
Copy the bundles (if any) into the .xcarchive files
Create the xcframework with the frameworks created in step 2
Here's a bash script, based on the one from this swift forums post, to create an XCFramework from a swift package (in my case, I have my package inside an xcworkspace. I didn't try it as a standalone package, not sure if that can be done):
Change the input parameters as needed :), but most importantly replace <Your project name> and <your workspace>.
#!/bin/bash
PROJECT_NAME="<Your project name>"
PROJECT_DIR="./Packages/${PROJECT_NAME}" # Relative path to the directory containing the `Package.swift` file
BUILD_FOLDER="./build"
OUTPUT_DIR="${PROJECT_DIR}/Output"
SIMULATOR_ARCHIVE="${OUTPUT_DIR}/${PROJECT_NAME}-iphonesimulator.xcarchive"
DEVICE_ARCHIVE="${OUTPUT_DIR}/${PROJECT_NAME}-iphoneos.xcarchive"
rm -rf "$OUTPUT_DIR"
mkdir -p "$OUTPUT_DIR"
# 2 iterations: 1 for device arch and another for simulator arch
for PLATFORM in "iOS" "iOS Simulator"; do
case $PLATFORM in
"iOS")
ARCHIVE=$DEVICE_ARCHIVE
SDK=iphoneos
RELEASE_FOLDER="Release-iphoneos"
;;
"iOS Simulator")
ARCHIVE=$SIMULATOR_ARCHIVE
SDK=iphonesimulator
RELEASE_FOLDER="Release-iphonesimulator"
;;
esac
# Step 2
xcodebuild archive \
-workspace <your workspace>.xcworkspace \
-scheme $PROJECT_NAME \
-destination="generic/platform=${PLATFORM}" \
-archivePath $ARCHIVE \
-sdk $SDK \
-derivedDataPath $BUILD_FOLDER \
SKIP_INSTALL=NO \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES
FRAMEWORK_PATH="${ARCHIVE}/Products/Library/Frameworks/${PROJECT_NAME}.framework"
MODULES_PATH="$FRAMEWORK_PATH/Modules"
mkdir -p $MODULES_PATH
BUILD_PRODUCTS_PATH="${BUILD_FOLDER}/Build/Intermediates.noindex/ArchiveIntermediates/${PROJECT_NAME}/BuildProductsPath"
RELEASE_PATH="${BUILD_PRODUCTS_PATH}/${RELEASE_FOLDER}"
SWIFT_MODULE_PATH="${RELEASE_PATH}/${PROJECT_NAME}.swiftmodule"
RESOURCES_BUNDLE_PATH="${RELEASE_PATH}/${PROJECT_NAME}_${PROJECT_NAME}.bundle"
# Step 3
if [ -d $SWIFT_MODULE_PATH ]
then
cp -r $SWIFT_MODULE_PATH $MODULES_PATH
fi
# Step 4
if [ -e $RESOURCES_BUNDLE_PATH ]
then
cp -r $RESOURCES_BUNDLE_PATH $FRAMEWORK_PATH
fi
done
# Step 5
xcodebuild -create-xcframework \
-framework "${DEVICE_ARCHIVE}/Products/Library/Frameworks/${PROJECT_NAME}.framework" \
-framework "${SIMULATOR_ARCHIVE}/Products/Library/Frameworks/${PROJECT_NAME}.framework" \
-output "${OUTPUT_DIR}/${PROJECT_NAME}.xcframework"
When the script ends, you will see 3 files in the output folder:
Device xcarchive
Simulator xcarchive
XCFramework
You can remove the xcarchives, as you won't need them anymore (you can also update the script to do that for you).

xcodebuild command in shell script iOS

I have a complete command to deploy the xCode project on real device.
i.e
xcodebuild -workspace jamesAppV2.xcworkspace -scheme jamesAppV2 -configuration Debug -destination 'platform=iOS,name=Shujaat’s iPad' clean test
its working fine using the command line.
Todo: I wanted to execute this command via a shell script.
here is my complete shell script deploy.sh so for.
#!/bin/bash
#My First Script
#Info to be configured
current_path=$(pwd)
appName="jamesApp"
jamesApp_workspace="jamesAppV2.xcworkspace"
echo "Searching for $jamesApp_workspace workspace..."
if [[ $(ls $jamesApp_workspace) ]]; then
echo "$jamesApp_workspace found in current directory."
echo "Listing all installed and connected devices..."
instruments -s devices
echo "Copy + Paste from above devices"
echo "specify name of your decice to launch $appName"
read d_device_name
echo "building workspace for $d_device_name..."
build_cmd=(xcodebuild -workspace jamesAppV2.xcworkspace -scheme jamesAppV2 -configuration Debug)
destination="'platform=iOS,name=$d_device_name'"
build_cmd+=(-destination "$destination" clean test)
echo "${build_cmd[#]}"
# Here it prints the valid command given above
"${build_cmd[#]}"
else
echo "$jamesApp_workspace workspace not found"
echo "Make sure your current path contains the $jamesApp_workspace workspace"
echo "Place this file i.e deploy.sh within the directory containing $jamesApp_workspace workspace"
fi;
Problem:
I have done like
build_cmd=(xcodebuild -workspace jamesAppV2.xcworkspace -scheme jamesAppV2 -configuration Debug)
destination="'platform=iOS,name=$d_device_name'"
build_cmd+=(-destination "$destination" clean test)
echo "${build_cmd[#]}" #Prints valid command
"${build_cmd[#]}"
but gives error on execution
xcodebuild: error: option 'Destination' requires at least one parameter of the form 'key=value'
if I run the above command via command line its working perfectly but If I run this via shell script its not working.
I have referred I want to concatenate arguments of xcodebuild as string, which have space in it ,then run this command to concatenate the xcodebuild command
The shell removes the single quotes in the original command, therefore you should not have any when creating the array either.
I am also trying to execute the command in a similar way by passing it via a string. The command works without the double quotes anywhere on the command for me.
example:
$ xcodebuild -project ~/ios_projects/example.xcodeproj -scheme Xcode9-XCtest destination id=EBCDFH7S-DCJD-EE8D-DSKDKD78

How to use cocoapods integrated project with OCLint?

I can build the project and generate OCLint report on a project without cocoapods but when integrated with cocoapods the build for project is successful but the build for OCLint results into errors for the file which are present into cocoapods and build fails.
So how to make build successful for cocoapods with OCLint?
Any help would be appreciated.
Below is the script I am using to generate html file for cocoapods integrated project with OCLint.
OCLINT_HOME is the path for oclint downloaded folder. I have renamed the folder to oclintrelease.
OCLINT_HOME=/Users/Dheeraj/Downloads/oclintrelease
export PATH=$OCLINT_HOME/bin:$PATH
hash oclint &> /dev/null
if [ $? -eq 1 ]; then
echo >&2 "oclint not found, analyzing stopped"
exit 1
fi
cd ${TARGET_TEMP_DIR}
if [ ! -f compile_commands.json ]; then
echo "[*] compile_commands.json not found, possibly clean was performed"
echo "Workspace Path : ${MY_WORKSPACE}"
echo "[*] starting xcodebuild to rebuild the project.."
# clean previous output
if [ -f xcodebuild.log ]; then
rm xcodebuild.log
echo "Oclint Clean performed"
fi
cd ${SRCROOT}
xcodebuild clean
#build xcodebuild.log
xcodebuild ONLY_ACTIVE_ARCH=NO -workspace ${PROJECT_NAME}.xcworkspace -scheme ${PROJECT_NAME} -configuration Debug clean build| tee ${TARGET_TEMP_DIR}/xcodebuild.log
#xcodebuild <options>| tee ${TARGET_TEMP_DIR}/xcodebuild.log
echo "[*] transforming xcodebuild.log into compile_commands.json..."
cd ${TARGET_TEMP_DIR}
#transform it into compile_commands.json
oclint-xcodebuild
fi
echo "[*] starting analyzing"
cd ${TARGET_TEMP_DIR}
oclint-json-compilation-database -e /Users/Dheeraj/Desktop/sampleCocoaPods/Pods/ -v oclint_args "-report-type html -o /Users/Dheeraj/NewHTMLREPORT.html" | sed 's/\(.*\.\m\{1,2\}:[0-9]*:[0-9]*:\)/\1 warning:/'
It will exclude all the Pods related files.
If you want to include Pods file as well then replace last line in script by :
oclint-json-compilation-database -v oclint_args "-report-type html -o /Users/Dheeraj/NewHTMLREPORT.html" | sed 's/\(.*\.\m\{1,2\}:[0-9]*:[0-9]*:\)/\1 warning:/'
Notes :
Please try first with a short sample Application including cocoapods and once you have generated report for sample application then integrate script into your real application as building with OCLint takes a lot of time to generate the report.
Always clean application and then build with OCLint.
Link for reference

Jenkins + iOS + TestFlight API

I installed a Jenkins and startet a Project with the Git Plugin, Xcode Plugin and the Testflight Plugin.
I can create automatic builds with the setup, but it is failing at the point on creating the .ipa files for Testflight.
The problem are at Debug and Release settings in different ways though…
If i try to create a .ipa via the Debug settings it will fail at the point that there is no build/Debug-iphoneos folder (i tried to turn of the clean option but it didn't helped). But the Xcode Build is not failing on the command line
When i try to switch to Release the linker is failing (ld).
Whithout the .ipa files i can't submit to Testflight and get a automated Test distributing.
Here is the script I'm using. (Obviously I removed the personal information, but you should be fine to understand it).
TARGET_NAME="-" # Target name
TARGET_SDK="iphoneos" # Target SDK: iphoneos
CONFIGURATION="Release" # Build Configuration
BUILD_DIR="build" # Directory where the build is generated
ARCHS="armv7" # Valid Architectures
APP_NAME="-" # Application name
## Provisioning configurations
BUILD_ARCHIVED_DIR="BuildArchived" # Directory with the history of builds
DEVELOPER_NAME="-" # Developer name
PROVISIONING_PROFILE=Prototype.mobileprovision # Provisioning profile file
PROVISIONING_DIR=~/Library/MobileDevice/Provisioning\ Profiles/ # Provisioning dir
## TestFlight App
TESTFLIGHT_API_TOKEN="-"
TESTFLIGHT_TEAM_TOKEN="-"
#Release Notes
BUILDSCRIPTS_DIR="build"
TESTFLIGHT_RELEASE_NOTES_FILE="ios_testflight-releasenotes"
#Distribution Lists
TESTFLIGHT_DISTRIBUTION_LISTS="Jenkins"
# Returns to the root directory of the build
cd ../ios
PROJECT_BUILDDIR="${BUILD_DIR}/${CONFIGURATION}-${TARGET_SDK}"
CURRENT_DIR=`pwd`
# fix for the newest sdk
# Only export the environment variable if the location exists,
# otherwise it breaks the signing process!
if [ -f "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate" ]
then
echo Export environment variable for codesign_allocate location
export CODESIGN_ALLOCATE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate
fi
#changing the build version
INFO_PLIST_PATH="${CURRENT_DIR}/${TARGET_NAME}/${TARGET_NAME}-Info.plist"
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion ${SVN_REVISION}" $INFO_PLIST_PATH
# compile project
echo Building Project
xcodebuild -target "${TARGET_NAME}" -sdk "${TARGET_SDK}" ARCHS=${ARCHS} -configuration "${CONFIGURATION}" clean build
#Check if build succeeded
#if [ $? != 0 ]
#then
# exit 1
#fi
# Create output dir ($x) if doesn't exist
mkdir -p $BUILD_ARCHIVED_DIR
# .ipa file generation
echo Generating .ipa file
/usr/bin/xcrun -sdk "${TARGET_SDK}" PackageApplication -v "${PROJECT_BUILDDIR}/${APP_NAME}.app" -o "${CURRENT_DIR}/${BUILD_ARCHIVED_DIR}/${APP_NAME}.ipa" --sign "${DEVELOPER_NAME}"
#zipping the .dSYM to send to Testflight
echo Generating zip file
/usr/bin/zip -r "${CURRENT_DIR}/${BUILD_ARCHIVED_DIR}/${APP_NAME}.app.dSYM.zip" "${CURRENT_DIR}/${PROJECT_BUILDDIR}/${APP_NAME}.app.dSYM"
echo Sending to TestFlight
curl http://testflightapp.com/api/builds.json -F file="#${CURRENT_DIR}/${BUILD_ARCHIVED_DIR}/${APP_NAME}.ipa" -F dsym="#${CURRENT_DIR}/${BUILD_ARCHIVED_DIR}/${APP_NAME}.app.dSYM.zip" -F api_token="${TESTFLIGHT_API_TOKEN}" -F team_token="${TESTFLIGHT_TEAM_TOKEN}" -F notes="This build was uploaded via the upload API" -F notify=False -F distribution_lists="${TESTFLIGHT_DISTRIBUTION_LISTS}"
echo Submission ended
I imagine the Scheme your build is targeting is incorrect.
Additionally, TestFlight has a plugin for Jenkins so you can script your build process and execute the upload to TestFlight using the their Jenkins Plugin. I have provided a build script example that works for me via manual command line and under Jenkins CI.
If you would like to see the full setup, you can find a iOS/Git/TestFlight tutorial here: Jenkins iOS – Git, xcodebuild, TestFlight
xcodebuild -alltargets clean
rm -rf "./JenkinsBuild/*"
xcodebuild -target HelloJenkins PROVISIONING_PROFILE="00000000-0000-0000-0000-000000000000" CONFIGURATION_BUILD_DIR=JenkinsBuild
rm -rf "./JenkinsArchive/*"
xcodebuild -scheme HelloJenkins archive PROVISIONING_PROFILE="00000000-0000-0000-0000-000000000000" CODE_SIGN_IDENTITY="iPhone Developer: Jonny Appleseed (XXXXXXXXXX)" -archivePath ./JenkinsArchive/HelloJenkins.xcarchive
rm -rf "./JenkinsIPAExport/*"
xcodebuild -exportArchive -exportFormat IPA -exportProvisioningProfile iOS\ Team\ Provisioning\ Profile:\ com.yourAPP.HelloJenkins -archivePath ./JenkinsArchive/HelloJenkins.xcarchive -exportPath ./JenkinsIPAExport/HelloJenkins.ipa

Find the ${PROJECT_DIR} for an Xcode project

How do I figure out what my absolute ${PROJECT_DIR} path is for my Xcode project? Is there a way to print this in Terminal? How?
Build Settings -> Preprocess Macros
PROJECT_DIR=#\""$PROJECT_DIR"\"
BUILD_ROOT=#\""$(BUILD_ROOT)"\"
Then you can log it directly
NSLog(#"project dir=%#, BUILD_ROOT_=%#", PROJECT_DIR, BUILD_ROOT);
Run this from Terminal
For a project:
xcodebuild -project yourProject.xcodeproj -target yourTarget -showBuildSettings | grep PROJECT_DIR
For a workspace:
xcodebuild -workspace yourWorkspace.xcworkspace -scheme yourScheme -showBuildSettings | grep PROJECT_DIR
As you can see, you can retrieve any other build settings value
Another interesting method is using a Run Script Phase in Build phases:
Then paste this script that will modify a swift file in your project
fileContent="// DO NOT EDIT,
// THIS IS AUTOMATICALLY GENERATED FILE
// params.swift
//
import Foundation
class Params {
static let srcRoot: String = \"${PROJECT_DIR}\"
}"
echo "${SRCROOT}/YourProjectFolderName/params.swift"
echo "$fileContent" > ${SRCROOT}/YourProjectFolderName/params.swift`
Make sure you added Params.swift in you project.

Resources