#import "SecureSessionExample.h"
@implementation SecureSessionExample
- (id)initWithExampleInterface:(ExampleInterface *)exampleInterface {
self = [super initWithExampleInterface:exampleInterface];
self.name = @"SecureSession";
self.description =
@"Demonstrates how to establish a secure session and then "
@"subscribe and publish to a topic";
[self.parameters parameterWithId:PARAMETER_HOST].value = @"tcps://";
[self.parameters removeParameter:PARAMETER_COMPRESSION];
[self.parameters addParameter:PARAMETER_NUM_MESSAGES];
[self.parameters addParameter:PARAMETER_SSL_NO_PROTOCOLS];
[self.parameters addParameter:PARAMETER_SSL_CIPHER_LIST];
[self.parameters addParameter:PARAMETER_SSL_CERTIFICATE_VALIDATION];
[self.parameters addParameter:PARAMETER_SSL_CERTIFICATE_DATE_VALIDATION];
[self.parameters addParameter:PARAMETER_SSL_TRUST_STORE_DIRECTORY];
[self.parameters addParameter:PARAMETER_SSL_COMMON_NAMES];
[self.parameters addParameter:PARAMETER_SSL_AUTHENTICATION_SCHEME];
[self.parameters addParameter:PARAMETER_SSL_CERTIFICATE];
[self.parameters addParameter:PARAMETER_SSL_PRIVATE_KEY];
[self.parameters addParameter:PARAMETER_SSL_PRIVATE_KEY_PASSWORD];
[self.parameters addParameter:PARAMETER_SSL_CONNECTION_DOWNGRADE_TO];
return self;
}
messageReceiveCallbackWithSession:
userData:(void *)user_p {
char buffer[5000];
[self handleErrorWithReturnCode:rc errorString:"solClient_msg_dump()"];
}
}
- (void)run {
[super run];
const char *sessionProps[60];
int propIndex = 0;
int msgsSent = 0;
[self handleErrorWithReturnCode:rc
errorString:"solClient_initialize()"];
goto notInitialized;
}
[self setLoggingLevel];
"SecureSessionExample.m (Copyright 2009-2024 Solace Corporation. All rights reserved.)\n");
[self logCCSMPVersion];
&contextFuncInfo,
sizeof(contextFuncInfo))) !=
SOLCLIENT_OK) {
[self handleErrorWithReturnCode:rc
errorString:"solClient_context_create()"];
goto cleanup;
}
{
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(
NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDir = [documentPaths objectAtIndex:0];
NSString *trustStoreDir = [[[NSBundle mainBundle] resourcePath]
stringByAppendingPathComponent:@"certificates.bundle/trustStores"];
propIndex = 0;
sessionProps[propIndex++] =
[[self.parameters parameterWithId:PARAMETER_HOST].value
cStringUsingEncoding:NSASCIIStringEncoding];
if ([(NSString *)[self.parameters
parameterWithId:PARAMETER_SSL_AUTHENTICATION_SCHEME].value
isEqualToString:@"Certificate"]) {
sessionProps[propIndex++] =
sessionProps[propIndex++] =
sessionProps[propIndex++] =
sessionProps[propIndex++] = [[documentDir
stringByAppendingPathComponent:
[self.parameters parameterWithId:PARAMETER_SSL_CERTIFICATE]
.value] cStringUsingEncoding:NSASCIIStringEncoding];
sessionProps[propIndex++] =
sessionProps[propIndex++] = [[documentDir
stringByAppendingPathComponent:
[self.parameters parameterWithId:PARAMETER_SSL_PRIVATE_KEY]
.value] cStringUsingEncoding:NSASCIIStringEncoding];
if (![[self.parameters parameterWithId:PARAMETER_SSL_PRIVATE_KEY]
.value isEqualToString:@""]) {
sessionProps[propIndex++] =
sessionProps[propIndex++] =
[[self.parameters parameterWithId:PARAMETER_SSL_PRIVATE_KEY_PASSWORD]
.value cStringUsingEncoding:NSASCIIStringEncoding];
}
}
if (strlen([[self.parameters parameterWithId:PARAMETER_USERNAME].value
cStringUsingEncoding:NSASCIIStringEncoding]) > 0) {
sessionProps[propIndex++] =
[[self.parameters parameterWithId:PARAMETER_USERNAME].value
cStringUsingEncoding:NSASCIIStringEncoding];
sessionProps[propIndex++] =
[[self.parameters parameterWithId:PARAMETER_PASSWORD].value
cStringUsingEncoding:NSASCIIStringEncoding];
}
if ([[self.parameters parameterWithId:PARAMETER_VPN].value
cStringUsingEncoding:NSASCIIStringEncoding][0]) {
sessionProps[propIndex++] =
[[self.parameters parameterWithId:PARAMETER_VPN].value
cStringUsingEncoding:NSASCIIStringEncoding];
}
sessionProps[propIndex++] = "3";
sessionProps[propIndex++] =
sessionProps[propIndex++] = "3";
sessionProps[propIndex++] =
if (![self.parameters
parameterWithId:PARAMETER_SSL_CERTIFICATE_VALIDATION]
.value.boolValue) {
sessionProps[propIndex++] =
}
if (![self.parameters
parameterWithId:PARAMETER_SSL_CERTIFICATE_DATE_VALIDATION]
.value.boolValue) {
sessionProps[propIndex++] =
}
if (![[self.parameters parameterWithId:PARAMETER_SSL_TRUST_STORE_DIRECTORY].value
isEqualToString:@""]) {
trustStoreDir = [documentDir stringByAppendingPathComponent:
[self.parameters parameterWithId:PARAMETER_SSL_TRUST_STORE_DIRECTORY].value];
}
sessionProps[propIndex++] = [trustStoreDir cStringUsingEncoding:NSASCIIStringEncoding];
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:trustStoreDir]){
NSArray *listOfFiles = [fileManager contentsOfDirectoryAtPath:trustStoreDir error:nil];
if ([listOfFiles count] == 0) {
[trustStoreDir cStringUsingEncoding:NSASCIIStringEncoding]);
}
}
if (![[self.parameters parameterWithId:PARAMETER_SSL_CIPHER_LIST].value
isEqualToString:@""]) {
sessionProps[propIndex++] =
sessionProps[propIndex++] =
[[self.parameters parameterWithId:PARAMETER_SSL_CIPHER_LIST]
.value cStringUsingEncoding:NSASCIIStringEncoding];
}
if (![[self.parameters parameterWithId:PARAMETER_SSL_COMMON_NAMES].value
isEqualToString:@""]) {
sessionProps[propIndex++] =
sessionProps[propIndex++] =
[[self.parameters parameterWithId:PARAMETER_SSL_COMMON_NAMES]
.value cStringUsingEncoding:NSASCIIStringEncoding];
}
if (![[self.parameters parameterWithId:PARAMETER_SSL_NO_PROTOCOLS].value
isEqualToString:@""]) {
sessionProps[propIndex++] =
[[self.parameters parameterWithId:PARAMETER_SSL_NO_PROTOCOLS].value
cStringUsingEncoding:NSASCIIStringEncoding];
}
if (![[self.parameters parameterWithId:PARAMETER_SSL_CONNECTION_DOWNGRADE_TO].value
isEqualToString:@""]) {
sessionProps[propIndex++] =
sessionProps[propIndex++] =
[[self.parameters parameterWithId:PARAMETER_SSL_CONNECTION_DOWNGRADE_TO]
.value cStringUsingEncoding:NSASCIIStringEncoding];
}
sessionProps[propIndex] = NULL;
}
(char **)sessionProps, context_p, &session_p, &sessionFuncInfo,
[self handleErrorWithReturnCode:rc
errorString:"solClient_session_create()"];
goto cleanup;
}
[self handleErrorWithReturnCode:rc
errorString:"solClient_session_connect()"];
goto cleanup;
}
[self handleErrorWithReturnCode:rc
errorString:"solClient_session_topicSubscribe()"];
goto sessionConnected;
}
for (msgsSent = 0;
msgsSent < [self.parameters parameterWithId:PARAMETER_NUM_MESSAGES]
.value.integerValue &&
!self.requestCancel;
++msgsSent) {
[self handleErrorWithReturnCode:rc
errorString:"solClient_msg_alloc()"];
goto sessionConnected;
}
[self handleErrorWithReturnCode:rc
errorString:"solClient_msg_setDeliveryMode()"];
goto freeMessage;
}
destination.
dest = COMMON_MY_SAMPLE_TOPIC;
msg_p, &destination,
sizeof(destination))) !=
SOLCLIENT_OK) {
[self handleErrorWithReturnCode:rc
errorString:"solClient_msg_setDestination()"];
goto freeMessage;
}
msg_p, COMMON_ATTACHMENT_TEXT,
(solClient_uint32_t)strlen(COMMON_ATTACHMENT_TEXT))) !=
[self handleErrorWithReturnCode:
rc errorString:"solClient_msg_setBinaryAttachment()"];
goto freeMessage;
}
[self handleErrorWithReturnCode:rc
errorString:"solClient_session_sendMsg()"];
goto freeMessage;
}
freeMessage:
[self handleErrorWithReturnCode:rc
errorString:"solClient_msg_free()"];
goto sessionConnected;
}
[NSThread sleepForTimeInterval:1];
}
[self handleErrorWithReturnCode:rc
errorString:"solClient_session_topicSubscribe()"];
goto sessionConnected;
}
sessionConnected:
[self handleErrorWithReturnCode:rc
errorString:"solClient_session_disconnect()"];
}
cleanup:
[self handleErrorWithReturnCode:rc errorString:"solClient_cleanup()"];
}
notInitialized:
[self cleanup];
}
@end