Skip to content

Commit

Permalink
Merge pull request #120 from neicnordic/bugfix/remove-deadcode-openssl
Browse files Browse the repository at this point in the history
Bugfix/remove deadcode openssl
  • Loading branch information
blankdots authored Feb 22, 2024
2 parents 0a32f4c + 39e6177 commit 88c2108
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ jobs:
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v4.0.0
with:
version: v1.51.1
version: latest
args: -E bodyclose,gocritic,gofmt,gosec,govet,nestif,nlreturn,revive,rowserrcheck --exclude G401,G501,G107
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
fi
- name: Test
run: go test -v -coverprofile=coverage.txt -covermode=atomic ./...
run: go test -v -coverprofile=coverage.txt -covermode=atomic $(go list ./... | grep -v /examples/)

- name: Codecov
uses: codecov/codecov-action@v4.0.1
Expand Down
22 changes: 1 addition & 21 deletions keys/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,33 +92,13 @@ func ReadPrivateKey(reader io.Reader, passPhrase []byte) (privateKey [chacha20po
return
}

// Not OpenSSH private key, assuming OpenSSL private key, trying to figure out type (Ed25519 or X25519)
block, _ := pem.Decode(allBytes)

if block == nil {
return [chacha20poly1305.KeySize]byte{}, fmt.Errorf("Read of unrecognized private key format failed; " +
return [chacha20poly1305.KeySize]byte{}, fmt.Errorf("read of unrecognized private key format failed; " +
"expected PEM encoded key")
}

var openSSLPrivateKey openSSLPrivateKey
if _, err = asn1.Unmarshal(block.Bytes, &openSSLPrivateKey); err == nil {
// Trying to read OpenSSL Ed25519 private key and convert to X25519 private key
if openSSLPrivateKey.Algorithm.Algorithm.Equal(ed25519Algorithm) {
var edKeyBytes ed25519.PrivateKey
copy(edKeyBytes[:], block.Bytes[len(block.Bytes)-chacha20poly1305.KeySize:])
PrivateKeyToCurve25519(&privateKey, edKeyBytes)

return
}

// Trying to read OpenSSL X25519 private key
if openSSLPrivateKey.Algorithm.Algorithm.Equal(x25519Algorithm) {
copy(privateKey[:], block.Bytes[len(block.Bytes)-chacha20poly1305.KeySize:])

return
}
}

// Interpreting bytes as Crypt4GH private key bytes (https://crypt4gh.readthedocs.io/en/latest/keys.html)
if len(block.Bytes) > 8 && string(block.Bytes[:7]) == magic {
return readCrypt4GHPrivateKey(block.Bytes, passPhrase)
Expand Down

0 comments on commit 88c2108

Please sign in to comment.