Skip to content

Commit

Permalink
Try to fix the bug of null pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
gefeili committed Nov 21, 2024
1 parent 5badfff commit 7d95b08
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,11 @@ private OutputStream open(
// data is encrypted by AEAD Encrypted Data packet (rfc4880bis10), so write v5 SKESK packet
if (isV5StyleAEAD)
{
writeOpenPGPv5ESKPacket(method, sessionInfo);
writeOpenPGPv5ESKPacket(method, sessionKey);
}
else // data is encrypted by v2 SEIPD (AEAD), so write v6 SKESK packet
{
writeOpenPGPv6ESKPacket(method, aeadDataEncryptor.getAEADAlgorithm(), sessionInfo);
writeOpenPGPv6ESKPacket(method, aeadDataEncryptor.getAEADAlgorithm(), sessionKey);
}
}
// OpenPGP v4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public ContainedPacket generateV6(int kekAlgorithm, int aeadAlgorithm, byte[] se

// If we use this method, roundtripping v5 AEAD is broken.
// TODO: Investigate
private ContainedPacket generateV5ESK(int kekAlgorithm, int aeadAlgorithm, byte[] sessionInfo)
private ContainedPacket generateV5ESK(int kekAlgorithm, int aeadAlgorithm, byte[] sessionKey)
throws PGPException
{
byte[] ikm = getKey(kekAlgorithm);
Expand All @@ -194,15 +194,14 @@ private ContainedPacket generateV5ESK(int kekAlgorithm, int aeadAlgorithm, byte[
random.nextBytes(iv);

int tagLen = AEADUtils.getAuthTagLength(aeadAlgorithm);
byte[] sessionKey = getSessionKey(sessionInfo);
byte[] eskAndTag = getEskAndTag(kekAlgorithm, aeadAlgorithm, sessionKey, ikm, iv, info);
byte[] esk = Arrays.copyOfRange(eskAndTag, 0, eskAndTag.length - tagLen);
byte[] tag = Arrays.copyOfRange(eskAndTag, esk.length, eskAndTag.length);

return SymmetricKeyEncSessionPacket.createV5Packet(kekAlgorithm, aeadAlgorithm, iv, s2k, esk, tag);
}

private ContainedPacket generateV6ESK(int kekAlgorithm, int aeadAlgorithm, byte[] sessionInfo)
private ContainedPacket generateV6ESK(int kekAlgorithm, int aeadAlgorithm, byte[] sessionKey)
throws PGPException
{
byte[] ikm = getKey(kekAlgorithm);
Expand All @@ -218,7 +217,6 @@ private ContainedPacket generateV6ESK(int kekAlgorithm, int aeadAlgorithm, byte[
random.nextBytes(iv);

int tagLen = AEADUtils.getAuthTagLength(aeadAlgorithm);
byte[] sessionKey = getSessionKey(sessionInfo);
byte[] eskAndTag = getEskAndTag(kekAlgorithm, aeadAlgorithm, sessionKey, kek, iv, info);
byte[] esk = Arrays.copyOfRange(eskAndTag, 0, eskAndTag.length - tagLen);
byte[] tag = Arrays.copyOfRange(eskAndTag, esk.length, eskAndTag.length);
Expand Down

0 comments on commit 7d95b08

Please sign in to comment.