ECDHE_GCM

本文介绍了使用Python的ECDH协议生成预主密钥,并通过AES-GCM进行消息加密与身份验证的过程。涉及移动设备与BSRM之间的密钥交换和加密通信细节。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#!/usr/bin/python

from tinyec import registry
from Crypto.Cipher import AES
import secrets, binascii

curve = registry.get_curve('secp256r1')

#mobile random generate ecdh key pair
mobile_dh_privKey = secrets.randbelow(curve.field.n)
print("mobile_dh_privKey: " + hex(mobile_dh_privKey))
mobile_dh_pubKey = mobile_dh_privKey * curve.g
print("mobile_dh_pubKey: " + hex(mobile_dh_pubKey.x) +  " , "  + hex(mobile_dh_pubKey.y))

#bsrm random generate ecdh key pair
bsrm_dh_privKey = secrets.randbelow(curve.field.n)
print("bsrm_dh_privKey: " + hex(bsrm_dh_privKey))
bsrm_dh_pubKey = bsrm_dh_privKey * curve.g
print("bsrm_dh_pubKey: " + hex(bsrm_dh_pubKey.x) +  " , "  + hex(bsrm_dh_pubKey.y))

#communication message
msg = b'fortest'
print("\noriginal msg: " + str(msg) + "\n")

### {{ mobile 

# mobile get bsrm_dh_pubKey from the hello message, calculate the Pre_Master_Secret
mobile_pre_master_secret = mobile_dh_privKey * bsrm_dh_pubKey 
print("mobile_pre_master_secret: " + hex(mobile_pre_master_secret.x) +  " , "  + hex(mobile_pre_master_secret.y))

#the first 128bits of x-coordinate of Pre_Master_Secret
mobile_aes_gcm_key = (hex(mobile_pre_master_secret.x))[2:34]
#the first 96bits of y-coordinate of Pre_Master_Secret
mobile_aes_gcm_iv = (hex(mobile_pre_master_secret.y))[2:26]
print("mobile aes gcm key: " + mobile_aes_gcm_key  + " , mobile aes gcm iv: " + mobile_aes_gcm_iv)

#mobile encrypt message, send the ciphertext and authTag to bsrm
aesCipher = AES.new(binascii.unhexlify(mobile_aes_gcm_key), AES.MODE_GCM, nonce = binascii.unhexlify(mobile_aes_gcm_iv))
ciphertext, authTag = aesCipher.encrypt_and_digest(msg)
print("\nmobile->bsrm ciphertext: " + str(binascii.hexlify(ciphertext)))
print("mobile->bsrm authTag: " + str(binascii.hexlify(authTag)) + "\n")
### }}

### {{ bsrm

# bsrm get mobile_dh_pubKey from the hello message, calculate the Pre_Master_Secret
bsrm_pre_master_secret = bsrm_dh_privKey * mobile_dh_pubKey 
print("bsrm_pre_master_secret: " + hex(bsrm_pre_master_secret.x) +  " , "  + hex(bsrm_pre_master_secret.y))

#the first 128bits of x-coordinate of Pre_Master_Secret
bsrm_aes_gcm_key = (hex(bsrm_pre_master_secret.x))[2:34]
#the first 96bits of y-coordinate of Pre_Master_Secret
bsrm_aes_gcm_iv = (hex(bsrm_pre_master_secret.y))[2:26]
print("bsrm aes gcm key: " + bsrm_aes_gcm_key  + " , bsrm aes gcm iv: " + bsrm_aes_gcm_iv)

#bsrm receive ciphertext and authTag from mobile, decrypt to plaintext message
aesCipher = AES.new(binascii.unhexlify(bsrm_aes_gcm_key), AES.MODE_GCM, nonce = binascii.unhexlify(bsrm_aes_gcm_iv))
plaintext = aesCipher.decrypt_and_verify(ciphertext, authTag)
print("\nbsrm decrypt plaintext: " + str(plaintext))
### }}

握手模拟 Android 4.4.2 RSA 2048(SHA256) TLS 1.2 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 ECDH secp256r1 FS Android 5.0.0 RSA 2048(SHA256) TLS 1.2 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 ECDH secp256r1 FS Android 6.0 RSA 2048(SHA256) TLS 1.2 > http/1.1 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 ECDH secp256r1 FS Android 7.0 RSA 2048(SHA256) TLS 1.2 > h2 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 ECDH x25519 FS Android 8.0 RSA 2048(SHA256) TLS 1.2 > h2 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 ECDH x25519 FS Android 8.1 - TLS 1.3 TLS_AES_256_GCM_SHA384 ECDH x25519 FS Android 9.0 - TLS 1.3 TLS_AES_256_GCM_SHA384 ECDH x25519 FS BingPreview 2015 年 1 月 RSA 2048(SHA256) TLS 1.2 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 ECDH secp256r1 FS Chrome 49 / XP SP3 RSA 2048(SHA256) TLS 1.2 > h2 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 ECDH secp256r1 FS Chrome 69 / Win 7 R RSA 2048(SHA256) TLS 1.2 > h2 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 ECDH x25519 FS Chrome 70 / Win 10 - TLS 1.3 TLS_AES_256_GCM_SHA384 ECDH x25519 FS Chrome 80 / Win 10 R - TLS 1.3 TLS_AES_256_GCM_SHA384 ECDH x25519 FS Firefox 31.3.0 ESR / Win 7 RSA 2048(SHA256) TLS 1.2 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 ECDH secp256r1 FS Firefox 47 / Win 7 R RSA 2048(SHA256) TLS 1.2 > h2 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 ECDH secp256r1 FS Firefox 49 / XP SP3 RSA 2048(SHA256) TLS 1.2 > h2 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 ECDH secp256r1 FS Firefox 62 / Win 7 R RSA 2048(SHA256) TLS 1.2 > h2 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 ECDH x25519 FS Firefox 73 / Win 10 R - TLS 1.3 TLS_AES_256_GCM_SHA384 ECDH x25519 FS Googlebot 2018 年 2 月 RSA 2048(SHA256) TLS 1.2 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 ECDH x25519 FS IE 11 / Win 7 R RSA 2048(SHA256) TLS 1.2 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 ECDH secp256r1 FS IE 11 / Win 8.1 R RSA 2048(SHA256) TLS 1.2 > http/1.1 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 ECDH secp256r1 FS IE 11 / Win Phone 8.1 R RSA 2048(SHA256) TLS 1.2 > http/1.1 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 ECDH secp256r1 FS IE 11 / Win Phone 8.1 更新 R RSA 2048(SHA256) TLS 1.2 > http/1.1 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 ECDH secp256r1 FS IE 11 / Win 10 R RSA 2048(SHA256) TLS 1.2 > h2 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 ECDH secp256r1 FS Edge 15 / Win 10 R RSA 2048(SHA256) TLS 1.2 > h2 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 ECDH x25519 FS Edge 16 / Win 10 R RSA 2048(SHA256) TLS 1.2 > h2 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 ECDH x25519 FS Edge 18 / Win 10 R RSA 2048(SHA256) TLS 1.2 > h2 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 ECDH x25519 FS Edge 13 / Win Phone 10 R RSA 2048(SHA256) TLS 1.2 > h2 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 ECDH secp256r1 FS Java 8u161 RSA 2048(SHA256) TLS 1.2 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 ECDH secp256r1 FS Java 11.0.3 - TLS 1.3 TLS_AES_256_GCM_SHA384 ECDH secp256r1 FS Java 12.0.1 - TLS 1.3 TLS_AES_256_GCM_SHA384 ECDH secp256r1 FS OpenSSL 1.0.1l R RSA 2048(SHA256) TLS 1.2 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 ECDH secp256r1 FS OpenSSL 1.0.2s R RSA 2048(SHA256) TLS 1.2 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 ECDH secp256r1 FS OpenSSL 1.1.0k R RSA 2048(SHA256) TLS 1.2 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 ECDH x25519 FS OpenSSL 1.1.1c R - TLS 1.3 TLS_AES_256_GCM_SHA384 ECDH x25519 FS Safari 6 / iOS 6.0.1 RSA 2048(SHA256) TLS 1.2 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 ECDH secp256r1 FS Safari 7 / iOS 7.1 R RSA 2048(SHA256) TLS 1.2 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 ECDH secp256r1 FS Safari 7 / OS X 10.9 R RSA 2048(SHA256) TLS 1.2 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 ECDH secp256r1 FS Safari 8 / iOS 8.4 R RSA 2048(SHA256) TLS 1.2 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 ECDH secp256r1 FS Safari 8 / OS X 10.10 R RSA 2048(SHA256) TLS 1.2 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 ECDH secp256r1 FS Safari 9 / iOS 9 R RSA 2048(SHA256) TLS 1.2 > h2 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 ECDH secp256r1 FS Safari 9 / OS X 10.11 R RSA 2048(SHA256) TLS 1.2 > h2 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 ECDH secp256r1 FS Safari 10 / iOS 10 R RSA 2048(SHA256) TLS 1.2 > h2 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 ECDH secp256r1 FS Safari 10 / OS X 10.12 R RSA 2048(SHA256) TLS 1.2 > h2 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 ECDH secp256r1 FS Safari 12.1.2 / MacOS 10.14.6 Beta R - TLS 1.3 TLS_AES_256_GCM_SHA384 ECDH x25519 FS Safari 12.1.1 / iOS 12.3.1 R - TLS 1.3 TLS_AES_256_GCM_SHA384 ECDH x25519 FS 苹果 ATS 9 / iOS 9 R RSA 2048(SHA256) TLS 1.2 > h2 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 ECDH secp256r1 FS Yahoo Slurp 2015 年 1 月 RSA 2048(SHA256) TLS 1.2 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 ECDH secp256r1 FS YandexBot 2015年1月 RSA 2048(SHA256) TLS 1.2 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 ECDH secp256r1 FS
07-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值