blob: a0756e85f4e88d7cd8a3bc0222f1581906365e53 [file] [log] [blame]
Alexandre Lision2450c3e2014-02-14 15:31:58 -05001/*
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
32package org.sflphone.model;
33
Alexandre Lision2450c3e2014-02-14 15:31:58 -050034import android.os.Parcel;
35import android.os.Parcelable;
Alexandre Lisiondbe396d2014-02-24 16:53:25 -050036import android.util.Log;
Alexandre Lision92ef0f22014-02-27 15:57:55 -050037import org.sflphone.account.AccountDetailSrtp;
38
39import java.io.Serializable;
Alexandre Lision2450c3e2014-02-14 15:31:58 -050040
41
42public class SecureSipCall extends SipCall {
43
Alexandre Lision92ef0f22014-02-27 15:57:55 -050044 public interface SecureLayer {
45 int ZRTP_LAYER = 0;
46 int SDES_LAYER = 1;
47 int TLS_LAYER = 2;
48 }
Alexandre Lision2450c3e2014-02-14 15:31:58 -050049
Alexandre Lisiondf222a52014-02-25 09:58:57 -050050 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 Lision92ef0f22014-02-27 15:57:55 -050055 int mSecureLayerUsed;
56 ZrtpModule mZrtpModule;
57 SdesModule mSdesModule;
Alexandre Lisione1b7f162014-02-26 16:45:32 -050058/*
Alexandre Lision2450c3e2014-02-14 15:31:58 -050059 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 Lisione1b7f162014-02-26 16:45:32 -050073*/
Alexandre Lision2450c3e2014-02-14 15:31:58 -050074
Alexandre Lision651b5262014-02-21 17:14:14 -050075 private boolean isInitialized;
76
Alexandre Lision2450c3e2014-02-14 15:31:58 -050077
Alexandre Lision92ef0f22014-02-27 15:57:55 -050078 public SecureSipCall(SipCall call) {
Alexandre Lision8162f4c2014-02-14 16:45:49 -050079 super(call);
Alexandre Lision651b5262014-02-21 17:14:14 -050080 isInitialized = false;
Alexandre Lision92ef0f22014-02-27 15:57:55 -050081 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 Lision2450c3e2014-02-14 15:31:58 -050090 }
91
Alexandre Lision651b5262014-02-21 17:14:14 -050092 public void setSASConfirmed(boolean confirmedSAS) {
Alexandre Lision92ef0f22014-02-27 15:57:55 -050093 mZrtpModule.needSASConfirmation = !confirmedSAS;
Alexandre Lision2450c3e2014-02-14 15:31:58 -050094 }
95
96 public String getSAS() {
Alexandre Lision92ef0f22014-02-27 15:57:55 -050097 return mZrtpModule.SAS;
Alexandre Lision2450c3e2014-02-14 15:31:58 -050098 }
99
100 public void setSAS(String SAS) {
Alexandre Lision92ef0f22014-02-27 15:57:55 -0500101 mZrtpModule.SAS = SAS;
Alexandre Lision2450c3e2014-02-14 15:31:58 -0500102 }
103
Alexandre Lisiondbe396d2014-02-24 16:53:25 -0500104 public SecureSipCall(Parcel in) {
Alexandre Lision2450c3e2014-02-14 15:31:58 -0500105 super(in);
Alexandre Lision651b5262014-02-21 17:14:14 -0500106 isInitialized = in.readByte() == 1;
Alexandre Lision92ef0f22014-02-27 15:57:55 -0500107 mSecureLayerUsed = in.readInt();
108 mSdesModule = new SdesModule(in);
109 mZrtpModule = new ZrtpModule(in);
Alexandre Lision2450c3e2014-02-14 15:31:58 -0500110 }
111
112 @Override
113 public void writeToParcel(Parcel out, int flags) {
114 super.writeToParcel(out, flags);
Alexandre Lision651b5262014-02-21 17:14:14 -0500115 out.writeByte((byte) (isInitialized ? 1 : 0));
Alexandre Lision92ef0f22014-02-27 15:57:55 -0500116 out.writeInt(mSecureLayerUsed);
117 mSdesModule.writeToParcel(out);
118 mZrtpModule.writeToParcel(out);
Alexandre Lision2450c3e2014-02-14 15:31:58 -0500119 }
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 Lision1b932d82014-02-21 10:03:19 -0500131 public void sasConfirmedByZrtpLayer(boolean verified) {
Alexandre Lisiondbe396d2014-02-24 16:53:25 -0500132 // Not used
Alexandre Lision1b932d82014-02-21 10:03:19 -0500133 }
Alexandre Lision651b5262014-02-21 17:14:14 -0500134
Alexandre Lisione1b7f162014-02-26 16:45:32 -0500135 public void setZrtpSupport(boolean support) {
Alexandre Lision92ef0f22014-02-27 15:57:55 -0500136 mZrtpModule.zrtpIsSupported = support;
137 if (!support)
138 mZrtpModule.needSASConfirmation = false;
Alexandre Lision651b5262014-02-21 17:14:14 -0500139 }
140
141 public void setInitialized() {
142 isInitialized = true;
143 }
Alexandre Lisiondf222a52014-02-25 09:58:57 -0500144
145 /*
146 * returns what state should be visible during call
147 */
148 public int displayModule() {
Alexandre Lisione1b7f162014-02-26 16:45:32 -0500149 if (isInitialized) {
Alexandre Lision92ef0f22014-02-27 15:57:55 -0500150 Log.i("SecureSIp", "needSASConfirmation" + mZrtpModule.needSASConfirmation);
151 if (mZrtpModule.needSASConfirmation) {
Alexandre Lisiondf222a52014-02-25 09:58:57 -0500152 return DISPLAY_CONFIRM_SAS;
Alexandre Lision92ef0f22014-02-27 15:57:55 -0500153 } else if (mZrtpModule.zrtpIsSupported || mSdesModule.sdesIsOn) {
Alexandre Lisiondf222a52014-02-25 09:58:57 -0500154 return DISPLAY_GREEN_LOCK;
155 } else {
156 return DISPLAY_RED_LOCK;
157 }
158 }
159 return DISPLAY_NONE;
160 }
Alexandre Lision8342eda2014-02-25 15:53:54 -0500161
162 public void useSecureSDES(boolean use) {
Alexandre Lision92ef0f22014-02-27 15:57:55 -0500163 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 Lision8342eda2014-02-25 15:53:54 -0500220 }
Alexandre Lision2450c3e2014-02-14 15:31:58 -0500221}