-
Notifications
You must be signed in to change notification settings - Fork 122
Define an enum for the RSA padding scheme #162
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
Changes from all commits
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 |
---|---|---|
|
@@ -21,7 +21,7 @@ public class RawRsaKeyringBuilder { | |
private String keyName; | ||
private PublicKey publicKey; | ||
private PrivateKey privateKey; | ||
private String wrappingAlgorithm; | ||
private RsaPaddingScheme paddingScheme; | ||
|
||
private RawRsaKeyringBuilder() { | ||
// Use RawRsaKeyringBuilder.standard() or StandardKeyrings.rawRsa() to instantiate | ||
|
@@ -81,13 +81,13 @@ public RawRsaKeyringBuilder privateKey(PrivateKey privateKey) { | |
} | ||
|
||
/** | ||
* The RSA algorithm to use with this keyring (required). | ||
* The RSA padding scheme to use with this keyring (required). | ||
* | ||
* @param wrappingAlgorithm The algorithm | ||
* @param paddingScheme The RSA padding scheme | ||
* @return The RawRsaKeyringBuilder, for method chaining | ||
*/ | ||
public RawRsaKeyringBuilder wrappingAlgorithm(String wrappingAlgorithm) { | ||
this.wrappingAlgorithm = wrappingAlgorithm; | ||
public RawRsaKeyringBuilder paddingScheme(RsaPaddingScheme paddingScheme) { | ||
this.paddingScheme = paddingScheme; | ||
return this; | ||
} | ||
|
||
|
@@ -97,6 +97,33 @@ public RawRsaKeyringBuilder wrappingAlgorithm(String wrappingAlgorithm) { | |
* @return The {@link Keyring} instance | ||
*/ | ||
public Keyring build() { | ||
return new RawRsaKeyring(keyNamespace, keyName, publicKey, privateKey, wrappingAlgorithm); | ||
return new RawRsaKeyring(keyNamespace, keyName, publicKey, privateKey, paddingScheme); | ||
} | ||
|
||
public enum RsaPaddingScheme { | ||
|
||
PKCS1("RSA/ECB/PKCS1Padding"), | ||
OAEP_SHA1_MGF1("RSA/ECB/OAEPWithSHA-1AndMGF1Padding"), | ||
OAEP_SHA256_MGF1("RSA/ECB/OAEPWithSHA-256AndMGF1Padding"), | ||
OAEP_SHA384_MGF1("RSA/ECB/OAEPWithSHA-384AndMGF1Padding"), | ||
OAEP_SHA512_MGF1("RSA/ECB/OAEPWithSHA-512AndMGF1Padding"); | ||
|
||
private final String transformation; | ||
|
||
RsaPaddingScheme(String transformation) { | ||
this.transformation = transformation; | ||
} | ||
|
||
/** | ||
* The Cipher transformation standard name as specified in | ||
* https://docs.oracle.com/javase/8/docs/technotes/guides/security/StandardNames.html#Cipher | ||
Comment on lines
+118
to
+119
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. This is almost correct. Please clarify that in all cases the hash function used with MGF1 is the same as the hash function used directly with the message. 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. Updated |
||
* Note: In all cases the hash function used with MGF1 is the | ||
* same as the hash function used directly with the message. | ||
* | ||
* @return The transformation name | ||
*/ | ||
public String getTransformation() { | ||
return transformation; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except | ||
* in compliance with the License. A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package com.amazonaws.encryptionsdk.model; | ||
|
||
import com.amazonaws.encryptionsdk.keyrings.RawRsaKeyringBuilder.RsaPaddingScheme; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import javax.crypto.Cipher; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
class RsaPaddingSchemeTest { | ||
|
||
@Test | ||
void testCipherInitialization() throws Exception { | ||
for (RsaPaddingScheme paddingScheme : RsaPaddingScheme.values()) { | ||
assertNotNull(Cipher.getInstance(paddingScheme.getTransformation())); | ||
} | ||
} | ||
} |
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.
NitPick: For ease of use, calculate the correct OAEPParameterSpec instances for each of these (they are immutable) and just pull them from the enum.
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'll hold off on this until Master Keys are deleted