-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Vault-16367: add support RSA padding scheme pkcs1v15 for encryption #16368
Changes from all commits
381d091
e61c72f
6d92f49
9b57e68
91d11dc
cbc17d1
31b0c51
8a7728d
99a82d4
a19b563
efa5fb1
9b56e02
8f79fc0
ee4a3c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:improvement | ||
secrets/transit: Add support for RSA padding scheme pkcs1v15 for encryption | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -818,7 +818,7 @@ func (p *Policy) convergentVersion(ver int) int { | |
return convergentVersion | ||
} | ||
|
||
func (p *Policy) Encrypt(ver int, context, nonce []byte, value string) (string, error) { | ||
func (p *Policy) Encrypt(ver int, context, nonce []byte, value string, paddingScheme string) (string, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I should double check I haven't violated this myself recently, but in general, we wish to avoid modifying these functions as they lie in our public I think you could change this to Then if/when we introduce ECEIS based schemes, I think it might make the most sense? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes perfectly sense for me too. Does the new There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, I don't think our SDK has much documentation sadly. I think it'd be cool to get better inline godoc in the future, but we don't have much presently. (If you want to work on this, happy to review such PRs in the future too!) |
||
if !p.Type.EncryptionSupported() { | ||
return "", errutil.UserError{Err: fmt.Sprintf("message encryption not supported for key type %v", p.Type)} | ||
} | ||
|
@@ -894,8 +894,19 @@ func (p *Policy) Encrypt(ver int, context, nonce []byte, value string) (string, | |
if err != nil { | ||
return "", err | ||
} | ||
if paddingScheme == "" { | ||
paddingScheme = "oaep" | ||
} | ||
key := keyEntry.RSAKey | ||
ciphertext, err = rsa.EncryptOAEP(sha256.New(), rand.Reader, &key.PublicKey, plaintext, nil) | ||
switch paddingScheme { | ||
case "pkcs1v15": | ||
ciphertext, err = rsa.EncryptPKCS1v15(rand.Reader, &key.PublicKey, plaintext) | ||
case "oaep": | ||
ciphertext, err = rsa.EncryptOAEP(sha256.New(), rand.Reader, &key.PublicKey, plaintext, nil) | ||
default: | ||
return "", errutil.InternalError{Err: fmt.Sprintf("unsupported RSA padding scheme %s", paddingScheme)} | ||
} | ||
|
||
if err != nil { | ||
return "", errutil.InternalError{Err: fmt.Sprintf("failed to RSA encrypt the plaintext: %v", err)} | ||
} | ||
|
@@ -913,7 +924,7 @@ func (p *Policy) Encrypt(ver int, context, nonce []byte, value string) (string, | |
return encoded, nil | ||
} | ||
|
||
func (p *Policy) Decrypt(context, nonce []byte, value string) (string, error) { | ||
func (p *Policy) Decrypt(context, nonce []byte, value string, paddingScheme string) (string, error) { | ||
cipherboy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if !p.Type.DecryptionSupported() { | ||
return "", errutil.UserError{Err: fmt.Sprintf("message decryption not supported for key type %v", p.Type)} | ||
} | ||
|
@@ -994,8 +1005,18 @@ func (p *Policy) Decrypt(context, nonce []byte, value string) (string, error) { | |
if err != nil { | ||
return "", err | ||
} | ||
if paddingScheme == "" { | ||
paddingScheme = "oaep" | ||
} | ||
key := keyEntry.RSAKey | ||
plain, err = rsa.DecryptOAEP(sha256.New(), rand.Reader, key, decoded, nil) | ||
switch paddingScheme { | ||
case "pkcs1v15": | ||
plain, err = rsa.DecryptPKCS1v15(rand.Reader, key, decoded) | ||
case "oaep": | ||
plain, err = rsa.DecryptOAEP(sha256.New(), rand.Reader, key, decoded, nil) | ||
default: | ||
return "", errutil.InternalError{Err: fmt.Sprintf("unsupported RSA padding scheme %s", paddingScheme)} | ||
} | ||
if err != nil { | ||
return "", errutil.InternalError{Err: fmt.Sprintf("failed to RSA decrypt the ciphertext: %v", err)} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
<form onsubmit={{action @doSubmit (hash ciphertext=@ciphertext context=@context nonce=@nonce)}}> | ||
<form | ||
onsubmit={{action @doSubmit (hash ciphertext=@ciphertext padding_scheme=@padding_scheme context=@context nonce=@nonce)}} | ||
> | ||
<div class="box is-sideless is-fullwidth is-marginless"> | ||
<div class="content"> | ||
<p>You can decrypt ciphertext using <code>{{@key.name}}</code> as the encryption key.</p> | ||
|
@@ -28,6 +30,27 @@ | |
</div> | ||
</div> | ||
{{/if}} | ||
{{#if (or (eq @key.type "rsa-2048") (eq @key.type "rsa-3072") (eq @key.type "rsa-4096"))}} | ||
<div class="field"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment here as above ☝️ |
||
<label for="padding_scheme" class="is-label">Padding Scheme</label> | ||
<div class="control is-expanded"> | ||
<div class="select is-fullwidth"> | ||
<select | ||
name="padding_scheme" | ||
id="padding_scheme" | ||
data-test-padding-scheme="true" | ||
onchange={{action (mut @padding_scheme) value="target.value"}} | ||
> | ||
{{#each (array "oaep" "pkcs1v15") as |scheme|}} | ||
<option selected={{if @padding_scheme (eq @padding_scheme scheme) (eq scheme "oaep")}} value={{scheme}}> | ||
{{scheme}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and here! 😄 |
||
</option> | ||
{{/each}} | ||
</select> | ||
</div> | ||
</div> | ||
</div> | ||
{{/if}} | ||
{{#if (eq @key.convergentEncryptionVersion 1)}} | ||
<div class="field"> | ||
<label for="nonce" class="is-label">Nonce</label> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
<form | ||
onsubmit={{action | ||
@doSubmit | ||
(hash plaintext=@plaintext context=@context nonce=@nonce key_version=@key_version encodedBase64=@encodedBase64) | ||
(hash | ||
plaintext=@plaintext | ||
padding_scheme=@padding_scheme | ||
context=@context | ||
nonce=@nonce | ||
key_version=@key_version | ||
encodedBase64=@encodedBase64 | ||
) | ||
}} | ||
> | ||
<div class="box is-sideless is-fullwidth is-marginless"> | ||
|
@@ -40,6 +47,27 @@ | |
</div> | ||
</div> | ||
{{/if}} | ||
{{#if (or (eq @key.type "rsa-2048") (eq @key.type "rsa-3072") (eq @key.type "rsa-4096"))}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also this file and line 62 |
||
<div class="field"> | ||
<label for="padding_scheme" class="is-label">Padding Scheme</label> | ||
<div class="control is-expanded"> | ||
<div class="select is-fullwidth"> | ||
<select | ||
name="padding_scheme" | ||
id="padding_scheme" | ||
data-test-padding-scheme="true" | ||
onchange={{action (mut @padding_scheme) value="target.value"}} | ||
> | ||
{{#each (array "oaep" "pkcs1v15") as |scheme|}} | ||
<option selected={{if @padding_scheme (eq @padding_scheme scheme) (eq scheme "oaep")}} value={{scheme}}> | ||
{{scheme}} | ||
</option> | ||
{{/each}} | ||
</select> | ||
</div> | ||
</div> | ||
</div> | ||
{{/if}} | ||
{{#if (eq @key.convergentEncryptionVersion 1)}} | ||
<div class="field"> | ||
<div class="level"> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
<form onsubmit={{action @doSubmit (hash ciphertext=@ciphertext context=@context nonce=@nonce key_version=@key_version)}}> | ||
<form | ||
onsubmit={{action | ||
@doSubmit | ||
(hash ciphertext=@ciphertext padding_scheme=@padding_scheme context=@context nonce=@nonce key_version=@key_version) | ||
}} | ||
> | ||
<div class="box is-sideless is-fullwidth is-marginless"> | ||
<NamespaceReminder @mode="perform" @noun="rewrap" /> | ||
<div class="content"> | ||
|
@@ -29,6 +34,27 @@ | |
</div> | ||
</div> | ||
{{/if}} | ||
{{#if (or (eq @key.type "rsa-2048") (eq @key.type "rsa-3072") (eq @key.type "rsa-4096"))}} | ||
<div class="field"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. last one! |
||
<label for="padding_scheme" class="is-label">Padding Scheme</label> | ||
<div class="control is-expanded"> | ||
<div class="select is-fullwidth"> | ||
<select | ||
name="padding_scheme" | ||
id="padding_scheme" | ||
data-test-padding-scheme="true" | ||
onchange={{action (mut @padding_scheme) value="target.value"}} | ||
> | ||
{{#each (array "oaep" "pkcs1v15") as |scheme|}} | ||
<option selected={{if @padding_scheme (eq @padding_scheme scheme) (eq scheme "oaep")}} value={{scheme}}> | ||
{{scheme}} | ||
</option> | ||
{{/each}} | ||
</select> | ||
</div> | ||
</div> | ||
</div> | ||
{{/if}} | ||
{{#if (eq @key.convergentEncryptionVersion 1)}} | ||
<div class="field"> | ||
<label for="nonce" class="is-label">Nonce</label> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be great to include
Default: "oaep"
here for consistency if we could :-) When you calld.Get(...)
below, it'll populate it withoaep
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This applies in a few places as well below :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I were to nitpick, for consistency with sign/verify I might suggest calling this
encryption_algorithm
, as it'll likely be more widely used than just RSA here.padding_scheme
is definitely more precise, but boxes us into a corner w.r.t. EC algorithms.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think too, this makes a lot of sense and is consistent with the existing API.