@@ -2,9 +2,9 @@ package aws_signing_helper
2
2
3
3
import (
4
4
"crypto/tls"
5
- "crypto/x509"
6
5
"encoding/base64"
7
6
"errors"
7
+ "log"
8
8
"net/http"
9
9
"runtime"
10
10
@@ -19,6 +19,7 @@ type CredentialsOpts struct {
19
19
PrivateKeyId string
20
20
CertificateId string
21
21
CertificateBundleId string
22
+ CertIdentifier CertIdentifier
22
23
RoleArn string
23
24
ProfileArnStr string
24
25
TrustAnchorArnStr string
@@ -51,30 +52,22 @@ func GenerateCredentials(opts *CredentialsOpts) (CredentialProcessOutput, error)
51
52
opts .Region = trustAnchorArn .Region
52
53
}
53
54
54
- privateKey , err := ReadPrivateKeyData (opts .PrivateKeyId )
55
- if err != nil {
56
- return CredentialProcessOutput {}, err
57
- }
58
- certificateData , err := ReadCertificateData (opts .CertificateId )
59
- if err != nil {
60
- return CredentialProcessOutput {}, err
61
- }
62
- certificateDerData , err := base64 .StdEncoding .DecodeString (certificateData .CertificateData )
63
- if err != nil {
64
- return CredentialProcessOutput {}, err
65
- }
66
- certificate , err := x509 .ParseCertificate ([]byte (certificateDerData ))
67
- if err != nil {
68
- return CredentialProcessOutput {}, err
69
- }
70
- var certificateChain []x509.Certificate
71
- if opts .CertificateBundleId != "" {
72
- certificateChainPointers , err := ReadCertificateBundleData (opts .CertificateBundleId )
55
+ var signer Signer
56
+ var signingAlgorithm string
57
+ if opts .PrivateKeyId != "" {
58
+ privateKey , err := ReadPrivateKeyData (opts .PrivateKeyId )
73
59
if err != nil {
74
60
return CredentialProcessOutput {}, err
75
61
}
76
- for _ , certificate := range certificateChainPointers {
77
- certificateChain = append (certificateChain , * certificate )
62
+ signer , signingAlgorithm , err = GetFileSystemSigner (privateKey , opts .CertificateId , opts .CertificateBundleId )
63
+ if err != nil {
64
+ return CredentialProcessOutput {}, errors .New ("unable to create request signer" )
65
+ }
66
+ } else {
67
+ signer , signingAlgorithm , err = GetDarwinCertStoreSigner (opts .CertIdentifier )
68
+ if err != nil {
69
+ log .Println (err )
70
+ return CredentialProcessOutput {}, errors .New ("unable to create request signer" )
78
71
}
79
72
}
80
73
@@ -107,11 +100,20 @@ func GenerateCredentials(opts *CredentialsOpts) (CredentialProcessOutput, error)
107
100
rolesAnywhereClient .Handlers .Build .RemoveByName ("core.SDKVersionUserAgentHandler" )
108
101
rolesAnywhereClient .Handlers .Build .PushBackNamed (request.NamedHandler {Name : "v4x509.CredHelperUserAgentHandler" , Fn : request .MakeAddToUserAgentHandler ("CredHelper" , opts .Version , runtime .Version (), runtime .GOOS , runtime .GOARCH )})
109
102
rolesAnywhereClient .Handlers .Sign .Clear ()
110
- rolesAnywhereClient .Handlers .Sign .PushBackNamed (request.NamedHandler {Name : "v4x509.SignRequestHandler" , Fn : CreateSignFunction (privateKey , * certificate , certificateChain )})
103
+ certificate , err := signer .Certificate ()
104
+ if err != nil {
105
+ return CredentialProcessOutput {}, errors .New ("unable to find certificate" )
106
+ }
107
+ certificateChain , err := signer .CertificateChain ()
108
+ if err != nil {
109
+ return CredentialProcessOutput {}, errors .New ("unable to find certificate chain" )
110
+ }
111
+ rolesAnywhereClient .Handlers .Sign .PushBackNamed (request.NamedHandler {Name : "v4x509.SignRequestHandler" , Fn : CreateRequestSignFunction (signer , signingAlgorithm , certificate , certificateChain )})
111
112
113
+ certificateStr := base64 .StdEncoding .EncodeToString (certificate .Raw )
112
114
durationSeconds := int64 (opts .SessionDuration )
113
115
createSessionRequest := rolesanywhere.CreateSessionInput {
114
- Cert : & certificateData . CertificateData ,
116
+ Cert : & certificateStr ,
115
117
ProfileArn : & opts .ProfileArnStr ,
116
118
TrustAnchorArn : & opts .TrustAnchorArnStr ,
117
119
DurationSeconds : & (durationSeconds ),
0 commit comments