Signal-iOS/SignalServiceKit/src/Network/API/OWSRequestBuilder.m
Michael Kirk 7499b3aaf0 Avatar API integration / WIP crypto scheme
Crypto Scheme:

- Name (un)padding
- WIP AES-GCM (funtioning, but need to verify against android
  implementation, and tag functionality)

Changes to avatar API:

- hard code avatar domain (cdn.signal.org)
- avatar form hands out new avatar key, invalidating old avatar
- preliminary aes-gcm integration

Also:

- New type to represent AES128 keys, rather than passing around opaque
  data blobs everywhere, we can use the compiler to help us make sure
  we're passing compliant keying material.

- Started using factory pattern for API requests. This is intended to be
  a lighter weight way to implement new API requests, rather than the
  current 1-method class ceremony.

// FREEBIE
2017-08-14 12:45:37 -04:00

44 lines
1.4 KiB
Objective-C

//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "OWSRequestBuilder.h"
#import "TSRequest.h"
#import "TSConstants.h"
#import "NSData+Base64.h"
NS_ASSUME_NONNULL_BEGIN
const NSUInteger kEncodedNameLength = 72;
@implementation OWSRequestBuilder
+ (TSRequest *)profileNameSetRequestWithEncryptedPaddedName:(nullable NSData *)encryptedPaddedName
{
NSString *urlString;
NSString *base64EncodedName = [encryptedPaddedName base64EncodedString];
// name length must match exactly
if (base64EncodedName.length == kEncodedNameLength) {
// Remove any "/" in the base64 (all other base64 chars are URL safe.
// Apples built-in `stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URL*]]` doesn't offer a
// flavor for encoding "/".
NSString *urlEncodedName = [base64EncodedName stringByReplacingOccurrencesOfString:@"/" withString:@"%2F"];
urlString = [NSString stringWithFormat:textSecureSetProfileNameAPIFormat, urlEncodedName];
} else {
// if name length doesn't match exactly, assume blank name
OWSAssert(encryptedPaddedName == nil);
urlString = [NSString stringWithFormat:textSecureSetProfileNameAPIFormat, @""];
}
NSURL *url = [NSURL URLWithString:urlString];
TSRequest *request = [[TSRequest alloc] initWithURL:url];
request.HTTPMethod = @"PUT";
return request;
}
@end
NS_ASSUME_NONNULL_END