passepartout-apple/Packages/PassepartoutOpenVPNOpenSSL/Sources/CPassepartoutOpenVPNOpenSSL/OpenVPNCryptoProtocol.m
Davide 7b8dbfe84a
Minimize dependencies of VPN implementations (#1057)
### OpenVPN

- Make CPassepartoutCryptoOpenSSL agnostic of PassepartoutKit
- Move Allocation/ZeroingData from PassepartoutKit to package for
internal use
  - Rename ZeroingData.count to .length for consistency with NSData
  - Duplicate some Data manipulation code in CryptoOpenSSL
- Retain a simplified version of ZeroingData in PassepartoutKit
(AutoerasingData)

### WireGuard

- Make WireGuardKit imports `internal`
2025-01-15 09:39:58 +01:00

66 lines
2.3 KiB
Objective-C

//
// OpenVPNCryptoProtocol.m
// PassepartoutKit
//
// Created by Davide De Rosa on 5/8/24.
// Copyright (c) 2024 Davide De Rosa. All rights reserved.
//
// https://github.com/passepartoutvpn
//
// This file is part of PassepartoutKit.
//
// PassepartoutKit is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// PassepartoutKit is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with PassepartoutKit. If not, see <http://www.gnu.org/licenses/>.
//
#import <Foundation/Foundation.h>
#import <PassepartoutKit/PassepartoutKit.h>
#import "OpenVPNCryptoProtocol.h"
@interface OpenVPNCryptoOptions ()
@property (nonatomic, copy) NSString *cipherAlgorithm;
@property (nonatomic, copy) NSString *digestAlgorithm;
@property (nonatomic, strong) ZeroingData *cipherEncKey;
@property (nonatomic, strong) ZeroingData *cipherDecKey;
@property (nonatomic, strong) ZeroingData *hmacEncKey;
@property (nonatomic, strong) ZeroingData *hmacDecKey;
@end
@implementation OpenVPNCryptoOptions
- (instancetype)initWithCipherAlgorithm:(NSString *)cipherAlgorithm
digestAlgorithm:(NSString *)digestAlgorithm
cipherEncKey:(ZeroingData *)cipherEncKey
cipherDecKey:(ZeroingData *)cipherDecKey
hmacEncKey:(ZeroingData *)hmacEncKey
hmacDecKey:(ZeroingData *)hmacDecKey
{
NSParameterAssert(cipherAlgorithm || digestAlgorithm);
NSParameterAssert((cipherEncKey && cipherDecKey) || (hmacEncKey && hmacDecKey));
if ((self = [super init])) {
self.cipherAlgorithm = [cipherAlgorithm lowercaseString];
self.digestAlgorithm = [digestAlgorithm lowercaseString];
self.cipherEncKey = cipherEncKey;
self.cipherDecKey = cipherDecKey;
self.hmacEncKey = hmacEncKey;
self.hmacDecKey = hmacDecKey;
}
return self;
}
@end