Merge branch 'nt/uuid-provisioning'
This commit is contained in:
commit
bd0f8545a7
@ -191,7 +191,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
OWSAssertDebug(identityKeyPair);
|
||||
NSData *myPublicKey = identityKeyPair.publicKey;
|
||||
NSData *myPrivateKey = identityKeyPair.privateKey;
|
||||
NSString *accountIdentifier = [TSAccountManager localNumber];
|
||||
SignalServiceAddress *accountAddress = [TSAccountManager localAddress];
|
||||
NSData *myProfileKeyData = self.profileManager.localProfileKey.keyData;
|
||||
BOOL areReadReceiptsEnabled = self.readReceiptManager.areReadReceiptsEnabled;
|
||||
|
||||
@ -199,7 +199,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
myPrivateKey:myPrivateKey
|
||||
theirPublicKey:parser.publicKey
|
||||
theirEphemeralDeviceId:parser.ephemeralDeviceId
|
||||
accountIdentifier:accountIdentifier
|
||||
accountAddress:accountAddress
|
||||
profileKey:myProfileKeyData
|
||||
readReceiptsEnabled:areReadReceiptsEnabled];
|
||||
|
||||
|
||||
@ -25,8 +25,8 @@ message ProvisionMessage {
|
||||
optional bytes identityKeyPublic = 1;
|
||||
// @required
|
||||
optional bytes identityKeyPrivate = 2;
|
||||
// @required
|
||||
optional string number = 3;
|
||||
optional string uuid = 8;
|
||||
// @required
|
||||
optional string provisioningCode = 4;
|
||||
// @required
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
//
|
||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class OWSDeviceProvisioningCodeService;
|
||||
@class OWSDeviceProvisioningService;
|
||||
@class SignalServiceAddress;
|
||||
|
||||
@interface OWSDeviceProvisioner : NSObject
|
||||
|
||||
@ -15,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
myPrivateKey:(NSData *)myPrivateKey
|
||||
theirPublicKey:(NSData *)theirPublicKey
|
||||
theirEphemeralDeviceId:(NSString *)ephemeralDeviceId
|
||||
accountIdentifier:(NSString *)accountIdentifier
|
||||
accountAddress:(SignalServiceAddress *)accountAddress
|
||||
profileKey:(NSData *)profileKey
|
||||
readReceiptsEnabled:(BOOL)areReadReceiptsEnabled
|
||||
provisioningCodeService:(OWSDeviceProvisioningCodeService *)provisioningCodeService
|
||||
@ -25,7 +26,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
myPrivateKey:(NSData *)myPrivateKey
|
||||
theirPublicKey:(NSData *)theirPublicKey
|
||||
theirEphemeralDeviceId:(NSString *)ephemeralDeviceId
|
||||
accountIdentifier:(NSString *)accountIdentifier
|
||||
accountAddress:(SignalServiceAddress *)accountAddress
|
||||
profileKey:(NSData *)profileKey
|
||||
readReceiptsEnabled:(BOOL)areReadReceiptsEnabled;
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "OWSDeviceProvisioner.h"
|
||||
@ -15,7 +15,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
@property (nonatomic, readonly) NSData *myPublicKey;
|
||||
@property (nonatomic, readonly) NSData *myPrivateKey;
|
||||
@property (nonatomic, readonly) NSData *theirPublicKey;
|
||||
@property (nonatomic, readonly) NSString *accountIdentifier;
|
||||
@property (nonatomic, readonly) SignalServiceAddress *accountAddress;
|
||||
@property (nonatomic, readonly) NSData *profileKey;
|
||||
@property (nonatomic, nullable) NSString *ephemeralDeviceId;
|
||||
@property (nonatomic, readonly) BOOL areReadReceiptsEnabled;
|
||||
@ -30,7 +30,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
myPrivateKey:(NSData *)myPrivateKey
|
||||
theirPublicKey:(NSData *)theirPublicKey
|
||||
theirEphemeralDeviceId:(NSString *)ephemeralDeviceId
|
||||
accountIdentifier:(NSString *)accountIdentifier
|
||||
accountAddress:(SignalServiceAddress *)accountAddress
|
||||
profileKey:(NSData *)profileKey
|
||||
readReceiptsEnabled:(BOOL)areReadReceiptsEnabled
|
||||
provisioningCodeService:(OWSDeviceProvisioningCodeService *)provisioningCodeService
|
||||
@ -44,7 +44,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
_myPublicKey = myPublicKey;
|
||||
_myPrivateKey = myPrivateKey;
|
||||
_theirPublicKey = theirPublicKey;
|
||||
_accountIdentifier = accountIdentifier;
|
||||
_accountAddress = accountAddress;
|
||||
_profileKey = profileKey;
|
||||
_ephemeralDeviceId = ephemeralDeviceId;
|
||||
_areReadReceiptsEnabled = areReadReceiptsEnabled;
|
||||
@ -58,7 +58,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
myPrivateKey:(NSData *)myPrivateKey
|
||||
theirPublicKey:(NSData *)theirPublicKey
|
||||
theirEphemeralDeviceId:(NSString *)ephemeralDeviceId
|
||||
accountIdentifier:(NSString *)accountIdentifier
|
||||
accountAddress:(SignalServiceAddress *)accountAddress
|
||||
profileKey:(NSData *)profileKey
|
||||
readReceiptsEnabled:(BOOL)areReadReceiptsEnabled
|
||||
{
|
||||
@ -66,7 +66,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
myPrivateKey:myPrivateKey
|
||||
theirPublicKey:theirPublicKey
|
||||
theirEphemeralDeviceId:ephemeralDeviceId
|
||||
accountIdentifier:accountIdentifier
|
||||
accountAddress:accountAddress
|
||||
profileKey:profileKey
|
||||
readReceiptsEnabled:areReadReceiptsEnabled
|
||||
provisioningCodeService:[OWSDeviceProvisioningCodeService new]
|
||||
@ -93,7 +93,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
OWSProvisioningMessage *message = [[OWSProvisioningMessage alloc] initWithMyPublicKey:self.myPublicKey
|
||||
myPrivateKey:self.myPrivateKey
|
||||
theirPublicKey:self.theirPublicKey
|
||||
accountIdentifier:self.accountIdentifier
|
||||
accountAddress:self.accountAddress
|
||||
profileKey:self.profileKey
|
||||
readReceiptsEnabled:self.areReadReceiptsEnabled
|
||||
provisioningCode:provisioningCode];
|
||||
|
||||
@ -1,15 +1,17 @@
|
||||
//
|
||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class SignalServiceAddress;
|
||||
|
||||
@interface OWSProvisioningMessage : NSObject
|
||||
|
||||
- (instancetype)initWithMyPublicKey:(NSData *)myPublicKey
|
||||
myPrivateKey:(NSData *)myPrivateKey
|
||||
theirPublicKey:(NSData *)theirPublicKey
|
||||
accountIdentifier:(NSString *)accountIdentifier
|
||||
accountAddress:(SignalServiceAddress *)accountAddress
|
||||
profileKey:(NSData *)profileKey
|
||||
readReceiptsEnabled:(BOOL)areReadReceiptsEnabled
|
||||
provisioningCode:(NSString *)provisioningCode;
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "OWSProvisioningMessage.h"
|
||||
@ -15,7 +15,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@property (nonatomic, readonly) NSData *myPublicKey;
|
||||
@property (nonatomic, readonly) NSData *myPrivateKey;
|
||||
@property (nonatomic, readonly) NSString *accountIdentifier;
|
||||
@property (nonatomic, readonly) SignalServiceAddress *accountAddress;
|
||||
@property (nonatomic, readonly) NSData *theirPublicKey;
|
||||
@property (nonatomic, readonly) NSData *profileKey;
|
||||
@property (nonatomic, readonly) BOOL areReadReceiptsEnabled;
|
||||
@ -28,7 +28,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
- (instancetype)initWithMyPublicKey:(NSData *)myPublicKey
|
||||
myPrivateKey:(NSData *)myPrivateKey
|
||||
theirPublicKey:(NSData *)theirPublicKey
|
||||
accountIdentifier:(NSString *)accountIdentifier
|
||||
accountAddress:(SignalServiceAddress *)accountAddress
|
||||
profileKey:(NSData *)profileKey
|
||||
readReceiptsEnabled:(BOOL)areReadReceiptsEnabled
|
||||
provisioningCode:(NSString *)provisioningCode
|
||||
@ -41,7 +41,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
_myPublicKey = myPublicKey;
|
||||
_myPrivateKey = myPrivateKey;
|
||||
_theirPublicKey = theirPublicKey;
|
||||
_accountIdentifier = accountIdentifier;
|
||||
_accountAddress = accountAddress;
|
||||
_profileKey = profileKey;
|
||||
_areReadReceiptsEnabled = areReadReceiptsEnabled;
|
||||
_provisioningCode = provisioningCode;
|
||||
@ -54,12 +54,24 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
ProvisioningProtoProvisionMessageBuilder *messageBuilder =
|
||||
[ProvisioningProtoProvisionMessage builderWithIdentityKeyPublic:self.myPublicKey
|
||||
identityKeyPrivate:self.myPrivateKey
|
||||
number:self.accountIdentifier
|
||||
provisioningCode:self.provisioningCode
|
||||
userAgent:@"OWI"
|
||||
profileKey:self.profileKey
|
||||
readReceipts:self.areReadReceiptsEnabled];
|
||||
|
||||
NSString *_Nullable phoneNumber = self.accountAddress.phoneNumber;
|
||||
if (!phoneNumber) {
|
||||
OWSFailDebug(@"phone number unexpectedly missing");
|
||||
return nil;
|
||||
}
|
||||
messageBuilder.number = phoneNumber;
|
||||
|
||||
NSString *_Nullable uuidString = self.accountAddress.uuidString;
|
||||
if (uuidString) {
|
||||
// TODO UUID: Eventually, this should be mandatory.
|
||||
messageBuilder.uuid = uuidString;
|
||||
}
|
||||
|
||||
NSError *error;
|
||||
NSData *_Nullable plainTextProvisionMessage = [messageBuilder buildSerializedDataAndReturnError:&error];
|
||||
if (!plainTextProvisionMessage || error) {
|
||||
|
||||
@ -85,7 +85,6 @@ struct ProvisioningProtos_ProvisionMessage {
|
||||
/// Clears the value of `identityKeyPrivate`. Subsequent reads from it will return its default value.
|
||||
mutating func clearIdentityKeyPrivate() {self._identityKeyPrivate = nil}
|
||||
|
||||
/// @required
|
||||
var number: String {
|
||||
get {return _number ?? String()}
|
||||
set {_number = newValue}
|
||||
@ -95,6 +94,15 @@ struct ProvisioningProtos_ProvisionMessage {
|
||||
/// Clears the value of `number`. Subsequent reads from it will return its default value.
|
||||
mutating func clearNumber() {self._number = nil}
|
||||
|
||||
var uuid: String {
|
||||
get {return _uuid ?? String()}
|
||||
set {_uuid = newValue}
|
||||
}
|
||||
/// Returns true if `uuid` has been explicitly set.
|
||||
var hasUuid: Bool {return self._uuid != nil}
|
||||
/// Clears the value of `uuid`. Subsequent reads from it will return its default value.
|
||||
mutating func clearUuid() {self._uuid = nil}
|
||||
|
||||
/// @required
|
||||
var provisioningCode: String {
|
||||
get {return _provisioningCode ?? String()}
|
||||
@ -142,6 +150,7 @@ struct ProvisioningProtos_ProvisionMessage {
|
||||
fileprivate var _identityKeyPublic: Data? = nil
|
||||
fileprivate var _identityKeyPrivate: Data? = nil
|
||||
fileprivate var _number: String? = nil
|
||||
fileprivate var _uuid: String? = nil
|
||||
fileprivate var _provisioningCode: String? = nil
|
||||
fileprivate var _userAgent: String? = nil
|
||||
fileprivate var _profileKey: Data? = nil
|
||||
@ -193,6 +202,7 @@ extension ProvisioningProtos_ProvisionMessage: SwiftProtobuf.Message, SwiftProto
|
||||
1: .same(proto: "identityKeyPublic"),
|
||||
2: .same(proto: "identityKeyPrivate"),
|
||||
3: .same(proto: "number"),
|
||||
8: .same(proto: "uuid"),
|
||||
4: .same(proto: "provisioningCode"),
|
||||
5: .same(proto: "userAgent"),
|
||||
6: .same(proto: "profileKey"),
|
||||
@ -209,6 +219,7 @@ extension ProvisioningProtos_ProvisionMessage: SwiftProtobuf.Message, SwiftProto
|
||||
case 5: try decoder.decodeSingularStringField(value: &self._userAgent)
|
||||
case 6: try decoder.decodeSingularBytesField(value: &self._profileKey)
|
||||
case 7: try decoder.decodeSingularBoolField(value: &self._readReceipts)
|
||||
case 8: try decoder.decodeSingularStringField(value: &self._uuid)
|
||||
default: break
|
||||
}
|
||||
}
|
||||
@ -236,6 +247,9 @@ extension ProvisioningProtos_ProvisionMessage: SwiftProtobuf.Message, SwiftProto
|
||||
if let v = self._readReceipts {
|
||||
try visitor.visitSingularBoolField(value: v, fieldNumber: 7)
|
||||
}
|
||||
if let v = self._uuid {
|
||||
try visitor.visitSingularStringField(value: v, fieldNumber: 8)
|
||||
}
|
||||
try unknownFields.traverse(visitor: &visitor)
|
||||
}
|
||||
|
||||
@ -243,6 +257,7 @@ extension ProvisioningProtos_ProvisionMessage: SwiftProtobuf.Message, SwiftProto
|
||||
if lhs._identityKeyPublic != rhs._identityKeyPublic {return false}
|
||||
if lhs._identityKeyPrivate != rhs._identityKeyPrivate {return false}
|
||||
if lhs._number != rhs._number {return false}
|
||||
if lhs._uuid != rhs._uuid {return false}
|
||||
if lhs._provisioningCode != rhs._provisioningCode {return false}
|
||||
if lhs._userAgent != rhs._userAgent {return false}
|
||||
if lhs._profileKey != rhs._profileKey {return false}
|
||||
|
||||
@ -143,13 +143,19 @@ extension ProvisioningProtoProvisionEnvelope.ProvisioningProtoProvisionEnvelopeB
|
||||
|
||||
// MARK: - ProvisioningProtoProvisionMessageBuilder
|
||||
|
||||
@objc public class func builder(identityKeyPublic: Data, identityKeyPrivate: Data, number: String, provisioningCode: String, userAgent: String, profileKey: Data, readReceipts: Bool) -> ProvisioningProtoProvisionMessageBuilder {
|
||||
return ProvisioningProtoProvisionMessageBuilder(identityKeyPublic: identityKeyPublic, identityKeyPrivate: identityKeyPrivate, number: number, provisioningCode: provisioningCode, userAgent: userAgent, profileKey: profileKey, readReceipts: readReceipts)
|
||||
@objc public class func builder(identityKeyPublic: Data, identityKeyPrivate: Data, provisioningCode: String, userAgent: String, profileKey: Data, readReceipts: Bool) -> ProvisioningProtoProvisionMessageBuilder {
|
||||
return ProvisioningProtoProvisionMessageBuilder(identityKeyPublic: identityKeyPublic, identityKeyPrivate: identityKeyPrivate, provisioningCode: provisioningCode, userAgent: userAgent, profileKey: profileKey, readReceipts: readReceipts)
|
||||
}
|
||||
|
||||
// asBuilder() constructs a builder that reflects the proto's contents.
|
||||
@objc public func asBuilder() -> ProvisioningProtoProvisionMessageBuilder {
|
||||
let builder = ProvisioningProtoProvisionMessageBuilder(identityKeyPublic: identityKeyPublic, identityKeyPrivate: identityKeyPrivate, number: number, provisioningCode: provisioningCode, userAgent: userAgent, profileKey: profileKey, readReceipts: readReceipts)
|
||||
let builder = ProvisioningProtoProvisionMessageBuilder(identityKeyPublic: identityKeyPublic, identityKeyPrivate: identityKeyPrivate, provisioningCode: provisioningCode, userAgent: userAgent, profileKey: profileKey, readReceipts: readReceipts)
|
||||
if let _value = number {
|
||||
builder.setNumber(_value)
|
||||
}
|
||||
if let _value = uuid {
|
||||
builder.setUuid(_value)
|
||||
}
|
||||
return builder
|
||||
}
|
||||
|
||||
@ -159,12 +165,11 @@ extension ProvisioningProtoProvisionEnvelope.ProvisioningProtoProvisionEnvelopeB
|
||||
|
||||
@objc fileprivate override init() {}
|
||||
|
||||
@objc fileprivate init(identityKeyPublic: Data, identityKeyPrivate: Data, number: String, provisioningCode: String, userAgent: String, profileKey: Data, readReceipts: Bool) {
|
||||
@objc fileprivate init(identityKeyPublic: Data, identityKeyPrivate: Data, provisioningCode: String, userAgent: String, profileKey: Data, readReceipts: Bool) {
|
||||
super.init()
|
||||
|
||||
setIdentityKeyPublic(identityKeyPublic)
|
||||
setIdentityKeyPrivate(identityKeyPrivate)
|
||||
setNumber(number)
|
||||
setProvisioningCode(provisioningCode)
|
||||
setUserAgent(userAgent)
|
||||
setProfileKey(profileKey)
|
||||
@ -204,6 +209,17 @@ extension ProvisioningProtoProvisionEnvelope.ProvisioningProtoProvisionEnvelopeB
|
||||
proto.number = valueParam
|
||||
}
|
||||
|
||||
@objc
|
||||
@available(swift, obsoleted: 1.0)
|
||||
public func setUuid(_ valueParam: String?) {
|
||||
guard let valueParam = valueParam else { return }
|
||||
proto.uuid = valueParam
|
||||
}
|
||||
|
||||
public func setUuid(_ valueParam: String) {
|
||||
proto.uuid = valueParam
|
||||
}
|
||||
|
||||
@objc
|
||||
@available(swift, obsoleted: 1.0)
|
||||
public func setProvisioningCode(_ valueParam: String?) {
|
||||
@ -257,8 +273,6 @@ extension ProvisioningProtoProvisionEnvelope.ProvisioningProtoProvisionEnvelopeB
|
||||
|
||||
@objc public let identityKeyPrivate: Data
|
||||
|
||||
@objc public let number: String
|
||||
|
||||
@objc public let provisioningCode: String
|
||||
|
||||
@objc public let userAgent: String
|
||||
@ -267,10 +281,29 @@ extension ProvisioningProtoProvisionEnvelope.ProvisioningProtoProvisionEnvelopeB
|
||||
|
||||
@objc public let readReceipts: Bool
|
||||
|
||||
@objc public var number: String? {
|
||||
guard proto.hasNumber else {
|
||||
return nil
|
||||
}
|
||||
return proto.number
|
||||
}
|
||||
@objc public var hasNumber: Bool {
|
||||
return proto.hasNumber
|
||||
}
|
||||
|
||||
@objc public var uuid: String? {
|
||||
guard proto.hasUuid else {
|
||||
return nil
|
||||
}
|
||||
return proto.uuid
|
||||
}
|
||||
@objc public var hasUuid: Bool {
|
||||
return proto.hasUuid
|
||||
}
|
||||
|
||||
private init(proto: ProvisioningProtos_ProvisionMessage,
|
||||
identityKeyPublic: Data,
|
||||
identityKeyPrivate: Data,
|
||||
number: String,
|
||||
provisioningCode: String,
|
||||
userAgent: String,
|
||||
profileKey: Data,
|
||||
@ -278,7 +311,6 @@ extension ProvisioningProtoProvisionEnvelope.ProvisioningProtoProvisionEnvelopeB
|
||||
self.proto = proto
|
||||
self.identityKeyPublic = identityKeyPublic
|
||||
self.identityKeyPrivate = identityKeyPrivate
|
||||
self.number = number
|
||||
self.provisioningCode = provisioningCode
|
||||
self.userAgent = userAgent
|
||||
self.profileKey = profileKey
|
||||
@ -306,11 +338,6 @@ extension ProvisioningProtoProvisionEnvelope.ProvisioningProtoProvisionEnvelopeB
|
||||
}
|
||||
let identityKeyPrivate = proto.identityKeyPrivate
|
||||
|
||||
guard proto.hasNumber else {
|
||||
throw ProvisioningProtoError.invalidProtobuf(description: "\(logTag) missing required field: number")
|
||||
}
|
||||
let number = proto.number
|
||||
|
||||
guard proto.hasProvisioningCode else {
|
||||
throw ProvisioningProtoError.invalidProtobuf(description: "\(logTag) missing required field: provisioningCode")
|
||||
}
|
||||
@ -338,7 +365,6 @@ extension ProvisioningProtoProvisionEnvelope.ProvisioningProtoProvisionEnvelopeB
|
||||
let result = ProvisioningProtoProvisionMessage(proto: proto,
|
||||
identityKeyPublic: identityKeyPublic,
|
||||
identityKeyPrivate: identityKeyPrivate,
|
||||
number: number,
|
||||
provisioningCode: provisioningCode,
|
||||
userAgent: userAgent,
|
||||
profileKey: profileKey,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user