Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix NPE when encoding signature without hashed area #2171

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

Draft
vanitasvitae wants to merge 2 commits into bcgit:main
base: main
Choose a base branch
Loading
from pgpainless:fixHashedSubpacketsNull
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion pg/src/main/java/org/bouncycastle/openpgp/PGPSignature.java
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,10 @@ public void encode(
throws IOException
{
// Exportable signatures MUST NOT be exported if forTransfer==true
if (forTransfer && (!getHashedSubPackets().isExportable() || !getUnhashedSubPackets().isExportable()))
if (forTransfer &&
((getHashedSubPackets() != null && !getHashedSubPackets().isExportable()) ||
(getUnhashedSubPackets() != null && !getUnhashedSubPackets().isExportable()))
)
{
return;
}
Expand Down
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,7 @@ public int compare(OpenPGPSignatureChain o1, OpenPGPSignatureChain o2)
{
OpenPGPSignatureChain binding = it.next();
PGPSignature sig = binding.getSignature().getSignature();
if (sig.getHashedSubPackets().isPrimaryUserID())
if (sig.getHashedSubPackets() != null && sig.getHashedSubPackets().isPrimaryUserID())
{
return binding;
}
Expand Down Expand Up @@ -1830,6 +1830,11 @@ private void verifyEmbeddedPrimaryKeyBinding(PGPContentVerifierBuilderProvider c
OpenPGPPolicy policy, Date signatureCreationTime)
throws PGPSignatureException
{
if (signature.getHashedSubPackets() == null)
{
return;
}

int keyFlags = signature.getHashedSubPackets().getKeyFlags();
if ((keyFlags & KeyFlags.SIGN_DATA) != KeyFlags.SIGN_DATA)
{
Expand Down
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.bouncycastle.openpgp.api.test;

import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.api.OpenPGPApi;
import org.bouncycastle.openpgp.api.OpenPGPCertificate;
import org.bouncycastle.openpgp.api.OpenPGPKey;

import java.io.IOException;

public class OpenPGPV3KeyTest
extends APITest
{

private static final String V3Key = "-----BEGIN PGP PRIVATE KEY BLOCK-----\n" +
"\n" +
"lQHYA2JqgDIAAAEEAOYdcIKFQ5ZWBx0D5DKwMMNFcIhFyqmfDJ0v23ehMxOkXN/o\n" +
"HO/43+dq6ZqQn0gNw53Tp9no+EmcCYNrZuN0C4Zu8XHSyY6UB+CqzNkz/CwmV10E\n" +
"dRDipcG1O6scJyy2MWpuOG67til+o+wOLgEkkVkSW8Bl2oqtzVVP4swtKLRZAAUR\n" +
"AAP+JBiyRqt+DYr8GKE85NBX9nlS6DMaxUYgGKgibR5OSVsJjIjNUtG0sNmODjTN\n" +
"sPMZqlNln6wS3l7APMWNoStNGc9JG9Puz3eR2W69lPDzhuxuxrHIUBO+3UlEQB/p\n" +
"N3NPhnwCjh3OWHSMM6rzsX5ExUv0Z4FypnzvMG1x6GRJDVECAO6PyY8NDHsktMVN\n" +
"HAdgC61iIOz+GbLhNGeikuB+DQpSoyckAF0N5reBxRbyjzNZQ7aVvWpxigUp5OdK\n" +
"HMK7YcwTAgD275bcqhd+oWHDhyesi6RVswlqGfix48qahf9wOmDkc0nzp8evy/4V\n" +
"4Qu5zUJGVzi4aEIbFaAnc5lMD9/ydTNjAf485vh4MDFRd3tPvx9mPrHQgaArCBX8\n" +
"9oImPDk0oaKixwSIFzXeg1qZQeLiwv26Fs8gawWsLVZpR4+zZc1nhZlGnrQpSm9o\n" +
"biBRLiBTbWl0aCA8MTIzNDUuNjc4OUBjb21wdXNlcnZlLmNvbT6JAJUDBRBiaoAy\n" +
"VU/izC0otFkBAYIsBACykJ7s82vqCIKewgLpFuqoVGjlfwn9z+G1oa7vr/GxA/mF\n" +
"Dr4E8rZ1ytUFMUCfzy52FfOtDQUVUeOpAraWQ4JfjXkHuDuZcW2VRh2ctT/hVHG7\n" +
"1GgOWUBH3EeXASSnFjvUVE39vEjEsidaMxZtMj5jmtieTMB8pSG1QJXPXGoNyQ==\n" +
"=p7Lr\n" +
"-----END PGP PRIVATE KEY BLOCK-----\n";

public static void main(String[] args)
{
runTest(new OpenPGPV3KeyTest());
}

@Override
public String getName()
{
return "OpenPGPV3KeyTest";
}

@Override
protected void performTestWith(OpenPGPApi api)
throws PGPException, IOException
{
OpenPGPKey key = api.readKeyOrCertificate().parseKey(V3Key);
isNotNull(key.getEncoded());

OpenPGPCertificate certificate = key.toCertificate();
isNotNull(certificate.getEncoded());
}
}

AltStyle によって変換されたページ (->オリジナル) /