Skip to content

Commit

Permalink
fix(snowflake): private keys provided through a textarea not being no…
Browse files Browse the repository at this point in the history
…rmalised properly (#106)

# Description
After normalisation private keys should look like this
```
-----BEGIN PRIVATE KEY-----
sometext1 sometext2 sometext3 ...
-----END PRIVATE KEY-----
```
A private key provided in a textarea element will look like this
```
-----BEGIN PRIVATE KEY-----
sometext1
sometext2
sometext3
...
-----END PRIVATE KEY-----
```
Thus in `normalisePem` we are first replacing all new lines with spaces
and then introducing new lines wherever it is needed.

## Linear Ticket

resolves PRO-2869

## Security

- [x] The code changed/added as part of this pull request won't create
any security issues with how the software is being used.
  • Loading branch information
atzoum authored Jun 19, 2024
1 parent f1d60f9 commit b15ffc5
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sqlconnect/internal/snowflake/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ func (c *Config) ParsePrivateKey() (*rsa.PrivateKey, error) {

// normalisePem formats the content of certificates and keys by adding necessary newlines around specific markers.
func normalisePem(content string) string {
// Remove all existing newline characters
formattedContent := strings.ReplaceAll(content, "\n", "")
// Remove all existing newline characters and replace them with a space
formattedContent := strings.ReplaceAll(content, "\n", " ")

// Add a newline after specific BEGIN markers
formattedContent = strings.Replace(formattedContent, "-----BEGIN CERTIFICATE-----", "-----BEGIN CERTIFICATE-----\n", 1)
Expand Down
Loading

0 comments on commit b15ffc5

Please sign in to comment.