apple / apple/swift-nio-ssh

underlyingCoreCryptoError while creating NIOSSHPrivateKey

Open
#60 6 comments 1 reaction 0 assignees View on GitHub
Dominant language
Swift
Stars
515
Forks
85
PR merge metrics
No merged PRs in 30d

Description

Hi,
I'm trying to setup a SSH tunnel in order to forward a remote port into my local device. I followed your PR #55 and I successfully implemented it into a brand new iOS project: I am able to forward a port using password authentication.

What I'm trying to do is performing a private key authentication. Due to the lack of the documentation, I'm going to ask you a few questions. Here's the code:

``` swift
//ssh-keygen -t ecdsa -b 521 -m pem

let sshPrivateText = """
-----BEGIN EC PRIVATE KEY-----
row1
row2
row3
row4
row5
-----END EC PRIVATE KEY-----
"""

let base64EncodedString:String = Data(sshPrivateText.utf8).base64EncodedString()
let ecdsaPrivateKeyData:Data = Data(base64Encoded: base64EncodedString, options: .ignoreUnknownCharacters)!
let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
let key: NIOSSHPrivateKey?
do {
key = NIOSSHPrivateKey(p521Key: try .init(rawRepresentation: ecdsaPrivateKeyData))
} catch let error {
fatalError(error.localizedDescription)
}
```

But I can't go further the `NIOSSHPrivateKey` constructor since the .init throws an error:
```
Fatal error: The operation couldn’t be completed. (CryptoKit.CryptoKitError error 0.): file /Users/user/XCode Projects/NioExample/NioExample/ContentView.swift, line 35
2020-12-13 12:57:48.397737+0100 NioExample[2711:69134] Fatal error: The operation couldn’t be completed. (CryptoKit.CryptoKitError error 0.): file /Users/user/XCode Projects/NioExample/NioExample/ContentView.swift, line 35
(lldb)
```

```
▿ CryptoKitError
▿ underlyingCoreCryptoError : 1 element
- error : -1
```

Also, I have another question. Why the minimum SDK level is iOS13? Could it be downgraded or something? It's a huge device cut! Will this project be included in cocoapods? I'm asking this because I'm going to integrate this script into a native Flutter plugin and it seems like Flutter projects are not compatibile with SwiftPM.

Thank you for this amazing project by the way!

Contributor guide

Open the contributing guide

Research direction

Start at the NIOSSHPrivateKey(p521Key:) call and compare the supplied PEM/Data conversion with the implementation referenced by PR #55. Reproduce the CryptoKit error, then establish the supported key representation and separately verify the iOS deployment target and package-distribution questions; the issue names no tests or source files.

Written by the indexing model from the issue text.

Assessment

Tech stack
ios, swift
Domain
mobile-dev, networking, security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.