Skip to content

Commit 878b444

Browse files
Hash SSIDs before logging them.
1 parent 63f9782 commit 878b444

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/darwin/Framework/CHIP/MTRCommissioningParameters.mm

+14-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717

1818
#import "MTRCommissioningParameters.h"
1919

20+
#import <CommonCrypto/CommonDigest.h>
21+
22+
#include <lib/support/BytesToHex.h>
23+
2024
NS_ASSUME_NONNULL_BEGIN
2125

2226
@implementation MTRCommissioningParameters : NSObject
@@ -47,10 +51,18 @@ - (void)setFailSafeExpiryTimeoutSecs:(NSNumber * _Nullable)failSafeExpiryTimeout
4751

4852
- (NSString *)description
4953
{
50-
// SSID is not required to be UTF-8, but almost always is.
5154
NSString * ssidString;
5255
if (self.wifiSSID) {
53-
ssidString = [[NSString alloc] initWithData:self.wifiSSID encoding:NSUTF8StringEncoding];
56+
// We want to log the SSID, but hash it, so that the actual SSID cannot be
57+
// recovered from the log.
58+
uint8_t hashedValue[CC_SHA256_DIGEST_LENGTH];
59+
CC_SHA256(self.wifiSSID.bytes, static_cast<CC_LONG>(self.wifiSSID.length), hashedValue);
60+
61+
char hexValue[sizeof(hashedValue) * 2];
62+
chip::Encoding::BytesToHex(hashedValue, sizeof(hashedValue), hexValue, sizeof(hexValue), chip::Encoding::HexFlags::kUppercase);
63+
ssidString = [[NSString alloc] initWithBytes:hexValue
64+
length:sizeof(hexValue)
65+
encoding:NSUTF8StringEncoding];
5466
} else {
5567
ssidString = nil;
5668
}

0 commit comments

Comments
 (0)