-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor cert handling for api, worker and snapshot (#726)
Co-authored-by: Kaushik Iska <[email protected]>
- Loading branch information
1 parent
a49d73a
commit 30152d0
Showing
4 changed files
with
38 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package main | ||
|
||
import ( | ||
"crypto/tls" | ||
"encoding/base64" | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
func Base64DecodeCertAndKey(cert string, key string) ([]tls.Certificate, error) { | ||
temporalCert := strings.TrimSpace(cert) | ||
certBytes, err := base64.StdEncoding.DecodeString(temporalCert) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to decode temporal certificate: %w", err) | ||
} | ||
|
||
temporalKey := strings.TrimSpace(key) | ||
keyBytes, err := base64.StdEncoding.DecodeString(temporalKey) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to decode temporal key: %w", err) | ||
} | ||
|
||
keyPair, err := tls.X509KeyPair(certBytes, keyBytes) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to obtain temporal key pair: %w", err) | ||
} | ||
|
||
return []tls.Certificate{keyPair}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters