Skip to content
Snippets Groups Projects
Commit 8106dcc8 authored by Oliver Wiese's avatar Oliver Wiese
Browse files

update ObjectivePGP

parent 12f75494
No related branches found
No related tags found
No related merge requests found
Showing
with 533 additions and 0 deletions
//
// PGPBigNum.h
// ObjectivePGP
//
// Created by Marcin Krzyzanowski on 26/06/2017.
// Copyright © 2017 Marcin Krzyżanowski. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface PGPBigNum : NSObject <NSCopying>
@property (nonatomic, readonly) unsigned int bitsCount;
@property (nonatomic, readonly) unsigned int bytesCount;
@property (nonatomic, readonly) NSData *data;
@end
NS_ASSUME_NONNULL_END
//
// PGPCompressedPacket.h
// ObjectivePGP
//
// Created by Marcin Krzyzanowski on 02/06/14.
// Copyright (c) 2014 Marcin Krzyżanowski. All rights reserved.
//
#import "PGPPacket.h"
// 9.3. Compression Algorithms
typedef NS_ENUM(UInt8, PGPCompressionAlgorithm) {
PGPCompressionUncompressed = 0,
PGPCompressionZIP = 1, // TODO: Unsupported
PGPCompressionZLIB = 2,
PGPCompressionBZIP2 = 3
};
@interface PGPCompressedPacket : PGPPacket
@property (nonatomic, readonly) PGPCompressionAlgorithm compressionType;
@property (nonatomic) NSData *decompressedData;
- (instancetype)initWithData:(NSData *)dataToCompress type:(PGPCompressionAlgorithm)type;
@end
//
// PGPCryptoCFB.h
// ObjectivePGP
//
// Created by Marcin Krzyzanowski on 05/06/14.
// Copyright (c) 2014 Marcin Krzyżanowski. All rights reserved.
//
#import "PGPS2K.h"
#import "PGPTypes.h"
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface PGPCryptoCFB : NSObject
+ (nullable NSData *)decryptData:(NSData *)encryptedData
sessionKeyData:(NSData *)sessionKeyData // s2k produceSessionKeyWithPassphrase
symmetricAlgorithm:(PGPSymmetricAlgorithm)symmetricAlgorithm
iv:(NSData *)ivData;
+ (nullable NSData *)encryptData:(NSData *)encryptedData
sessionKeyData:(NSData *)sessionKeyData // s2k produceSessionKeyWithPassphrase
symmetricAlgorithm:(PGPSymmetricAlgorithm)symmetricAlgorithm
iv:(NSData *)ivData;
@end
NS_ASSUME_NONNULL_END
//
// Copyright (c) Marcin Krzyżanowski. All rights reserved.
//
// THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY
// INTERNATIONAL COPYRIGHT LAW. USAGE IS BOUND TO THE LICENSE AGREEMENT.
// This notice may not be removed from this file.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
#define PGPCast(obj, c) ((c * _Nullable) _pgp__cast(obj, c.class))
id _Nullable _pgp__cast(id _Nullable obj, Class objClass);
BOOL PGPEqualObjects(id _Nullable obj1, id _Nullable obj2);
@interface PGPFoundation : NSObject
@end
NS_ASSUME_NONNULL_END
//
// PGPKeyMaterial.h
// ObjectivePGP
//
// Created by Marcin Krzyzanowski on 25/08/2017.
// Copyright © 2017 Marcin Krzyżanowski. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "PGPMPI.h"
@interface PGPKeyMaterial: NSObject
@property (nonatomic) PGPMPI *n;
@property (nonatomic) PGPMPI *e;
@property (nonatomic) PGPMPI *d;
@property (nonatomic) PGPMPI *p;
@property (nonatomic) PGPMPI *q;
@property (nonatomic) PGPMPI *r;
@property (nonatomic) PGPMPI *g;
@property (nonatomic) PGPMPI *u;
@property (nonatomic) PGPMPI *x;
@property (nonatomic) PGPMPI *y;
@end
//
// PGPLiteralPacket.h
// ObjectivePGP
//
// Created by Marcin Krzyzanowski on 24/05/14.
// Copyright (c) 2014 Marcin Krzyżanowski. All rights reserved.
//
#import "PGPExportableProtocol.h"
#import "PGPPacket.h"
NS_ASSUME_NONNULL_BEGIN
typedef NS_ENUM(UInt8, PGPLiteralPacketFormat) { PGPLiteralPacketBinary = 'b', PGPLiteralPacketText = 't', PGPLiteralPacketTextUTF8 = 'u' };
@interface PGPLiteralPacket : PGPPacket <PGPExportable>
@property (nonatomic) PGPLiteralPacketFormat format;
@property (nonatomic) NSDate *timestamp;
@property (nonatomic, nullable) NSString *filename;
@property (nonatomic) NSData *literalRawData;
- (instancetype)initWithData:(NSData *)rawData;
+ (PGPLiteralPacket *)literalPacket:(PGPLiteralPacketFormat)format withData:(NSData *)rawData;
@end
NS_ASSUME_NONNULL_END
//
// PGPLogging.h
// ObjectivePGP
//
// Created by Marcin Krzyzanowski on 14/05/2017.
// Copyright © 2017 Marcin Krzyżanowski. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
#define PGPLogMacro(_level, _tag, _message) NSLog(@"[%s] %@ %s/%tu %@", _tag, @(_level), __PRETTY_FUNCTION__, __LINE__, _message())
#ifdef DEBUG
#define PGPLogDebug(format, ...) \
PGPLogMacro(0, "ObjectivePGP", (^{ \
return [NSString stringWithFormat:(@"" format), ##__VA_ARGS__]; \
}))
#else
#define PGPLogDebug(format, ...)
#endif
#define PGPLogWarning(format, ...) \
PGPLogMacro(1, "ObjectivePGP", (^{ \
return [NSString stringWithFormat:(@"" format), ##__VA_ARGS__]; \
}))
#define PGPLogError(format, ...) \
PGPLogMacro(2, "ObjectivePGP", (^{ \
return [NSString stringWithFormat:(@"" format), ##__VA_ARGS__]; \
}))
NS_ASSUME_NONNULL_END
//
// OpenPGPMPI.h
// ObjectivePGP
//
// Created by Marcin Krzyzanowski on 04/05/14.
// Copyright (c) 2014 Marcin Krzyżanowski. All rights reserved.
//
#import <ObjectivePGP/PGPBigNum.h>
#import <ObjectivePGP/PGPMacros.h>
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
OBJC_EXTERN NSString * const PGPMPI_N;
OBJC_EXTERN NSString * const PGPMPI_E;
OBJC_EXTERN NSString * const PGPMPI_P;
OBJC_EXTERN NSString * const PGPMPI_G;
OBJC_EXTERN NSString * const PGPMPI_Q;
OBJC_EXTERN NSString * const PGPMPI_D;
OBJC_EXTERN NSString * const PGPMPI_U;
OBJC_EXTERN NSString * const PGPMPI_X;
OBJC_EXTERN NSString * const PGPMPI_R;
OBJC_EXTERN NSString * const PGPMPI_S;
OBJC_EXTERN NSString * const PGPMPI_Y;
OBJC_EXTERN NSString * const PGPMPI_M;
@interface PGPMPI : NSObject <NSCopying>
@property (nonatomic, copy, readonly) NSString *identifier;
@property (nonatomic, readonly) PGPBigNum *bigNum;
/**
* Total bytes, header + body
*/
@property (nonatomic, readonly) NSUInteger packetLength;
PGP_EMPTY_INIT_UNAVAILABLE;
- (instancetype)initWithData:(NSData *)dataToMPI identifier:(NSString *)identifier NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithBigNum:(PGPBigNum *)bigNum identifier:(NSString *)identifier;
- (instancetype)initWithMPIData:(NSData *)mpiData identifier:(NSString *)identifier atPosition:(NSUInteger)position;
- (nullable NSData *)exportMPI;
- (nullable NSData *)bodyData;
@end
NS_ASSUME_NONNULL_END
//
// PGPModificationDetectionCodePacket.h
// ObjectivePGP
//
// Created by Marcin Krzyzanowski on 12/05/14.
// Copyright (c) 2014 Marcin Krzyżanowski. All rights reserved.
//
#import "PGPPacket.h"
@interface PGPModificationDetectionCodePacket : PGPPacket
@property (nonatomic, readonly) NSData *hashData;
- (instancetype)initWithData:(NSData *)data;
@end
//
// PGPOnePassSignaturePacket.h
// ObjectivePGP
//
// Created by Marcin Krzyzanowski on 29/05/14.
// Copyright (c) 2014 Marcin Krzyżanowski. All rights reserved.
//
#import "PGPPacket.h"
#import "PGPExportableProtocol.h"
NS_ASSUME_NONNULL_BEGIN
@class PGPKeyID;
@interface PGPOnePassSignaturePacket : PGPPacket <PGPExportable>
@property (nonatomic) UInt8 version; // The current version is 3.
@property (nonatomic) PGPSignatureType signatureType;
@property (nonatomic) PGPHashAlgorithm hashAlgorith;
@property (nonatomic) PGPPublicKeyAlgorithm publicKeyAlgorithm;
@property (nonatomic) PGPKeyID *keyID; // 8
@property (nonatomic) BOOL notNested;
@end
NS_ASSUME_NONNULL_END
//
// PGPPKCSEme.h
// ObjectivePGP
//
// Created by Marcin Krzyzanowski on 06/06/14.
// Copyright (c) 2014 Marcin Krzyżanowski. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface PGPPKCSEme : NSObject
+ (NSData *)encodeMessage:(NSData *)m keyModulusLength:(NSUInteger)k error:(NSError *__autoreleasing *)error;
+ (NSData *)decodeMessage:(NSData *)m error:(NSError *__autoreleasing *)error;
@end
//
// PGPPKCS.h
// ObjectivePGP
//
// Created by Marcin Krzyzanowski on 22/05/14.
// Copyright (c) 2014 Marcin Krzyżanowski. All rights reserved.
//
#import "PGPTypes.h"
#import <Foundation/Foundation.h>
@interface PGPPKCSEmsa : NSObject
+ (NSData *)encode:(PGPHashAlgorithm)hashAlgorithm message:(NSData *)m encodedMessageLength:(NSUInteger)emLen error:(NSError *__autoreleasing *)error;
@end
//
// PGPPacket.h
// ObjectivePGP
//
// Created by Marcin Krzyzanowski on 06/05/14.
// Copyright (c) 2014 Marcin Krzyżanowski. All rights reserved.
//
#import "PGPExportableProtocol.h"
#import "PGPPacketProtocol.h"
#import "PGPTypes.h"
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
extern const UInt32 PGPUnknownLength;
@interface PGPPacket : NSObject <PGPPacketProtocol, NSCopying, PGPExportable>
@property (nonatomic) BOOL indeterminateLength; // should not be used, but gpg use it
- (instancetype)init NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithHeader:(NSData *)headerData body:(NSData *)bodyData;
+ (nullable NSData *)parsePacketHeader:(NSData *)data headerLength:(UInt32 *)headerLength nextPacketOffset:(nullable NSUInteger *)nextPacketOffset packetTag:(PGPPacketTag *)tag indeterminateLength:(BOOL *)indeterminateLength;
- (NSUInteger)parsePacketBody:(NSData *)packetBody error:(NSError *__autoreleasing *)error;
+ (NSData *)buildPacketOfType:(PGPPacketTag)tag withBody:(PGP_NOESCAPE NSData *(^)(void))body;
@end
NS_ASSUME_NONNULL_END
//
// PGPPacket.h
// ObjectivePGP
//
// Created by Marcin Krzyzanowski on 04/05/14.
// Copyright (c) 2014 Marcin Krzyżanowski. All rights reserved.
//
#import "PGPPacket.h"
#import "PGPTypes.h"
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface PGPPacketFactory : NSObject
+ (nullable PGPPacket *)packetWithData:(NSData *)packetsData offset:(NSUInteger)offset nextPacketOffset:(nullable NSUInteger *)nextPacketOffset;
@end
NS_ASSUME_NONNULL_END
//
// PGPPacketProtocol.h
// ObjectivePGP
//
// Created by Marcin Krzyzanowski on 24/08/2017.
// Copyright © 2017 Marcin Krzyżanowski. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "PGPTypes.h"
@protocol PGPPacketProtocol <NSObject>
@property (nonatomic, readonly) PGPPacketTag tag;
@end
//
// PGPPublicKeyEncryptedSessionKeyPacket.h
// ObjectivePGP
//
// Created by Marcin Krzyzanowski on 06/06/14.
// Copyright (c) 2014 Marcin Krzyżanowski. All rights reserved.
//
#import "PGPPacket.h"
#import "PGPExportableProtocol.h"
NS_ASSUME_NONNULL_BEGIN
@class PGPKeyID, PGPPublicKeyPacket, PGPSecretKeyPacket;
@interface PGPPublicKeyEncryptedSessionKeyPacket : PGPPacket <NSCopying, PGPExportable>
@property (nonatomic) UInt8 version;
@property (nonatomic) PGPKeyID *keyID;
@property (nonatomic) PGPPublicKeyAlgorithm publicKeyAlgorithm;
@property (nonatomic, getter=isEncrypted) BOOL encrypted;
- (BOOL)encrypt:(PGPPublicKeyPacket *)publicKeyPacket sessionKeyData:(NSData *)sessionKeyData sessionKeyAlgorithm:(PGPSymmetricAlgorithm)sessionKeyAlgorithm error:(NSError *__autoreleasing *)error;
- (nullable NSData *)decryptSessionKeyData:(PGPSecretKeyPacket *)secretKeyPacket sessionKeyAlgorithm:(PGPSymmetricAlgorithm *)sessionKeyAlgorithm error:(NSError *__autoreleasing *)error;
@end
NS_ASSUME_NONNULL_END
//
// OpenPGPPublicKey.h
// ObjectivePGP
//
// Created by Marcin Krzyzanowski on 04/05/14.
// Copyright (c) 2014 Marcin Krzyżanowski. All rights reserved.
//
// Tag 6
#import "PGPFingerprint.h"
#import "PGPKeyID.h"
#import "PGPPacketFactory.h"
#import "PGPTypes.h"
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@class PGPMPI;
@interface PGPPublicKeyPacket : PGPPacket <NSCopying, PGPExportable>
@property (nonatomic, readonly) UInt8 version;
@property (nonatomic, readonly) NSDate *createDate;
@property (nonatomic, readonly) UInt16 V3validityPeriod; // obsolete
@property (nonatomic, readonly) PGPPublicKeyAlgorithm publicKeyAlgorithm;
@property (nonatomic, copy, readonly) NSArray<PGPMPI *> *publicMPIArray;
// generated properties
@property (nonatomic, readonly) NSUInteger keySize;
@property (nonatomic, readonly) PGPFingerprint *fingerprint;
@property (nonatomic, readonly) PGPKeyID *keyID;
- (NSData *)exportKeyPacketOldStyle;
- (NSData *)buildKeyBodyData:(BOOL)forceV4;
- (nullable PGPMPI *)publicMPI:(NSString *)identifier;
- (nullable NSData *)encryptData:(NSData *)data withPublicKeyAlgorithm:(PGPPublicKeyAlgorithm)publicKeyAlgorithm;
@end
NS_ASSUME_NONNULL_END
//
// PGPPublicSubKey.h
// ObjectivePGP
//
// Created by Marcin Krzyzanowski on 04/05/14.
// Copyright (c) 2014 Marcin Krzyżanowski. All rights reserved.
//
// Tag 14
#import "PGPPacketFactory.h"
#import "PGPPublicKeyPacket.h"
#import <Foundation/Foundation.h>
@interface PGPPublicSubKeyPacket : PGPPublicKeyPacket
@end
//
// PGPS2K.h
// ObjectivePGP
//
// Created by Marcin Krzyzanowski on 07/05/14.
// Copyright (c) 2014 Marcin Krzyżanowski. All rights reserved.
//
#import <ObjectivePGP/PGPMacros.h>
#import <ObjectivePGP/PGPTypes.h>
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface PGPS2K : NSObject <NSCopying>
@property (nonatomic, readonly) PGPS2KSpecifier specifier;
@property (nonatomic, readonly) PGPHashAlgorithm hashAlgorithm;
// random 8 bytes.
@property (nonatomic, copy, readonly) NSData *salt;
// Iteration count.
@property (nonatomic) UInt32 iterationsCount;
PGP_EMPTY_INIT_UNAVAILABLE
- (instancetype)initWithSpecifier:(PGPS2KSpecifier)specifier hashAlgorithm:(PGPHashAlgorithm)hashAlgorithm NS_DESIGNATED_INITIALIZER;
+ (PGPS2K *)S2KFromData:(NSData *)data atPosition:(NSUInteger)position length:(nullable NSUInteger *)length;
- (nullable NSData *)buildKeyDataForPassphrase:(NSData *)passphrase prefix:(nullable NSData *)prefix salt:(NSData *)salt codedCount:(UInt32)codedCount;
- (nullable NSData *)produceSessionKeyWithPassphrase:(NSString *)passphrase symmetricAlgorithm:(PGPSymmetricAlgorithm)symmetricAlgorithm;
- (nullable NSData *)export:(NSError *__autoreleasing *)error;
@end
NS_ASSUME_NONNULL_END
//
// PGPSecretKeyPacket.h
// ObjectivePGP
//
// Created by Marcin Krzyzanowski on 07/05/14.
// Copyright (c) 2014 Marcin Krzyżanowski. All rights reserved.
//
#import "PGPPublicKeyPacket.h"
#import "PGPS2K.h"
NS_ASSUME_NONNULL_BEGIN
@interface PGPSecretKeyPacket : PGPPublicKeyPacket <NSCopying, PGPExportable>
@property (nonatomic, readonly) PGPS2KUsage s2kUsage;
@property (nonatomic, readonly) PGPS2K *s2k;
@property (nonatomic, readonly) PGPSymmetricAlgorithm symmetricAlgorithm;
@property (nonatomic, nullable, copy, readonly) NSData *ivData;
@property (nonatomic, getter=isEncryptedWithPassphrase, readonly) BOOL encryptedWithPassphrase;
/**
* Decrypt packet
*
* @param passphrase Passphrase
* @param error error
*
* @return Decrypted key on success
*/
- (nullable PGPSecretKeyPacket *)decryptedKeyPacket:(NSString *)passphrase error:(NSError *__autoreleasing *)error;
- (nullable PGPMPI *)secretMPI:(NSString *)identifier;
@end
NS_ASSUME_NONNULL_END
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment