Skip to content

[PS] Refactor the http signing auth with ecdsa support #6397

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

Merged
merged 23 commits into from
May 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
49f2b4b
Merge pull request #1 from OpenAPITools/master
Ghufz Apr 16, 2020
ad24d34
ValidatePattern having double quote(") throws exception on running Bu…
Ghufz Apr 16, 2020
8bcd51d
Merge remote-tracking branch 'upstream/master'
Ghufz Apr 17, 2020
ff00948
fix tab with space
Ghufz Apr 17, 2020
f865bd8
Merge remote-tracking branch 'upstream/master'
Ghufz May 5, 2020
1d0d4e1
[powershell-experimental] : http signature auth
Ghufz May 5, 2020
5372b5a
fix the tab issue
Ghufz May 5, 2020
e6a4344
Merge remote-tracking branch 'upstream/master'
Ghufz May 22, 2020
c6a6a82
merge cnflict fix for powershell experimental
Ghufz May 22, 2020
0d66824
Htpp signing : added support for ecdsa
Ghufz May 22, 2020
206be22
Merge remote-tracking branch 'upstream/master'
Ghufz May 26, 2020
7c67a2a
Update modules/openapi-generator/src/main/resources/powershell/config…
Ghufz May 26, 2020
c1f19a2
Update modules/openapi-generator/src/main/resources/powershell/config…
Ghufz May 26, 2020
1381f3b
Update modules/openapi-generator/src/main/resources/powershell/config…
Ghufz May 26, 2020
83e81bc
Update modules/openapi-generator/src/main/resources/powershell/config…
Ghufz May 26, 2020
dd6d0b5
Update modules/openapi-generator/src/main/resources/powershell/config…
Ghufz May 26, 2020
984f77f
HttpSigningHeader accepts any header available in request to calculat…
Ghufz May 26, 2020
c8676f5
Merge branch 'master' of github.com:Ghufz/openapi-generator
Ghufz May 26, 2020
e954b4f
Update modules/openapi-generator/src/main/resources/powershell/http_s…
Ghufz May 26, 2020
9ef5ac6
Incorporated the review comments
Ghufz May 27, 2020
979b6d1
Merge branch 'master' of github.com:Ghufz/openapi-generator
Ghufz May 27, 2020
a78a8dd
addressed the merge conflict
Ghufz May 27, 2020
1096e49
fix the pester issueMerge remote-tracking branch 'upstream/master'
Ghufz May 29, 2020
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 @@ -91,11 +91,13 @@ function Invoke-{{{apiNamePrefix}}}ApiClient {

{{#hasHttpSignatureMethods}}
# http signature authentication
if ($null -ne $Configuration['ApiKey'] -and $Configuration['ApiKey'].Count -gt 0) {
$httpSigningConfig = Get-{{{apiNamePrefix}}}ConfigurationHttpSigning
if ($null -ne $httpSigningConfig) {
$httpSignHeaderArgument = @{
Method = $Method
UriBuilder = $UriBuilder
Body = $Body
RequestHeader = $HeaderParameters
}
$signedHeader = Get-{{{apiNamePrefix}}}HttpSignedHeader @httpSignHeaderArgument
if($null -ne $signedHeader -and $signedHeader.Count -gt 0){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,3 +372,140 @@ function Get-{{apiNamePrefix}}UrlFromHostSetting {

}
}

<#
.SYNOPSIS
Sets the configuration for http signing.
.DESCRIPTION

Sets the configuration for the HTTP signature security scheme.
The HTTP signature security scheme is used to sign HTTP requests with a key
which is in possession of the API client.
An 'Authorization' header is calculated by creating a hash of select headers,
and optionally the body of the HTTP request, then signing the hash value using
a key. The 'Authorization' header is added to outbound HTTP requests.

Ref: https://openapi-generator.tech

.PARAMETER KeyId
KeyId for HTTP signing

.PARAMETER KeyFilePath
KeyFilePath for HTTP signing

.PARAMETER KeyPassPhrase
KeyPassPhrase, if the HTTP signing key is protected

.PARAMETER HttpSigningHeader
HttpSigningHeader list of HTTP headers used to calculate the signature. The two special signature headers '(request-target)' and '(created)'
SHOULD be included.
The '(created)' header expresses when the signature was created.
The '(request-target)' header is a concatenation of the lowercased :method, an
ASCII space, and the :path pseudo-headers.
If no headers are specified then '(created)' sets as default.

.PARAMETER HashAlgorithm
HashAlgrithm to calculate the hash, Supported values are "sha256" and "sha512"

.PARAMETER SigningAlgorithm
SigningAlgorithm specifies the signature algorithm, supported values are "RSASSA-PKCS1-v1_5" and "RSASSA-PSS"
RSA key : Supported values "RSASSA-PKCS1-v1_5" and "RSASSA-PSS", for ECDSA key this parameter is not applicable

.PARAMETER SignatureValidityPeriod
SignatureValidityPeriod specifies the signature maximum validity time in seconds. It accepts integer value

.OUTPUTS

System.Collections.Hashtable
#>
function Set-{{{apiNamePrefix}}}ConfigurationHttpSigning {
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]$KeyId,
[Parameter(Mandatory = $true)]
[string]$KeyFilePath,
[Parameter(Mandatory = $false)]
[securestring]$KeyPassPhrase,
[Parameter(Mandatory = $false)]
[ValidateNotNullOrEmpty()]
[string[]] $HttpSigningHeader = @("(created)"),
[Parameter(Mandatory = $false)]
[ValidateSet("sha256", "sha512")]
[string] $HashAlgorithm = "sha256",
[Parameter(Mandatory = $false)]
[ValidateSet("RSASSA-PKCS1-v1_5", "RSASSA-PSS")]
[string]$SigningAlgorithm ,
[Parameter(Mandatory = $false)]
[int]$SignatureValidityPeriod
)

Process {
$httpSignatureConfiguration = @{ }

if (Test-Path -Path $KeyFilePath) {
$httpSignatureConfiguration["KeyId"] = $KeyId
$httpSignatureConfiguration["KeyFilePath"] = $KeyFilePath
}
else {
throw "Private key file path does not exist"
}

$keyType = Get-{{{apiNamePrefix}}}KeyTypeFromFile -KeyFilePath $KeyFilePath
if ([String]::IsNullOrEmpty($SigningAlgorithm)) {
if ($keyType -eq "RSA") {
$SigningAlgorithm = "RSASSA-PKCS1-v1_5"
}
}

if ($keyType -eq "RSA" -and
($SigningAlgorithm -ne "RSASSA-PKCS1-v1_5" -and $SigningAlgorithm -ne "RSASSA-PSS" )) {
throw "Provided Key and SigningAlgorithm : $SigningAlgorithm is not compatible."
}

if ($HttpSigningHeader -contains "(expires)" -and $SignatureValidityPeriod -le 0) {
throw "SignatureValidityPeriod must be greater than 0 seconds."
}

if ($HttpSigningHeader -contains "(expires)") {
$httpSignatureConfiguration["SignatureValidityPeriod"] = $SignatureValidityPeriod
}
if ($null -ne $HttpSigningHeader -and $HttpSigningHeader.Length -gt 0) {
$httpSignatureConfiguration["HttpSigningHeader"] = $HttpSigningHeader
}

if ($null -ne $HashAlgorithm ) {
$httpSignatureConfiguration["HashAlgorithm"] = $HashAlgorithm
}

if ($null -ne $SigningAlgorithm) {
$httpSignatureConfiguration["SigningAlgorithm"] = $SigningAlgorithm
}

if ($null -ne $KeyPassPhrase) {
$httpSignatureConfiguration["KeyPassPhrase"] = $KeyPassPhrase
}

$Script:Configuration["HttpSigning"] = New-Object -TypeName PSCustomObject -Property $httpSignatureConfiguration
}
}

<#
.SYNOPSIS

Get the configuration object '{{{apiNamePrefix}}}ConfigurationHttpSigning'.

.DESCRIPTION

Get the configuration object '{{{apiNamePrefix}}}ConfigurationHttpSigning'.

.OUTPUTS

[PSCustomObject]
#>
function Get-{{{apiNamePrefix}}}ConfigurationHttpSigning{

$httpSignatureConfiguration = $Script:Configuration["HttpSigning"]
return $httpSignatureConfiguration
}
Loading