| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 809371a commit 4617512
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -898,6 +898,14 @@ bool CipherBase::Final(std::unique_ptr<BackingStore>* out) { | |||
| 898 | 898 | if (kind_ == kDecipher && IsSupportedAuthenticatedMode(ctx_.get())) | |
| 899 | 899 | MaybePassAuthTagToOpenSSL(); | |
| 900 | 900 | ||
| 901 | + // OpenSSL v1.x doesn't verify the presence of the auth tag so do | ||
| 902 | + // it ourselves, see https://github.com/nodejs/node/issues/45874. | ||
| 903 | + if (OPENSSL_VERSION_NUMBER < 0x30000000L && kind_ == kDecipher && | ||
| 904 | + NID_chacha20_poly1305 == EVP_CIPHER_CTX_nid(ctx_.get()) && | ||
| 905 | + auth_tag_state_ != kAuthTagPassedToOpenSSL) { | ||
| 906 | + return false; | ||
| 907 | + } | ||
| 908 | + | ||
| 901 | 909 | // In CCM mode, final() only checks whether authentication failed in update(). | |
| 902 | 910 | // EVP_CipherFinal_ex must not be called and will fail. | |
| 903 | 911 | bool ok; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -786,3 +786,34 @@ for (const test of TEST_CASES) { | |||
| 786 | 786 | assert.strictEqual(plaintext.toString('hex'), testCase.plain); | |
| 787 | 787 | } | |
| 788 | 788 | } | |
| 789 | + | ||
| 790 | + // https://github.com/nodejs/node/issues/45874 | ||
| 791 | + { | ||
| 792 | + const rfcTestCases = TEST_CASES.filter(({ algo, tampered }) => { | ||
| 793 | + return algo === 'chacha20-poly1305' && tampered === false; | ||
| 794 | + }); | ||
| 795 | + assert.strictEqual(rfcTestCases.length, 1); | ||
| 796 | + | ||
| 797 | + const [testCase] = rfcTestCases; | ||
| 798 | + const key = Buffer.from(testCase.key, 'hex'); | ||
| 799 | + const iv = Buffer.from(testCase.iv, 'hex'); | ||
| 800 | + const aad = Buffer.from(testCase.aad, 'hex'); | ||
| 801 | + const opt = { authTagLength: 16 }; | ||
| 802 | + | ||
| 803 | + const cipher = crypto.createCipheriv('chacha20-poly1305', key, iv, opt); | ||
| 804 | + const ciphertext = Buffer.concat([ | ||
| 805 | + cipher.setAAD(aad).update(testCase.plain, 'hex'), | ||
| 806 | + cipher.final(), | ||
| 807 | + ]); | ||
| 808 | + const authTag = cipher.getAuthTag(); | ||
| 809 | + | ||
| 810 | + assert.strictEqual(ciphertext.toString('hex'), testCase.ct); | ||
| 811 | + assert.strictEqual(authTag.toString('hex'), testCase.tag); | ||
| 812 | + | ||
| 813 | + const decipher = crypto.createDecipheriv('chacha20-poly1305', key, iv, opt); | ||
| 814 | + decipher.setAAD(aad).update(ciphertext); | ||
| 815 | + | ||
| 816 | + assert.throws(() => { | ||
| 817 | + decipher.final(); | ||
| 818 | + }, /Unsupported state or unable to authenticate data/); | ||
| 819 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments