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

Smaller key size when testing #198

Closed
wants to merge 2 commits into from
Closed

Conversation

richardschneider
Copy link
Contributor

A 2048 bit RSA key can take up to 20 seconds to generate. When testing, a smaller key size can be used.

For js-ipfs a 512 bit key size is used. For go-ipfs, because it enforces minimum key size, 1024 bits is used.

@ghost ghost assigned richardschneider Feb 3, 2018
@ghost ghost added the status/in-progress In progress label Feb 3, 2018
const args = ['init', '-b', initOpts.keysize || 2048]
let keysize = initOpts.keysize
if (!keysize) {
if (typeof global.it === 'function') {
Copy link
Member

Choose a reason for hiding this comment

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

@richardschneider @diasdavid I'm really not sure we should do this.

  • Why do we have to change this for test only?
  • Can we be sure that this is not going to hide some subtle issues by running with different defaults in tests vs prod?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why do we have to change this for test only?

Because small key sizes are unsafe. If someone is using this interface to create a 'real' peer then proper key sizes should be used. This is just hack to get tests to run faster.

libp2p-keychain and libp2p-crypto tests use real key sizes.

Can we be sure that this is not going to hide some subtle issues by running with different defaults in tests vs prod?

I did think about this and came to the conclusion that because none of the ipfs an ipfs-api tests specify a key size it should be safe. But running the tests against this PR is the only sure way.

Copy link
Member

Choose a reason for hiding this comment

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

also, checking for global.it ties us to mocha and feels a bit iffy...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dryajov Open to any suggestions. But the current tests are in mocha. Worse case, someone writes a new a test in another framework and all they get is bigger key sizes.

Copy link
Member

Choose a reason for hiding this comment

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

@richardschneider can we use an ENV variable to set the keysize, that way, in test we can just set it, rather than checking for global.it?

i.e.

IPFS_KEYSIZE=1024 npm test

Copy link
Member

@dryajov dryajov Feb 3, 2018

Choose a reason for hiding this comment

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

that's true, maybe this is a change that needs to happen in aegir, where we set an ENV variable signaling that we're in test - global.it, IMO would just end up being too brittle.

i.e.

process.env['AEGIR_TEST']

Copy link
Member

Choose a reason for hiding this comment

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

Thinking about it some more, I really think we should just have IPFS_KEYSIZE_[JS|GO|PROC]. This carries the most changes, but it's also the most consistent and gives us more flexibility down the road.

Copy link
Member

Choose a reason for hiding this comment

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

The reason I say this, is because ipfsd-ctl is not used only in tests, and there might be other use cases and applications that can benefit from this functionality as well.

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 other app, could simply set the keysize. I expect an other app, would init an repo only once.

Our tests are an exception, as there are many of creating many repos..

Copy link
Member

Choose a reason for hiding this comment

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

I agree. Let's not peg on globals that are used by specific test frameworks.

If another batch of tests wants to drop down the keysize, then it should do that explicitly rather than having this module making the decision.

const args = ['init', '-b', initOpts.keysize || 2048]
let keysize = initOpts.keysize
if (!keysize) {
if (typeof global.it === 'function') {
Copy link
Member

Choose a reason for hiding this comment

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

I agree. Let's not peg on globals that are used by specific test frameworks.

If another batch of tests wants to drop down the keysize, then it should do that explicitly rather than having this module making the decision.

let keysize = initOpts.keysize
if (!keysize) {
if (typeof global.it === 'function') {
keysize = this.opts.type === 'go' ? 1024 : 512
Copy link
Member

Choose a reason for hiding this comment

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

@richardschneider why are we setting different sizes for go and js, could you please remind me?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

RTFM the top comment on this PR

@daviddias
Copy link
Member

closing in favor of #203

@daviddias daviddias closed this Feb 16, 2018
@ghost ghost removed the status/in-progress In progress label Feb 16, 2018
@daviddias daviddias deleted the small-keysize branch February 16, 2018 17:26
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.

None yet

3 participants