优化MacOS的Anyconnect安装包

Mac系统的Anyconnect Predeploy安装包中集成了VPN、Web Security、Diagnostics and Reporting Tool、AMP Enabler、Posture、ISE Posture、Network Visibility、Umbrella Roaming Security组件,在正常的安装过程中,这些组件都是默认勾选安装的。

虽然安装过程很简单,但是难免有傻X用户看都不看直接下一步,所以我决定优化一下客户端。


最开始的思路是先从官方找,除了Predeploy版本外,官方还提供了Web deploy版本,这两个版本的区别在于Web deploy用于上传到ASA内部,用户从web端访问VPN的时候自动部署anyconnect软件;Pre Deploy是用于预先部署的单独安装包。

官方的anyconnect手册中写了如何通过ASDM定制安装包,但是经过测试ASDM仅支持windows版的定制,手册也没有提供macOS版的相关参数。
不过在手册的#Disable the Customer Experience Feedback Module章节发现了一段描述可以把dmg文件从只读转换为可读写。

Convert the dmg package from read-only to read-write using Disk Utility or hdiutil. For example:

hdiutil convert anyconnect-macosx-i386-ver-k9.dmg -format UDRW -o anyconnect-macosx-i386-ver-k9-rw.dmg

那么新的思路就是修改dmg文件包的内容,再重新打包。
首先是打开anyconnect-macos-4.8.00175-predeploy-k9.dmg ,把Anyconnect.pkg复制出来。
使用pkgutil工具解压,目录结构如下:

pkgutil --expand AnyConnect.pkg anyconnect

ls -las 
dart_module.pkg     
nvm_module.pkg      
vpn_module.pkg
fireamp_module.pkg  
posture_module.pkg  
websecurity_module.pkg
iseposture_module.pkg   
umbrella_module.pkg

Distribution是安装过程中的配置文件
Resources是安装过程中的字体、license服务协议、背景图片等资源
其他的pkg就是各个组件了。

优化的办法就删掉其他pkg,只保留vpn_module.pkg。然后在修改Distribution,注释或者删掉其他组件的调用:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<installer-gui-script minSpecVersion="1">
    <title>AnyConnect Secure Mobility Client</title>
    <background file="pkg_background.png" scaling="proportional" alignment="bottomleft"/>
    <license file="License.rtf"/>
    <options customize="always" rootVolumeOnly="true" hostArchitectures="x86_64"/>
    <choices-outline>
        <line choice="choice_vpn"/> 
<!--        
        <line choice="choice_websecurity"/>
        <line choice="choice_fireamp"/>
        <line choice="choice_dart"/>
        <line choice="choice_posture"/>
        <line choice="choice_iseposture"/>
        <line choice="choice_nvm"/>
        <line choice="choice_umbrella"/> 
-->
    </choices-outline>
    <choice id="choice_vpn" start_enabled="1" enabled="choice_vpn_enabled()" start_selected="check_upgrade()" selected="choice_vpn_selected()" title="VPN" description="Installs the module that enables VPN capabilities.">
        <pkg-ref id="com.cisco.pkg.anyconnect.vpn"/>
    </choice>
<!--    
    <choice id="choice_websecurity" start_selected="check_upgrade()" start_enabled="enable_module()" title="Web Security" description="Installs the WebSecurity module that enables cloud scanning of web content to protect against malware and enforce acceptable use policies via the ScanSafe cloud proxies.">
        <pkg-ref id="com.cisco.pkg.anyconnect.websecurity_v2"/>
    </choice>
    <choice id="choice_dart" start_selected="check_upgrade()" start_enabled="enable_module()" title="Diagnostics and Reporting Tool" description="Installs the diagnostics module that collects AnyConnect Secure Mobility Client troubleshooting information.">
        <pkg-ref id="com.cisco.pkg.anyconnect.dart"/>
    </choice>
    <choice id="choice_fireamp" start_selected="check_upgrade()" start_enabled="enable_module()" title="AMP Enabler" description="Installs the AMP Enabler module that downloads and deploys AMP for Endpoints, as configured by the administrator.">  
        <pkg-ref id="com.cisco.pkg.anyconnect.fireamp"/>
    </choice>
    <choice id="choice_posture" start_selected="check_upgrade()" start_enabled="enable_module()" title="Posture" description="Installs the module that provides the AnyConnect Secure Mobility Client with the ability to identify the operating system, antivirus, antispyware, and firewall software installed on the host prior to creating a remote access connection to the secure gateway.">
        <pkg-ref id="com.cisco.pkg.anyconnect.posture"/>
    </choice>
    <choice id="choice_iseposture" start_selected="check_upgrade()" start_enabled="enable_module()" title="ISE Posture" description="Installs the module that provides the AnyConnect Secure Mobility Client with the functionality needed to authenticate to wired or wireless networks controlled by the Identity Services Engine, including examination and any needed remediation of the connecting host environment.">
        <pkg-ref id="com.cisco.pkg.anyconnect.iseposture"/>
    </choice>
    <choice id="choice_nvm" start_selected="check_upgrade()" start_enabled="enable_module()" title="Network Visibility" description="Installs the Network Visibility Module which collects application telemetry data.">
        <pkg-ref id="com.cisco.pkg.anyconnect.nvm_v2"/>
    </choice>
    <choice id="choice_umbrella" start_selected="check_upgrade()" start_enabled="enable_module()" title="Umbrella Roaming Security" description="Installs the module that enables Umbrella Roaming Security.">
        <pkg-ref id="com.cisco.pkg.anyconnect.umbrella"/>
    </choice> 
-->
    <pkg-ref id="com.cisco.pkg.anyconnect.vpn" version="4.8.00175" installKBytes="23133">#vpn_module.pkg</pkg-ref>
<!--   
     <pkg-ref id="com.cisco.pkg.anyconnect.dart" version="4.8.00175" installKBytes="5355">#dart_module.pkg</pkg-ref>
    <pkg-ref id="com.cisco.pkg.anyconnect.websecurity_v2" version="4.8.00175" installKBytes="2613">#websecurity_module.pkg</pkg-ref>
    <pkg-ref id="com.cisco.pkg.anyconnect.fireamp" version="4.8.00175" installKBytes="519">#fireamp_module.pkg</pkg-ref>
    <pkg-ref id="com.cisco.pkg.anyconnect.posture" version="4.8.00175" installKBytes="27649">#posture_module.pkg</pkg-ref>
    <pkg-ref id="com.cisco.pkg.anyconnect.iseposture" version="4.8.00175" installKBytes="3433">#iseposture_module.pkg</pkg-ref>
    <pkg-ref id="com.cisco.pkg.anyconnect.nvm_v2" version="4.8.00175" installKBytes="5222">#nvm_module.pkg</pkg-ref>
    <pkg-ref id="com.cisco.pkg.anyconnect.umbrella" version="4.8.00175" installKBytes="4050">#umbrella_module.pkg</pkg-ref>   
-->
    <installation-check script="InstallationCheck()"/>
    <volume-check script="VolumeCheck()"/>
    <script>
    
    var gUpgradeModules = [];

    function check_upgrade()
    {
        var modulePkgInfo = my.choice.packages[0];
        var moduleReceipt = my.target.receiptForIdentifier(modulePkgInfo.identifier);

        if (moduleReceipt)
        {
            var comparison = system.compareVersions(moduleReceipt.version, modulePkgInfo.version);

            if (comparison == 0)
            {
                system.log("Found an existing installed version: " + my.choice.title);
                return false;
            }
        }

        gUpgradeModules.push(my.choice.id);
        return true;
    }
    
    function enable_module()
    {
        var moduleID = my.choice.id;
        return (gUpgradeModules.indexOf(moduleID) &gt; -1);
    }

    function InstallationCheck()
    {
        if(!(system.compareVersions(system.version.ProductVersion, '10.9') &gt;= 0))
        {
            my.result.title = 'Cisco AnyConnect Secure Mobility Client';
            my.result.message = 'This software requires Mac OS X version 10.9 or later.';
            my.result.type = 'Fatal';
            return false;
        }

        return true;
    }
    
    function VolumeCheck()
    {
        // version of VPN being installed has to be higher than the version already installed

        var vpnReceipt = my.target.receiptForIdentifier("com.cisco.pkg.anyconnect.vpn");
        var vpnPackage = choices.choice_vpn.packages[0];

        // if the receipt is not there assume no VPN installed or pre-3.1.1 version so it is OK to install
        if (vpnReceipt)
        {
            // there is a 3.1.1+ version of VPN already installed
            // check to see if version in this package is newer
            var comparison = system.compareVersions(vpnReceipt.version, vpnPackage.version);

            if (comparison &gt; 0)
            {
                // installed version is newer
                my.result.message = 'Newer version ' + vpnReceipt.version + ' of the Cisco AnyConnect Secure Mobility Client is already installed.';
                my.result.type = 'Fatal';
                return false;
            }
        }

        // Check if standalone NVM is installed

        var nvmStandaloneReceipt = my.target.receiptForIdentifier("com.cisco.pkg.anyconnect.nvmstandalone");
        if(nvmStandaloneReceipt)
        {
            // if version of standalone NVM installed is greater than AC package version, fail with an error message
            var comparison = system.compareVersions(nvmStandaloneReceipt.version, vpnPackage.version);

            if (comparison &gt; 0)
            {
                my.result.message = 'Version ' + nvmStandaloneReceipt.version + ' of the Cisco AnyConnect Standalone Network Visibility Module is already installed.';
                my.result.type = 'Fatal';
                return false;
            }
        }

        return true;
    }

    function choice_vpn_enabled()
    {
        if (!enable_module())
        {
            return false;
        }

        return (!choices.choice_websecurity.selected &amp;&amp; !choices.choice_posture.selected &amp;&amp; !choices.choice_iseposture.selected &amp;&amp; !choices.choice_fireamp.selected &amp;&amp; !choices.choice_nvm.selected &amp;&amp; !choices.choice_umbrella.selected);
    }

    function choice_vpn_selected()
    {
        if (!enable_module())
        {
            return false;
        }
        
        var tSelected;

        tSelected=((choices.choice_websecurity.selected || choices.choice_posture.selected || choices.choice_iseposture.selected || choices.choice_fireamp.selected || choices.choice_nvm.selected || choices.choice_umbrella.selected) || (!choices.choice_websecurity.selected &amp;&amp; !choices.choice_posture.selected &amp;&amp; !choices.choice_iseposture.selected &amp;&amp; !choices.choice_fireamp.selected &amp;&amp; !choices.choice_nvm.selected &amp;&amp; !choices.choice_umbrella.selected));

        if (choice_vpn_enabled()==false)
        {
            return tSelected;
        }

        return (tSelected &amp;&amp; my.choice.selected);
    }
    </script>
    <pkg-ref id="com.cisco.pkg.anyconnect.vpn">
        <bundle-version>
            <bundle CFBundleShortVersionString="4.8.00175" CFBundleVersion="4.8.00175" id="com.cisco.anyconnect.kext.notification" path="opt/cisco/anyconnect/bin/Cisco AnyConnect Secure Mobility Client Notification.app"/>
            <bundle CFBundleShortVersionString="4.8.00175" CFBundleVersion="4.8.00175" id="com.cisco.anyconnect.gui" path="Applications/Cisco/Cisco AnyConnect Secure Mobility Client.app"/>
            <bundle CFBundleVersion="4.8.00175" id="com.cisco.anyconnect.vpndownloader" path="opt/cisco/anyconnect/bin/vpndownloader.app"/>
            <bundle CFBundleShortVersionString="4.8.00175" CFBundleVersion="4.8.00175" id="com.cisco.anyconnect.uninstaller" path="Applications/Cisco/Uninstall AnyConnect.app"/>
        </bundle-version>
    </pkg-ref>
<!--  
  <pkg-ref id="com.cisco.pkg.anyconnect.websecurity_v2">
        <bundle-version/>
    </pkg-ref>
    <pkg-ref id="com.cisco.pkg.anyconnect.fireamp">
        <bundle-version/>
    </pkg-ref>
    <pkg-ref id="com.cisco.pkg.anyconnect.dart">
        <bundle-version>
            <bundle CFBundleShortVersionString="4.8.00175" CFBundleVersion="4.8.00175" id="com.cisco.anyconnect.dart" path="Applications/Cisco/Cisco AnyConnect DART.app"/>
            <bundle CFBundleShortVersionString="4.8.00175" CFBundleVersion="4.8.00175" id="com.cisco.anyconnect.dartuninstaller" path="Applications/Cisco/Uninstall AnyConnect DART.app"/>
        </bundle-version>
    </pkg-ref>
    <pkg-ref id="com.cisco.pkg.anyconnect.posture">
        <bundle-version/>
    </pkg-ref>
    <pkg-ref id="com.cisco.pkg.anyconnect.iseposture">
        <bundle-version/>
    </pkg-ref>
    <pkg-ref id="com.cisco.pkg.anyconnect.nvm_v2">
        <bundle-version/>
    </pkg-ref>
    <pkg-ref id="com.cisco.pkg.anyconnect.umbrella">
        <bundle-version>
            <bundle CFBundleVersion="1.5.5" id="com.opendns.OpenDNS-Diagnostic" path="opt/cisco/anyconnect/bin/UmbrellaDiagnostic.app"/>
        </bundle-version>
    </pkg-ref> 
-->
</installer-gui-script>

简单看了下里面的判断逻辑,还需要吧<choice id="choice_vpn" start_enabled="enable_module()"修改为<choice id="choice_vpn" start_enabled="1"即可。

使用pkgutil重新打包

$pkgutil  --flatten anyconnect Anyconnect-New.pkg

重新挂载之前改为可读写的dmg,然后替换新的pkg文件。移除挂载后,再用macOS磁盘工具重新调整dmg的大小,调整后改为只读:

在 Mac 上使用“磁盘工具”调整磁盘映像大小

$hdiutil convert anyconnect-macos-4.8.00175-predeploy-k9.dmg -format UDRO -o anyconnect-macos-4.8.00175-VPN.dmg

参考资料:
Cisco AnyConnect Secure Mobility Client Administrator Guide, Release 4.7
优化MacOS的Anyconnect安装包

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 219,539评论 6 508
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 93,594评论 3 396
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 165,871评论 0 356
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,963评论 1 295
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,984评论 6 393
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,763评论 1 307
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,468评论 3 420
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,357评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,850评论 1 317
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 38,002评论 3 338
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 40,144评论 1 351
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,823评论 5 346
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,483评论 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 32,026评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,150评论 1 272
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,415评论 3 373
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 45,092评论 2 355