1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
/*
* Dibbler - a portable DHCPv6
*
* author : Michal Kowalczuk <michal@kowalczuk.eu>
* changes: Tomasz Mrugalski <thomson(at)klub.com.pl>
*
* released under GNU GPL v2 licence
*
* $Id: OptAAAAuthentication.cpp,v 1.2 2008-06-18 23:22:14 thomson Exp $
*
* $Log: OptAAAAuthentication.cpp,v $
* Revision 1.2 2008-06-18 23:22:14 thomson
* Cosmetic changes.
*
* Revision 1.1 2008-02-25 20:42:46 thomson
* Missing new AUTH files added.
*
*
*/
#ifdef WIN32
#include <winsock2.h>
#endif
#ifdef LINUX
#include <netinet/in.h>
#endif
#include <stdlib.h>
#include "OptAAAAuthentication.h"
#include "DHCPConst.h"
#include "Portable.h"
#include "Portable.h"
#include "Logger.h"
#include "Msg.h"
#include "Portable.h"
// in AAAAUTH we always use HMAC-SHA1
#define AAAAuthInfoLen 20
TOptAAAAuthentication::TOptAAAAuthentication( char * &buf, int &n, TMsg* parent)
:TOpt(OPTION_AAAAUTH, parent)
{
Valid=true;
if (n<4)
{
Valid=false;
buf+=n;
n=0;
return;
}
this->setAAASPI(ntohl(*(uint32_t*)buf));
this->Parent->setAAASPI(ntohl(*(uint32_t*)buf));
buf +=4; n -=4;
if (n != AAAAuthInfoLen)
{
Log(Warning) << "Auth: Malformed AAAAUTH option received: length= " << n << ", expected " << AAAAuthInfoLen << LogEnd;
Valid=false;
buf+=n;
n=0;
return;
}
this->Parent->setAuthInfoPtr(buf);
PrintHex("Auth: received digest: ", buf, AAAAuthInfoLen);
buf+=n; n = 0;
PrintHex("Auth:received AAA-SPI: ", (char *)&this->AAASPI, sizeof(this->AAASPI));
this->Parent->setAuthInfoKey();
}
TOptAAAAuthentication::TOptAAAAuthentication(TMsg* parent)
:TOpt(OPTION_AAAAUTH, parent)
{
}
void TOptAAAAuthentication::setAAASPI( uint32_t value)
{
AAASPI = value;
}
uint32_t TOptAAAAuthentication::getAAASPI()
{
return AAASPI;
}
int TOptAAAAuthentication::getSize()
{
return 8 + AAAAuthInfoLen;
}
char * TOptAAAAuthentication::storeSelf( char* buf)
{
*(uint16_t*)buf = htons(OptType);
buf+=2;
*(uint16_t*)buf = htons(getSize() - 4);
buf+=2;
*(uint32_t*)buf = htonl(AAASPI);
buf+=4;
memset(buf, 0, AAAAuthInfoLen);
this->Parent->setAuthInfoPtr(buf);
this->Parent->setAAASPI(AAASPI);
// FIXME is this neccesary? AuthInfoKey will be different later anyway
this->Parent->setAuthInfoKey();
buf+=AAAAuthInfoLen;
return buf;
}
|