{"record":{"id":"7bf1adb3ad129da7","repo":"theonedev/onedev","slug":"no-public-key-found","errorCode":null,"errorMessage":"No public key found","messagePattern":"No public key found","errorType":"exception","errorClass":"ExplicitException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/util/GpgUtils.java","lineNumber":55,"sourceCode":"\nimport io.onedev.commons.utils.ExplicitException;\nimport io.onedev.commons.utils.StringUtils;\n\npublic class GpgUtils {\n\n\tpublic static List<PGPPublicKey> parse(String publicKeyString) {\n\t\ttry (InputStream in = PGPUtil\n\t\t\t\t.getDecoderStream(new ByteArrayInputStream(publicKeyString.getBytes(StandardCharsets.UTF_8)))) {\n\t\t\tList<PGPPublicKey> publicKeys = new ArrayList<>();\n\t\t\tJcaPGPPublicKeyRingCollection ringCollection = new JcaPGPPublicKeyRingCollection(in);\n\t\t\tIterator<PGPPublicKeyRing> itRing = ringCollection.getKeyRings();\n\t\t\twhile (itRing.hasNext()) {\n\t\t\t\tIterator<PGPPublicKey> itKey = itRing.next().getPublicKeys();\n\t\t\t\twhile (itKey.hasNext()) \n\t\t\t\t\tpublicKeys.add(itKey.next());\n\t\t\t}\n\t\t\tif (publicKeys.isEmpty())\n\t\t\t\tthrow new ExplicitException(\"No public key found\");\n\t\t\treturn publicKeys;\n\t\t} catch (IOException | PGPException e) {\n\t\t\tthrow new RuntimeException(e);\n\t\t}\n\t}\n\n\tpublic static List<String> getEmailAddresses(PGPPublicKey publicKey) {\n\t\tList<String> emailAddresses = new ArrayList<>();\n\t\tIterator<String> it = publicKey.getUserIDs();\n\t\twhile (it.hasNext())\n\t\t\temailAddresses.add(getEmailAddress(it.next()));\n\t\treturn emailAddresses;\n\t}\n\t\n\tpublic static String getEmailAddress(String userId) {\n\t\treturn StringUtils.substringBefore(StringUtils.substringAfter(userId, \"<\"), \">\");\n\t}\n","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/util/GpgUtils.java#L37-L73","documentation":"GpgUtils.parse reads an armored/binary keyring and iterates all key rings collecting public keys. If the ring contains no public keys at all, it throws ExplicitException(\"No public key found\"). ExplicitException means this is an expected, user-facing validation error, not a bug.","triggerScenarios":"Parsing a GPG key block that contains only secret keys or subkey packets the loader cannot expose, an empty file/stream, or an armored blob whose packets decode but yield no PGPPublicKey entries.","commonSituations":"Users pasting a private key where a public key is expected (e.g. verifiers/commit signing settings), pasting text that isn't a public key (passwords, SSH keys), or truncated/corrupted key exports.","solutions":["Export the public key properly: gpg --armor --export <key-id> (or --export-options export-public) and paste that.","Verify the content with gpg --show-keys (or gpg --list-packets) before uploading; ensure it starts with -----BEGIN PGP PUBLIC KEY BLOCK-----.","If the file is a secret keyring, derive the public key: gpg --armor --export <fingerprint>.","Check the file is not empty and was fully copied (no truncation)."],"exampleFix":"// before: pasting secret key\n-----BEGIN PGP PRIVATE KEY BLOCK----- ... // throws 'No public key found'\n// after\ngpg --armor --export ABCD1234 > pubkey.asc  # paste contents of pubkey.asc","handlingStrategy":"validation","validationCode":"String content = keyValue.trim();\nif (content.isEmpty() || !content.contains(\"BEGIN PGP PUBLIC KEY BLOCK\")) {\n    throw new IllegalArgumentException(\"Please provide an armored public key\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    List<PGPPublicKey> keys = GpgUtils.parse(in);\n} catch (ExplicitException e) {\n    // show user-facing message: 'the provided key material contains no public key'\n}","preventionTips":["Validate pasted key text starts with -----BEGIN PGP PUBLIC KEY BLOCK----- before parsing.","Never accept private key blocks where a public key is required.","Verify exports with gpg --show-keys before uploading."],"tags":["gpg","pgp","keys","validation"],"backgroundTag":"empty-result-set","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}