MSCHAPv2 work continues...
This commit is contained in:
260
lib/MSCHAPv2/include/MSCHAPv2.h
Normal file
260
lib/MSCHAPv2/include/MSCHAPv2.h
Normal file
@@ -0,0 +1,260 @@
|
||||
/*
|
||||
Copyright 2015-2016 Amebis
|
||||
Copyright 2016 G<>ANT
|
||||
|
||||
This file is part of G<>ANTLink.
|
||||
|
||||
G<>ANTLink is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
G<>ANTLink is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with G<>ANTLink. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <WinStd/Crypt.h>
|
||||
|
||||
|
||||
namespace eap
|
||||
{
|
||||
///
|
||||
/// MSCHAPv2 Challenge
|
||||
///
|
||||
struct challenge_mschapv2;
|
||||
|
||||
///
|
||||
/// MSCHAPv2 Challenge Hash
|
||||
///
|
||||
struct challenge_hash;
|
||||
|
||||
///
|
||||
/// NT-Password Hash
|
||||
///
|
||||
struct nt_password_hash;
|
||||
|
||||
///
|
||||
/// NT-Response
|
||||
///
|
||||
struct nt_response;
|
||||
|
||||
///
|
||||
/// Authenticator Response
|
||||
///
|
||||
struct authenticator_response;
|
||||
|
||||
///
|
||||
/// Creates DES encryption key with given plaintext key
|
||||
///
|
||||
/// \param[in] cp Handle of the cryptographics provider
|
||||
/// \param[in] key The key (without parity bits)
|
||||
/// \param[in] size Size of \p key (maximum 7B)
|
||||
///
|
||||
winstd::crypt_key create_des_key(_In_ HCRYPTPROV cp, _In_count_(size) const unsigned char *key, _In_ size_t size);
|
||||
}
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../../EAPBase/include/EAP.h"
|
||||
|
||||
|
||||
namespace eap
|
||||
{
|
||||
#pragma pack(push)
|
||||
#pragma pack(1)
|
||||
|
||||
struct __declspec(novtable) challenge_mschapv2 : public sanitizing_blob_xf<16>
|
||||
{
|
||||
///
|
||||
/// Generate challenge random
|
||||
///
|
||||
/// \param[in] cp Handle of the cryptographics provider
|
||||
///
|
||||
void randomize(_In_ HCRYPTPROV cp);
|
||||
};
|
||||
|
||||
|
||||
struct __declspec(novtable) challenge_hash : public sanitizing_blob_xf<8>
|
||||
{
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
challenge_hash();
|
||||
|
||||
///
|
||||
/// Constructs a challenge hash
|
||||
///
|
||||
/// \sa [Microsoft PPP CHAP Extensions, Version 2 (Chapter 8.2. ChallengeHash())](https://tools.ietf.org/html/rfc2759#section-8.2)
|
||||
///
|
||||
/// \param[in] cp Handle of the cryptographics provider
|
||||
/// \param[in] challenge_server Authenticator challenge
|
||||
/// \param[in] challenge_client Peer challenge
|
||||
/// \param[in] username Username
|
||||
///
|
||||
challenge_hash(
|
||||
_In_ HCRYPTPROV cp,
|
||||
_In_ const challenge_mschapv2 &challenge_server,
|
||||
_In_ const challenge_mschapv2 &challenge_client,
|
||||
_In_z_ const char *username);
|
||||
|
||||
///
|
||||
/// Copies a challenge hash
|
||||
///
|
||||
/// \param[in] other Challenge hash to copy from
|
||||
///
|
||||
challenge_hash(_In_ const sanitizing_blob_f<8> &other);
|
||||
|
||||
#ifdef _DEBUG
|
||||
///
|
||||
/// Moves the challenge hash
|
||||
///
|
||||
/// \param[inout] other Challenge hash to move from
|
||||
///
|
||||
challenge_hash(_Inout_ sanitizing_blob_zf<8> &&other);
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
struct __declspec(novtable) nt_password_hash : public sanitizing_blob_xf<16>
|
||||
{
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
nt_password_hash();
|
||||
|
||||
///
|
||||
/// Constructs a NT-Password hash
|
||||
///
|
||||
/// \sa [Microsoft PPP CHAP Extensions, Version 2 (Chapter 8.3. NtPasswordHash())](https://tools.ietf.org/html/rfc2759#section-8.3)
|
||||
///
|
||||
/// \param[in] cp Handle of the cryptographics provider
|
||||
/// \param[in] password Password
|
||||
///
|
||||
nt_password_hash(
|
||||
_In_ HCRYPTPROV cp,
|
||||
_In_z_ const wchar_t *password);
|
||||
|
||||
///
|
||||
/// Constructs a hash of NT-Password hash
|
||||
///
|
||||
/// \sa [Microsoft PPP CHAP Extensions, Version 2 (Chapter 8.4. HashNtPasswordHash())](https://tools.ietf.org/html/rfc2759#section-8.4)
|
||||
///
|
||||
/// \param[in] cp Handle of the cryptographics provider
|
||||
/// \param[in] pwd_hash NT-Password hash
|
||||
///
|
||||
nt_password_hash(
|
||||
_In_ HCRYPTPROV cp,
|
||||
_In_ const nt_password_hash &pwd_hash);
|
||||
|
||||
///
|
||||
/// Copies a NT-Password hash
|
||||
///
|
||||
/// \param[in] other NT-Password to copy from
|
||||
///
|
||||
nt_password_hash(_In_ const sanitizing_blob_f<16> &other);
|
||||
|
||||
#ifdef _DEBUG
|
||||
///
|
||||
/// Moves the NT-Password hash
|
||||
///
|
||||
/// \param[inout] other NT-Password hash to move from
|
||||
///
|
||||
nt_password_hash(_Inout_ sanitizing_blob_zf<16> &&other);
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
struct __declspec(novtable) nt_response : public sanitizing_blob_xf<24>
|
||||
{
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
nt_response();
|
||||
|
||||
///
|
||||
/// Constructs a NT-Response
|
||||
///
|
||||
/// \sa [Microsoft PPP CHAP Extensions, Version 2 (Chapter 8.1. GenerateNTResponse())](https://tools.ietf.org/html/rfc2759#section-8.1)
|
||||
///
|
||||
/// \param[in] cp Handle of the cryptographics provider
|
||||
/// \param[in] challenge_server Authenticator challenge
|
||||
/// \param[in] challenge_client Peer challenge
|
||||
/// \param[in] username Username
|
||||
/// \param[in] password Password
|
||||
///
|
||||
nt_response(
|
||||
_In_ HCRYPTPROV cp,
|
||||
_In_ const challenge_mschapv2 &challenge_server,
|
||||
_In_ const challenge_mschapv2 &challenge_client,
|
||||
_In_z_ const char *username,
|
||||
_In_z_ const wchar_t *password);
|
||||
|
||||
///
|
||||
/// Copies a NT-Response
|
||||
///
|
||||
/// \param[in] other NT-Response to copy from
|
||||
///
|
||||
nt_response(_In_ const sanitizing_blob_f<24> &other);
|
||||
|
||||
#ifdef _DEBUG
|
||||
///
|
||||
/// Moves the NT-Response
|
||||
///
|
||||
/// \param[inout] other NT-Response to move from
|
||||
///
|
||||
nt_response(_Inout_ sanitizing_blob_zf<24> &&other);
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
struct __declspec(novtable) authenticator_response : public sanitizing_blob_xf<20>
|
||||
{
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
authenticator_response();
|
||||
|
||||
///
|
||||
/// Constructs an authenticator response
|
||||
///
|
||||
/// \sa [Microsoft PPP CHAP Extensions, Version 2 (Chapter 8.7. GenerateAuthenticatorResponse())](https://tools.ietf.org/html/rfc2759#section-8.7)
|
||||
///
|
||||
/// \param[in] cp Handle of the cryptographics provider
|
||||
/// \param[in] challenge_server Authenticator challenge
|
||||
/// \param[in] challenge_client Peer challenge
|
||||
/// \param[in] username Username
|
||||
/// \param[in] password Password
|
||||
/// \param[in] nt_resp NT-Response
|
||||
///
|
||||
authenticator_response(
|
||||
_In_ HCRYPTPROV cp,
|
||||
_In_ const challenge_mschapv2 &challenge_server,
|
||||
_In_ const challenge_mschapv2 &challenge_client,
|
||||
_In_z_ const char *username,
|
||||
_In_z_ const wchar_t *password,
|
||||
_In_ const nt_response &nt_resp);
|
||||
|
||||
///
|
||||
/// Copies an authenticator response
|
||||
///
|
||||
/// \param[in] other Authenticator response to copy from
|
||||
///
|
||||
authenticator_response(_In_ const sanitizing_blob_f<20> &other);
|
||||
|
||||
#ifdef _DEBUG
|
||||
///
|
||||
/// Moves the authenticator response
|
||||
///
|
||||
/// \param[inout] other Authenticator response to move from
|
||||
///
|
||||
authenticator_response(_Inout_ sanitizing_blob_zf<20> &&other);
|
||||
#endif
|
||||
};
|
||||
|
||||
#pragma pack(pop)
|
||||
}
|
@@ -26,11 +26,11 @@ namespace eap
|
||||
class method_mschapv2;
|
||||
}
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Config.h"
|
||||
#include "Credentials.h"
|
||||
#include "MSCHAPv2.h"
|
||||
|
||||
#include "../../EAPBase/include/Method.h"
|
||||
|
||||
@@ -100,13 +100,52 @@ namespace eap
|
||||
|
||||
/// @}
|
||||
|
||||
friend class method_ttls; // Setting of initial challenge derived from TLS PRF
|
||||
|
||||
protected:
|
||||
credentials_mschapv2 &m_cred; ///< EAP-TLS user credentials
|
||||
///
|
||||
/// Processes AVPs in a Diameter packet
|
||||
///
|
||||
/// \param[in] pck Packet data
|
||||
/// \param[in] size_pck \p pck size in bytes
|
||||
///
|
||||
void process_packet(_In_bytecount_(size_pck) const void *pck, _In_ size_t size_pck);
|
||||
|
||||
///
|
||||
/// Processes MS-CHAP2-Success AVP
|
||||
///
|
||||
/// \sa [Microsoft PPP CHAP Extensions, Version 2 (Chapter 5. Success Packet)](https://tools.ietf.org/html/rfc2759#section-5)
|
||||
///
|
||||
/// \param[in] pck Packet data
|
||||
/// \param[in] size_pck \p pck size in bytes
|
||||
///
|
||||
void process_success(_In_ int argc, _In_count_(argc) const wchar_t *argv[]);
|
||||
|
||||
///
|
||||
/// Processes MS-CHAP-Error AVP
|
||||
///
|
||||
/// \sa [Microsoft PPP CHAP Extensions, Version 2 (Chapter 6. Failure Packet)](https://tools.ietf.org/html/rfc2759#section-6)
|
||||
///
|
||||
/// \param[in] pck Packet data
|
||||
/// \param[in] size_pck \p pck size in bytes
|
||||
///
|
||||
void process_error(_In_ int argc, _In_count_(argc) const wchar_t *argv[]);
|
||||
|
||||
protected:
|
||||
credentials_mschapv2 &m_cred; ///< EAP-TLS user credentials
|
||||
winstd::crypt_prov m_cp; ///< Cryptography provider for general services
|
||||
|
||||
challenge_mschapv2 m_challenge_server; ///< MSCHAP server challenge
|
||||
challenge_mschapv2 m_challenge_client; ///< MSCHAP client challenge
|
||||
unsigned char m_ident; ///< Ident
|
||||
nt_response m_nt_resp; ///< NT-Response
|
||||
bool m_success; ///< Did we receive MS-CHAP2-Success?
|
||||
|
||||
enum {
|
||||
phase_unknown = -1, ///< Unknown phase
|
||||
phase_init = 0, ///< Handshake initialize
|
||||
phase_finished, ///< Connection shut down
|
||||
} m_phase, m_phase_prev; ///< What phase is our communication at?
|
||||
phase_unknown = -1, ///< Unknown phase
|
||||
phase_init = 0, ///< Send client challenge
|
||||
phase_challenge_server, ///< Verify server challenge
|
||||
phase_finished, ///< Connection shut down
|
||||
} m_phase, m_phase_prev; ///< What phase is our communication at?
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user