Debian Codegraph @

ntlm/challenge_responses.go

raw symbols SCIP
1 //Copyright 2013 Thomson Reuters Global Resources. BSD License please see License file for more information
2
3 package ntlm
4
5 import (
6 "bytes"
7 "encoding/hex"
8 "errors"
9 "fmt"
10 )
11
12 // NTLMv1
13 // ******
14 type NtlmV1Response struct {
15 // 24 byte array
16 Response []byte
17 }
18
19 func (n *NtlmV1Response) String() string {
20 return fmt.Sprintf("NtlmV1Response: %s", hex.EncodeToString(n.Response))
21 }
22
23 func ReadNtlmV1Response(bytes []byte) (*NtlmV1Response, error) {
24 r := new(NtlmV1Response)
25 r.Response = bytes[0:24]
26 return r, nil
27 }
28
29 // *** NTLMv2
30 // The NTLMv2_CLIENT_CHALLENGE structure defines the client challenge in the AUTHENTICATE_MESSAGE.
31 // This structure is used only when NTLM v2 authentication is configured.
32 type NtlmV2ClientChallenge struct {
33 // An 8-bit unsigned char that contains the current version of the challenge response type.
34 // This field MUST be 0x01.
35 RespType byte
36 // An 8-bit unsigned char that contains the maximum supported version of the challenge response type.
37 // This field MUST be 0x01.
38 HiRespType byte
39 // A 16-bit unsigned integer that SHOULD be 0x0000 and MUST be ignored on receipt.
40 Reserved1 uint16
41 // A 32-bit unsigned integer that SHOULD be 0x00000000 and MUST be ignored on receipt.
42 Reserved2 uint32
43 // A 64-bit unsigned integer that contains the current system time, represented as the number of 100 nanosecond
44 // ticks elapsed since midnight of January 1, 1601 (UTC).
45 TimeStamp []byte
46 // An 8-byte array of unsigned char that contains the client's ClientChallenge (section 3.1.5.1.2).
47 ChallengeFromClient []byte
48 // A 32-bit unsigned integer that SHOULD be 0x00000000 and MUST be ignored on receipt.
49 Reserved3 uint32
50 AvPairs *AvPairs
51 }
52
53 func (n *NtlmV2ClientChallenge) String() string {
54 var buffer bytes.Buffer
55
56 buffer.WriteString("NTLM v2 ClientChallenge\n")
57 buffer.WriteString(fmt.Sprintf("Timestamp: %s\n", hex.EncodeToString(n.TimeStamp)))
58 buffer.WriteString(fmt.Sprintf("ChallengeFromClient: %s\n", hex.EncodeToString(n.ChallengeFromClient)))
59 buffer.WriteString("AvPairs\n")
60 buffer.WriteString(n.AvPairs.String())
61
62 return buffer.String()
63 }
64
65 // The NTLMv2_RESPONSE structure defines the NTLMv2 authentication NtChallengeResponse in the AUTHENTICATE_MESSAGE.
66 // This response is used only when NTLMv2 authentication is configured.
67 type NtlmV2Response struct {
68 // A 16-byte array of unsigned char that contains the client's NT challenge- response as defined in section 3.3.2.
69 // Response corresponds to the NTProofStr variable from section 3.3.2.
70 Response []byte
71 // A variable-length byte array that contains the ClientChallenge as defined in section 3.3.2.
72 // ChallengeFromClient corresponds to the temp variable from section 3.3.2.
73 NtlmV2ClientChallenge *NtlmV2ClientChallenge
74 }
75
76 func (n *NtlmV2Response) String() string {
77 var buffer bytes.Buffer
78
79 buffer.WriteString("NTLM v2 Response\n")
80 buffer.WriteString(fmt.Sprintf("Response: %s\n", hex.EncodeToString(n.Response)))
81 buffer.WriteString(n.NtlmV2ClientChallenge.String())
82
83 return buffer.String()
84 }
85
86 func ReadNtlmV2Response(bytes []byte) (*NtlmV2Response, error) {
87 r := new(NtlmV2Response)
88 r.Response = bytes[0:16]
89 r.NtlmV2ClientChallenge = new(NtlmV2ClientChallenge)
90 c := r.NtlmV2ClientChallenge
91 c.RespType = bytes[16]
92 c.HiRespType = bytes[17]
93
94 if c.RespType != 1 || c.HiRespType != 1 {
95 return nil, errors.New("Does not contain a valid NTLM v2 client challenge - could be NTLMv1.")
96 }
97
98 // Ignoring - 2 bytes reserved
99 // c.Reserved1
100 // Ignoring - 4 bytes reserved
101 // c.Reserved2
102 c.TimeStamp = bytes[24:32]
103 c.ChallengeFromClient = bytes[32:40]
104 // Ignoring - 4 bytes reserved
105 // c.Reserved3
106 c.AvPairs = ReadAvPairs(bytes[44:])
107 return r, nil
108 }
109
110 // LMv1
111 // ****
112 type LmV1Response struct {
113 // 24 bytes
114 Response []byte
115 }
116
117 func ReadLmV1Response(bytes []byte) *LmV1Response {
118 r := new(LmV1Response)
119 r.Response = bytes[0:24]
120 return r
121 }
122
123 func (l *LmV1Response) String() string {
124 return fmt.Sprintf("LmV1Response: %s", hex.EncodeToString(l.Response))
125 }
126
127 // *** LMv2
128 type LmV2Response struct {
129 // A 16-byte array of unsigned char that contains the client's LM challenge-response.
130 // This is the portion of the LmChallengeResponse field to which the HMAC_MD5 algorithm
131 /// has been applied, as defined in section 3.3.2. Specifically, Response corresponds
132 // to the result of applying the HMAC_MD5 algorithm, using the key ResponseKeyLM, to a
133 // message consisting of the concatenation of the ResponseKeyLM, ServerChallenge and ClientChallenge.
134 Response []byte
135 // An 8-byte array of unsigned char that contains the client's ClientChallenge, as defined in section 3.1.5.1.2.
136 ChallengeFromClient []byte
137 }
138
139 func ReadLmV2Response(bytes []byte) *LmV2Response {
140 r := new(LmV2Response)
141 r.Response = bytes[0:16]
142 r.ChallengeFromClient = bytes[16:24]
143 return r
144 }
145
146 func (l *LmV2Response) String() string {
147 var buffer bytes.Buffer
148
149 buffer.WriteString("LM v2 Response\n")
150 buffer.WriteString(fmt.Sprintf("Response: %s\n", hex.EncodeToString(l.Response)))
151 buffer.WriteString(fmt.Sprintf("ChallengeFromClient: %s\n", hex.EncodeToString(l.ChallengeFromClient)))
152
153 return buffer.String()
154 }