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

Objective pgp2 #234

Open
wants to merge 95 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
0543677
clean. fresh start.
krzyzanowskim Jan 17, 2015
f44efc7
Initials reading headers. Remove cocoapods
krzyzanowskim Jan 17, 2015
a69aa73
Add test target
krzyzanowskim Jan 17, 2015
fe3746f
Tests for parsing header data
krzyzanowskim Jan 17, 2015
1a0dc0f
fix Two-Octet Lengths
krzyzanowskim Jan 17, 2015
b701615
Rework header api
krzyzanowskim Jan 18, 2015
f6a838d
read PGPPublicKeyPacket
krzyzanowskim Jan 18, 2015
f74c0c3
PGPUserIDPacket. Fix reading ints from stream (BE->LE is already done)
krzyzanowskim Jan 19, 2015
55a4384
Signature initials
krzyzanowskim Jan 19, 2015
98e898f
work on reading signature packet
krzyzanowskim Jan 20, 2015
c16155a
Signature packet and subpackets - not done yet
krzyzanowskim Jan 21, 2015
93f569d
subpackets
krzyzanowskim Jan 21, 2015
cd0c818
fix parsing subpackets. Intorduce PGPFunctions
krzyzanowskim Jan 21, 2015
20bef31
minor, error checking
krzyzanowskim Jan 21, 2015
17493d7
proper key data for test
krzyzanowskim Jan 21, 2015
2423a8d
PGPSignaturePacket valueOfSubacketOfType
krzyzanowskim Jan 21, 2015
ed3d63a
read bytes to buffer
krzyzanowskim Jan 29, 2015
6f3c0f6
eadUInt32BytesAppendTo:
krzyzanowskim Jan 29, 2015
0be6190
fix 32
krzyzanowskim Jan 29, 2015
40d5698
Store hashed data of signature
krzyzanowskim Jan 30, 2015
ac40526
hashedData is not public
krzyzanowskim Jan 30, 2015
aa91e6f
pgpNumBits
krzyzanowskim Feb 2, 2015
4ab03ee
Whole a lot a things. Signature. PGPMPI. PacketHeader refactoring and…
krzyzanowskim Feb 3, 2015
8ec518b
partial and indeterminate length of headers
krzyzanowskim Feb 4, 2015
df0e8f2
Write public key packet
krzyzanowskim Feb 5, 2015
f7a65db
write user id packet
krzyzanowskim Feb 5, 2015
e56622a
Initial work to output signature packet
krzyzanowskim Feb 13, 2015
bd80f1d
write Big Endian. Refactor method names for clear BE->LE->BE conversion.
krzyzanowskim Feb 17, 2015
db58f1e
Read and Write all known subpacket types. Not supported marked as TODO
krzyzanowskim Feb 17, 2015
8c2b49e
Fix exporting signature + test
krzyzanowskim Feb 17, 2015
a6d82ca
buildData with NSData
krzyzanowskim Feb 17, 2015
f37ddd5
more build data
krzyzanowskim Feb 17, 2015
25ba5f2
MPI buildData
krzyzanowskim Feb 17, 2015
a6ada3a
computeSignatureHashOverKey
krzyzanowskim Feb 17, 2015
c6a067c
Refactor signature calculation (in progress)
krzyzanowskim Feb 18, 2015
effe729
MPI order matter. buildDataToSign is a function.
krzyzanowskim Feb 19, 2015
1a6d6c0
Calculate fingerprint and key ids
krzyzanowskim Feb 19, 2015
39e362d
mpiForIdentifier and key id v3
krzyzanowskim Feb 20, 2015
c148211
jefferyq2 Jun 6, 2024
41df2f3
jefferyq2 Jun 10, 2024
e645d73
jefferyq2 Jun 6, 2024
ea04722
jefferyq2 Jun 10, 2024
1d4b799
jefferyq2 Jun 10, 2024
57ce04a
jefferyq2 Jun 10, 2024
c3fe7ad
jefferyq2 Jun 10, 2024
39452fe
jefferyq2 Jun 10, 2024
cd2ee16
jefferyq2 Jun 10, 2024
6004031
jefferyq2 Nov 10, 2024
f7080cb
jefferyq2 Nov 10, 2024
78509c7
jefferyq2 Nov 10, 2024
49304f9
jefferyq2 Nov 10, 2024
7d17f09
jefferyq2 Nov 10, 2024
04638f5
jefferyq2 Jun 6, 2024
d083f27
jefferyq2 Jun 10, 2024
50a8697
jefferyq2 Jun 6, 2024
81096d0
jefferyq2 Jun 10, 2024
701d267
jefferyq2 Jun 10, 2024
d5fd255
jefferyq2 Jun 10, 2024
d6523b4
jefferyq2 Jun 10, 2024
2b2fb44
jefferyq2 Jun 10, 2024
846de1c
jefferyq2 Jun 10, 2024
5b1285b
jefferyq2 Nov 10, 2024
6da93c6
jefferyq2 Nov 10, 2024
7a17aae
jefferyq2 Nov 10, 2024
1e81895
jefferyq2 Nov 10, 2024
e50ba00
jefferyq2 Nov 10, 2024
e6c710c
jefferyq2 Nov 11, 2024
9121741
jefferyq2 Nov 11, 2024
92a57a5
jefferyq2 Nov 11, 2024
f90196c
jefferyq2 Nov 11, 2024
4f283ff
jefferyq2 Nov 11, 2024
77b45b5
jefferyq2 Nov 11, 2024
df4e60a
jefferyq2 Nov 11, 2024
9c4adce
jefferyq2 Nov 11, 2024
ca8fda4
jefferyq2 Nov 11, 2024
b8ace34
jefferyq2 Nov 11, 2024
91fe753
jefferyq2 Nov 11, 2024
f1e761a
jefferyq2 Nov 11, 2024
df997e2
jefferyq2 Nov 11, 2024
00c4d5c
jefferyq2 Nov 11, 2024
734e337
jefferyq2 Nov 11, 2024
434b447
jefferyq2 Nov 11, 2024
504f45e
jefferyq2 Nov 11, 2024
8770fe6
jefferyq2 Nov 11, 2024
1a1b5ad
jefferyq2 Nov 11, 2024
8b934fb
jefferyq2 Nov 11, 2024
1c3b6ba
jefferyq2 Nov 12, 2024
69212ac
jefferyq2 Nov 12, 2024
15461a8
jefferyq2 Nov 12, 2024
5b740e7
jefferyq2 Nov 12, 2024
1e1492d
jefferyq2 Nov 19, 2024
f7db08b
jefferyq2 Nov 19, 2024
3a6dafe
jefferyq2 Nov 19, 2024
725cf32
jefferyq2 Nov 23, 2024
4dae99b
jefferyq2 Nov 23, 2024
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
Prev Previous commit
Next Next commit
write Big Endian. Refactor method names for clear BE->LE->BE conversion.
krzyzanowskim committed Feb 17, 2015
commit bd80f1de3cd24c40778f75197f89ec1bb78d8b07
10 changes: 5 additions & 5 deletions ObjectivePGP/Categories/NSInputStream+PGP.h
Original file line number Diff line number Diff line change
@@ -12,11 +12,11 @@
- (UInt8) readUInt8; // BE->LE
- (UInt8) readUInt8:(UInt8 *)bytes;
- (UInt8) readUInt8BytesAppendTo:(NSMutableData *)data;
- (UInt16) readUInt16; // BE->LE
- (UInt16) readUInt16:(UInt8 *)readBytes;
- (UInt16) readUInt16BytesAppendTo:(NSMutableData *)data;
- (UInt32) readUInt32; // BE->LE
- (UInt32) readUInt32:(UInt8 *)readBytes;
- (UInt16) readUInt16BE; // BE->LE
- (UInt16) readUInt16BE:(UInt8 *)readBytes;
- (UInt16) readUInt16BEBytesAppendTo:(NSMutableData *)data;
- (UInt32) readUInt32BE; // BE->LE
- (UInt32) readUInt32BE:(UInt8 *)readBytes;
- (UInt32) readUInt32BytesAppendTo:(NSMutableData *)data;
- (NSData *) readDataLength:(NSUInteger)length;
@end
26 changes: 15 additions & 11 deletions ObjectivePGP/Categories/NSInputStream+PGP.m
Original file line number Diff line number Diff line change
@@ -37,38 +37,40 @@ - (UInt8) readUInt8:(UInt8 *)readBytes
return result;
}

- (UInt16) readUInt16
- (UInt16) readUInt16BE
{
return [self readUInt16:nil];
return [self readUInt16BE:nil];
}

- (UInt16) readUInt16BytesAppendTo:(NSMutableData *)data
- (UInt16) readUInt16BEBytesAppendTo:(NSMutableData *)data
{
NSParameterAssert(data);

UInt16 result;
UInt8 bytes[2];
result = [self readUInt16:bytes];
result = [self readUInt16BE:bytes];
[data appendBytes:bytes length:sizeof(bytes)];
return result;
}

- (UInt16) readUInt16:(UInt8 *)readBytes
- (UInt16) readUInt16BE:(UInt8 *)readBytes
{
UInt8 bytes[2];
if ([self read:bytes maxLength:sizeof(bytes)] > 0) {
if (readBytes) {
bcopy(bytes, readBytes, sizeof(bytes));
}
return bytes[0] << 8 | bytes[1];
UInt16 value = 0;
bcopy(bytes, &value, sizeof(bytes));
return CFSwapInt16BigToHost(value);
}
NSAssert(false,@"readUInt16 failed");
return 0;
}

- (UInt32) readUInt32
- (UInt32) readUInt32BE
{
return [self readUInt32:nil];
return [self readUInt32BE:nil];
}

- (UInt32) readUInt32BytesAppendTo:(NSMutableData *)data
@@ -77,20 +79,22 @@ - (UInt32) readUInt32BytesAppendTo:(NSMutableData *)data

UInt32 result;
UInt8 bytes[4];
result = [self readUInt32:bytes];
result = [self readUInt32BE:bytes];
[data appendBytes:bytes length:sizeof(bytes)];
return result;
}


- (UInt32) readUInt32:(UInt8 *)readBytes
- (UInt32) readUInt32BE:(UInt8 *)readBytes
{
UInt8 bytes[4];
if ([self read:bytes maxLength:sizeof(bytes)] > 0) {
if (readBytes) {
bcopy(bytes, readBytes, sizeof(bytes));
}
return bytes[0] << 24 | bytes[1] << 16 | bytes[2] << 8 | bytes[3];
UInt32 value;
bcopy(bytes, &value, sizeof(bytes));
return CFSwapInt32BigToHost(value);
}
NSAssert(false,@"readUInt32 failed");
return 0;
4 changes: 2 additions & 2 deletions ObjectivePGP/Categories/NSOutputStream+PGP.h
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@

@interface NSOutputStream (PGP)
- (BOOL) writeUInt8:(UInt8)value;
- (BOOL) writeUInt16:(UInt16)value;
- (BOOL) writeUInt32:(UInt32)value;
- (BOOL) writeUInt16BE:(UInt16)value;
- (BOOL) writeUInt32BE:(UInt32)value;
- (BOOL) writeData:(NSData *)data;
@end
10 changes: 6 additions & 4 deletions ObjectivePGP/Categories/NSOutputStream+PGP.m
Original file line number Diff line number Diff line change
@@ -21,21 +21,23 @@ - (BOOL) writeUInt8:(UInt8)value

}

- (BOOL) writeUInt16:(UInt16)value
- (BOOL) writeUInt16BE:(UInt16)value
{
UInt16 valueBE = CFSwapInt16HostToBig(value);
UInt8 bytes[2];
bcopy(&value, bytes, sizeof(bytes));
bcopy(&valueBE, bytes, sizeof(bytes));
if ([self write:bytes maxLength:sizeof(bytes)] == -1) {
return NO;
}
return YES;
}


- (BOOL) writeUInt32:(UInt32)value
- (BOOL) writeUInt32BE:(UInt32)value
{
UInt32 valueBE = CFSwapInt32BigToHost(value);
UInt8 bytes[4];
bcopy(&value, bytes, sizeof(bytes));
bcopy(&valueBE, bytes, sizeof(bytes));
if ([self write:bytes maxLength:sizeof(bytes)] == -1) {
return NO;
}
2 changes: 1 addition & 1 deletion ObjectivePGP/PGPMPI.m
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ + (instancetype) readFromStream:(NSInputStream *)inputStream error:(NSError * __

PGPMPI *mpi = [[PGPMPI alloc] init];

UInt16 bits = [inputStream readUInt16];
UInt16 bits = [inputStream readUInt16BE];
NSUInteger bytesCount = (bits + 7) / 8;

UInt8 *mpiBuffer = calloc(1, bytesCount);
6 changes: 3 additions & 3 deletions ObjectivePGP/PGPPacketHeader.m
Original file line number Diff line number Diff line change
@@ -152,7 +152,7 @@ - (BOOL) readNewLengthFromStream:(NSInputStream *)inputStream error:(NSError * _
// 4.2.2.3. Five-Octet Length
// bodyLen = (2nd_octet << 24) | (3rd_octet << 16) |
// (4th_octet << 8) | 5th_octet
self.bodyLength = [inputStream readUInt32];
self.bodyLength = [inputStream readUInt32BE];
//self.bodyLength = (secondOctet << 24) | (thirdOctet << 16) | (fourthOctet << 8) | fifthOctet;
} else if (firstOctet >= 224 && firstOctet < 255) {
// 4.2.2.4. Partial Body Length
@@ -182,12 +182,12 @@ - (BOOL) readOldLengthFromStream:(NSInputStream *)inputStream lengthType:(UInt8)
case 1:
{
// value of a two-octet scalar is ((n[0] << 8) + n[1]).
self.bodyLength = [inputStream readUInt16];
self.bodyLength = [inputStream readUInt16BE];
}
break;
case 2:
{
self.bodyLength = [inputStream readUInt32];
self.bodyLength = [inputStream readUInt32BE];
}
break;
case 3:
8 changes: 4 additions & 4 deletions ObjectivePGP/Packets/PGPPublicKeyPacket.m
Original file line number Diff line number Diff line change
@@ -34,15 +34,15 @@ + (instancetype) readFromStream:(NSInputStream *)inputStream maxLength:(NSUInteg
}

// A four-octet number denoting the time that the key was created.
UInt32 timestamp = [inputStream readUInt32];
UInt32 timestamp = [inputStream readUInt32BE];
if (timestamp) {
packet.createDate = [NSDate dateWithTimeIntervalSince1970:timestamp];
}

if (version == 0x03) {
// A two-octet number denoting the time in days that this key is
// valid. If this number is zero, then it does not expire.
UInt16 validityPeriod = [inputStream readUInt16];
UInt16 validityPeriod = [inputStream readUInt16BE];
packet.validityPeriod = validityPeriod;
}

@@ -125,9 +125,9 @@ - (BOOL) writeToStream:(NSOutputStream *)outputStream error:(NSError * __autorel
NSParameterAssert(outputStream);

[outputStream writeUInt8:self.version];
[outputStream writeUInt32:[self.createDate timeIntervalSince1970]];
[outputStream writeUInt32BE:[self.createDate timeIntervalSince1970]];
if (self.version == 0x03) {
[outputStream writeUInt16:self.validityPeriod];
[outputStream writeUInt16BE:self.validityPeriod];
}
[outputStream writeUInt8:self.keyAlgorithm];
for (PGPMPI *mpi in self.MPIs) {
22 changes: 12 additions & 10 deletions ObjectivePGP/Packets/PGPSignaturePacket.m
Original file line number Diff line number Diff line change
@@ -70,7 +70,7 @@ - (BOOL) readV3FromStream:(NSInputStream *)inputStream error:(NSError * __autore
self.signatureType = [inputStream readUInt8];

// - Four-octet creation time
UInt32 timestamp = [inputStream readUInt32];
UInt32 timestamp = [inputStream readUInt32BE];
self.creationDate = [NSDate dateWithTimeIntervalSince1970:timestamp];

//Eight-octet Key ID of signer
@@ -84,7 +84,7 @@ - (BOOL) readV3FromStream:(NSInputStream *)inputStream error:(NSError * __autore
self.hashAlgoritm = [inputStream readUInt8];

// Two-octet field holding the left 16 bits of the signed hash value.
UInt16 signedHashValue = [inputStream readUInt16];
UInt16 signedHashValue = [inputStream readUInt16BE];
self.hashValue = signedHashValue;

// 5.2.2. One or more multiprecision integers comprising the signature. This portion is algorithm specific Signature
@@ -145,7 +145,7 @@ - (BOOL) readV4FromStream:(NSInputStream *)inputStream error:(NSError * __autore
self.hashAlgoritm = [inputStream readUInt8BytesAppendTo:toHashData];

// Two-octet scalar octet count for following hashed subpacket data.
UInt16 hashedSubpacketsBytes = [inputStream readUInt16BytesAppendTo:toHashData];
UInt16 hashedSubpacketsBytes = [inputStream readUInt16BEBytesAppendTo:toHashData];
UInt16 consumedBytes = 0;
if (hashedSubpacketsBytes) {
while (consumedBytes < hashedSubpacketsBytes) {
@@ -162,7 +162,7 @@ - (BOOL) readV4FromStream:(NSInputStream *)inputStream error:(NSError * __autore
//-->HASHED

// Two-octet scalar octet count for following unhashed subpacket data.
UInt16 unhashedSubpacketsBytes = [inputStream readUInt16];
UInt16 unhashedSubpacketsBytes = [inputStream readUInt16BE];
consumedBytes = 0;
if (unhashedSubpacketsBytes) {
while (consumedBytes < unhashedSubpacketsBytes) {
@@ -176,7 +176,7 @@ - (BOOL) readV4FromStream:(NSInputStream *)inputStream error:(NSError * __autore
}

// Two-octet field holding the left 16 bits of the signed hash value.
UInt16 signedHashValue = [inputStream readUInt16];
UInt16 signedHashValue = [inputStream readUInt16BE];
self.hashValue = signedHashValue;

// One or more multiprecision integers comprising the signature.
@@ -262,19 +262,21 @@ - (BOOL) writeToStream:(NSOutputStream *)outputStream error:(NSError * __autorel
{
NSParameterAssert(outputStream);

NSMutableData *outputData = [NSMutableData dataWithCapacity:5];

[outputStream writeUInt8:self.version];
switch (self.version) {
case 0x04:
{
[outputStream writeUInt8:self.signatureType];
[outputStream writeUInt8:self.publicKeyAlgorithm];
[outputStream writeUInt8:self.hashAlgoritm];
[outputStream writeUInt16:self.hashedSubpackets.count];
[outputStream writeUInt16BE:self.hashedSubpackets.count];
//TODO: hashed subpackets here
//TODO: Two-octet field holding the left 16 bits of the signed hash value.
[outputStream writeUInt16:self.hashValue]; //TODO: calculate hash first
[outputStream writeUInt16BE:self.hashValue]; //TODO: calculate hash first
NSAssert(self.hashValue != 0, @"Calculate hash");
[outputStream writeUInt16:self.unhashedSubpackets.count];
[outputStream writeUInt16BE:self.unhashedSubpackets.count];
//TODO: unhashed subpackets here
for (PGPMPI *mpi in self.MPIs) {
if (![mpi writeToStream:outputStream error:error]) {
@@ -287,12 +289,12 @@ - (BOOL) writeToStream:(NSOutputStream *)outputStream error:(NSError * __autorel
{
[outputStream writeUInt8:0x05];
[outputStream writeUInt8:self.signatureType];
[outputStream writeUInt32:[self.creationDate timeIntervalSince1970]];
[outputStream writeUInt32BE:[self.creationDate timeIntervalSince1970]];

NSAssert(self.issuerKeyID, @"Missing issued key id");
[outputStream writeData:self.issuerKeyID.octetsData];

[outputStream writeUInt16:self.hashValue];
[outputStream writeUInt16BE:self.hashValue];
NSAssert(self.hashValue != 0, @"Calculate hash");

for (PGPMPI *mpi in self.MPIs) {
4 changes: 2 additions & 2 deletions ObjectivePGPTests/PGPInputStreamCategoryTests.m
Original file line number Diff line number Diff line change
@@ -45,7 +45,7 @@ - (void) testReadUInt16
[stream open];
XCTAssertNotNil(stream);
UInt8 readBytes[2];
UInt16 result = [stream readUInt16:readBytes];
UInt16 result = [stream readUInt16BE:readBytes];
XCTAssertEqual(result, 0x0102);
for (int i = 0; i < sizeof(bytes); i++) {
XCTAssertEqual(readBytes[i], bytes[i]);
@@ -60,7 +60,7 @@ - (void) testReadUInt32
[stream open];
XCTAssertNotNil(stream);
UInt8 readBytes[4];
UInt32 result = [stream readUInt32:readBytes];
UInt32 result = [stream readUInt32BE:readBytes];
XCTAssertEqual(result, 0x01020304);
for (int i = 0; i < sizeof(bytes); i++) {
XCTAssertEqual(readBytes[i], bytes[i]);