-
Notifications
You must be signed in to change notification settings - Fork 22
/
authenticators.cxx
301 lines (239 loc) · 8.26 KB
/
authenticators.cxx
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
//////////////////////////////////////////////////////////////////
//
// authenticators.cxx
//
// Copyright (c) 2015, Jan Willamowius
//
// additional authentication modules
//
// This work is published under the GNU Public License version 2 (GPLv2)
// see file COPYING for details.
// We also explicitly grant the right to link this code
// with the OpenH323/H323Plus and OpenSSL library.
//
//////////////////////////////////////////////////////////////////
#include <ptlib.h>
#include <h225.h>
#include "Toolkit.h"
#include "authenticators.h"
#ifdef P_SSL
#include <openssl/err.h>
#include <openssl/rand.h>
#endif // P_SSL
#ifdef HAS_DES_ECB
static const char OID_DesECB[] = "1.3.14.3.2.6";
H235AuthDesECB::H235AuthDesECB()
{
usage = AnyApplication; // Can be used either for GKAdmission or EPAuthenticstion
}
PObject * H235AuthDesECB::Clone() const
{
return new H235AuthDesECB(*this);
}
const char * H235AuthDesECB::GetName() const
{
return "desECB";
}
PStringArray H235AuthDesECB::GetAuthenticatorNames()
{
return PStringArray("desECB");
}
#if PTLIB_VER >= 2110
PBoolean H235AuthDesECB::GetAuthenticationCapabilities(H235Authenticator::Capabilities * ids)
{
H235Authenticator::Capability cap;
cap.m_identifier = OID_DesECB;
cap.m_cipher = "DES";
cap.m_description= "desECB";
ids->capabilityList.push_back(cap);
return true;
}
#endif
PBoolean H235AuthDesECB::IsMatch(const PString & identifier) const
{
return (identifier == PString(OID_DesECB));
}
H225_CryptoH323Token * H235AuthDesECB::CreateCryptoToken()
{
if (!IsActive())
return NULL;
// Create the H.225 crypto token
H225_CryptoH323Token * cryptoToken = new H225_CryptoH323Token;
cryptoToken->SetTag(H225_CryptoH323Token::e_cryptoEPPwdEncr);
// TODO: encryption not implemented, yet (GnuGk only needs the decrypt)
// see OPAL 3.14.x for encryption implementation (h235auth1.cxx)
return cryptoToken;
}
H235Authenticator::ValidationResult H235AuthDesECB::ValidateCryptoToken(
const H225_CryptoH323Token & cryptoToken,
const PBYTEArray &)
{
if (!IsActive())
return e_Disabled;
// verify the token is of correct type
if (cryptoToken.GetTag() != H225_CryptoH323Token::e_cryptoEPPwdEncr)
return e_Absent;
PBYTEArray remoteEncryptedData = ((H235_ENCRYPTED<H235_EncodedPwdCertToken>)cryptoToken).m_encryptedData;
PBYTEArray decryptedToken(remoteEncryptedData.GetSize());
EVP_CIPHER_CTX * cipher = EVP_CIPHER_CTX_new();
EVP_CIPHER_CTX_init(cipher);
EVP_CIPHER_CTX_set_padding(cipher, 1);
PBYTEArray key(8);
// Build key from password according to H.235.0/8.2.1
memcpy(key.GetPointer(), (const char *)password, std::min(key.GetSize(), password.GetLength()));
for (PINDEX i = key.GetSize(); i < password.GetLength(); ++i)
key[i%key.GetSize()] ^= password[i];
EVP_CipherInit_ex(cipher, EVP_des_ecb(), NULL, key, NULL, 0);
H235CryptoHelper cryptoHelper;
int len = -1;
if (!cryptoHelper.DecryptUpdateCTS(cipher, decryptedToken.GetPointer(), &len, remoteEncryptedData.GetPointer(), remoteEncryptedData.GetSize())) {
PTRACE(1, "H235RAS\tEVP_DecryptUpdate_cts failed");
}
int f_len = -1;
if(!cryptoHelper.DecryptFinalCTS(cipher, decryptedToken.GetPointer() + len, &f_len)) {
char buf[256];
ERR_error_string(ERR_get_error(), buf);
PTRACE(1, "H235RAS\tEVP_DecryptFinal_cts failed: " << buf);
}
EVP_CIPHER_CTX_cleanup(cipher);
EVP_CIPHER_CTX_free(cipher);
PPER_Stream asn(decryptedToken);
H235_ClearToken clearToken;
clearToken.Decode(asn);
PString generalID = clearToken.m_generalID;
if (generalID == Toolkit::GKName()
&& clearToken.m_timeStamp == (unsigned)time(NULL)) // TODO: add grace period ?
return e_OK;
PTRACE(1, "H235RAS\tH235AuthDesECB password does not match.");
return e_BadPassword;
}
PBoolean H235AuthDesECB::IsCapability(const H235_AuthenticationMechanism & mechanism,
const PASN_ObjectId & algorithmOID)
{
PTRACE(5, "H235RAS\tmechanism.GetTag=" << mechanism.GetTag() << " OID=" << algorithmOID.AsString());
return mechanism.GetTag() == H235_AuthenticationMechanism::e_pwdSymEnc &&
algorithmOID.AsString() == OID_DesECB;
}
PBoolean H235AuthDesECB::SetCapability(H225_ArrayOf_AuthenticationMechanism & mechanisms,
H225_ArrayOf_PASN_ObjectId & algorithmOIDs)
{
return AddCapability(H235_AuthenticationMechanism::e_pwdSymEnc, OID_DesECB, mechanisms, algorithmOIDs);
}
PBoolean H235AuthDesECB::IsSecuredPDU(unsigned rasPDU, PBoolean received) const
{
switch (rasPDU) {
case H225_RasMessage::e_registrationRequest :
return received ? !remoteId.IsEmpty() : !localId.IsEmpty();
default :
return FALSE;
}
}
PBoolean H235AuthDesECB::IsSecuredSignalPDU(unsigned signalPDU, PBoolean received) const
{
return FALSE;
}
#if PTLIB_VER >= 2110
// disabled on PTLib 2.11.x, crashes on startup
#if PTLIB_VER >= 2120
typedef H235AuthDesECB H235AuthenticatorDesECB;
PPLUGIN_STATIC_LOAD(DesECB,H235Authenticator);
H235SECURITY(DesECB);
#endif
#else
static PFactory<H235Authenticator>::Worker<H235AuthDesECB> factoryH235AuthDesECB("desECB");
#endif
/////////////////////////////////////////////////////////////////////////////
#endif
#ifdef HAS_AVAYA_SUPPORT
// This stub is enough to fake 2.16.840.1.114187.1.3 support.
// We don't know what the actual crypto is.
#if defined(H323_H235)
static const char OID_DesCTS[] = "2.16.840.1.114187.1.3";
H235AuthDesCTS::H235AuthDesCTS()
{
usage = AnyApplication; // Can be used either for GKAdmission or EPAuthenticstion
}
PObject * H235AuthDesCTS::Clone() const
{
return new H235AuthDesCTS(*this);
}
const char * H235AuthDesCTS::GetName() const
{
return "desCTS";
}
PStringArray H235AuthDesCTS::GetAuthenticatorNames()
{
return PStringArray("desCTS");
}
#if PTLIB_VER >= 2110
PBoolean H235AuthDesCTS::GetAuthenticationCapabilities(H235Authenticator::Capabilities * ids)
{
H235Authenticator::Capability cap;
cap.m_identifier = OID_DesCTS;
cap.m_cipher = "DES";
cap.m_description= "desCTS";
ids->capabilityList.push_back(cap);
return true;
}
#endif
PBoolean H235AuthDesCTS::IsMatch(const PString & identifier) const
{
return (identifier == PString(OID_DesCTS));
}
H225_CryptoH323Token * H235AuthDesCTS::CreateCryptoToken()
{
if (!IsActive())
return NULL;
// Create the H.225 crypto token
H225_CryptoH323Token * cryptoToken = new H225_CryptoH323Token;
cryptoToken->SetTag(H225_CryptoH323Token::e_cryptoEPPwdEncr);
// TODO: encryption not implemented, yet (GnuGk only needs the decrypt)
return cryptoToken;
}
H235Authenticator::ValidationResult H235AuthDesCTS::ValidateCryptoToken(
const H225_CryptoH323Token & cryptoToken,
const PBYTEArray &)
{
if (!IsActive())
return e_Disabled;
// verify the token is of correct type
if (cryptoToken.GetTag() != H225_CryptoH323Token::e_cryptoEPPwdEncr)
return e_Absent;
return e_OK; // TODO: always OK for now
}
PBoolean H235AuthDesCTS::IsCapability(const H235_AuthenticationMechanism & mechanism,
const PASN_ObjectId & algorithmOID)
{
return mechanism.GetTag() == H235_AuthenticationMechanism::e_pwdSymEnc &&
algorithmOID.AsString() == OID_DesCTS;
}
PBoolean H235AuthDesCTS::SetCapability(H225_ArrayOf_AuthenticationMechanism & mechanisms,
H225_ArrayOf_PASN_ObjectId & algorithmOIDs)
{
return AddCapability(H235_AuthenticationMechanism::e_pwdSymEnc, OID_DesCTS, mechanisms, algorithmOIDs);
}
PBoolean H235AuthDesCTS::IsSecuredPDU(unsigned rasPDU, PBoolean received) const
{
switch (rasPDU) {
case H225_RasMessage::e_registrationRequest :
return received ? !remoteId.IsEmpty() : !localId.IsEmpty();
default :
return FALSE;
}
}
PBoolean H235AuthDesCTS::IsSecuredSignalPDU(unsigned signalPDU, PBoolean received) const
{
return FALSE;
}
#if PTLIB_VER >= 2110
// disabled on PTLib 2.11.x, crashes on startup
#if PTLIB_VER >= 2120
typedef H235AuthDesCTS H235AuthenticatorDesCTS;
PPLUGIN_STATIC_LOAD(DesCTS,H235Authenticator);
H235SECURITY(DesCTS);
#endif
#else
static PFactory<H235Authenticator>::Worker<H235AuthDesCTS> factoryH235AuthDesCTS("desCTS");
#endif
#endif // H323_H235
#endif // OFF