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

chore: Add input validation for private key in oauth flow #11790

Merged
merged 2 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,7 @@ const supportedServices = {
},
{
key: 'signinwithapplePrivateKeyUserPool',
question: 'Enter your Private Key for your OAuth flow: ',
question: 'Enter your Private Key for your OAuth flow (entire key without line breaks): ',
required: true,
andConditions: [
{
Expand All @@ -1249,6 +1249,12 @@ const supportedServices = {
operator: 'includes',
},
],
validation: {
operator: 'regex',
value: '(-+BEGIN PRIVATE KEY-+)(.+[^-])(-+END PRIVATE KEY-+)',
onErrorMsg:
'Private key provided is invalid. You must provide the entire key (including the -----BEGIN PRIVATE KEY----- and -----END PRIVATE KEY----- on a single line)',
},
},
],
cfnFilename: 'auth-template.yml.ejs',
Expand Down
10 changes: 5 additions & 5 deletions packages/amplify-e2e-core/src/categories/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ export function addAuthWithDefaultSocial(cwd: string, settings: any): Promise<vo
.wait('Enter your Key ID for your OAuth flow:')
.send(APPLE_KEY_ID)
.sendCarriageReturn()
.wait('Enter your Private Key for your OAuth flow:')
.wait('Enter your Private Key for your OAuth flow (entire key without line breaks):')
.send(APPLE_PRIVATE_KEY)
.sendCarriageReturn()
.sendEof()
Expand Down Expand Up @@ -881,7 +881,7 @@ export function addAuthUserPoolOnly(cwd: string, settings: any): Promise<void> {
.sendLine(APPLE_TEAM_ID)
.wait('Enter your Key ID for your OAuth flow')
.sendLine(APPLE_KEY_ID)
.wait('Enter your Private Key for your OAuth flow')
.wait('Enter your Private Key for your OAuth flow (entire key without line breaks):')
.sendLine(APPLE_PRIVATE_KEY)
.wait('Do you want to configure Lambda Triggers for Cognito')
.sendConfirmYes()
Expand Down Expand Up @@ -1224,7 +1224,7 @@ export function addAuthWithMaxOptions(cwd: string, settings: any): Promise<void>
.sendLine(APPLE_TEAM_ID)
.wait('Enter your Key ID for your OAuth flow')
.sendLine(APPLE_KEY_ID)
.wait('Enter your Private Key for your OAuth flow')
.wait('Enter your Private Key for your OAuth flow (entire key without line breaks):')
.sendLine(APPLE_PRIVATE_KEY)
.wait('Do you want to configure Lambda Triggers for Cognito')
.sendConfirmYes()
Expand Down Expand Up @@ -1439,7 +1439,7 @@ export function addAuthUserPoolOnlyWithOAuth(cwd: string, settings: AddAuthUserP
.sendLine(settings.appleAppTeamId)
.wait('Enter your Key ID for your OAuth flow:')
.sendLine(settings.appleAppKeyID)
.wait('Enter your Private Key for your OAuth flow:')
.wait('Enter your Private Key for your OAuth flow (entire key without line breaks):')
.sendLine(settings.appleAppPrivateKey)
.wait('Do you want to configure Lambda Triggers for Cognito')
.sendConfirmNo()
Expand Down Expand Up @@ -1563,7 +1563,7 @@ export function addAuthIdentityPoolAndUserPoolWithOAuth(
.sendLine(settings.appleAppTeamId)
.wait('Enter your Key ID for your OAuth flow:')
.sendLine(settings.appleAppKeyID)
.wait('Enter your Private Key for your OAuth flow:')
.wait('Enter your Private Key for your OAuth flow (entire key without line breaks):')
.sendLine(settings.appleAppPrivateKey)
.wait('Do you want to configure Lambda Triggers for Cognito')
.sendConfirmNo()
Expand Down
8 changes: 4 additions & 4 deletions packages/amplify-e2e-core/src/utils/envVars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function getSocialProviders(getEnv = false): SocialProviders {
APPLE_KEY_ID: '2QLZXKYJ8J',
// Cognito validates the private key, this is an invalidated key.
APPLE_PRIVATE_KEY:
'MIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgIltgNsTgTfSzUadYiCS0VYtDDMFln/J8i1yJsSIw5g+gCgYIKoZIzj0DAQehRANCAASI8E0L/DhR/mIfTT07v3VwQu6q8I76lgn7kFhT0HvWoLuHKGQFcFkXXCgztgBrprzd419mUChAnKE6y89bWcNw',
'----BEGIN PRIVATE KEY-----MIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgIltgNsTgTfSzUadYiCS0VYtDDMFln/J8i1yJsSIw5g+gCgYIKoZIzj0DAQehRANCAASI8E0L/DhR/mIfTT07v3VwQu6q8I76lgn7kFhT0HvWoLuHKGQFcFkXXCgztgBrprzd419mUChAnKE6y89bWcNw----END PRIVATE KEY----',
};
}
const {
Expand All @@ -49,7 +49,7 @@ export function getSocialProviders(getEnv = false): SocialProviders {
APPLE_APP_ID,
APPLE_TEAM_ID,
APPLE_KEY_ID,
APPLE_PRIVATE_KEY,
APPLE_PRIVATE_KEY_2,
}: any = getEnvVars();

const missingVars = [];
Expand Down Expand Up @@ -80,7 +80,7 @@ export function getSocialProviders(getEnv = false): SocialProviders {
if (!APPLE_KEY_ID) {
missingVars.push('APPLE_KEY_ID');
}
if (!APPLE_PRIVATE_KEY) {
if (!APPLE_PRIVATE_KEY_2) {
missingVars.push('APPLE_PRIVATE_KEY');
}

Expand All @@ -97,6 +97,6 @@ export function getSocialProviders(getEnv = false): SocialProviders {
APPLE_APP_ID,
APPLE_TEAM_ID,
APPLE_KEY_ID,
APPLE_PRIVATE_KEY,
APPLE_PRIVATE_KEY: APPLE_PRIVATE_KEY_2,
};
}
2 changes: 1 addition & 1 deletion packages/amplify-e2e-tests/src/environment/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export function addEnvironmentHostedUI(cwd: string, settings: { envName: string
.sendLine(APPLE_TEAM_ID)
.wait('Enter your Key ID for your OAuth flow:')
.sendLine(APPLE_KEY_ID)
.wait('Enter your Private Key for your OAuth flow:')
.wait('Enter your Private Key for your OAuth flow (entire key without line breaks):')
.sendLine(APPLE_PRIVATE_KEY)
.wait(/Try "amplify add api" to create a backend API and then "amplify (push|publish)" to deploy everything/)
.run((err: Error) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const createUserPoolOnlyWithOAuthSettings = (projectPrefix: string, short
appleAppTeamId: '2QLEWNDK6K',
appleAppKeyID: '2QLZXKYJ8J',
appleAppPrivateKey:
'MIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgIltgNsTgTfSzUadYiCS0VYtDDMFln/J8i1yJsSIw5g+gCgYIKoZIzj0DAQehRANCAASI8E0L/DhR/mIfTT07v3VwQu6q8I76lgn7kFhT0HvWoLuHKGQFcFkXXCgztgBrprzd419mUChAnKE6y89bWcNw',
'----BEGIN PRIVATE KEY----MIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgIltgNsTgTfSzUadYiCS0VYtDDMFln/J8i1yJsSIw5g+gCgYIKoZIzj0DAQehRANCAASI8E0L/DhR/mIfTT07v3VwQu6q8I76lgn7kFhT0HvWoLuHKGQFcFkXXCgztgBrprzd419mUChAnKE6y89bWcNw----END PRIVATE KEY----',
};
};

Expand Down