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
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
Domain: patch-diff.githubusercontent.com
| route-pattern | /:user_id/:repository/pull/:id/checks(.:format) |
| route-controller | pull_requests |
| route-action | checks |
| fetch-nonce | v2:07605f2b-7951-3fa1-6388-48f90ace015b |
| current-catalog-service-hash | 87dc3bc62d9b466312751bfd5f889726f4f1337bdff4e8be7da7c93d6c00a25a |
| request-id | CDAA:18807F:6970100:8FEE085:6978616F |
| html-safe-nonce | 52923aba639c20c2b8fa5f467752fb433d3023fb5d28baa4fc83fced814777c7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDREFBOjE4ODA3Rjo2OTcwMTAwOjhGRUUwODU6Njk3ODYxNkYiLCJ2aXNpdG9yX2lkIjoiMjk5OTA2OTQ0MTQzNTEzMjI3MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 30286d0a33a6a7966bb2f74af96ce7de8b1f50a1d4f3c466aee8af41452336cd |
| hovercard-subject-tag | pull_request:2511558877 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,checks,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/spotify/github-java-client/pull/232/checks |
| twitter:image | https://avatars.githubusercontent.com/u/142914809?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/142914809?s=400&v=4 |
| og:image:alt | 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... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 2981c597c945c1d90ac6fa355ce7929b2f413dfe7872ca5c435ee53a24a1de50 |
| turbo-cache-control | no-cache |
| go-import | github.com/spotify/github-java-client git https://github.com/spotify/github-java-client.git |
| octolytics-dimension-user_id | 251374 |
| octolytics-dimension-user_login | spotify |
| octolytics-dimension-repository_id | 254401089 |
| octolytics-dimension-repository_nwo | spotify/github-java-client |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 254401089 |
| octolytics-dimension-repository_network_root_nwo | spotify/github-java-client |
| turbo-body-classes | logged-out env-production page-responsive full-width full-width-p-0 |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 520b65a872113b919c1bbdb03834a50af15859fd |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width