René's URL Explorer Experiment


Title: fix: more robust handling of whitespace and alternate pem format by Vikas-Sajanani · Pull Request #232 · spotify/github-java-client · GitHub

Open Graph Title: fix: more robust handling of whitespace and alternate pem format by Vikas-Sajanani · Pull Request #232 · spotify/github-java-client

X Title: fix: more robust handling of whitespace and alternate pem format by Vikas-Sajanani · Pull Request #232 · spotify/github-java-client

Description: I'll explain line by line what changed from the original version to make the code more robust for handling various PEM key formats. Let me break down the key differences: Original Version javaprivate static final Pattern PKCS1_PEM_KEY_PATTERN = Pattern.compile("(?m)(?s)^---*BEGIN RSA PRIVATE KEY.*---*$(.*)^---*END.*---*$.*"); New Version java// Matches RSA PEM format private static final Pattern PKCS1_PEM_KEY_PATTERN = Pattern.compile("(?m)(?s)^\\s*-{3,}\\s*BEGIN\\s+RSA\\s+PRIVATE\\s+KEY\\s*-{3,}\\s*$(.*)^\\s*-{3,}\\s*END\\s+RSA\\s+PRIVATE\\s+KEY\\s*-{3,}\\s*$.*"); // Matches PKCS8 PEM format private static final Pattern PKCS8_PEM_KEY_PATTERN = Pattern.compile("(?m)(?s)^\\s*-{3,}\\s*BEGIN\\s+PRIVATE\\s+KEY\\s*-{3,}\\s*$(.*)^\\s*-{3,}\\s*END\\s+PRIVATE\\s+KEY\\s*-{3,}\\s*$.*"); Changes and Reasons: Added whitespace flexibility (\s*): Original: ^---BEGIN RSA PRIVATE KEY.---$ New: ^\s-{3,}\sBEGIN\s+RSA\s+PRIVATE\s+KEY\s-{3,}\s*$ Reason: The original pattern didn't handle spaces well. The new pattern allows for spaces before, after, and within the delimiters. Explicit dash counting (-{3,}): Original: ---* (three dashes followed by zero or more dashes) New: -{3,} (three or more dashes) Reason: More explicit and readable way to handle variable numbers of dashes. Explicit whitespace between words (\s+): Original: No explicit handling of spaces between words New: BEGIN\s+RSA\s+PRIVATE\s+KEY Reason: Specifically allows for extra spaces between words like "BEGIN", "RSA", etc. Full END pattern matching: Original: ^---END.---$ New: ^\s-{3,}\sEND\s+RSA\s+PRIVATE\s+KEY\s-{3,}\s*$ Reason: The original pattern used .* after "END", which was too permissive. The new pattern requires the full "END RSA PRIVATE KEY" text, preventing incorrect matches. Added PKCS8 pattern: Original: Only had PKCS1 pattern New: Added separate pattern for PKCS8 format (BEGIN PRIVATE KEY without "RSA") Reason: Some PEM files use the PKCS8 format header/footer without "RSA" in the text. Original loadKeySpec Method javapublic static Optional loadKeySpec(final byte[] privateKey) { final Matcher isPEM = PKCS1_PEM_KEY_PATTERN.matcher(new String(privateKey)); if (!isPEM.matches()) { return Optional.empty(); } byte[] pkcs1Key = Base64.getMimeDecoder().decode(isPEM.group(1)); byte[] pkcs8Key = toPkcs8(pkcs1Key); final PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(pkcs8Key); return Optional.of(keySpec); } New loadKeySpec Method javapublic static Optional loadKeySpec(final byte[] privateKey) { final String keyString = new String(privateKey); // Try to match PKCS1 (RSA) format first Matcher isPKCS1 = PKCS1_PEM_KEY_PATTERN.matcher(keyString); if (isPKCS1.matches()) { return extractKeySpec(isPKCS1.group(1), true); } // Try to match PKCS8 format Matcher isPKCS8 = PKCS8_PEM_KEY_PATTERN.matcher(keyString); if (isPKCS8.matches()) { return extractKeySpec(isPKCS8.group(1), false); } // Not a recognized PEM format return Optional.empty(); } private static Optional extractKeySpec(String base64Content, boolean isPKCS1) { try { // Remove all whitespace base64Content = base64Content.replaceAll("\\s+", ""); // Check if content is empty after whitespace removal if (base64Content.isEmpty()) { return Optional.empty(); } // Decode the base64 content byte[] decodedKey = Base64.getDecoder().decode(base64Content); // Convert to PKCS8 if necessary byte[] pkcs8Key = isPKCS1 ? toPkcs8(decodedKey) : decodedKey; return Optional.of(new PKCS8EncodedKeySpec(pkcs8Key)); } catch (IllegalArgumentException e) { // Failed to decode base64 content return Optional.empty(); } } Changes and Reasons: Dual format support: Original: Only tested against PKCS1 pattern New: Tests against both PKCS1 and PKCS8 patterns Reason: Provides support for both key formats, increasing compatibility Extracted shared logic: Original: All processing in the main method New: Dedicated extractKeySpec method for common processing Reason: Better code organization and avoids duplication Whitespace handling: Original: Used Base64.getMimeDecoder() New: Explicitly removes all whitespace with replaceAll("\s+", "") Reason: More explicit control over whitespace handling Empty content detection: Original: No explicit check for empty content New: if (base64Content.isEmpty()) { return Optional.empty(); } Reason: Prevents trying to decode empty strings, which caused one of your test failures Exception handling: Original: No exception handling New: try/catch block for IllegalArgumentException Reason: More robust handling of invalid base64 content Decoder change: Original: Base64.getMimeDecoder() New: Base64.getDecoder() Reason: After explicitly handling whitespace, the standard decoder is more appropriate Conditional PKCS8 conversion: Original: Always converted to PKCS8 New: byte[] pkcs8Key = isPKCS1 ? toPkcs8(decodedKey) : decodedKey; Reason: Only converts when necessary (PKCS8 format is already in the right format)

Open Graph Description: I'll explain line by line what changed from the original version to make the code more robust for handling various PEM key formats. Let me break down the key differences: Original Version javap...

X Description: I'll explain line by line what changed from the original version to make the code more robust for handling various PEM key formats. Let me break down the key differences: Original Version j...

Opengraph URL: https://github.com/spotify/github-java-client/pull/232

X: @github

direct link

Domain: patch-diff.githubusercontent.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:dc4e0e9b-464a-4424-aae7-6a0bf6983b58
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idDA8A:6230D:2A366D:373D3B:697826BE
html-safe-nonce38ba4c8b352512901eb341a551d2c3277a24cd21c6d23d9c03a8b9b723323378
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQThBOjYyMzBEOjJBMzY2RDozNzNEM0I6Njk3ODI2QkUiLCJ2aXNpdG9yX2lkIjoiODc2NjU4MzMzODc3Mzc4NDI1NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac564bec78fc4a1443abe5f1fb6fc40c9284736dc51116331aeb075916b00cf7e5
hovercard-subject-tagpull_request:2511558877
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/spotify/github-java-client/pull/232/files
twitter:imagehttps://avatars.githubusercontent.com/u/142914809?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/142914809?s=400&v=4
og:image:altI'll explain line by line what changed from the original version to make the code more robust for handling various PEM key formats. Let me break down the key differences: Original Version javap...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None2981c597c945c1d90ac6fa355ce7929b2f413dfe7872ca5c435ee53a24a1de50
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/spotify/github-java-client git https://github.com/spotify/github-java-client.git
octolytics-dimension-user_id251374
octolytics-dimension-user_loginspotify
octolytics-dimension-repository_id254401089
octolytics-dimension-repository_nwospotify/github-java-client
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id254401089
octolytics-dimension-repository_network_root_nwospotify/github-java-client
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release8cc3e064910e26648760f573a358cfc07c97b42c
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://patch-diff.githubusercontent.com/spotify/github-java-client/pull/232/files#start-of-content
https://patch-diff.githubusercontent.com/
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Fspotify%2Fgithub-java-client%2Fpull%2F232%2Ffiles
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Fspotify%2Fgithub-java-client%2Fpull%2F232%2Ffiles
Sign up https://patch-diff.githubusercontent.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=spotify%2Fgithub-java-client
Reloadhttps://patch-diff.githubusercontent.com/spotify/github-java-client/pull/232/files
Reloadhttps://patch-diff.githubusercontent.com/spotify/github-java-client/pull/232/files
Reloadhttps://patch-diff.githubusercontent.com/spotify/github-java-client/pull/232/files
spotify https://patch-diff.githubusercontent.com/spotify
github-java-clienthttps://patch-diff.githubusercontent.com/spotify/github-java-client
Notifications https://patch-diff.githubusercontent.com/login?return_to=%2Fspotify%2Fgithub-java-client
Fork 97 https://patch-diff.githubusercontent.com/login?return_to=%2Fspotify%2Fgithub-java-client
Star 148 https://patch-diff.githubusercontent.com/login?return_to=%2Fspotify%2Fgithub-java-client
Code https://patch-diff.githubusercontent.com/spotify/github-java-client
Issues 11 https://patch-diff.githubusercontent.com/spotify/github-java-client/issues
Pull requests 7 https://patch-diff.githubusercontent.com/spotify/github-java-client/pulls
Actions https://patch-diff.githubusercontent.com/spotify/github-java-client/actions
Security 0 https://patch-diff.githubusercontent.com/spotify/github-java-client/security
Insights https://patch-diff.githubusercontent.com/spotify/github-java-client/pulse
Code https://patch-diff.githubusercontent.com/spotify/github-java-client
Issues https://patch-diff.githubusercontent.com/spotify/github-java-client/issues
Pull requests https://patch-diff.githubusercontent.com/spotify/github-java-client/pulls
Actions https://patch-diff.githubusercontent.com/spotify/github-java-client/actions
Security https://patch-diff.githubusercontent.com/spotify/github-java-client/security
Insights https://patch-diff.githubusercontent.com/spotify/github-java-client/pulse
Sign up for GitHub https://patch-diff.githubusercontent.com/signup?return_to=%2Fspotify%2Fgithub-java-client%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://patch-diff.githubusercontent.com/login?return_to=%2Fspotify%2Fgithub-java-client%2Fissues%2Fnew%2Fchoose
Vikas-Sajananihttps://patch-diff.githubusercontent.com/Vikas-Sajanani
spotify:masterhttps://patch-diff.githubusercontent.com/spotify/github-java-client/tree/master
Vikas-Sajanani:fix/trim-pem-whitespacehttps://patch-diff.githubusercontent.com/Vikas-Sajanani/github-java-client/tree/fix/trim-pem-whitespace
Conversation 0 https://patch-diff.githubusercontent.com/spotify/github-java-client/pull/232
Commits 3 https://patch-diff.githubusercontent.com/spotify/github-java-client/pull/232/commits
Checks 3 https://patch-diff.githubusercontent.com/spotify/github-java-client/pull/232/checks
Files changed https://patch-diff.githubusercontent.com/spotify/github-java-client/pull/232/files
Please reload this pagehttps://patch-diff.githubusercontent.com/spotify/github-java-client/pull/232/files
fix: more robust handling of whitespace and alternate pem format https://patch-diff.githubusercontent.com/spotify/github-java-client/pull/232/files#top
Show all changes 3 commits https://patch-diff.githubusercontent.com/spotify/github-java-client/pull/232/files
2db92ee fix: more robust handling of whitespace and alternate pem format with… Vikas-Sajanani May 10, 2025 https://patch-diff.githubusercontent.com/spotify/github-java-client/pull/232/commits/2db92eeef81b76cc285f32a1fe0d27fd66ab2659
ae85938 fix: format changes for jdk 17 pipeline Vikas-Sajanani May 10, 2025 https://patch-diff.githubusercontent.com/spotify/github-java-client/pull/232/commits/ae85938fb8853023d80818b6375c2a333bbea7dd
438ba18 fix: add newline char to clear pipeline Vikas-Sajanani May 25, 2025 https://patch-diff.githubusercontent.com/spotify/github-java-client/pull/232/commits/438ba18c43f1b85846b1c5a6b47e752442edd8d9
Clear filters https://patch-diff.githubusercontent.com/spotify/github-java-client/pull/232/files
Please reload this pagehttps://patch-diff.githubusercontent.com/spotify/github-java-client/pull/232/files
Please reload this pagehttps://patch-diff.githubusercontent.com/spotify/github-java-client/pull/232/files
PKCS1PEMKey.java https://patch-diff.githubusercontent.com/spotify/github-java-client/pull/232/files#diff-d26afe2eb21ef9247caf51dd110b64fd798839439f112b51c9c46c476f8e38d3
GitHubClientPEMTest.java https://patch-diff.githubusercontent.com/spotify/github-java-client/pull/232/files#diff-bf2aff7a1364a78542d2ad4824262693d19286679cd62ddd07416d23a1733523
JwtTokenIssuerTest.java https://patch-diff.githubusercontent.com/spotify/github-java-client/pull/232/files#diff-e06dd52a85d38eddd9a91c13255213971d5c25effa4ee490cd1bcf9b80bcda0d
PKCS1PEMKeyTest.java https://patch-diff.githubusercontent.com/spotify/github-java-client/pull/232/files#diff-7fbef6b1f0588782e87f5657b195cbb5549c80edc33266ccc915ef36adfa37bd
src/main/java/com/spotify/github/v3/clients/PKCS1PEMKey.javahttps://patch-diff.githubusercontent.com/spotify/github-java-client/pull/232/files#diff-d26afe2eb21ef9247caf51dd110b64fd798839439f112b51c9c46c476f8e38d3
View file https://patch-diff.githubusercontent.com/spotify/github-java-client/blob/438ba18c43f1b85846b1c5a6b47e752442edd8d9/src/main/java/com/spotify/github/v3/clients/PKCS1PEMKey.java
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://patch-diff.githubusercontent.com/spotify/github-java-client/pull/232/{{ revealButtonHref }}
https://patch-diff.githubusercontent.com/spotify/github-java-client/pull/232/files#diff-d26afe2eb21ef9247caf51dd110b64fd798839439f112b51c9c46c476f8e38d3
https://patch-diff.githubusercontent.com/spotify/github-java-client/pull/232/files#diff-d26afe2eb21ef9247caf51dd110b64fd798839439f112b51c9c46c476f8e38d3
https://patch-diff.githubusercontent.com/spotify/github-java-client/pull/232/files#diff-d26afe2eb21ef9247caf51dd110b64fd798839439f112b51c9c46c476f8e38d3
https://patch-diff.githubusercontent.com/spotify/github-java-client/pull/232/files#diff-d26afe2eb21ef9247caf51dd110b64fd798839439f112b51c9c46c476f8e38d3
src/test/java/com/spotify/github/v3/clients/GitHubClientPEMTest.javahttps://patch-diff.githubusercontent.com/spotify/github-java-client/pull/232/files#diff-bf2aff7a1364a78542d2ad4824262693d19286679cd62ddd07416d23a1733523
View file https://patch-diff.githubusercontent.com/spotify/github-java-client/blob/438ba18c43f1b85846b1c5a6b47e752442edd8d9/src/test/java/com/spotify/github/v3/clients/GitHubClientPEMTest.java
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://patch-diff.githubusercontent.com/spotify/github-java-client/pull/232/{{ revealButtonHref }}
src/test/java/com/spotify/github/v3/clients/JwtTokenIssuerTest.javahttps://patch-diff.githubusercontent.com/spotify/github-java-client/pull/232/files#diff-e06dd52a85d38eddd9a91c13255213971d5c25effa4ee490cd1bcf9b80bcda0d
View file https://patch-diff.githubusercontent.com/spotify/github-java-client/blob/438ba18c43f1b85846b1c5a6b47e752442edd8d9/src/test/java/com/spotify/github/v3/clients/JwtTokenIssuerTest.java
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://patch-diff.githubusercontent.com/spotify/github-java-client/pull/232/{{ revealButtonHref }}
https://patch-diff.githubusercontent.com/spotify/github-java-client/pull/232/files#diff-e06dd52a85d38eddd9a91c13255213971d5c25effa4ee490cd1bcf9b80bcda0d
https://patch-diff.githubusercontent.com/spotify/github-java-client/pull/232/files#diff-e06dd52a85d38eddd9a91c13255213971d5c25effa4ee490cd1bcf9b80bcda0d
https://patch-diff.githubusercontent.com/spotify/github-java-client/pull/232/files#diff-e06dd52a85d38eddd9a91c13255213971d5c25effa4ee490cd1bcf9b80bcda0d
src/test/java/com/spotify/github/v3/clients/PKCS1PEMKeyTest.javahttps://patch-diff.githubusercontent.com/spotify/github-java-client/pull/232/files#diff-7fbef6b1f0588782e87f5657b195cbb5549c80edc33266ccc915ef36adfa37bd
View file https://patch-diff.githubusercontent.com/spotify/github-java-client/blob/438ba18c43f1b85846b1c5a6b47e752442edd8d9/src/test/java/com/spotify/github/v3/clients/PKCS1PEMKeyTest.java
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://patch-diff.githubusercontent.com/spotify/github-java-client/pull/232/{{ revealButtonHref }}
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.