Skip to content

underlyingCoreCryptoError while creating NIOSSHPrivateKey #60

@AngeloAvv

Description

@AngeloAvv

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:

//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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions