Skip to content

Conversation

@RJPercival
Copy link
Contributor

@RJPercival RJPercival commented Jul 27, 2017

Makes the Trillian admin server generate the private key, rather than requiring the user to provide one. This may be more secure, depending on how the server stores the generated key.

It is hard-coded to generate a key using the default parameters. Users that require more control over the key specification should communicate with the admin server directly.

@RJPercival RJPercival self-assigned this Jul 27, 2017
@RJPercival RJPercival requested a review from gdbelvin July 27, 2017 16:16
@RJPercival RJPercival force-pushed the cmd_createtree_keygen branch 3 times, most recently from 64a8515 to 91c7ac9 Compare July 27, 2017 17:55
maxRootDuration = flag.Duration("max_root_duration", 0, "Interval after which a new signed root is produced despite no submissions; zero means never")

privateKeyFormat = flag.String("private_key_format", "PrivateKey", "Type of private key to be used (PrivateKey, PEMKeyFile, or PKCS11ConfigFile)")
privateKeyFormat = flag.String("private_key_format", "", "Type of protobuf message to send the key as (PrivateKey, PEMKeyFile, or PKCS11ConfigFile). If empty, a key will be generated for you by Trillian.")
Copy link
Contributor

Choose a reason for hiding this comment

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

If empty, the list of valid choices will be printed out?

MaxRootDuration: ptypes.DurationProto(opts.maxRootDuration),
}}

if opts.privateKeyType != "" {
Copy link
Contributor

@gdbelvin gdbelvin Jul 28, 2017

Choose a reason for hiding this comment

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

Perhaps we should have a --generateKey flag?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

An earlier version of this PR had such a flag, but I removed it because this reduces the number of mutually-exclusive flags and leads to more reasonable default behaviour. I want to encourage letting Trillian generate the key, so I'd like that to be the default. This would require the --generateKey flag defaulting to true. However, that would mean you'd need to pass --generate_key=false when providing your own key else you'd get an error. Without this flag, it automatically won't generate a key if you provide the flags that specify one - this seemed cleaner.

Of course, as another of your comments seemed to suggest, this will clash with PR #734, which makes an empty --private_key_format flag print out the accepted formats. I could add a --list_private_key_formats flag for that, or just not provide that feature (users should probably have researched the protobuf message type they want to use, rather than blindly pick from a list).

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm happy if we don't implement the list formats feature


if diff := pretty.Compare(tree, test.wantTree); diff != "" {
t.Errorf("%v: post-createTree diff:\n%v", test.desc, diff)
if !proto.Equal(tree, test.wantTree) {
Copy link
Contributor

Choose a reason for hiding this comment

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

good change. consider using the full got, want format

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@gdbelvin gdbelvin requested review from codingllama and gdbelvin July 28, 2017 10:22
@gdbelvin
Copy link
Contributor

Love the shortness of this PR. We seem to have some extra flag processing that would be nice to simplify.

return nil, s.err
}
resp := *req.Tree
if req.KeySpec != nil && s.generatedKey != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it worth to error if req.KeySpec != nil && s.generatedKey == nil ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the past, I've gotten the impression that you'd rather avoid having test code that simply detects whether the test is misconfigured. However, I'm happy to add this if you'd prefer in this case.

Copy link
Contributor

Choose a reason for hiding this comment

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

True, but in this case I think it's more about mimicking AdminServer and less about the test checking itself. This is a suggestion that doesn't change much in practice right now, so feel free to ignore it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've made it panic in this case. While I know panic is to be avoided, it seems the best option here as I don't want tests to accidentally interpret this mistake in test setup as an expected error (in those test cases where fakeAdminServer.err != nil).

// Cannot continue if options specifying a key were provided but
// privateKeyType is not set, as there's no way to know what protobuf
// message type was intended.
if opts.pemKeyPath != "" || opts.pemKeyPass != "" || opts.pkcs11ConfigPath != "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a little confusing. If we want to generate a key, doesn't that take precedence over the other parameters? Perhaps issue a warning that these options will be ignored?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the user specified these options, I think it indicates that they don't want to generate a key, but have inadvertently omitted the key format flag. Therefore, printing an error and aborting seems better, rather than continuing on the (probably incorrect) assumption that a key should be generated.

Copy link
Contributor

@gdbelvin gdbelvin left a comment

Choose a reason for hiding this comment

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

LGTM, with some nits

@google google deleted a comment from gdbelvin Aug 9, 2017
Copy link
Contributor

@gdbelvin gdbelvin left a comment

Choose a reason for hiding this comment

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

:-)

Makes the Trillian admin server generate the private key, rather than
requiring the user to provide one. This may be more secure, depending
on how the server stores the generated key.

It is hard-coded to generate an ECDSA key using the default parameters.
Users that require more control over the key specification should
communicate with the admin server directly.
@RJPercival RJPercival force-pushed the cmd_createtree_keygen branch from 91c7ac9 to 98fe3b0 Compare August 9, 2017 15:34
Rob Percival added 3 commits August 9, 2017 16:41
This seems the best option as I don't want tests to accidentally
interpret this mistake in test setup as an expected error (in those test
cases where fakeAdminServer.err != nil).
@RJPercival
Copy link
Contributor Author

RJPercival commented Aug 9, 2017

Travis will only be happy with this PR once google/certificate-transparency-go#55 is merged.

@RJPercival
Copy link
Contributor Author

Travis is now happy.

@RJPercival RJPercival merged commit 4bb3d90 into google:master Aug 10, 2017
@RJPercival RJPercival deleted the cmd_createtree_keygen branch August 10, 2017 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants