Skip to content

Commit

Permalink
Fix file formatting using
Browse files Browse the repository at this point in the history
  • Loading branch information
13ajay committed Aug 1, 2023
1 parent f9d8b99 commit 31845d5
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
34 changes: 17 additions & 17 deletions aws_signing_helper/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func GetSigner(opts *CredentialsOpts) (signer Signer, signatureAlgorithm string,
privateKeyId = opts.CertificateId
}

if opts.CertificateId != "" && !strings.HasPrefix(opts.CertificateId, "pkcs11:") {
if opts.CertificateId != "" && !strings.HasPrefix(opts.CertificateId, "pkcs11:") {
certificateData, err := ReadCertificateData(opts.CertificateId)
if err == nil {
certificateDerData, err := base64.StdEncoding.DecodeString(certificateData.CertificateData)
Expand Down Expand Up @@ -202,22 +202,22 @@ func GetSigner(opts *CredentialsOpts) (signer Signer, signatureAlgorithm string,
}
}

if strings.HasPrefix(privateKeyId, "pkcs11:") {
if Debug {
fmt.Fprintln(os.Stderr, "attempting to use PKCS#11")
}
return GetPKCS11Signer(opts.LibPkcs11, certificate, certificateChain, opts.PrivateKeyId, opts.CertificateId)
} else {
privateKey, err := ReadPrivateKeyData(privateKeyId)
if err != nil {
return nil, "", err
}

if Debug {
fmt.Fprintln(os.Stderr, "attempting to use FileSystemSigner")
}
return GetFileSystemSigner(privateKey, certificate, certificateChain)
}
if strings.HasPrefix(privateKeyId, "pkcs11:") {
if Debug {
fmt.Fprintln(os.Stderr, "attempting to use PKCS#11")
}
return GetPKCS11Signer(opts.LibPkcs11, certificate, certificateChain, opts.PrivateKeyId, opts.CertificateId)
} else {
privateKey, err := ReadPrivateKeyData(privateKeyId)
if err != nil {
return nil, "", err
}

if Debug {
fmt.Fprintln(os.Stderr, "attempting to use FileSystemSigner")
}
return GetFileSystemSigner(privateKey, certificate, certificateChain)
}
}

// Obtain the date-time, formatted as specified by SigV4
Expand Down
4 changes: 2 additions & 2 deletions aws_signing_helper/signer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func TestSign(t *testing.T) {

}
}

pkcs11_objects := []string{"RSA", "EC"}

for _, object := range pkcs11_objects {
Expand All @@ -264,7 +264,7 @@ func TestSign(t *testing.T) {
for _, credOpts := range testTable {
signer, _, err := GetSigner(&credOpts)
if err != nil {
t.Log(err)
t.Log(err)
var logMsg string
if credOpts.CertificateId != "" || credOpts.PrivateKeyId != "" {
logMsg = fmt.Sprintf("Failed to get signer for '%s'/'%s'",
Expand Down
2 changes: 1 addition & 1 deletion cmd/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func initCredentialsSubCommand(subCmd *cobra.Command) {
subCmd.PersistentFlags().StringVar(&certificateBundleId, "intermediates", "", "Path to intermediate certificate bundle file")
subCmd.PersistentFlags().StringVar(&certSelector, "cert-selector", "", "JSON structure to identify a certificate from a certificate store. "+
"Can be passed in either as string or a file name (prefixed by \"file://\")")
subCmd.PersistentFlags().StringVar(&libPkcs11, "pkcs11-lib", "", "Library for smart card / cryptographic device (OpenSC or vendor specific)")
subCmd.PersistentFlags().StringVar(&libPkcs11, "pkcs11-lib", "", "Library for smart card / cryptographic device (OpenSC or vendor specific)")
subCmd.PersistentFlags().StringVar(&pinPkcs11, "pkcs11-pin", "-", "Pin of the PKCS #11 user for private key access")
subCmd.PersistentFlags().UintVar(&slotPkcs11, "pkcs11-slot", 0, "PKCS #11 slot in which to search for the private key (and potentially certificate as well)")

Expand Down
4 changes: 2 additions & 2 deletions cmd/read_certificate_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"fmt"
"log"
"os"
"strings"
"strings"

helper "github.com/aws/rolesanywhere-credential-helper/aws_signing_helper"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -55,7 +55,7 @@ var readCertificateDataCmd = &cobra.Command{
// PrintCertificate interface can be assigned to this variable.
var printFunction PrintCertificate = DefaultPrintCertificate

if strings.HasPrefix(certificateId, "pkcs11:") {
if strings.HasPrefix(certificateId, "pkcs11:") {
certContainers, err = helper.GetMatchingPKCSCerts(certificateId, libPkcs11)
if err != nil {
log.Println(err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/sign_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func init() {
signStringCmd.PersistentFlags().BoolVar(&debug, "debug", false, "To print debug output")
signStringCmd.PersistentFlags().StringVar(&certSelector, "cert-selector", "", "JSON structure to identify a certificate from a certificate store. "+
"Can be passed in either as string or a file name (prefixed by \"file://\")")
signStringCmd.PersistentFlags().StringVar(&libPkcs11, "pkcs11-lib", "", "Library for smart card / cryptographic device (default: p11-kit-proxy.{so, dll, dylib})")
signStringCmd.PersistentFlags().StringVar(&libPkcs11, "pkcs11-lib", "", "Library for smart card / cryptographic device (default: p11-kit-proxy.{so, dll, dylib})")
signStringCmd.PersistentFlags().Var(format, "format", "Output format. One of json, text, and bin")
signStringCmd.PersistentFlags().Var(digestArg, "digest", "One of SHA256, SHA384, and SHA512")
}
Expand Down

0 comments on commit 31845d5

Please sign in to comment.