diff --git a/WireGuard/Base.lproj/Main.storyboard b/WireGuard/Base.lproj/Main.storyboard
index bf68b14..5d8e3f5 100644
--- a/WireGuard/Base.lproj/Main.storyboard
+++ b/WireGuard/Base.lproj/Main.storyboard
@@ -117,24 +117,24 @@
-
-
+
+
-
+
-
+
-
+
-
+
@@ -155,7 +155,7 @@
-
+
-
+
-
+
@@ -177,7 +177,10 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
+
@@ -209,7 +247,7 @@
-
+
-
+
@@ -230,19 +268,19 @@
-
+
-
+
-
+
@@ -254,16 +292,16 @@
-
+
-
+
@@ -273,14 +311,13 @@
+
+
+
-
-
-
-
@@ -297,10 +334,11 @@
+
-
+
@@ -325,7 +363,7 @@
-
+
@@ -365,16 +403,31 @@
-
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -527,33 +580,36 @@
-
-
+
+
-
+
-
+
-
+
-
-
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
+
+
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -665,123 +684,102 @@
-
-
-
-
+
-
-
+
+
-
+
-
+
-
+
-
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
+
+
-
-
+
+
+
+
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
@@ -794,8 +792,6 @@
-
-
diff --git a/WireGuard/Models/Interface+Extension.swift b/WireGuard/Models/Interface+Extension.swift
index 5dbeb5a..aa4e3cb 100644
--- a/WireGuard/Models/Interface+Extension.swift
+++ b/WireGuard/Models/Interface+Extension.swift
@@ -10,6 +10,20 @@ import Foundation
extension Interface {
+ var publicKey: String? {
+ if let privateKeyString = privateKey, let privateKey = Data(base64Encoded: privateKeyString) {
+ var publicKey = Data(count: 32)
+ privateKey.withUnsafeBytes({ (privateKeyBytes) -> Void in
+ publicKey.withUnsafeMutableBytes({ (mutableBytes) -> Void in
+ curve25519_derive_public_key(mutableBytes, privateKeyBytes)
+ })
+ })
+ return publicKey.base64EncodedString()
+ } else {
+ return nil
+ }
+ }
+
func validate() throws {
guard let privateKey = privateKey, !privateKey.isEmpty else {
throw InterfaceValidationError.emptyPrivateKey
diff --git a/WireGuard/ViewControllers/TunnelConfigurationTableViewController.swift b/WireGuard/ViewControllers/TunnelConfigurationTableViewController.swift
index db5182e..d5b0740 100644
--- a/WireGuard/ViewControllers/TunnelConfigurationTableViewController.swift
+++ b/WireGuard/ViewControllers/TunnelConfigurationTableViewController.swift
@@ -150,18 +150,6 @@ extension TunnelConfigurationTableViewController: InterfaceTableViewCellDelegate
}
self.tunnel.interface?.privateKey = privateKey.base64EncodedString()
-
- if let peers = self.tunnel.peers?.array as? [Peer] {
- peers.forEach {
- var publicKey = Data(count: 32)
- privateKey.withUnsafeBytes({ (privateKeyBytes) -> Void in
- publicKey.withUnsafeMutableBytes({ (mutableBytes) -> Void in
- curve25519_derive_public_key(mutableBytes, privateKeyBytes)
- })
- })
- $0.publicKey = publicKey.base64EncodedString()
- }
- }
}
}
self.tableView.reloadData()
@@ -178,17 +166,26 @@ class InterfaceTableViewCell: UITableViewCell {
nameField.text = model.tunnel?.title
addressesField.text = model.addresses
privateKeyField.text = model.privateKey
+ publicKeyField.text = model.publicKey
+
listenPortField.text = String(model.listenPort)
dnsField.text = model.dns
mtuField.text = String(model.mtu)
}
}
+ @IBAction func copyPublicKey(_ sender: Any) {
+ if let publicKey = model.publicKey {
+ UIPasteboard.general.string = publicKey
+ }
+ }
+
weak var delegate: InterfaceTableViewCellDelegate?
@IBOutlet weak var nameField: UITextField!
@IBOutlet weak var addressesField: UITextField!
@IBOutlet weak var privateKeyField: UITextField!
+ @IBOutlet weak var publicKeyField: UILabel!
@IBOutlet weak var listenPortField: UITextField!
@IBOutlet weak var dnsField: UITextField!
@IBOutlet weak var mtuField: UITextField!
@@ -208,6 +205,7 @@ extension InterfaceTableViewCell: UITextFieldDelegate {
model.tunnel?.title = string
} else if sender == privateKeyField {
model.privateKey = string
+ publicKeyField.text = model.publicKey
} else if sender == addressesField {
model.addresses = string
} else if sender == listenPortField {
@@ -246,6 +244,12 @@ class PeerTableViewCell: UITableViewCell {
@IBOutlet weak var endpointField: UITextField!
@IBOutlet weak var persistentKeepaliveField: UITextField!
+ @IBAction func copyPublicKey(_ sender: Any) {
+ if let publicKey = peer.publicKey {
+ UIPasteboard.general.string = publicKey
+ }
+ }
+
@IBAction func deletePeer(_ sender: Any) {
delegate?.delete(peer: peer)
}
diff --git a/WireGuard/ViewControllers/TunnelInfoTableViewController.swift b/WireGuard/ViewControllers/TunnelInfoTableViewController.swift
index 7e05222..094114a 100644
--- a/WireGuard/ViewControllers/TunnelInfoTableViewController.swift
+++ b/WireGuard/ViewControllers/TunnelInfoTableViewController.swift
@@ -73,37 +73,39 @@ class InterfaceInfoTableViewCell: UITableViewCell {
didSet {
nameField.text = model.tunnel?.title
addressesField.text = model.addresses
- privateKeyField.text = model.privateKey
- listenPortField.text = String(model.listenPort)
- dnsField.text = model.dns
- mtuField.text = String(model.mtu)
+ publicKeyField.text = model.publicKey
}
}
@IBOutlet weak var nameField: UILabel!
@IBOutlet weak var addressesField: UILabel!
- @IBOutlet weak var privateKeyField: UILabel!
- @IBOutlet weak var listenPortField: UILabel!
- @IBOutlet weak var dnsField: UILabel!
- @IBOutlet weak var mtuField: UILabel!
+ @IBOutlet weak var publicKeyField: UILabel!
+
+ @IBAction func copyPublicKey(_ sender: Any) {
+ if let publicKey = model.publicKey {
+ UIPasteboard.general.string = publicKey
+ }
+ }
}
class PeerInfoTableViewCell: UITableViewCell {
var peer: Peer! {
didSet {
publicKeyField.text = peer.publicKey
- preSharedKeyField.text = peer.presharedKey
allowedIpsField.text = peer.allowedIPs
endpointField.text = peer.endpoint
- persistentKeepaliveField.text = String(peer.persistentKeepalive)
}
}
@IBOutlet weak var publicKeyField: UILabel!
- @IBOutlet weak var preSharedKeyField: UILabel!
@IBOutlet weak var allowedIpsField: UILabel!
@IBOutlet weak var endpointField: UILabel!
- @IBOutlet weak var persistentKeepaliveField: UILabel!
+
+ @IBAction func copyPublicKey(_ sender: Any) {
+ if let publicKey = peer.publicKey {
+ UIPasteboard.general.string = publicKey
+ }
+ }
}
extension TunnelInfoTableViewController: Identifyable {}