Skip to content

SERVER-46275 Add ECDSA w/OCSP support to cert gen tool #1351

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

Closed
wants to merge 3 commits into from

Conversation

vincentkam
Copy link

@vincentkam vincentkam commented Feb 20, 2020

Copy link
Collaborator

@shreyaskalyan shreyaskalyan left a comment

Choose a reason for hiding this comment

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

A few comments. If you need help with certs.yml, let me know.

open(extfile, 'wt').write('basicConstraints=CA:FALSE\n')
open(extfile, 'at').write('subjectAltName=DNS:localhost,IP:127.0.0.1\n')
open(extfile, 'at').write('subjectKeyIdentifier=hash\n')
key_usage = ('keyUsage=nonRepudiation,digitalSignature,keyEncipherment\n' if "responder" in cert['name']
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should these extensions be listed in certs.yml ?

Copy link
Author

Choose a reason for hiding this comment

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

I think long term it would be ideal if we could define ECDSA certs much like we define RSA certs. And I admit that hard coding can be inconvenient e.g. hard-coding the AIA extensions means that once we get the OCSP responder working without the trailing slashes, we'll need to make a small change to this script to remove the trailing slashes from the AIA section when generating ECDSA OCSP certs. For this PR though, I would rather minimize the amount of changes needed and keep ECDSA special cased, such that the only thing we define in the cert.yml file is their name, description, issuer, and (now) tags.

If desired, I'd be happy to create a ticket to track the feature of allowing us to define ECDSA certs in the same fashion as RSA certs :)

MUST_STAPLE_VALUE = str('DER:30:03:02:01:05').encode('utf-8')
MUST_STAPLE_KEY_STR = '1.3.6.1.5.5.7.1.24'
MUST_STAPLE_KEY = bytes(MUST_STAPLE_KEY_STR, "utf-8")
MUST_STAPLE_VALUE_STR ='DER:30:03:02:01:05'
Copy link

Choose a reason for hiding this comment

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

I know this commit isn't adding it, but could either of you document what SEQ: [ 1, NULL ] actually signifies? (Also that I'm decoding that correctly?)

Copy link
Author

Choose a reason for hiding this comment

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

Added some clarifying comments!

extfile = tempfile.mkstemp()[1]
open(extfile, 'wt').write('subjectAltName=DNS:localhost,DNS:127.0.0.1')
open(extfile, 'wt').write('basicConstraints=CA:FALSE\n')
Copy link

Choose a reason for hiding this comment

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

This template is getting big enough we might consider putting it in an external file which we load from here.

Copy link
Author

@vincentkam vincentkam Mar 13, 2020

Choose a reason for hiding this comment

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

Noted! I've left it the way it is for now since other drivers work is more pressing at the moment, but if you feel strongly about making this optimization now as part of this PR, I can look into it :)

@@ -558,7 +558,7 @@ certs:
- 'trusted-ca.pem'
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the other parts of this file need to be tagged as well, like the other ECDSA certs and the other OCSP certs.

Copy link
Author

Choose a reason for hiding this comment

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

I've tagged the other ECDSA certs and added checks for the ECDSA tag. Should the RSA OCSP certs be updated with a tags field if the tags only apply to special cases handling i.e. ECDSA certs? I'm inclined to say no, since they perform no useful function at the moment.

Copy link
Author

Choose a reason for hiding this comment

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

It's also worth noting that the current code leaves the previous ECDSA tree untouched: they still retain their explicit text header and the private keys are not converted into PKCS8 format as I did not know what those certs were being used for.

cert_filename = make_filename({'name': f"{filename}.crt"})
open(cert_filename, 'wt').write(open(temp_cert_filename, 'rt').read())
key_filename = make_filename({'name': f"{filename}.key"})
open(key_filename, 'wt').write(open(temp_key_filename, 'rt').read())
Copy link

Choose a reason for hiding this comment

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

This line does not close either of the two files that it opens. Consider using shutil.copyfile instead (https://docs.python.org/2/library/shutil.html#shutil.copyfile).

extended_key_usage = ('extendedKeyUsage=serverAuth,clientAuth,OCSPSigning\n'
if (cert.get('tags') and "responder" in cert['tags'])
else 'extendedKeyUsage=serverAuth,clientAuth\n')
open(extfile, 'at').write(extended_key_usage)
Copy link

Choose a reason for hiding this comment

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

Instead of the individual open calls that do not close the file (and do not guarantee that the data has been written at all or before the next open call happens), the writes will be better expressed with a scope:

with open(extfile, 'wt') as f:
  f.write(...)
  #  ...
  f.write(...)

Copy link
Author

Choose a reason for hiding this comment

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

Ah thanks! I've taken your suggestion :)

Copy link

@sgolemon sgolemon left a comment

Choose a reason for hiding this comment

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

lgtm

@vincentkam
Copy link
Author

Rebased and squashed! I don't have merge permissions, so I leave the rest to @shreyaskalyan 😸

@vincentkam
Copy link
Author

@shreyaskalyan I've added one more commit to strip the trailing slashes from the ECDSA endpoints (and regenerate the certs), per https://jira.mongodb.org/browse/SERVER-46413.

@vincentkam
Copy link
Author

Merged here: 8289739
so I'm closing this PR :) Thanks everyone!

@vincentkam vincentkam closed this Apr 17, 2020
@vincentkam vincentkam deleted the mkcert-ecdsa branch April 17, 2020 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants