Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hash SSIDs before logging them. #37524

Closed
wants to merge 1 commit into from
Closed
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
16 changes: 14 additions & 2 deletions src/darwin/Framework/CHIP/MTRCommissioningParameters.mm
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

#import "MTRCommissioningParameters.h"

#import <CommonCrypto/CommonDigest.h>

#include <lib/support/BytesToHex.h>

NS_ASSUME_NONNULL_BEGIN

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

- (NSString *)description
{
// SSID is not required to be UTF-8, but almost always is.
NSString * ssidString;
if (self.wifiSSID) {
ssidString = [[NSString alloc] initWithData:self.wifiSSID encoding:NSUTF8StringEncoding];
// We want to log the SSID, but hash it, so that the actual SSID cannot be
// recovered from the log.
uint8_t hashedValue[CC_SHA256_DIGEST_LENGTH];
CC_SHA256(self.wifiSSID.bytes, static_cast<CC_LONG>(self.wifiSSID.length), hashedValue);

char hexValue[sizeof(hashedValue) * 2];
chip::Encoding::BytesToHex(hashedValue, sizeof(hashedValue), hexValue, sizeof(hexValue), chip::Encoding::HexFlags::kUppercase);
ssidString = [[NSString alloc] initWithBytes:hexValue
length:sizeof(hexValue)
encoding:NSUTF8StringEncoding];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just [string hash] per discussion? This is awfully complicated/expensive (not that the cost matters), what's the value here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I said in the discussion if you do [string hash] then to check whether a given SSID is the one that went through this code you have to run [string hash] on the exact same operating system version of the same operating system as the one that created the log, no?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, which is fine.

} else {
ssidString = nil;
}
Expand Down
Loading