File: OptAuthentication.cpp

package info (click to toggle)
dibbler 0.7.3-1.3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 11,148 kB
  • ctags: 8,720
  • sloc: cpp: 54,863; sh: 9,389; ansic: 8,659; yacc: 2,570; makefile: 1,061; lex: 842; perl: 49; xml: 6
file content (138 lines) | stat: -rw-r--r-- 3,149 bytes parent folder | download | duplicates (2)
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
 * Dibbler - a portable DHCPv6
 *
 * author: Michal Kowalczuk <michal@kowalczuk.eu>
 *
 * released under GNU GPL v2 licence
 *
 * $Id: OptAuthentication.cpp,v 1.6 2008-06-18 23:22:14 thomson Exp $
 *
 * $Log: OptAuthentication.cpp,v $
 * Revision 1.6  2008-06-18 23:22:14  thomson
 * Cosmetic changes.
 *
 * Revision 1.5  2008-02-25 17:49:09  thomson
 * Authentication added. Megapatch by Michal Kowalczuk.
 * (small changes by Tomasz Mrugalski)
 *
 * Revision 1.4  2006-11-30 03:17:46  thomson
 * Auth related changes by Sammael.
 *
 * Revision 1.3  2006-11-24 01:33:43  thomson
 * *** empty log message ***
 *
 * Revision 1.2  2006-11-17 01:28:38  thomson
 * Partial AUTH support by Sammael, fixes by thomson
 *
 * Revision 1.1  2006-11-17 00:37:16  thomson
 * Partial AUTH support by Sammael, fixes by thomson
 *
 *
 *
 */

#ifdef WIN32
#include <winsock2.h>
#endif
#ifdef LINUX
#include <netinet/in.h>
#endif 
#include <stdlib.h>
#include "OptAuthentication.h"
#include "DHCPConst.h"
#include "Portable.h"
#include "Portable.h"
#include "Logger.h"
#include "Msg.h"
#include "Portable.h"

TOptAuthentication::TOptAuthentication( char * &buf,  int &n, TMsg* parent)
	:TOpt(OPTION_AUTH, parent)
{
    AuthInfoLen = getDigestSize(parent->DigestType);

    Valid=true;
    if (n<13)
    {
        Valid=false;
        buf+=n;
        n=0;
        return;
    }
    this->setRDM(*buf);
    buf +=1; n -=1;

    this->Parent->setReplayDetection(ntohll(*(uint64_t*)buf));
    buf +=8; n -=8;

    this->Parent->setSPI(ntohl(*(uint32_t*)buf));
    buf +=4; n -=4;

    if (n != AuthInfoLen)
    {
        Valid=false;
        buf+=n;
        n=0;
        return;
    }

    this->Parent->setAuthInfoPtr(buf);

    if (this->Parent->getType() != ADVERTISE_MSG)
        this->Parent->setAuthInfoKey(this->Parent->AuthKeys->Get(this->Parent->getSPI()));

    PrintHex("Received digest: ", buf, AuthInfoLen);
    
    buf+=n; n = 0;
}

TOptAuthentication::TOptAuthentication(TMsg* parent)
	:TOpt(OPTION_AUTH, parent)
{
    AuthInfoLen = getDigestSize(parent->DigestType);
}

 void TOptAuthentication::setRDM( uint8_t value)
{
    RDM = value;
}

 int TOptAuthentication::getSize()
{
	return 17 + AuthInfoLen;
}

 char * TOptAuthentication::storeSelf( char* buf)
{
    AuthInfoLen = getDigestSize(this->Parent->DigestType);
    uint32_t spi = this->Parent->getSPI();
    uint32_t aaaspi = this->Parent->getAAASPI();

    *(uint16_t*)buf = htons(OptType);
    buf+=2;
    *(uint16_t*)buf = htons(getSize() - 4);
    buf+=2;
    *buf = RDM;
    buf+=1;
    *(uint64_t*)buf = htonll(this->Parent->getReplayDetection());
    buf+=8;
    *(uint32_t*)buf = htonl(spi);
    buf+=4;

    memset(buf, 0, AuthInfoLen);

    this->Parent->setAuthInfoPtr(buf);

    this->Parent->setAuthInfoKey(this->Parent->AuthKeys->Get(spi));

    // check if we should calculate the key
    if (this->Parent->getAuthInfoKey() == NULL && this->Parent->getType() == REQUEST_MSG) {
        this->Parent->setAuthInfoKey();
        if (spi && aaaspi)
            this->Parent->AuthKeys->Add(spi, aaaspi, this->Parent->getAuthInfoKey());
    }

    buf+=AuthInfoLen;

    return buf;
}