diff options
author | Samuel Holland <samuel@sholland.org> | 2017-08-24 02:00:53 -0500 |
---|---|---|
committer | Samuel Holland <samuel@sholland.org> | 2017-08-24 02:00:53 -0500 |
commit | 3d6109e6d9e0deb8aa2e1069e7c2b5fc2fcfe6fa (patch) | |
tree | 8b6832d065f2fcb6451fad48127da0eeaac27259 /app/src/main | |
parent | 881ad4fd4706ac985b576216d23d7d48df31d39a (diff) |
Peer: Add a field for the optional pre-shared key
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src/main')
-rw-r--r-- | app/src/main/java/com/wireguard/config/Attribute.java | 1 | ||||
-rw-r--r-- | app/src/main/java/com/wireguard/config/Peer.java | 20 |
2 files changed, 21 insertions, 0 deletions
diff --git a/app/src/main/java/com/wireguard/config/Attribute.java b/app/src/main/java/com/wireguard/config/Attribute.java index e00ebb4c..4ee4e9f5 100644 --- a/app/src/main/java/com/wireguard/config/Attribute.java +++ b/app/src/main/java/com/wireguard/config/Attribute.java @@ -17,6 +17,7 @@ enum Attribute { LISTEN_PORT("ListenPort"), MTU("MTU"), PERSISTENT_KEEPALIVE("PersistentKeepalive"), + PRE_SHARED_KEY("PresharedKey"), PRIVATE_KEY("PrivateKey"), PUBLIC_KEY("PublicKey"); diff --git a/app/src/main/java/com/wireguard/config/Peer.java b/app/src/main/java/com/wireguard/config/Peer.java index 4f6d88b2..718a5c3c 100644 --- a/app/src/main/java/com/wireguard/config/Peer.java +++ b/app/src/main/java/com/wireguard/config/Peer.java @@ -29,6 +29,7 @@ public class Peer extends BaseObservable implements Copyable<Peer>, Observable, private final Config config; private String endpoint; private String persistentKeepalive; + private String preSharedKey; private String publicKey; public Peer(final Config config) { @@ -40,6 +41,7 @@ public class Peer extends BaseObservable implements Copyable<Peer>, Observable, config = null; endpoint = in.readString(); persistentKeepalive = in.readString(); + preSharedKey = in.readString(); publicKey = in.readString(); } @@ -59,6 +61,7 @@ public class Peer extends BaseObservable implements Copyable<Peer>, Observable, allowedIPs = source.allowedIPs; endpoint = source.endpoint; persistentKeepalive = source.persistentKeepalive; + preSharedKey = source.preSharedKey; publicKey = source.publicKey; notifyChange(); } @@ -84,6 +87,11 @@ public class Peer extends BaseObservable implements Copyable<Peer>, Observable, } @Bindable + public String getPreSharedKey() { + return preSharedKey; + } + + @Bindable public String getPublicKey() { return publicKey; } @@ -96,6 +104,8 @@ public class Peer extends BaseObservable implements Copyable<Peer>, Observable, setEndpoint(key.parseFrom(line)); else if (key == Attribute.PERSISTENT_KEEPALIVE) setPersistentKeepalive(key.parseFrom(line)); + else if (key == Attribute.PRE_SHARED_KEY) + setPreSharedKey(key.parseFrom(line)); else if (key == Attribute.PUBLIC_KEY) setPublicKey(key.parseFrom(line)); else @@ -128,6 +138,13 @@ public class Peer extends BaseObservable implements Copyable<Peer>, Observable, notifyPropertyChanged(BR.persistentKeepalive); } + public void setPreSharedKey(String preSharedKey) { + if (preSharedKey != null && preSharedKey.isEmpty()) + preSharedKey = null; + this.preSharedKey = preSharedKey; + notifyPropertyChanged(BR.preSharedKey); + } + public void setPublicKey(String publicKey) { if (publicKey != null && publicKey.isEmpty()) publicKey = null; @@ -143,6 +160,8 @@ public class Peer extends BaseObservable implements Copyable<Peer>, Observable, sb.append(Attribute.ENDPOINT.composeWith(endpoint)); if (persistentKeepalive != null) sb.append(Attribute.PERSISTENT_KEEPALIVE.composeWith(persistentKeepalive)); + if (preSharedKey != null) + sb.append(Attribute.PRE_SHARED_KEY.composeWith(preSharedKey)); if (publicKey != null) sb.append(Attribute.PUBLIC_KEY.composeWith(publicKey)); return sb.toString(); @@ -153,6 +172,7 @@ public class Peer extends BaseObservable implements Copyable<Peer>, Observable, dest.writeString(allowedIPs); dest.writeString(endpoint); dest.writeString(persistentKeepalive); + dest.writeString(preSharedKey); dest.writeString(publicKey); } } |