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/checks(.:format)
route-controllerpull_requests
route-actionchecks
fetch-noncev2:07605f2b-7951-3fa1-6388-48f90ace015b
current-catalog-service-hash87dc3bc62d9b466312751bfd5f889726f4f1337bdff4e8be7da7c93d6c00a25a
request-idCDAA:18807F:6970100:8FEE085:6978616F
html-safe-nonce52923aba639c20c2b8fa5f467752fb433d3023fb5d28baa4fc83fced814777c7
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDREFBOjE4ODA3Rjo2OTcwMTAwOjhGRUUwODU6Njk3ODYxNkYiLCJ2aXNpdG9yX2lkIjoiMjk5OTA2OTQ0MTQzNTEzMjI3MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac30286d0a33a6a7966bb2f74af96ce7de8b1f50a1d4f3c466aee8af41452336cd
hovercard-subject-tagpull_request:2511558877
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,checks,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/checks
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/spotify/github-java-client/pull/232/checks
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-cache
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 full-width-p-0
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release520b65a872113b919c1bbdb03834a50af15859fd
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://patch-diff.githubusercontent.com/spotify/github-java-client/pull/232/checks#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%2Fchecks
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%2Fchecks
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%2Fchecks&source=header-repo&source_repo=spotify%2Fgithub-java-client
Reloadhttps://patch-diff.githubusercontent.com/spotify/github-java-client/pull/232/checks
Reloadhttps://patch-diff.githubusercontent.com/spotify/github-java-client/pull/232/checks
Reloadhttps://patch-diff.githubusercontent.com/spotify/github-java-client/pull/232/checks
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/checks
Please reload this pagehttps://patch-diff.githubusercontent.com/spotify/github-java-client/pull/232/checks
Sign in for the full log viewhttps://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Fspotify%2Fgithub-java-client%2Fpull%2F232%2Fchecks
fix: more robust handling of whitespace and alternate pem format https://patch-diff.githubusercontent.com/spotify/github-java-client/pull/232/checks#top
Please reload this pagehttps://patch-diff.githubusercontent.com/spotify/github-java-client/pull/232/checks
maven-build on: pull_request https://patch-diff.githubusercontent.com/spotify/github-java-client/actions/runs/15237194692
build (ubuntu-latest, 11) https://patch-diff.githubusercontent.com/spotify/github-java-client/actions/runs/15237194692/job/42852631859?pr=232
build (ubuntu-latest, 17) https://patch-diff.githubusercontent.com/spotify/github-java-client/actions/runs/15237194692/job/42852631990?pr=232
build (ubuntu-latest, 21) https://patch-diff.githubusercontent.com/spotify/github-java-client/actions/runs/15237194692/job/42852632136?pr=232
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.