︙ | | | ︙ | |
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#include <assert.h>
#include <stringprep.h>
#include <idna.h>
#import <ObjOpenSSL/SSLSocket.h>
#import "XMPPConnection.h"
#import "XMPPSRVLookup.h"
#import "XMPPSCRAMAuth.h"
#import "XMPPPLAINAuth.h"
#import "XMPPStanza.h"
#import "XMPPJID.h"
|
>
>
|
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
#include <assert.h>
#include <stringprep.h>
#include <idna.h>
#import <ObjOpenSSL/SSLSocket.h>
#import <ObjOpenSSL/SSLInvalidCertificateException.h>
#import <ObjOpenSSL/X509Certificate.h>
#import "XMPPConnection.h"
#import "XMPPSRVLookup.h"
#import "XMPPSCRAMAuth.h"
#import "XMPPPLAINAuth.h"
#import "XMPPStanza.h"
#import "XMPPJID.h"
|
︙ | | | ︙ | |
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
|
{
return [[resource copy] autorelease];
}
- (void)setServer: (OFString*)server_
{
OFString *old = server;
char *srv;
Idna_rc rc;
if ((rc = idna_to_ascii_8z([server_ UTF8String],
&srv, IDNA_USE_STD3_ASCII_RULES)) != IDNA_SUCCESS)
@throw [XMPPIDNATranslationFailedException
exceptionWithClass: isa
connection: self
operation: @"ToASCII"
string: server_];
@try {
server = [[OFString alloc] initWithUTF8String: srv];
} @finally {
free(srv);
}
[old release];
}
- (OFString*)server
{
return [[server copy] autorelease];
}
- (void)setDomain: (OFString*)domain_
{
OFString *old = domain;
char *srv;
Stringprep_rc rc;
if ((rc = stringprep_profile([domain_ UTF8String], &srv,
"Nameprep", 0)) != STRINGPREP_OK)
@throw [XMPPStringPrepFailedException
exceptionWithClass: isa
connection: self
profile: @"Nameprep"
string: domain_];
@try {
domain = [[OFString alloc] initWithUTF8String: srv];
} @finally {
free(srv);
}
[old release];
}
- (OFString*)domain
{
return [[domain copy] autorelease];
}
|
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
|
>
>
>
|
|
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
|
{
return [[resource copy] autorelease];
}
- (void)setServer: (OFString*)server_
{
OFString *old = server;
server = [self XMPP_IDNAToASCII: server_];
[old release];
}
- (OFString*)server
{
return [[server copy] autorelease];
}
- (void)setDomain: (OFString*)domain_
{
OFString *oldDomain = domain;
OFString *oldDomainToASCII = domainToASCII;
char *srv;
Stringprep_rc rc;
if ((rc = stringprep_profile([domain_ UTF8String], &srv,
"Nameprep", 0)) != STRINGPREP_OK)
@throw [XMPPStringPrepFailedException
exceptionWithClass: isa
connection: self
profile: @"Nameprep"
string: domain_];
@try {
domain = [[OFString alloc] initWithUTF8String: srv];
} @finally {
free(srv);
}
[oldDomain release];
domainToASCII = [self XMPP_IDNAToASCII: domain];
[oldDomainToASCII release];
}
- (OFString*)domain
{
return [[domain copy] autorelease];
}
|
︙ | | | ︙ | |
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
|
- (void)connect
{
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
XMPPSRVEntry *candidate = nil;
XMPPSRVLookup *SRVLookup = nil;
OFEnumerator *enumerator;
OFString *domainToASCII;
char *cDomainToASCII;
Idna_rc rc;
if (server)
[sock connectToHost: server
port: port];
else {
if ((rc = idna_to_ascii_8z([domain UTF8String], &cDomainToASCII,
IDNA_USE_STD3_ASCII_RULES)) != IDNA_SUCCESS)
@throw [XMPPIDNATranslationFailedException
exceptionWithClass: isa
connection: self
operation: @"ToASCII"
string: domain];
@try {
domainToASCII = [OFString
stringWithUTF8String: cDomainToASCII];
} @finally {
free(cDomainToASCII);
}
@try {
SRVLookup = [XMPPSRVLookup
lookupWithDomain: domainToASCII];
} @catch (id e) {
}
enumerator = [SRVLookup objectEnumerator];
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
- (void)connect
{
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
XMPPSRVEntry *candidate = nil;
XMPPSRVLookup *SRVLookup = nil;
OFEnumerator *enumerator;
if (server)
[sock connectToHost: server
port: port];
else {
@try {
SRVLookup = [XMPPSRVLookup
lookupWithDomain: domainToASCII];
} @catch (id e) {
}
enumerator = [SRVLookup objectEnumerator];
|
︙ | | | ︙ | |
338
339
340
341
342
343
344
345
346
347
348
349
350
351
|
encryptionRequired = required;
}
- (BOOL)encrypted
{
return encrypted;
}
- (void)sendStanza: (OFXMLElement*)element
{
of_log(@"Out: %@", element);
[sock writeString: [element XMLString]];
}
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
|
encryptionRequired = required;
}
- (BOOL)encrypted
{
return encrypted;
}
- (void)checkCertificate
{
X509Certificate *cert;
OFDictionary *SANs;
BOOL serviceSpecific = NO;
[sock verifyPeerCertificate];
cert = [sock peerCertificate];
SANs = [cert subjectAlternativeName];
if ([[SANs objectForKey: @"otherName"]
objectForKey: OID_SRVName] ||
[SANs objectForKey: @"dNSName"] ||
[SANs objectForKey: @"uniformResourceIdentifier"])
serviceSpecific = YES;
if ([cert hasSRVNameMatchingDomain: domainToASCII
service: @"xmpp-client"] ||
[cert hasDNSNameMatchingDomain: domainToASCII])
return;
if (serviceSpecific ||
![cert hasCommonNameMatchingDomain: domainToASCII])
@throw [SSLInvalidCertificateException
exceptionWithClass: isa
reason: @"No matching identifier"];
}
- (void)sendStanza: (OFXMLElement*)element
{
of_log(@"Out: %@", element);
[sock writeString: [element XMLString]];
}
|
︙ | | | ︙ | |
872
873
874
875
876
877
878
879
880
881
882
883
884
885
|
if ([delegate respondsToSelector: @selector(connection:wasBoundToJID:)])
[delegate connection: self
wasBoundToJID: JID];
[sessionID release];
sessionID = nil;
}
- (XMPPJID*)JID
{
return [[JID copy] autorelease];
}
- (void)setPort: (uint16_t)port_
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
|
if ([delegate respondsToSelector: @selector(connection:wasBoundToJID:)])
[delegate connection: self
wasBoundToJID: JID];
[sessionID release];
sessionID = nil;
}
- (OFString*)XMPP_IDNAToASCII: (OFString*)domain_
{
OFString *ret;
char *cDomain;
Idna_rc rc;
if ((rc = idna_to_ascii_8z([domain_ UTF8String],
&cDomain, IDNA_USE_STD3_ASCII_RULES)) != IDNA_SUCCESS)
@throw [XMPPIDNATranslationFailedException
exceptionWithClass: isa
connection: self
operation: @"ToASCII"
string: domain_];
@try {
ret = [[OFString alloc] initWithUTF8String: cDomain];
} @finally {
free(cDomain);
}
return ret;
}
- (XMPPJID*)JID
{
return [[JID copy] autorelease];
}
- (void)setPort: (uint16_t)port_
|
︙ | | | ︙ | |