Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix check of broken implementations of GOST ciphersuites #3588

Closed

Conversation

deemru
Copy link
Contributor

@deemru deemru commented May 31, 2017

This patch moves the current check of "broken implementations of GOST ciphersuites" to a correct place and adds new GOST 2012 nids to this check.

@deemru deemru changed the title fix broken implementations of GOST ciphersuites fix check of broken implementations of GOST ciphersuites May 31, 2017
@deemru
Copy link
Contributor Author

deemru commented May 31, 2017

Because it is a GOST only issue, @beldmit are welcomed.

@beldmit
Copy link
Member

beldmit commented May 31, 2017

The proposed patch seems wrong to me, because

  1. GOST ciphersuites match the check SSL_USE_SIGALGS
  2. All the known implementations of the new ciphersuites do not have this bug, so checks for the GOST2012 are redundant.

@deemru
Copy link
Contributor Author

deemru commented May 31, 2017

Current issue is for all GOSTs TLS < 1.2 (see the fixed comment in code)

SSL_USE_SIGALGS is valid for TLS 1.2, but GOST2012 (CryptoPro implementations) can work on TLS 1.0

@deemru
Copy link
Contributor Author

deemru commented May 31, 2017

In any case, the place of original check is wrong, because md variable is never filled.

@beldmit
Copy link
Member

beldmit commented May 31, 2017

Have you checked your patch against at least the CryptoPro implementation?

@deemru
Copy link
Contributor Author

deemru commented May 31, 2017

CryptoPro GOST 2012 client authentications have 64 and 128 bytes bare signatures without length fields if TLS 1.2 (sigalgs) does not used.

Currently i am working on GOST engine for OpenSSL 1.1.0 with GOST 2012 support. Everything seems fine except this client authentication code. Even CryptoPro GOST 2001 does not work without this patch because of empty md in EVP_VerifyInit_ex() below.

@beldmit
Copy link
Member

beldmit commented May 31, 2017

And what problems do you have with the existing engine?

@deemru
Copy link
Contributor Author

deemru commented May 31, 2017

I did not try https://github.com/gost-engine/engine (if you mean it), but it does not matter.

That is looks better?

#ifndef OPENSSL_NO_GOST
        if (!SSL_USE_SIGALGS(s)
            && ((PACKET_remaining(pkt) == 64
             && (EVP_PKEY_id(pkey) == NID_id_GostR3410_2001
                 || EVP_PKEY_id(pkey) == NID_id_GostR3410_2012_256))
            || (PACKET_remaining(pkt) == 128
                && EVP_PKEY_id(pkey) == NID_id_GostR3410_2012_512))) {
            len = PACKET_remaining(pkt);
        } else
#endif

@openssl-machine openssl-machine added the hold: cla required The contributor needs to submit a license agreement label May 31, 2017
@beldmit
Copy link
Member

beldmit commented Jun 1, 2017

For now we agreed to get more tests for this code, both current implementation and the proposed patch.

@deemru
Copy link
Contributor Author

deemru commented Jun 1, 2017

Unfortunately, the code for creating the client's signature in all versions of CryptoPro CSP is looks like this:

<...>
if (pCPContext->session->dwTLSVersion == SP_PROT_TLS1_2_CLIENT)
{
    pbSig = (BYTE*)AllocMemory(dwSigLen + 4);
    <...>
    memcpy(pbSig + 4, old, dwSigLen);
    dwSigLen += 4;
}
SecStatus = ssl3_put_message (pCPContext, pbSig, dwSigLen, SSL3_MT_CERTIFICATE_VERIFY);
<...>

As you can see, regardless of an algorithm when using TLS not equal 1.2 a message with a client's signature will be a bare signature without length field.

Fortunately, a CryptoPro server-side code verification of client signatures supports messages with a length field and without.

To test this issue you'll need CryptoPro CSP with 3 certificates with NID_id_GostR3410_2001, NID_id_GostR3410_2012_256, NID_id_GostR3410_2012_512 keys, and an appropriate openssl s_server with client verify.

Then if you run:

csptest -tlsc -server <hostname> -port 4433 -user <certname> -proto 4

-proto 4 stands for TLS 1.0, you can use -proto 5 (TLS 1.1) with same effect: you'll get errors without this patch on all 3 certificates, even with NID_id_GostR3410_2001. And you'll get no errors with this patch.

TLS 1.2 (-proto 6 or by default) works well with and without this patch:

csptest -tlsc -server <hostname> -port 4433 -user <certname> -proto 6

@richsalz
Copy link
Contributor

richsalz commented Jun 1, 2017

CLA received, removing tag.

@richsalz richsalz removed the hold: cla required The contributor needs to submit a license agreement label Jun 1, 2017
@beldmit
Copy link
Member

beldmit commented Jun 8, 2017

Seems ok to me.

Copy link
Contributor

@richsalz richsalz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on @beldmit's review.

@richsalz richsalz self-assigned this Jun 8, 2017
@richsalz richsalz added 1.1.0 branch: master Merge to master branch approval: review pending This pull request needs review by a committer labels Jun 8, 2017
@richsalz
Copy link
Contributor

richsalz commented Jun 8, 2017

maybe 1.0.2 also?

@deemru
Copy link
Contributor Author

deemru commented Jun 8, 2017

no patch is needed for 1.0.2:

@richsalz
Copy link
Contributor

richsalz commented Jun 8, 2017 via email

Copy link
Member

@mattcaswell mattcaswell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is targeting 1.1.0, but presumably the same change needs to be applied to master. However this PR does not apply cleanly to master, so we need another PR for there.

&& EVP_PKEY_id(pkey) == NID_id_GostR3410_2001) {
len = 64;
} else
#endif
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we could lose this { and everything below moved to the left.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is right, but i was afraid of massive changes, fixed.

@mattcaswell
Copy link
Member

@richsalz are you still ok with this?

@richsalz
Copy link
Contributor

richsalz commented Jun 9, 2017 via email

@richsalz richsalz added approval: done This pull request has the required number of approvals and removed branch: master Merge to master branch approval: review pending This pull request needs review by a committer labels Jun 9, 2017
levitte pushed a commit that referenced this pull request Jun 9, 2017
removed the unnecessary upper bracket
add !SSL_USE_SIGALGS to check for broken implementations of GOST
client signature (signature without length field)

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from #3588)
@richsalz
Copy link
Contributor

richsalz commented Jun 9, 2017

Thanks for your patience on this, and work to improve openssl! Merged with commit a892766 in 1.1.0

@richsalz richsalz closed this Jun 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approval: done This pull request has the required number of approvals
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants