diff options
author | Dave Airlie <airlied@redhat.com> | 2014-11-07 14:07:59 +1000 |
---|---|---|
committer | Dave Airlie <airlied@redhat.com> | 2014-11-07 14:07:59 +1000 |
commit | ed4368c9999a4df354b48ac04bdf43f053c7c3bb (patch) | |
tree | a32feaeb1e46969b26a8485d75f3152b4c8a8e88 | |
parent | ac2c399d69a4255366235ce5ecf79337b9addb2a (diff) |
start RE'ing trace
-rw-r--r-- | dl3.c | 98 | ||||
-rw-r--r-- | dl3_hdcp.c | 16 | ||||
-rw-r--r-- | dl_pkts.h | 1 | ||||
-rw-r--r-- | pkts.h | 3 |
4 files changed, 115 insertions, 3 deletions
@@ -39,12 +39,16 @@ struct hdcp_session_info { const uint8_t *ks; }; static int VID = 0x17e9; -static int PID = 0x4301; +static int PID = 0x4300; /* make km all 0s for now */ static unsigned char mykm[16] = { 0xcd, 0xef, 0x65, 0x33, 0x69, 0x23, 0xfa, 0x3e, 0x60, 0xee, 0xdd, 0x5c, 0xce, 0xfb, 0x39, 0x19 }; +static unsigned char myfakekm[16] = { 0x16, 0xC6, 0xE5, 0xF6, 0x1B, 0x65, 0x5C, 0xBC, 0x79, 0xC9, 0xC2, 0xCC, 0x03, 0x91, 0xC2, 0x36 }; + +static unsigned char forgekm[16] = { 0x72, 0x9d, 0x7d, 0xd6, 0x6c, 0x2e, 0xa6, 0x55, 0xf3, 0xb4, 0x1f, 0x93, 0x1a, 0x5a, 0xd9, 0xeb }; + static const uint8_t Rtx[] = { 0x84, 0xd7, 0xcf, 0x64, 0x2d, 0x68, 0xff, 0xd5 }; static const uint8_t lc_Rn[] = { 0xd7, 0xfa, 0xf6, 0x99, 0x14, 0xd2, 0x51, 0xe0 }; @@ -54,6 +58,18 @@ static const uint8_t riv[] = { 0xea, 0xc1, 0x6d, 0xd3, 0x07, 0xf0, 0x5c, 0x9b}; /* session key */ static unsigned char myks[16] = { 0xcf, 0xef, 0x65, 0x33, 0x69, 0x23, 0xfa, 0x3e, 0x61, 0xee, 0xdd, 0x5c, 0xce, 0xfb, 0x39, 0x19}; + +static unsigned char myks2[16] = { 0x55, 0xf9, 0x55, 0x87, + 0xaf, 0x69, 0x22, 0x9a, + 0x4f, 0x2a, 0xb2, 0x70, + 0xce, 0x3f, 0xec, 0xf4 }; + +/* sent from host to USB */ +static const uint8_t edkey_ks[16] = { 0x60, 0x06, 0x77, 0xE4, 0x5F, 0xD1, 0xCF, 0x5A, 0x62, 0x2D, 0xFE, 0x25, 0xBC, 0xD2, 0x9F, 0x92 }; +static const uint8_t fake_rrx[8] = { 0xCC, 0x28, 0xA9, 0x8B, 0x61, 0x32, 0x44, 0x07 }; + +static const uint8_t mypkt_enc_data[] = {0xCF, 0xD2, 0x64, 0x70, 0x10, 0x8E, 0x5F, 0xAC, 0xD8, 0xB2, 0xD6, 0xC2, 0x2C, 0x2F, 0xCA, 0xBE, 0x94, 0x92, 0x37, 0xA9, 0x8B, 0x21, 0xF3, 0xC6, 0x28, 0x29, 0xB1, 0x0C, 0xA8, 0x93, 0x8F, 0xDD, 0x3B, 0x53, 0xE3, 0xDA, 0xE3, 0xFA, 0xC3, 0x1C, 0xCF, 0xEC, 0xBE, 0x7C, 0x90, 0x49, 0xAD, 0x86}; + static int create_gcrypt_pubkey(struct hdcp_session_info *info, const uint8_t *n, const uint8_t *e, @@ -123,6 +139,31 @@ static int create_gcrypt_km(gcry_sexp_t *km, #define NULL_BYTES \ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +static void calc_ks_ctr(struct hdcp_session_info *info, uint32_t streamctr, + uint64_t input_ctr, + uint8_t *buf) +{ + uint8_t tmp[100]; + unsigned char input[] = {NULL_BYTES, NULL_BYTES}; + uint8_t iv[16]; + int outl; + int ret; + int i; + memset(iv, 0, 16); + + memcpy(iv, riv, 8); + + ret = EVP_EncryptInit_ex(&info->aes_ctx, EVP_aes_128_ctr(), NULL, info->ks, iv); + assert(ret == 1); + + ret = EVP_EncryptUpdate(&info->aes_ctx, buf, &outl, input, sizeof(input)); + assert(ret == 1); + assert(outl == sizeof(input)); + + ret = EVP_EncryptFinal_ex(&info->aes_ctx, tmp, &outl); + assert(ret == 1); + assert(outl == 0); +} static void calc_kd_ctr(struct hdcp_session_info *info, uint8_t ctr, uint8_t *buf) { @@ -161,6 +202,33 @@ static void calculate_kd(struct hdcp_session_info *info) calc_kd_ctr(info, 1, &buf[16]); } +static void calculate_hacker_key(struct hdcp_session_info *info) +{ + uint8_t *buf = info->edkey_ks; + int i; + + calc_kd_ctr(info, 2, buf); + + /* we have dkey2 in buf now */ + printf("dkey2:"); + for (i = 0; i < 16; i++) { + printf("%02x", buf[i]); + } + + for (i = 0; i < 8; i++) { + buf[8 + i] ^= fake_rrx[i]; + } + + for (i = 0; i < 16; i++) { + buf[i] ^= edkey_ks[i]; + } + + printf("posks:"); + for (i = 0; i < 16; i++) { + printf("%02x", buf[i]); + } +} + static void calculate_edkey_ks(struct hdcp_session_info *info) { uint8_t *buf = info->edkey_ks; @@ -475,9 +543,22 @@ static int send_buffer(libusb_device_handle *handle, int endpoint_out, int endpo EVP_CIPHER_CTX_init(&info.aes_ctx); info.rtx = Rtx; - info.km = mykm; - info.ks = myks; + info.km = forgekm; + info.ks = myks2; + { + uint8_t mybuf[48]; + int i; + memset(mybuf, 0, 48); + calc_ks_ctr(&info, 0, 0, mybuf); + for (i = 0; i < 16; i++) { + printf("%02x", mybuf[i] ^ mypkt_enc_data[0 + i]); + } + printf("\n"); + } +// return; +// calculate_hacker_key(&info); +// return; dl3_empty_packet(buf, &len); r = write_to_usb(handle, endpoint_out, buf, len, &size); if (r != 0) @@ -597,7 +678,18 @@ static int send_buffer(libusb_device_handle *handle, int endpoint_out, int endpo if (r != 0) goto out; + dl3_packet_send_enc_data(buf, &len, mypkt_enc_data); + r = write_to_usb(handle, endpoint_out, buf, len, &size); + if (r != 0) + goto out; + do { + r = block_read_usb(handle, endpoint_in, buf, &size); + if (r < 0) + break; + decode_rx(&info, buf, size); + /* find L' */ + } while (1); r = 0; out: EVP_CIPHER_CTX_cleanup(&info.aes_ctx); @@ -209,3 +209,19 @@ void dl3_packet_hdcp_ske_send_eks(uint8_t *buf, int *len_p, const uint8_t *edkey *len_p = total_len + 4; } + +void dl3_packet_send_enc_data(uint8_t *buf, int *len_p, const uint8_t *enc_data) +{ + int total_len = 0; + + total_len = 48 + 12; + + memset(buf, 0, ROUND_TO_4(total_len + 4)); + fill_hdcp_header1(buf, total_len, MSG_TYPE_4); + fill_hdcp_header2(buf, MSG4_PKT6); + + buf[10] = 0xa; + + memcpy(&buf[16], enc_data, 48); + *len_p = total_len + 4; +} @@ -9,5 +9,6 @@ void dl3_packet_hdcp_ake_init(uint8_t *buf, int *len_p, const uint8_t *Rtx); void dl3_packet_hdcp_ake_no_stored_km(uint8_t *buf, int *len_p, const uint8_t *ekpubkm); void dl3_packet_hdcp_lc_init(uint8_t *buf, int *len_p, const uint8_t *Rn); void dl3_packet_hdcp_ske_send_eks(uint8_t *buf, int *len_p, const uint8_t *edkey_ks, const uint8_t *riv); +void dl3_packet_send_enc_data(uint8_t *buf, int *len_p, const uint8_t *enc_data); #define ROUND_TO_4(x) ((((x) + 3) / 4) * 4) #endif @@ -106,5 +106,8 @@ static unsigned char dplinkcert[] = 0x81, 0xf1, 0xc6, 0x18, 0xd0, 0xc4, 0x85, 0x3d, 0x2b, 0x2b }; +static unsigned char kpubkm[] = { +0x6D, 0xD2, 0x81, 0x00, 0x9E, 0x63, 0xBC, 0x98, 0x7C, 0x94, 0x9F, 0x9B, 0x83, 0x3B, 0x25, 0xC6, 0xFD, 0x88, 0x70, 0x9F, 0x3A, 0xFD, 0x32, 0x0E, 0x83, 0xFB, 0xBB, 0xFC, 0xAA, 0xF9, 0x52, 0xE8, 0xCE, 0x62, 0x1D, 0x13, 0x8C, 0xAC, 0x4D, 0x06, 0x16, 0x47, 0x75, 0x69, 0x80, 0x56, 0x58, 0xE1, 0xA7, 0xC0, 0x95, 0x4B, 0x9D, 0xF4, 0x13, 0xC8, 0x52, 0x29, 0xA5, 0xCA, 0x69, 0xBD, 0xAC, 0x42, 0xBB, 0xC2, 0x7E, 0x05, 0x30, 0xCF, 0x04, 0xC9, 0x40, 0xA1, 0x5C, 0x65, 0xC4, 0xF4, 0x6A, 0xFC, 0x58, 0xA2, 0x29, 0xA6, 0x7D, 0x3C, 0xD0, 0x5C, 0xDC, 0x7D, 0x9B, 0xD4, 0xC9, 0xB6, 0x8A, 0x41, 0x74, 0xFB, 0x78, 0x81, 0x8C, 0x6E, 0xD4, 0xE4, 0x5E, 0x17, 0xE1, 0x41, 0x79, 0xBA, 0x0B, 0xEF, 0x55, 0x86, 0x95, 0x52, 0x4C, 0xED, 0x3C, 0xD3, 0x7C, 0x7E, 0x19, 0x6E, 0x78, 0xD6, 0x9B, 0xB7 +}; #endif |