Alexandre Lision | 2450c3e | 2014-02-14 15:31:58 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2004-2014 Savoir-Faire Linux Inc. |
| 3 | * |
| 4 | * Author: Alexandre Lision <alexandre.lision@savoirfairelinux> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 19 | * |
| 20 | * Additional permission under GNU GPL version 3 section 7: |
| 21 | * |
| 22 | * If you modify this program, or any covered work, by linking or |
| 23 | * combining it with the OpenSSL project's OpenSSL library (or a |
| 24 | * modified version of that library), containing parts covered by the |
| 25 | * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. |
| 26 | * grants you additional permission to convey the resulting work. |
| 27 | * Corresponding Source for a non-source form of such a combination |
| 28 | * shall include the source code for the parts of OpenSSL used as well |
| 29 | * as that of the covered work. |
| 30 | */ |
| 31 | |
| 32 | package org.sflphone.model; |
| 33 | |
Alexandre Lision | 2450c3e | 2014-02-14 15:31:58 -0500 | [diff] [blame] | 34 | import android.os.Parcel; |
| 35 | import android.os.Parcelable; |
Alexandre Lision | dbe396d | 2014-02-24 16:53:25 -0500 | [diff] [blame] | 36 | import android.util.Log; |
Alexandre Lision | 92ef0f2 | 2014-02-27 15:57:55 -0500 | [diff] [blame^] | 37 | import org.sflphone.account.AccountDetailSrtp; |
| 38 | |
| 39 | import java.io.Serializable; |
Alexandre Lision | 2450c3e | 2014-02-14 15:31:58 -0500 | [diff] [blame] | 40 | |
| 41 | |
| 42 | public class SecureSipCall extends SipCall { |
| 43 | |
Alexandre Lision | 92ef0f2 | 2014-02-27 15:57:55 -0500 | [diff] [blame^] | 44 | public interface SecureLayer { |
| 45 | int ZRTP_LAYER = 0; |
| 46 | int SDES_LAYER = 1; |
| 47 | int TLS_LAYER = 2; |
| 48 | } |
Alexandre Lision | 2450c3e | 2014-02-14 15:31:58 -0500 | [diff] [blame] | 49 | |
Alexandre Lision | df222a5 | 2014-02-25 09:58:57 -0500 | [diff] [blame] | 50 | public final static int DISPLAY_GREEN_LOCK = 0; |
| 51 | public final static int DISPLAY_RED_LOCK = 1; |
| 52 | public final static int DISPLAY_CONFIRM_SAS = 2; |
| 53 | public final static int DISPLAY_NONE = 3; |
| 54 | |
Alexandre Lision | 92ef0f2 | 2014-02-27 15:57:55 -0500 | [diff] [blame^] | 55 | int mSecureLayerUsed; |
| 56 | ZrtpModule mZrtpModule; |
| 57 | SdesModule mSdesModule; |
Alexandre Lision | e1b7f16 | 2014-02-26 16:45:32 -0500 | [diff] [blame] | 58 | /* |
Alexandre Lision | 2450c3e | 2014-02-14 15:31:58 -0500 | [diff] [blame] | 59 | tls: |
| 60 | calist: |
| 61 | certificate: |
| 62 | ciphers: |
| 63 | enable: false |
| 64 | method: TLSv1 |
| 65 | password: |
| 66 | privateKey: |
| 67 | requireCertif: true |
| 68 | server: |
| 69 | timeout: 2 |
| 70 | tlsPort: 5061 |
| 71 | verifyClient: true |
| 72 | verifyServer: true |
Alexandre Lision | e1b7f16 | 2014-02-26 16:45:32 -0500 | [diff] [blame] | 73 | */ |
Alexandre Lision | 2450c3e | 2014-02-14 15:31:58 -0500 | [diff] [blame] | 74 | |
Alexandre Lision | 651b526 | 2014-02-21 17:14:14 -0500 | [diff] [blame] | 75 | private boolean isInitialized; |
| 76 | |
Alexandre Lision | 2450c3e | 2014-02-14 15:31:58 -0500 | [diff] [blame] | 77 | |
Alexandre Lision | 92ef0f2 | 2014-02-27 15:57:55 -0500 | [diff] [blame^] | 78 | public SecureSipCall(SipCall call) { |
Alexandre Lision | 8162f4c | 2014-02-14 16:45:49 -0500 | [diff] [blame] | 79 | super(call); |
Alexandre Lision | 651b526 | 2014-02-21 17:14:14 -0500 | [diff] [blame] | 80 | isInitialized = false; |
Alexandre Lision | 92ef0f2 | 2014-02-27 15:57:55 -0500 | [diff] [blame^] | 81 | String keyExchange = getAccount().getSrtpDetails().getDetailString(AccountDetailSrtp.CONFIG_SRTP_KEY_EXCHANGE); |
| 82 | if (keyExchange.contentEquals("zrtp")) { |
| 83 | mSecureLayerUsed = SecureLayer.ZRTP_LAYER; |
| 84 | } else if (keyExchange.contentEquals("sdes")) { |
| 85 | mSecureLayerUsed = SecureLayer.SDES_LAYER; |
| 86 | } |
| 87 | |
| 88 | mZrtpModule = new ZrtpModule(); |
| 89 | mSdesModule = new SdesModule(); |
Alexandre Lision | 2450c3e | 2014-02-14 15:31:58 -0500 | [diff] [blame] | 90 | } |
| 91 | |
Alexandre Lision | 651b526 | 2014-02-21 17:14:14 -0500 | [diff] [blame] | 92 | public void setSASConfirmed(boolean confirmedSAS) { |
Alexandre Lision | 92ef0f2 | 2014-02-27 15:57:55 -0500 | [diff] [blame^] | 93 | mZrtpModule.needSASConfirmation = !confirmedSAS; |
Alexandre Lision | 2450c3e | 2014-02-14 15:31:58 -0500 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | public String getSAS() { |
Alexandre Lision | 92ef0f2 | 2014-02-27 15:57:55 -0500 | [diff] [blame^] | 97 | return mZrtpModule.SAS; |
Alexandre Lision | 2450c3e | 2014-02-14 15:31:58 -0500 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | public void setSAS(String SAS) { |
Alexandre Lision | 92ef0f2 | 2014-02-27 15:57:55 -0500 | [diff] [blame^] | 101 | mZrtpModule.SAS = SAS; |
Alexandre Lision | 2450c3e | 2014-02-14 15:31:58 -0500 | [diff] [blame] | 102 | } |
| 103 | |
Alexandre Lision | dbe396d | 2014-02-24 16:53:25 -0500 | [diff] [blame] | 104 | public SecureSipCall(Parcel in) { |
Alexandre Lision | 2450c3e | 2014-02-14 15:31:58 -0500 | [diff] [blame] | 105 | super(in); |
Alexandre Lision | 651b526 | 2014-02-21 17:14:14 -0500 | [diff] [blame] | 106 | isInitialized = in.readByte() == 1; |
Alexandre Lision | 92ef0f2 | 2014-02-27 15:57:55 -0500 | [diff] [blame^] | 107 | mSecureLayerUsed = in.readInt(); |
| 108 | mSdesModule = new SdesModule(in); |
| 109 | mZrtpModule = new ZrtpModule(in); |
Alexandre Lision | 2450c3e | 2014-02-14 15:31:58 -0500 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | @Override |
| 113 | public void writeToParcel(Parcel out, int flags) { |
| 114 | super.writeToParcel(out, flags); |
Alexandre Lision | 651b526 | 2014-02-21 17:14:14 -0500 | [diff] [blame] | 115 | out.writeByte((byte) (isInitialized ? 1 : 0)); |
Alexandre Lision | 92ef0f2 | 2014-02-27 15:57:55 -0500 | [diff] [blame^] | 116 | out.writeInt(mSecureLayerUsed); |
| 117 | mSdesModule.writeToParcel(out); |
| 118 | mZrtpModule.writeToParcel(out); |
Alexandre Lision | 2450c3e | 2014-02-14 15:31:58 -0500 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | public static final Parcelable.Creator<SecureSipCall> CREATOR = new Parcelable.Creator<SecureSipCall>() { |
| 122 | public SecureSipCall createFromParcel(Parcel in) { |
| 123 | return new SecureSipCall(in); |
| 124 | } |
| 125 | |
| 126 | public SecureSipCall[] newArray(int size) { |
| 127 | return new SecureSipCall[size]; |
| 128 | } |
| 129 | }; |
| 130 | |
Alexandre Lision | 1b932d8 | 2014-02-21 10:03:19 -0500 | [diff] [blame] | 131 | public void sasConfirmedByZrtpLayer(boolean verified) { |
Alexandre Lision | dbe396d | 2014-02-24 16:53:25 -0500 | [diff] [blame] | 132 | // Not used |
Alexandre Lision | 1b932d8 | 2014-02-21 10:03:19 -0500 | [diff] [blame] | 133 | } |
Alexandre Lision | 651b526 | 2014-02-21 17:14:14 -0500 | [diff] [blame] | 134 | |
Alexandre Lision | e1b7f16 | 2014-02-26 16:45:32 -0500 | [diff] [blame] | 135 | public void setZrtpSupport(boolean support) { |
Alexandre Lision | 92ef0f2 | 2014-02-27 15:57:55 -0500 | [diff] [blame^] | 136 | mZrtpModule.zrtpIsSupported = support; |
| 137 | if (!support) |
| 138 | mZrtpModule.needSASConfirmation = false; |
Alexandre Lision | 651b526 | 2014-02-21 17:14:14 -0500 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | public void setInitialized() { |
| 142 | isInitialized = true; |
| 143 | } |
Alexandre Lision | df222a5 | 2014-02-25 09:58:57 -0500 | [diff] [blame] | 144 | |
| 145 | /* |
| 146 | * returns what state should be visible during call |
| 147 | */ |
| 148 | public int displayModule() { |
Alexandre Lision | e1b7f16 | 2014-02-26 16:45:32 -0500 | [diff] [blame] | 149 | if (isInitialized) { |
Alexandre Lision | 92ef0f2 | 2014-02-27 15:57:55 -0500 | [diff] [blame^] | 150 | Log.i("SecureSIp", "needSASConfirmation" + mZrtpModule.needSASConfirmation); |
| 151 | if (mZrtpModule.needSASConfirmation) { |
Alexandre Lision | df222a5 | 2014-02-25 09:58:57 -0500 | [diff] [blame] | 152 | return DISPLAY_CONFIRM_SAS; |
Alexandre Lision | 92ef0f2 | 2014-02-27 15:57:55 -0500 | [diff] [blame^] | 153 | } else if (mZrtpModule.zrtpIsSupported || mSdesModule.sdesIsOn) { |
Alexandre Lision | df222a5 | 2014-02-25 09:58:57 -0500 | [diff] [blame] | 154 | return DISPLAY_GREEN_LOCK; |
| 155 | } else { |
| 156 | return DISPLAY_RED_LOCK; |
| 157 | } |
| 158 | } |
| 159 | return DISPLAY_NONE; |
| 160 | } |
Alexandre Lision | 8342eda | 2014-02-25 15:53:54 -0500 | [diff] [blame] | 161 | |
| 162 | public void useSecureSDES(boolean use) { |
Alexandre Lision | 92ef0f2 | 2014-02-27 15:57:55 -0500 | [diff] [blame^] | 163 | mSdesModule.sdesIsOn = use; |
| 164 | mZrtpModule.needSASConfirmation = false; |
| 165 | } |
| 166 | |
| 167 | |
| 168 | private class ZrtpModule { |
| 169 | private String SAS; |
| 170 | private boolean needSASConfirmation; |
| 171 | private boolean zrtpIsSupported; |
| 172 | |
| 173 | // static preferences of account |
| 174 | private final boolean displaySas; |
| 175 | private final boolean alertIfZrtpNotSupported; |
| 176 | private final boolean displaySASOnHold; |
| 177 | |
| 178 | public ZrtpModule() { |
| 179 | displaySas = getAccount().getSrtpDetails().getDetailBoolean(AccountDetailSrtp.CONFIG_ZRTP_DISPLAY_SAS); |
| 180 | alertIfZrtpNotSupported = getAccount().getSrtpDetails().getDetailBoolean(AccountDetailSrtp.CONFIG_ZRTP_NOT_SUPP_WARNING); |
| 181 | displaySASOnHold = getAccount().getSrtpDetails().getDetailBoolean(AccountDetailSrtp.CONFIG_ZRTP_NOT_SUPP_WARNING); |
| 182 | needSASConfirmation = displaySas; |
| 183 | zrtpIsSupported = false; |
| 184 | } |
| 185 | |
| 186 | public ZrtpModule(Parcel in) { |
| 187 | SAS = in.readString(); |
| 188 | displaySas = in.readByte() == 1; |
| 189 | alertIfZrtpNotSupported = in.readByte() == 1; |
| 190 | displaySASOnHold = in.readByte() == 1; |
| 191 | zrtpIsSupported = in.readByte() == 1; |
| 192 | needSASConfirmation = in.readByte() == 1; |
| 193 | } |
| 194 | |
| 195 | public void writeToParcel(Parcel dest) { |
| 196 | dest.writeString(SAS); |
| 197 | dest.writeByte((byte) (displaySas ? 1 : 0)); |
| 198 | dest.writeByte((byte) (alertIfZrtpNotSupported ? 1 : 0)); |
| 199 | dest.writeByte((byte) (displaySASOnHold ? 1 : 0)); |
| 200 | dest.writeByte((byte) (zrtpIsSupported ? 1 : 0)); |
| 201 | dest.writeByte((byte) (needSASConfirmation ? 1 : 0)); |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | private class SdesModule { |
| 206 | |
| 207 | private boolean sdesIsOn; |
| 208 | |
| 209 | public SdesModule() { |
| 210 | sdesIsOn = false; |
| 211 | } |
| 212 | |
| 213 | public SdesModule(Parcel in) { |
| 214 | sdesIsOn = in.readByte() == 1; |
| 215 | } |
| 216 | |
| 217 | public void writeToParcel(Parcel dest) { |
| 218 | dest.writeByte((byte) (sdesIsOn ? 1 : 0)); |
| 219 | } |
Alexandre Lision | 8342eda | 2014-02-25 15:53:54 -0500 | [diff] [blame] | 220 | } |
Alexandre Lision | 2450c3e | 2014-02-14 15:31:58 -0500 | [diff] [blame] | 221 | } |