|
4 | 4 |
|
5 | 5 | class PhpAwsSmtpPassword
|
6 | 6 | {
|
| 7 | + protected static $allowed_regions = [ |
| 8 | + 'us-east-1', # US East (N. Virginia) |
| 9 | + 'us-east-2', # US East (Ohio) |
| 10 | + 'us-west-1', # US West (N. California) |
| 11 | + 'us-west-2', # US West (Oregon) |
| 12 | + 'af-south-1', # Africa (Cape Town) |
| 13 | + 'ap-south-1', # Asia Pacific (Mumbai) |
| 14 | + 'ap-northeast-2', # Asia Pacific (Seoul) |
| 15 | + 'ap-southeast-1', # Asia Pacific (Singapore) |
| 16 | + 'ap-southeast-2', # Asia Pacific (Sydney) |
| 17 | + 'ap-northeast-1', # Asia Pacific (Tokyo) |
| 18 | + 'ca-central-1', # Canada (Central) |
| 19 | + 'eu-central-1', # Europe (Frankfurt) |
| 20 | + 'eu-west-1', # Europe (Ireland) |
| 21 | + 'eu-west-2', # Europe (London) |
| 22 | + 'eu-south-1', # Europe (Milan) |
| 23 | + 'eu-west-3', # Europe (Paris) |
| 24 | + 'eu-north-1', # Europe (Stockholm) |
| 25 | + 'me-south-1', # Middle East (Bahrain) |
| 26 | + 'sa-east-1', # South America (Sao Paulo) |
| 27 | + 'us-gov-west-1', # AWS GovCloud (US) |
| 28 | + ]; |
| 29 | + |
7 | 30 | /**
|
8 | 31 | * Per https://docs.aws.amazon.com/ses/latest/DeveloperGuide/smtp-credentials.html this should never change
|
9 | 32 | * @var string Date to hash with
|
@@ -43,6 +66,10 @@ class PhpAwsSmtpPassword
|
43 | 66 | */
|
44 | 67 | public static function convert($key, $region)
|
45 | 68 | {
|
| 69 | + $region = strtolower($region); |
| 70 | + if (!in_array($region, PhpAwsSmtpPassword::$allowed_regions)) { |
| 71 | + throw new \InvalidArgumentException($region . ' is not setup for SES.'); |
| 72 | + } |
46 | 73 | $signature = hash_hmac('sha256', PhpAwsSmtpPassword::$date, 'AWS4' . $key, true);
|
47 | 74 | $signature = hash_hmac('sha256', $region, $signature, true);
|
48 | 75 | $signature = hash_hmac('sha256', PhpAwsSmtpPassword::$service, $signature, true);
|
|
0 commit comments