Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 1 | /* |
| 2 | This class maps the ZRTP C++ callback methods to C callback methods. |
Alexandre Lision | e24852d | 2014-02-04 13:13:02 -0500 | [diff] [blame] | 3 | Copyright (C) 2010 Werner Dittmann |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 4 | |
| 5 | This program is free software: you can redistribute it and/or modify |
Alexandre Lision | e24852d | 2014-02-04 13:13:02 -0500 | [diff] [blame] | 6 | it under the terms of the GNU General Public License as published by |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 7 | the Free Software Foundation, either version 3 of the License, or |
| 8 | (at your option) any later version. |
| 9 | |
| 10 | This program is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | GNU General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License |
| 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | */ |
| 19 | |
| 20 | #include <libzrtpcpp/ZrtpCallbackWrapper.h> |
| 21 | |
| 22 | ZrtpCallbackWrapper::ZrtpCallbackWrapper(zrtp_Callbacks* cb, ZrtpContext* ctx) : |
| 23 | c_callbacks(cb), zrtpCtx(ctx) |
| 24 | { |
| 25 | init(); |
| 26 | } |
| 27 | |
| 28 | void ZrtpCallbackWrapper::init() |
| 29 | { |
| 30 | } |
| 31 | /* |
| 32 | * The following methods implement the GNU ZRTP callback interface. |
| 33 | * For detailed documentation refer to file ZrtpCallback.h |
| 34 | */ |
| 35 | int32_t ZrtpCallbackWrapper::sendDataZRTP(const unsigned char* data, int32_t length) |
| 36 | { |
| 37 | return c_callbacks->zrtp_sendDataZRTP(zrtpCtx, data, length); |
| 38 | } |
| 39 | |
| 40 | int32_t ZrtpCallbackWrapper::activateTimer (int32_t time) |
| 41 | { |
| 42 | c_callbacks->zrtp_activateTimer(zrtpCtx, time); |
| 43 | return 1; |
| 44 | } |
| 45 | |
| 46 | int32_t ZrtpCallbackWrapper::cancelTimer() |
| 47 | { |
| 48 | c_callbacks->zrtp_cancelTimer(zrtpCtx); |
| 49 | return 0; |
| 50 | } |
| 51 | |
| 52 | void ZrtpCallbackWrapper::sendInfo (GnuZrtpCodes::MessageSeverity severity, int32_t subCode) |
| 53 | { |
| 54 | c_callbacks->zrtp_sendInfo(zrtpCtx, (int32_t)severity, subCode); |
| 55 | } |
| 56 | |
| 57 | bool ZrtpCallbackWrapper::srtpSecretsReady(SrtpSecret_t* secrets, EnableSecurity part) |
| 58 | { |
| 59 | C_SrtpSecret_t* cs = new C_SrtpSecret_t; |
| 60 | cs->symEncAlgorithm = (zrtp_SrtpAlgorithms)secrets->symEncAlgorithm; |
| 61 | cs->initKeyLen = secrets->initKeyLen; |
| 62 | cs->initSaltLen = secrets->initSaltLen; |
| 63 | cs->keyInitiator = secrets->keyInitiator; |
| 64 | cs->keyResponder = secrets->keyResponder; |
| 65 | cs->respKeyLen = secrets->respKeyLen; |
| 66 | cs->respSaltLen = secrets->respSaltLen; |
| 67 | cs->role = (int32_t)secrets->role; |
| 68 | cs->saltInitiator = secrets->saltInitiator; |
| 69 | cs->saltResponder = secrets->saltResponder; |
| 70 | cs->sas = new char [secrets->sas.size()+1]; |
| 71 | strcpy(cs->sas, secrets->sas.c_str()); |
| 72 | cs->authAlgorithm = (zrtp_SrtpAlgorithms)secrets->authAlgorithm; |
| 73 | cs->srtpAuthTagLen = secrets->srtpAuthTagLen; |
| 74 | |
| 75 | bool retval = (c_callbacks->zrtp_srtpSecretsReady(zrtpCtx, cs, (int32_t)part) == 0) ? false : true ; |
| 76 | |
| 77 | delete[] cs->sas; |
| 78 | delete cs; |
| 79 | |
| 80 | return retval; |
| 81 | } |
| 82 | |
| 83 | void ZrtpCallbackWrapper::srtpSecretsOff (EnableSecurity part ) |
| 84 | { |
| 85 | c_callbacks->zrtp_srtpSecretsOff(zrtpCtx, (int32_t)part); |
| 86 | } |
| 87 | |
| 88 | void ZrtpCallbackWrapper::srtpSecretsOn ( std::string c, std::string s, bool verified ) |
| 89 | { |
| 90 | char* cc = new char [c.size()+1]; |
| 91 | char* cs = new char [s.size()+1]; |
| 92 | |
| 93 | strcpy(cc, c.c_str()); |
| 94 | if(!s.empty()) |
| 95 | strcpy(cs, s.c_str()); |
| 96 | else |
| 97 | *cs = '\0'; |
| 98 | |
| 99 | c_callbacks->zrtp_rtpSecretsOn(zrtpCtx, cc, cs, verified?1:0); |
| 100 | |
| 101 | delete[] cc; |
| 102 | delete[] cs; |
| 103 | } |
| 104 | |
| 105 | void ZrtpCallbackWrapper::handleGoClear() |
| 106 | { |
| 107 | } |
| 108 | |
| 109 | void ZrtpCallbackWrapper::zrtpNegotiationFailed(GnuZrtpCodes::MessageSeverity severity, int32_t subCode) |
| 110 | { |
| 111 | c_callbacks->zrtp_zrtpNegotiationFailed(zrtpCtx, (int32_t)severity, subCode); |
| 112 | } |
| 113 | |
| 114 | void ZrtpCallbackWrapper::zrtpNotSuppOther() |
| 115 | { |
| 116 | c_callbacks->zrtp_zrtpNotSuppOther(zrtpCtx); |
| 117 | } |
| 118 | |
| 119 | void ZrtpCallbackWrapper::synchEnter() |
| 120 | { |
| 121 | c_callbacks->zrtp_synchEnter(zrtpCtx); |
| 122 | } |
| 123 | |
| 124 | |
| 125 | void ZrtpCallbackWrapper::synchLeave() |
| 126 | { |
| 127 | c_callbacks->zrtp_synchLeave(zrtpCtx); |
| 128 | } |
| 129 | |
| 130 | void ZrtpCallbackWrapper::zrtpAskEnrollment(GnuZrtpCodes::InfoEnrollment info) |
| 131 | { |
| 132 | c_callbacks->zrtp_zrtpAskEnrollment(zrtpCtx, (zrtp_InfoEnrollment)info); |
| 133 | } |
| 134 | |
| 135 | void ZrtpCallbackWrapper::zrtpInformEnrollment(GnuZrtpCodes::InfoEnrollment info) |
| 136 | { |
| 137 | c_callbacks->zrtp_zrtpInformEnrollment(zrtpCtx, (zrtp_InfoEnrollment)info); |
| 138 | |
| 139 | } |
| 140 | |
| 141 | void ZrtpCallbackWrapper::signSAS(uint8_t* sasHash) |
| 142 | { |
| 143 | c_callbacks->zrtp_signSAS(zrtpCtx, sasHash); |
| 144 | } |
| 145 | |
| 146 | bool ZrtpCallbackWrapper::checkSASSignature(uint8_t* sasHash) |
| 147 | { |
| 148 | bool retval = (c_callbacks->zrtp_checkSASSignature(zrtpCtx, sasHash) == 0) ? false : true; |
| 149 | |
| 150 | return retval; |
| 151 | } |