Skip to content

Comments

Added certificates generate command#68

Closed
sajayantony wants to merge 3 commits intonotaryproject:prototype-2from
sajayantony:cert
Closed

Added certificates generate command#68
sajayantony wants to merge 3 commits intonotaryproject:prototype-2from
sajayantony:cert

Conversation

@sajayantony
Copy link
Contributor

@sajayantony sajayantony commented Aug 13, 2021

The command will generate an 2084 bits rsa based crt and key file.
The files will be placed in $HOME/.notary/keys

Signed-off-by: Sajay Antony sajaya@microsoft.com

Fixes #66

❯ ./bin/nv2 certificates generate wabbit-networks
Generating RSA Key with 3072 bits
Generated certificates expiring on 2022-08-25T12:22:00-07:00
Wrote self-signed certificate file: /home/sajay/.notation/keys/wabbit-networks.crt
Wrote private key file: /home/sajay/.notation/keys/wabbit-networks.key

The command will generate an 2084 bits rsa based crt and key file.
The files will be placed in $HOME/.notary/keys

Signed-off-by: Sajay Antony <sajaya@microsoft.com>
@sajayantony
Copy link
Contributor Author

@lachie83 - This composes with my other PR that will make adding and removing the certs much cleaner - #70

- Default to 3047 for RSA Bits
- Added --not-after flag for supporting expiry
- Remove organization defaults
- Remove TLS capabilities

Signed-off-by: Sajay Antony <sajaya@microsoft.com>
}
}

return keysDir, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to ensure that keysDir is really a directory. It could be a regular file or symbolic link.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to use IsDir. Is that good enough or do we need to ensure more checks. I believe you handled this in ORAS a well.

Comment on lines 174 to 175
fmt.Printf("Generating certificates expiring on %s\n", notAfter.Format(time.RFC3339))
fmt.Printf("Writing public key file: %s\n", crtFilePath)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be Generated and Wrote.

Copy link
Contributor

Choose a reason for hiding this comment

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

BTW, it is not just a public key, but a self-signed cert.

Signed-off-by: Sajay Antony <sajaya@microsoft.com>
@sajayantony sajayantony changed the title Added generate-certificates command. Added certificates generate command Aug 25, 2021
@sajayantony sajayantony marked this pull request as draft August 31, 2021 07:15
@SteveLasker SteveLasker added the cli Issue or PR released to Notation CLI label Sep 1, 2021

// Set certificate validity
notBefore := time.Now()
notAfter := notBefore.Add(time.Duration(365 * 24 * time.Hour))
Copy link
Contributor

Choose a reason for hiding this comment

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

dead code?

Comment on lines +139 to +146
hosts := strings.Split(host, ",")
for _, h := range hosts {
if ip := net.ParseIP(h); ip != nil {
template.IPAddresses = append(template.IPAddresses, ip)
} else {
template.DNSNames = append(template.DNSNames, h)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

as this is codesigning not ssl certificate, we don't need to support DNSName or ip-address.

Copy link
Contributor

Choose a reason for hiding this comment

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

We still need them as the x509 package checks SAN instead of CN starting from golang 1.15. See https://golang.org/doc/go1.15#commonname

Comment on lines +149 to +150
Organization: []string{hosts[0]},
CommonName: hosts[0],
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we take Organization Name from user instead of host? host is confusing as certificate is not used for tls.

Copy link
Contributor

Choose a reason for hiding this comment

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

Organization is removed in the Notation CLI Alpha PR.

Comment on lines +159 to +162
keysDir, err := ensureKeysDir()
if err != nil {
return fmt.Errorf("Could not access keys directory: %v", err)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be done as first thing after validating arguments.

func ensureKeysDir() (string, error) {

// Expected to ensure ~/.notation/keys
dirname, err := os.UserHomeDir()
Copy link
Contributor

Choose a reason for hiding this comment

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

As discussed in #76 we should support XDG_Base_Directory.

Copy link
Contributor

Choose a reason for hiding this comment

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

Notation CLI Alpha honors XDG directories.


certOut, err := os.OpenFile(crtFileName, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0600)
if err != nil {
return fmt.Errorf("Failed to open %s for writing: %v", crtFilePath, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

s/open/create file?

Value: 3072,
},
&cli.StringFlag{
Name: "not-after",
Copy link
Contributor

Choose a reason for hiding this comment

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

Will it be a better customer experience to take validity period validForDays instead of actual date?
Pros:

  • easy to associate default value of 1 year
  • No need to worry about not-after being in past.
certificates generate --not-after 2006-01-02T15:04:05-07:00
certificates generate --valid-for-days 365

Copy link
Contributor

Choose a reason for hiding this comment

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

validForDays might not be a good one. For testing purposes, people may want short-lived certs like serveral hours or minutes.

@shizhMSFT shizhMSFT mentioned this pull request Sep 3, 2021
@sajayantony
Copy link
Contributor Author

@priteshbandi #83 PR adds all this capability into notation alpha.
I will close this draft PR and we should be now trying to get this all into one alpha release which we can iterate on is my thinking.

@shizhMSFT - can see if there are inputs here you might not have already considered in your PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli Issue or PR released to Notation CLI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add key generation support to nv2

7 participants