Skip to content
This repository was archived by the owner on Jan 21, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions MASFoundation/Classes/MQTT/MASMQTTClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -844,13 +844,13 @@ - (void)setupTLSWithServerCert:(NSString *)certPath withClientCert:(NSString *)c
//
if (!certPath) {

thisFile = [[MASSecurityService sharedService] getClientCertificate];
thisFile = [[MASSecurityService sharedService] getServerCertificate];
certPath = [thisFile filePath];
//[[MASFile findFileWithName:@"MAS.crt"] filePath];
}
if (!clientCertPath) {

thisFile = [[MASSecurityService sharedService] getSignedCertificate];
thisFile = [[MASSecurityService sharedService] getDeviceClientCertificate];
clientCertPath = [thisFile filePath];
//[[MASFile findFileWithName:@"MASSigned.crt"] filePath];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ - (NSString *)debugDescription
//
// ServerCertificate
//
MASFile *file = [[MASSecurityService sharedService] getClientCertificate]; //[self findFileWithName:MASCertificate];
MASFile *file = [[MASSecurityService sharedService] getServerCertificate]; //[self findFileWithName:MASCertificate];
if(file)
{
filesFound = YES;
Expand All @@ -68,7 +68,7 @@ - (NSString *)debugDescription
//
// SignedCertificate
//
file = [[MASSecurityService sharedService] getSignedCertificate]; //[self findFileWithName:MASSignedCertificate];
file = [[MASSecurityService sharedService] getDeviceClientCertificate]; //[self findFileWithName:MASSignedCertificate];
if(file)
{
filesFound = YES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1309,10 +1309,10 @@ - (void)renewClientCertificateWithCompletion:(MASCompletionErrorBlock)completion
[[MASAccessService sharedService] setAccessValueNumber:[NSNumber numberWithInt:0] withAccessValueType:MASAccessValueTypeSignedPublicCertificateExpirationDate];

//
// Remove signedCertificate MASFile for re-generation
// Remove device's client MASFile for re-generation
//
MASFile *signedCertificate = [[MASSecurityService sharedService] getSignedCertificate];
[MASFile removeItemAtFilePath:[signedCertificate filePath]];
MASFile *deviceClientCert = [[MASSecurityService sharedService] getDeviceClientCertificate];
[MASFile removeItemAtFilePath:[deviceClientCert filePath]];

//
// Updated with latest info
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,20 @@
# pragma mark - MASFile Security

/**
* Generate MASFile object for current gateway's signed certificate.
* Generate MASFile object for current device's client certificate.
*
* @return Returns MASFile object of signed certificate for current configuration's gateway.
* @return Returns MASFile object of device's client for current configuration's gateway.
*/
- (MASFile *)getSignedCertificate;
- (MASFile *)getDeviceClientCertificate;



/**
* Generate MASFile object for current gateway's client certificate.
* Generate MASFile object for current gateway's server certificate.
*
* @return Returns MASFile object of client certificate for current configuration's gateway.
* @return Returns MASFile object of server certificate for current configuration's gateway.
*/
- (MASFile *)getClientCertificate;
- (MASFile *)getServerCertificate;



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ - (NSData *)publicKeyBits

# pragma mark - MASFile Security

- (MASFile *)getSignedCertificate
- (MASFile *)getDeviceClientCertificate
{
NSString *gatewayIdentifier = [[[MASConfiguration currentConfiguration].gatewayUrl.absoluteString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] stringByReplacingOccurrencesOfString:@"https://" withString:@""];
MASFile *signedCert = [MASFile findFileWithName:[NSString stringWithFormat:@"%@.%@", gatewayIdentifier, MASSignedCertificate]];
Expand All @@ -435,7 +435,7 @@ - (MASFile *)getSignedCertificate
}


- (MASFile *)getClientCertificate
- (MASFile *)getServerCertificate
{
NSString *gatewayIdentifier = [[[MASConfiguration currentConfiguration].gatewayUrl.absoluteString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] stringByReplacingOccurrencesOfString:@"https://" withString:@""];
MASFile *clientCert = [MASFile findFileWithName:[NSString stringWithFormat:@"%@.%@", gatewayIdentifier, MASCertificate]];
Expand All @@ -446,17 +446,18 @@ - (MASFile *)getClientCertificate
// Create the public server certificate file
//
NSArray *certs = [[MASConfiguration currentConfiguration] gatewayCertificatesAsPEMData];
if(certs.count > 0)
NSMutableData *certificateData = [NSMutableData data];

for (NSData *cert in certs)
{
[certificateData appendData:cert];
[certificateData appendData:[@"\n" dataUsingEncoding:NSUTF8StringEncoding]];
}

if (certificateData)
{
NSData *certificateData = certs[0];

//DLog(@"\n\nServer Certificate class is: %@\n\n and value: %@\n\n", [[certificateData class] debugDescription], certificateData);

if(certificateData)
{
clientCert = [MASFile fileWithName:[NSString stringWithFormat:@"%@.%@", gatewayIdentifier, MASCertificate] contents:certificateData];
[clientCert save];
}
clientCert = [MASFile fileWithName:[NSString stringWithFormat:@"%@.%@", gatewayIdentifier, MASCertificate] contents:certificateData];
[clientCert save];
}
}

Expand Down Expand Up @@ -496,22 +497,22 @@ - (MASFile *)getPrivateKey
- (void)removeAllFiles
{
MASFile *privateKey = [self getPrivateKey];
MASFile *clientCert = [self getClientCertificate];
MASFile *signedCert = [self getSignedCertificate];
MASFile *serverCert = [self getServerCertificate];
MASFile *deviceClientCert = [self getDeviceClientCertificate];

if ([privateKey filePath])
{
[MASFile removeItemAtFilePath:[privateKey filePath]];
}

if ([clientCert filePath])
if ([serverCert filePath])
{
[MASFile removeItemAtFilePath:[clientCert filePath]];
[MASFile removeItemAtFilePath:[serverCert filePath]];
}

if ([signedCert filePath])
if ([deviceClientCert filePath])
{
[MASFile removeItemAtFilePath:[signedCert filePath]];
[MASFile removeItemAtFilePath:[deviceClientCert filePath]];
}
}

Expand Down