MikroTik + IKEv2 + RSA/PSK authentication + iOS/macOS/Android/Windows

本帖最後由 张无忌 於 2025-7-28 10:53 編輯

MikroTik hAP ac3 v7.19.3
iPhone iOS v18.5

以前用MikroTik hAP ac2[1], 那个时候iPhone 7 and iPhone SE1,到现在iPhone 16e and iPhone 13 Pro,hardware encryption有所提升,在[1]不再适合,而iPhone 16e and iPhone 13 Pro都有error。现在MikroTik要有所改动后,那么iPhone SE1,iPhone 7,iPhone 13 Pro and iPhone 16e都同时适合。iPhone用家可以有两个选择 1)用certs 和 2)只用pre-shared key (secret)。除了iOS(iPhone和iPad),可以参考macOS / Android / Windows[1]。

下面用MikroTik "New Terminal",然后输入,当"sign"要实行之一句完,再继续执行其他多段。

Listing 1: Part A-Firewall输入
  1. #Suitable position
  2. /ip firewall filter
  3. add chain=input action=accept protocol=udp dst-port=500,4500 comment="Allow IKEv2"
複製代碼
Listing 2: Part B-Certificates of dt1.ca, dt1.server, and peter
  1. #Define and sign CA "dt1.ca"
  2. /certificate
  3. add common-name=dt1.ca name=dt1.ca days-valid=4900
  4. sign dt1.ca ca-crl-host=xyz.abc.org

  5. #Define and sign Server "dt1.server"
  6. add common-name=xyz.abc.org subject-alt-name=DNS:xyz.abc.org name=dt1.server key-usage=tls-server days-valid=4900
  7. sign dt1.server ca=dt1.ca

  8. #Server certificate trusted
  9. /certificate/set dt1.server trusted=yes

  10. ######################
  11. #Define and sign client 1 "peter"
  12. /certificate
  13. add common-name=peter name=peter subject-alt-name=DNS:peter key-usage=tls-client days-valid=4900
  14. sign peter ca=dt1.ca

  15. #Client certificate trusted
  16. /certificate/set peter trusted=yes

  17. ######################
  18. #export certificate of server
  19. /certificate
  20. export-certificate dt1.ca type=pem

  21. #export certificate of "peter"
  22. /certificate
  23. export-certificate peter export-passphrase=12345678 type=pkcs12
複製代碼
上面certificates可以delete,重新再来都可以。

Listing 3: Part C-IPsec config including ip pool
  1. /ip ipsec profile
  2. add name=ike2 hash-algorithm=sha256 enc-algorithm=aes-256,aes-128,3des dh-group=ecp256,modp2048,modp1024

  3. /ip ipsec proposal
  4. add name=ike2 pfs-group=none auth-algorithms=sha1,sha256

  5. /ip pool
  6. add name=ike2-pool ranges=192.168.77.2-192.168.77.254

  7. /ip ipsec mode-config
  8. add address-pool=ike2-pool address-prefix-length=32 name=ike2-conf

  9. /ip ipsec policy group
  10. add name=ike2-policies

  11. /ip ipsec policy
  12. add dst-address=192.168.77.0/24 group=ike2-policies proposal=ike2 src-address=0.0.0.0/0 template=yes

  13. /ip ipsec peer
  14. add exchange-mode=ike2 name=ike2 passive=yes profile=ike2

  15. /ip ipsec identity
  16. add auth-method=digital-signature certificate=dt1.server generate-policy=port-strict mode-config=ike2-conf peer=ike2 policy-template-group=ike2-policies
複製代碼
在最后一句"certificate=dt1.server"要看清楚。如果Part C要有改动都可以,不影响Part B-Certifications。

Files in FILE folder
1. drag "cert_export_dt1.ca.crt" into Windows folder
2. darg "cert_export_peter.p12" into Windows folder

Mail to Windows Gmail
1. mail "cert_export_dt1.ca.crt"
2. mail "cert_export_peter.p12"

iPhone Mail (Gmail) for "dt1.ca" , open "dt1.ca", tap "cert_export_dt1.ca.crt"
iPhone Settings: Profile Downloaded, Install Profile "dt1.ca", iPhone passcode

iPhone Mail (Gmail) for "peter.p12" , open "peter", tap "cert_export_peter.p12"
iPhone Settings: Profile Downloaded, Install Profile "peter.p12", iPhone passcode and "12345678" for peter

Listing 4: iPhone IKEv2 configuration with certificates
  1. Type=IKEv2
  2. Desciption=IKEv2-DT1-peter
  3. Server=xyz.abc.org
  4. Remote ID=xyz.abc.org
  5. Local ID=peter

  6. User Authentication=None
  7. Use Certificate=(green on)
  8. Certificate=peter
複製代碼
以前的code都可以要求certs,今次我们可以用PSK (pre-shared key),用iPhone可以用PSK去注册IKEv2。

Listing 5: Part D-PSK for iPhone and Android without certificates
  1. /ip ipsec identity
  2. add peer=ike2 auth-method=pre-shared-key secret=hk1997 policy-template-group=ike2-policies mode-config=ike2-conf generate-policy=port-strict remote-id=ignore
複製代碼
"remote-id=ignore" is added to ignore "Local ID=<blank>".

Listing 6: iPhone IKEv2 configuration using a PSK without certificates
  1. Type=IKEv2
  2. Desciption=IKEv2-DT1-PSK
  3. Server=xyz.abc.org
  4. Remote ID=xyz.abc.org
  5. Local ID=

  6. User Authentication=None
  7. Use Certificate=(grey off)
  8. Secret=hk1997
複製代碼
Listing 7: Android IKEv2 configuration using a PSK without certificates
  1. Name=<Any name>
  2. Type=IKEv2/IPSec PSK
  3. Server address=xyz.abc.org
  4. IPsec identifier=xyz.abc.org
  5. Pre-shared key=hk1997
複製代碼
测试:
1. iOS iPhone/iPad: RSA SE1、7、13 Pro、16e、iPad Pro all passed
2. iOS iPhone/iPad: PSK SE1、7、13 Pro、16e、iPad Pro all passed
3. macOS: PSK passed
4. Android PSK: all passed
5. Windows 10 RSA: all passed

Remarks:
1. 现在最新的iPhone 16e and SE1都可以注册成功及正常使用。
2. 用certs可以,只有一个certs。不用certs而用PSK都可以,可以多人login。
3. 现在是用ARM microprocessors,改用TILE microprocessors不行,测试时可以,但是只有单边流动,原因要MikroTik才能找出答案。
4. 而你家里hAP ax3 (IPQ-6010) and RB5009UG+S+IN (88F7040)可以在"/ip/ipsec/proposal"加入aes256-gcm[2],但是怎样选,决定于MikroTk。
5. 如果不考虑用Windows IKEv2,可以上面Listing 3:23 "remote-id=ignore"补上去,iPhone IKEv2 configuration "Local ID"不填。

References:
[1] MikroTik RouterOS IKEv2 RSA VPN Settings for both Apple and Android devices
[2] Hardware acceleration

本帖最後由 张无忌 於 2025-7-21 04:09 編輯

MikroTik logging for IPsec debug

以前不知道怎样debug,所以不知道错在哪里,这次经过朋友说,在MikroTik里有ipsec debug,这样可以知道那些缺,例如sha256,ecp256,aes256-cbc可以加上去。

Add IPsec debug
  1. /system logging
  2. add topics=ipsec
複製代碼
log iPhone 16e and iPhone 13 Pro
  1. IKE Protocol: IKE
  2. propsal #1
  3.   enc: aes256-gcm
  4.   prf: hmac-sha256
  5.   dh: ecp256
  6. proposal #2
  7.   enc: aes256-gcm
  8.   prf: hmac-sha256
  9.   dh: modp2048
  10. proposal #3
  11.   enc: aes256-cbc
  12.   prf: hmac-sha256
  13.   dh: ecp256
  14. proposal #4
  15.   enc: aes256-cbc
  16.   prf: hmac-sha256
  17.   dh: modp2048
  18. matched proposal
  19. proposal #3
  20.   enc: aes256-cbc
  21.   prf: hmac-sha256
  22.   dh: ecp256
  23. processing payload: IKE
複製代碼
因为本身hAP ac3没有hardware acceleration for aes256-gcm,所以没有选上。如果CPU是88F7040、AL21400、AL32400、AL52400、AL73400、IPQ-6010、IPQ-8072、x86 (AES-NI),可以加入aes256-gcm。而你家里hAP ax3 (IPQ-6010) and RB5009UG+S+IN (88F7040)可以用aes256-gcm,最后选定于MikroTik。
https://help.mikrotik.com/docs/s ... ardwareacceleration

log iPhone SE1 and iPhone 7
  1. IKE Protocol: IKE
  2. propsal #1
  3.   enc: aes256-cbc
  4.   prf: hmac-sha256
  5.   auth: sha256
  6.   dh: modp2048
  7. proposal #2
  8.   enc: aes256-cbc
  9.   prf: hmac-sha256
  10.   auth: sha256
  11.   dh: ecp256
  12. proposal #3
  13.   enc: aes256-cbc
  14.   prf: hmac-sha256
  15.   auth: sha256
  16.   dh: modp1536
  17. proposal #4
  18.   enc: aes128-cbc
  19.   prf: hmac-sha1
  20.   auth: sha1
  21.   dh: modp1024
  22. proposal #5
  23.   enc: 3des-cbc
  24.   prf: hmac-sha1
  25.   auth: sha1
  26.   dh: modp1024
  27. matched proposal
  28. propsal #1
  29.   enc: aes256-cbc
  30.   prf: hmac-sha256
  31.   auth: sha256
  32.   dh: modp2048
  33. processing payload: IKE
複製代碼

TOP

本帖最後由 张无忌 於 2025-7-23 14:00 編輯

以前我学MikroTik通常利用screenshots,把所有settings都记录下来,用一个reference是。

Figure 1: Certificate


Figure 2a: Policy-General


Figure 2b: Policy-Action


Figure 2c: Policy-Status


Figure 3: Proposal


Figure 4. Group


Figure 5: Peer


Figure 6: Identity with certs

"Remote ID Type=ignore" for Listing 4:05 "Load ID=<blank>"

Figure 7: Identity with PSK for both iPhone and Android


Figure 8: Profile


Figure 9: Config
附件: 您需要登錄才可以下載或查看附件。沒有帳號?註冊

TOP

本帖最後由 张无忌 於 2025-7-25 22:55 編輯

Certification:
  1. [admin@MikroTik] /certificate> print
  2. Flags: K - PRIVATE-KEY; L - CRL; A - AUTHORITY; I - ISSUED; T - TRUSTED
  3. Columns: NAME, COMMON-NAME
  4. #       NAME                          COMMON-NAME                 
  5. 0 KLA T dt1.ca                        dt1.ca                     
  6. 1 K  IT dt1.server                    dt1.abc.org            
  7. 2 K  IT peter                         peter                       
  8. [admin@MikroTik] /certificate>
複製代碼
Using "/ip/ipsec" in Terminal can read a lot of information:
  1. [admin@MikroTik] /ip/ipsec>
  2. active-peers     key             policy       settings     
  3. identity         mode-config     profile      statistics   
  4. installed-sa     peer            proposal     export      
  5. [admin@MikroTik] /ip/ipsec>
複製代碼
For example "Proposal"
  1. [admin@MikroTik] /ip/ipsec> proposal/
  2. [admin@MikroTik] /ip/ipsec/proposal> print
  3. Flags: X - disabled; * - default
  4. 0  * name="default" auth-algorithms=sha1
  5.       enc-algorithms=aes-256-cbc,aes-192-cbc,aes-128-cbc lifetime=30m
  6.       pfs-group=modp1024

  7. 1    name="ike2" auth-algorithms=sha256,sha1
  8.       enc-algorithms=aes-256-cbc,aes-192-cbc,aes-128-cbc lifetime=30m
  9.       pfs-group=none
  10. [admin@MikroTik] /ip/ipsec/proposal>
複製代碼
以前"1" "auth-algorithms=sha1"。

For another example "Profile"
  1. [admin@MikroTik] /ip/ipsec> profile
  2. [admin@MikroTik] /ip/ipsec/profile> print
  3. Flags: * - default
  4. 0 * name="default" hash-algorithm=sha1 enc-algorithm=aes-128,3des
  5.      dh-group=modp2048,modp1024 lifetime=1d proposal-check=obey
  6.      nat-traversal=yes dpd-interval=2m dpd-maximum-failures=5

  7. 1   name="ike2" hash-algorithm=sha256 enc-algorithm=aes-256,aes-128,3des
  8.      dh-group=ecp256,modp2048,modp1024 lifetime=1d proposal-check=obey
  9.      nat-traversal=yes dpd-interval=8s dpd-maximum-failures=4
  10. [admin@MikroTik] /ip/ipsec/profile>
複製代碼
以前"1" "auth-algorithms=sha1","dh-group=modp2048,modp1024"。

Admin Panel and OpenWrt Contents

TOP

感謝張無忌兄的無私分享, 做福在墻内的港燦。

我們是國内互聯網封鎖的受害者, 長居在國内的港燦,上不了美帝的 YouTube FaceBook Whatsapp Google 基本上就是生不如死的:活著的死人。 完全與西方文明世界脫節,只能接收黨媒一面倒的報喜不報憂的厲害了我的國的資訊

其實我們冒死觀看的美帝的 YouTube FaceBook Whatsapp Google 基本上不是什麽國家的機密, 在西方文明世界是一些 【公開的資訊】而已

因此我們的 VPN 科學上網,只 觀看的美帝的 YouTube FaceBook Whatsapp Google 這些公開的資訊,是不需要任何【加密】的

不需要那些  Digital Certificate 和密碼保護那麽【軍事級別的加密】的

就是最簡單的   Password 登入就可以啦, 最重要就是簡單, 能【科學上網】就可以, 其他的完全不重要的。    我們不是什麽銀行這些金融機構, 因此不需要高規格的【軍事級別的加密】

就算是沒有 Security 保安, 被黑客入侵, 我的電腦什麽都沒有,只是用來上網和看 YouTube Facebook 而已, 就算中毒,就【洗機】重灌快樂版本的 Window, Easy Job 啦, 定期清清  C Drive 也是很不錯, 已經成爲生活的 Routine 啦, 沒有什麽大不了的吧

TOP

拜读 楼主的精彩好文,学习和收藏!赞!!!

TOP

呢啲史前技術就咪成日重覆拎嚟提完又提啦,仲要搵人推。

仲IKEv2
用一個鐘個Destination IP就被GFW收皮啦。

TOP

回覆 4# 张无忌


    十分有用的资料, 感谢楼主技术分享,造福我们这些新手。。。

TOP