File: OptKeyGeneration.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 (118 lines) | stat: -rw-r--r-- 2,699 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
/*
 * 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: OptKeyGeneration.cpp,v 1.2 2008-06-18 23:22:14 thomson Exp $
 *
 */

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

TOptKeyGeneration::TOptKeyGeneration( char * &buf,  int &n, TMsg* parent)
	:TOpt(OPTION_KEYGEN, parent)
{
    Valid=true;
    if (n<13)
    {
        Valid=false;
        buf+=n;
        n=0;
        return;
    }
    this->Parent->setSPI(ntohl(*(uint32_t*)buf));
    buf +=4; n -=4;

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

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

    this->setAlgorithmId(ntohs(*(uint16_t*)buf));
    buf +=2; n -=2;

    this->Parent->setKeyGenNonce(buf, n);

    PrintHex("KeyGenNonce: ", buf, n);
    
    buf+=n; n = 0;

    this->Parent->setAuthInfoKey();
    this->Parent->AuthKeys->Add(this->Parent->getSPI(), this->Parent->getAAASPI(), this->Parent->getAuthInfoKey());
}

TOptKeyGeneration::TOptKeyGeneration(TMsg* parent)
	:TOpt(OPTION_KEYGEN, parent)
{
}

 void TOptKeyGeneration::setLifetime( uint32_t value)
{
	Lifetime = value;
}

 void TOptKeyGeneration::setAlgorithmId( uint16_t value)
{
	AlgorithmId = value;
}

 uint16_t TOptKeyGeneration::getAlgorithmId()
{
	return AlgorithmId;
}

 int TOptKeyGeneration::getSize()
{
	return 18 + this->Parent->getKeyGenNonceLen();
}

 char * TOptKeyGeneration::storeSelf( char* buf)
{
    *(uint16_t*)buf = htons(OptType);
    buf+=2;
    *(uint16_t*)buf = htons(getSize() - 4);
    buf+=2;
    *(uint32_t*)buf = htonl(this->Parent->getSPI());
    buf+=4;
    *(uint32_t*)buf = htonl(Lifetime);
    buf+=4;
    *(uint32_t*)buf = htonl(this->Parent->getAAASPI());
    buf+=4;
    *(uint16_t*)buf = htons(AlgorithmId);
    buf+=2;

    Log(Debug) << "Auth:Key Generation Nonce length: " << this->Parent->getKeyGenNonceLen() << LogEnd;
    if (this->Parent->getKeyGenNonceLen()) {
        memcpy(buf, this->Parent->getKeyGenNonce(), this->Parent->getKeyGenNonceLen());
        buf+=this->Parent->getKeyGenNonceLen();
    }

    if (0 == this->Parent->setAuthInfoKey())
        this->Parent->AuthKeys->Add(this->Parent->getSPI(), this->Parent->getAAASPI(), this->Parent->getAuthInfoKey());

    return buf;
}

TOptKeyGeneration::~TOptKeyGeneration()
{
// FIXME: do it in Msg.cpp    
//    if (KeyGenNonceLen)
//        delete [] KeyGenNonce;
}