From 84e544c2f6dbf14f76b930b2672c3cc2b77bfc3f Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Fri, 12 Aug 2016 21:09:38 +0200 Subject: [PATCH] eap_attr::create_ms_mppe_key() method for MS-MPPE-Send-Key and MS-MPPE-Recv-Key generation added --- include/WinStd/EAP.h | 12 ++++++++++++ src/EAP.cpp | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/include/WinStd/EAP.h b/include/WinStd/EAP.h index fc5c3d06..fe843089 100644 --- a/include/WinStd/EAP.h +++ b/include/WinStd/EAP.h @@ -151,6 +151,18 @@ namespace winstd } return *this; } + + /// + /// Creates MS-MPPE-Send-Key or MS-MPPE-Recv-Key + /// + /// \sa [RADIUS Vendor-Specific](https://tools.ietf.org/html/rfc2865#section-5.26) + /// \sa [MS-MPPE-Send-Key](https://tools.ietf.org/html/rfc2548#section-2.4.2) + /// \sa [MS-MPPE-Recv-Key](https://tools.ietf.org/html/rfc2548#section-2.4.3) + /// + void create_ms_mppe_key(_In_ BYTE bVendorType, _In_count_(nKeySize) LPCBYTE pbKey, _In_ BYTE nKeySize); + + public: + static const EAP_ATTRIBUTE blank; }; diff --git a/src/EAP.cpp b/src/EAP.cpp index 3787a0af..6b84daab 100644 --- a/src/EAP.cpp +++ b/src/EAP.cpp @@ -32,6 +32,43 @@ winstd::eap_attr::~eap_attr() } +void winstd::eap_attr::create_ms_mppe_key(_In_ BYTE bVendorType, _In_count_(nKeySize) LPCBYTE pbKey, _In_ BYTE nKeySize) +{ + BYTE nPaddingLength = (BYTE)((16 - (1 + nKeySize)) % 16); + DWORD dwLengthNew = + 4 + // Vendor-Id + 1 + // Vendor type + 1 + // Vendor length + 2 + // Salt + 1 + // Key-Length + nKeySize + // Key + nPaddingLength; // Padding + + LPBYTE p = new BYTE[dwLengthNew]; + p[0] = 0x00; // Vendor-Id (0x137 = 311 = Microsoft) + p[1] = 0x00; // --| + p[2] = 0x01; // --| + p[3] = 0x37; // --^ + p[4] = bVendorType; // Vendor type + p[5] = (BYTE)(dwLengthNew - 4); // Vendor length + p[6] = 0x00; // Salt + p[7] = 0x00; // --^ + p[8] = nKeySize; // Key-Length + memcpy(p + 9, pbKey, nKeySize); // Key + memset(p + 9 + nKeySize, 0, nPaddingLength); // Padding + + if (pValue) + delete [] pValue; + + eaType = eatVendorSpecific; + dwLength = dwLengthNew; + pValue = p; +} + + +const EAP_ATTRIBUTE winstd::eap_attr::blank = {}; + + ////////////////////////////////////////////////////////////////////// // winstd::eap_packet //////////////////////////////////////////////////////////////////////