René's URL Explorer Experiment


Title: OpenPGP: decryption of session key with RSA fails with custom cipher provider if the first byte is 0 · Issue #1003 · bcgit/bc-java · GitHub

Open Graph Title: OpenPGP: decryption of session key with RSA fails with custom cipher provider if the first byte is 0 · Issue #1003 · bcgit/bc-java

X Title: OpenPGP: decryption of session key with RSA fails with custom cipher provider if the first byte is 0 · Issue #1003 · bcgit/bc-java

Description: Hello, we are using bcpg-jdk15on v1.69 to read OpenPGP messages encrypted using RSA keys. The private RSA key is stored in a Hardware Security Module, thus when we are performing the decryption of the session key we are not using org.bou...

Open Graph Description: Hello, we are using bcpg-jdk15on v1.69 to read OpenPGP messages encrypted using RSA keys. The private RSA key is stored in a Hardware Security Module, thus when we are performing the decryption of ...

X Description: Hello, we are using bcpg-jdk15on v1.69 to read OpenPGP messages encrypted using RSA keys. The private RSA key is stored in a Hardware Security Module, thus when we are performing the decryption of ...

Opengraph URL: https://github.com/bcgit/bc-java/issues/1003

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"OpenPGP: decryption of session key with RSA fails with custom cipher provider if the first byte is 0","articleBody":"Hello, we are using **bcpg-jdk15on v1.69** to read OpenPGP messages encrypted using RSA keys.\r\n\r\nThe private RSA key is stored in a Hardware Security Module, thus when we are performing the decryption of the session key we are not using **org.bouncycastle.jcajce.provider.asymmetric.rsa.CipherSpi**, but a class from a jar provided by our HSM provider.\r\n\r\nWe sometimes have an IllegalBlockSizeException in the Cipher engine when the library tries to decrypt the session key of the message from the Multiprecision Integer contained in Public-Key Encrypted Session Key Packet.\r\n\r\nWe found that this exception occurred everytime that when writing the PGP message, the ciphered session key had its first byte being a 0.\r\n\r\nAfter digging in the library, we found that in the class JcePublicKeyDataDecryptorFactoryBuilder, it takes whatever the multiprecision integer from the public key packet is, and passes the bytes from it directly to the Cipher engine (after removing the first 2 bytes corresponding to the MPI length). See: https://github.com/bcgit/bc-java/blob/master/pg/src/main/java/org/bouncycastle/openpgp/operator/jcajce/JcePublicKeyDataDecryptorFactoryBuilder.java#L262\r\n\r\nHowever, in a PGP message the multiprecision integer does not always have a size corresponding to the modulus of the RSA key (n), as all leading 0 bits are lost when converting the ciphertext to a multiprecision integer.\r\n\r\nThus when the first 8 bits of the ciphertext have a value of zero, the length of the MPI is no more (n + 2) bytes, but only (n - 1 + 2) bytes, meaning that when we send the MPI bytes without the first two bytes to the engine at decryption time, there are only (n - 1) bytes sent.\r\n\r\nIt means that we do not send the correct number of bytes to the Cipher engine to decrypt the key. The RSABlindedEngine that is used by Bouncy Castle works fine with it, but the RSA engine from our HSM provider throws an IllegalBlockSizeException.\r\n\r\nAccording to the RFC 8017 which I think is the correct one (PKCS #1: RSA Cryptography Specifications Version 2.2), the way it is handled by the library from our HSM provider seems to be expected. In section 7.2.2 about RSAES-PKCS1-v1_5 decryption that given the input:\r\n\r\n```\r\nInput:\r\n\r\n      K        recipient's RSA private key\r\n      C        ciphertext to be decrypted, an octet string of length k,\r\n               where k is the length in octets of the RSA modulus n\r\n```\r\n\r\nThen the first step of the decryption is: \r\n```\r\n      1.  Length checking: If the length of the ciphertext C is not k\r\n          octets (or if k \u003c 11), output \"decryption error\" and stop.\r\n```\r\n\r\nWhich seems to explain why the library from our HSM provider throws an IllegalBlockSizeException when we only send a ciphertext of (n - 1) bytes to it.\r\n\r\nWe fixed the issue by manually adding the \"missing\" 0 bytes in the Cipher engine in JcePublicKeyDataDecryptorFactoryBuilder#decryptSessionData when we detect them, before adding the bytes from the MPI (there can be more than one leading 0 bytes in ciphertext after encrypting the session key with RSA, that will absent in the MPI).\r\n\r\nIn conclusion, I think that the Bouncy Castle library should be doing this padding with 0 bytes, as the size of the MPI is not guaranteed to be equal to the size of the RSA key, and trying to decrypt a ciphertext of a size not equal to the modulus of the key should not be allowed. What do you think about it ?","author":{"url":"https://github.com/lclement57","@type":"Person","name":"lclement57"},"datePublished":"2021-08-02T08:42:24Z","url":"https://github.com/bcgit/bc-java/issues/1003"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:f789a465-f7ee-4ef0-e997-9b8856c124ce
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id94D2:76282:D46A83:1258F14:6AFBED11
html-safe-nonceff527b5c822246c31777aa519261a4621896584ea75882d9834b89d18639fd3a
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NEQyOjc2MjgyOkQ0NkE4MzoxMjU4RjE0OjZBRkJFRDExIiwidmlzaXRvcl9pZCI6IjgzODUxMDU5OTcxMzA4ODY0MTciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac284a14a73a8775ee8a3333edcafe07f11e14e7a751f742546281194b1ae5a97e
hovercard-subject-tagissue:957908274
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/bcgit/bc-java/1003/issue_layout
twitter:imagehttps://opengraph.githubassets.com/0be53a3988e27c677ace5871f3e8e48feeee53b3d174396217ec19567fafa635/bcgit/bc-java/issues/1003
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/0be53a3988e27c677ace5871f3e8e48feeee53b3d174396217ec19567fafa635/bcgit/bc-java/issues/1003
og:image:altHello, we are using bcpg-jdk15on v1.69 to read OpenPGP messages encrypted using RSA keys. The private RSA key is stored in a Hardware Security Module, thus when we are performing the decryption of ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamelclement57
hostnamegithub.com
expected-hostnamegithub.com
None744d4381b1c4dbd6d8736c7d7e5bbe7dc11217584e457a3555020c631764e8ec
turbo-cache-controlno-preview
go-importgithub.com/bcgit/bc-java git https://github.com/bcgit/bc-java.git
octolytics-dimension-user_id4566970
octolytics-dimension-user_loginbcgit
octolytics-dimension-repository_id10416648
octolytics-dimension-repository_nwobcgit/bc-java
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id10416648
octolytics-dimension-repository_network_root_nwobcgit/bc-java
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasedf859c48a4c8b4c0009c19bb4e82101aacb4b998
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/bcgit/bc-java/issues/1003#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fbcgit%2Fbc-java%2Fissues%2F1003
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
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
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://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/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fbcgit%2Fbc-java%2Fissues%2F1003
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=bcgit%2Fbc-java
Reloadhttps://github.com/bcgit/bc-java/issues/1003
Reloadhttps://github.com/bcgit/bc-java/issues/1003
Reloadhttps://github.com/bcgit/bc-java/issues/1003
bcgithttps://github.com/bcgit
bc-javahttps://github.com/bcgit/bc-java
Codehttps://github.com/bcgit/bc-java
Issues47 (47)https://github.com/bcgit/bc-java/issues
Pull requests18 (18)https://github.com/bcgit/bc-java/pulls
Discussionshttps://github.com/bcgit/bc-java/discussions
Actionshttps://github.com/bcgit/bc-java/actions
Projectshttps://github.com/bcgit/bc-java/projects
Wikihttps://github.com/bcgit/bc-java/wiki
Security and qualityhttps://github.com/bcgit/bc-java/security
Insightshttps://github.com/bcgit/bc-java/pulse
https://github.com/bcgit/bc-java
New issuehttps://github.com/login?return_to=https://github.com/bcgit/bc-java/issues/1003
New issuehttps://github.com/login?return_to=https://github.com/bcgit/bc-java/issues/1003
OpenPGP: decryption of session key with RSA fails with custom cipher provider if the first byte is 0https://github.com/bcgit/bc-java/issues/1003#top
https://github.com/lclement57
lclement57https://github.com/lclement57
on Aug 2, 2021https://github.com/bcgit/bc-java/issues/1003#issue-957908274
https://github.com/bcgit/bc-java/blob/master/pg/src/main/java/org/bouncycastle/openpgp/operator/jcajce/JcePublicKeyDataDecryptorFactoryBuilder.java#L262https://github.com/bcgit/bc-java/blob/master/pg/src/main/java/org/bouncycastle/openpgp/operator/jcajce/JcePublicKeyDataDecryptorFactoryBuilder.java#L262
#1https://github.com/bcgit/bc-java/pull/1
https://github.com/dghgit
dghgithttps://github.com/dghgit
on Aug 31, 2021https://github.com/bcgit/bc-java/issues/1003#issuecomment-908988324
https://github.com/lclement57
lclement57https://github.com/lclement57
on Aug 31, 2021https://github.com/bcgit/bc-java/issues/1003#issuecomment-909067012
Javadochttps://thalesdocs.com/gphsm/luna/7/docs/network/Content/sdk/java/javadoc-JSP/10_3_0/index.html
LunaPrivateKeyRsahttps://thalesdocs.com/gphsm/luna/7/docs/network/Content/sdk/java/javadoc-JSP/10_3_0/com/safenetinc/luna/provider/key/LunaPrivateKeyRsa.html
https://github.com/dghgit
dghgithttps://github.com/dghgit
on Aug 31, 2021https://github.com/bcgit/bc-java/issues/1003#issuecomment-909110703
https://github.com/dghgit
dghgithttps://github.com/dghgit
on Aug 31, 2021https://github.com/bcgit/bc-java/issues/1003#issuecomment-909120284
https://github.com/lclement57
lclement57https://github.com/lclement57
on Aug 31, 2021https://github.com/bcgit/bc-java/issues/1003#issuecomment-909160269
7.2.1. Encryption Operationhttps://datatracker.ietf.org/doc/html/rfc8017#section-7.2.1
https://github.com/lclement57
lclement57https://github.com/lclement57
on Aug 31, 2021https://github.com/bcgit/bc-java/issues/1003#issuecomment-909165492
https://github.com/dghgit
dghgithttps://github.com/dghgit
on Aug 31, 2021https://github.com/bcgit/bc-java/issues/1003#issuecomment-909167233
https://github.com/dghgit
dghgithttps://github.com/dghgit
on Sep 1, 2021https://github.com/bcgit/bc-java/issues/1003#issuecomment-910255940
https://www.bouncycastle.org/betashttps://www.bouncycastle.org/betas
https://github.com/lclement57
lclement57https://github.com/lclement57
on Sep 1, 2021https://github.com/bcgit/bc-java/issues/1003#issuecomment-910323652
https://github.com/dghgit
dghgithttps://github.com/dghgit
on Sep 1, 2021https://github.com/bcgit/bc-java/issues/1003#issuecomment-910348799
dghgithttps://github.com/dghgit
completedhttps://github.com/bcgit/bc-java/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Sep 1, 2021https://github.com/bcgit/bc-java/issues/1003#event-5240068343
Sign up for freehttps://github.com/signup?return_to=https://github.com/bcgit/bc-java/issues/1003
Sign in to commenthttps://github.com/login?return_to=https://github.com/bcgit/bc-java/issues/1003
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.