Fonta1n3 / FullyNoded

Self sovereign, secure, powerful, easy to use wallet that utilizes your own node as a backend. Powered by PSBT's and descriptors. Acts as an offline signer using your node as a watch-only wallet. C-Lightning compatible for instant, unfairly cheap payments.
https://fullynoded.app
Other
201 stars 31 forks source link

Derive x25519 keys locally for tor v3 authentication #12

Closed Fonta1n3 closed 4 years ago

Fonta1n3 commented 4 years ago

In KeyGen.swift I am attempting to make use of the iOS13 module CryptoKit. I am trying to mirror the functionality of this python script to generate x25519 keypair, trim the trailing ==== and base32 encode it.

Everytime I try and use the keypair to authenticate my tor v3 HS it fails. I think I am going wrong in the base32 encoding, do not have the time to focus on this. If anyone can help it would be much appreciated.

Fonta1n3 commented 4 years ago

Encoding the data to base64 string then base32 seems to have fixed this:

import CryptoKit
import Foundation

class KeyGen {

    var privKey = ""
    var pubKey = ""

    func generate() {

        if #available(iOS 13.0, *) {

            let privKeyRaw = Curve25519.Signing.PrivateKey.init()
            let pubKeyRaw = privKeyRaw.publicKey

            let privKeyData = privKeyRaw.rawRepresentation
            let pubkeyData = pubKeyRaw.rawRepresentation

            let privkeyBase64 = privKeyData.base64EncodedString()
            let pubkeyBase64 = pubkeyData.base64EncodedString()

            let privkeyBase32 = privkeyBase64.base32EncodedString
            let pubkeyBase32 = pubkeyBase64.base32EncodedString

            privKey = privkeyBase32.replacingOccurrences(of: "=", with: "")
            pubKey = pubkeyBase32.replacingOccurrences(of: "=", with: "")

        }

    }

}