r3245 - in trunk/libminisip: include include/libminisip/media include/libminisip/media/zrtp include/libminisip/signaling source source/subsystem_media source/subsystem_media/zrtp source/subsystem_signaling

erik at minisip.org erik at minisip.org
Tue Mar 13 02:12:24 CET 2007


Author: erik
Date: 2007-03-13 02:12:23 +0100 (Tue, 13 Mar 2007)
New Revision: 3245

Added:
   trunk/libminisip/include/libminisip/media/zrtp/
   trunk/libminisip/include/libminisip/media/zrtp/ZrtpHostBridgeMinisip.h
   trunk/libminisip/source/subsystem_media/zrtp/
   trunk/libminisip/source/subsystem_media/zrtp/ZrtpHostBridgeMinisip.cxx
Removed:
   trunk/libminisip/include/libminisip/media/zrtp/ZrtpHostBridgeMinisip.h
   trunk/libminisip/include/libminisip/signaling/zrtp/
   trunk/libminisip/source/subsystem_media/zrtp/ZrtpHostBridgeMinisip.cxx
   trunk/libminisip/source/subsystem_signaling/zrtp/
Modified:
   trunk/libminisip/include/Makefile.am
   trunk/libminisip/include/libminisip/media/MediaStream.h
   trunk/libminisip/source/Minisip.cxx
   trunk/libminisip/source/subsystem_media/Session.cxx
Log:

 * libminisip: ZRTP code was put in the wrong folder (signaling -> media).
               This should fix the zrtp test build.



Modified: trunk/libminisip/include/Makefile.am
===================================================================
--- trunk/libminisip/include/Makefile.am	2007-03-12 23:08:04 UTC (rev 3244)
+++ trunk/libminisip/include/Makefile.am	2007-03-13 01:12:23 UTC (rev 3245)
@@ -117,7 +117,7 @@
 			libminisip/Minisip.h \
 			libminisip/MinisipExceptions.h \
 			libminisip/libminisip_config.h \
-			libminisip/signaling/zrtp/ZrtpHostBridgeMinisip.h
+			libminisip/media/zrtp/ZrtpHostBridgeMinisip.h
 
 
 noinst_HEADERS = 	config.h

Modified: trunk/libminisip/include/libminisip/media/MediaStream.h
===================================================================
--- trunk/libminisip/include/libminisip/media/MediaStream.h	2007-03-12 23:08:04 UTC (rev 3244)
+++ trunk/libminisip/include/libminisip/media/MediaStream.h	2007-03-13 01:12:23 UTC (rev 3245)
@@ -36,7 +36,7 @@
 #include<libminisip/media/rtp/SRtpPacket.h>
 
 #ifdef ZRTP_SUPPORT
-#include <libminisip/signaling/zrtp/ZrtpHostBridgeMinisip.h>
+#include <libminisip/media/zrtp/ZrtpHostBridgeMinisip.h>
 #include <time.h>
 class ZrtpHostBridgeMinisip;
 #endif

Copied: trunk/libminisip/include/libminisip/media/zrtp (from rev 3243, trunk/libminisip/include/libminisip/signaling/zrtp)

Deleted: trunk/libminisip/include/libminisip/media/zrtp/ZrtpHostBridgeMinisip.h
===================================================================
--- trunk/libminisip/include/libminisip/signaling/zrtp/ZrtpHostBridgeMinisip.h	2007-03-12 22:27:07 UTC (rev 3243)
+++ trunk/libminisip/include/libminisip/media/zrtp/ZrtpHostBridgeMinisip.h	2007-03-13 01:12:23 UTC (rev 3245)
@@ -1,363 +0,0 @@
-/*
-  Copyright (C) 2006 Werner Dittmann
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
- */
-
-
-/*
- * Authors: Werner Dittmann <Werner.Dittmann at t-online.de>
- */
-
-
-#ifndef _ZIDHOSTBRIDGEMINISIP_H_
-#define _ZIDHOSTBRIDGEMINISIP_H_
-
-#ifdef ZRTP_SUPPORT
-// #include<libminisip/libminisip_config.h>
-
-#include <stdio.h>
-#include <stdint.h>
-#include <string.h>
-
-#include <libmutil/StateMachine.h>
-#include <libmutil/MessageRouter.h>
-#include <libmsip/SipSMCommand.h>
-
-#include <libminisip/mediahandler/MediaStream.h>
-#include <libminisip/rtp/SRtpPacket.h>
-#include <libminisip/rtp/CryptoContext.h>
-
-#include <libzrtpcpp/ZrtpCallback.h>
-#include <libzrtpcpp/ZRtp.h>
-
-/**
- * The connection between the ZRTP implementation and Minisip.
- *
- * The ZRPT implementation is fairly independent from the underlying
- * SIP and RTP/SRTP implementation. This class implements specific
- * functions and interfaces that ZRTP uses to call functions of the
- * hosting SIP client. In this case the host is Minisip.
- *
- * <p/>
- *
- * As required by ZRTP base implementation the bridge implements
- * the ZrtpCallback interface.
- *
- * <p/>
- *
- * The most minisip specific part is the implementation of the timer.
- * The minisip <e>startSip</e> method calls the bridge's
- * <e>initialize</e> method after the whole SIP was initialized. To
- * avoid a new timeout provider this bridge reuses the timeout
- * provider created by SipStack. Thus the initialize call looks like:
- *
- * <br>
- *
- * ZrtpHostBridge::initialize(sip->getSipStack()->getTimeoutProvider(),
-filename?);
- *
- * <br/>
- *
- * The <code>initialize</code> method stores the timeout provider and
- * reuses it for every instance. To do so the bridge inherits from
- * Minisip's <e>StateMachine<e/> but does use the timeout specific
- * parts only. The destructor frees the StateMachine to maintain the
- * timout provider's reference counter.
- */
-
-class ZrtpHostBridgeMinisip : public StateMachine<SipSMCommand,std::string>,
-public ZrtpCallback {
-
- public:
-
-    virtual std::string getMemObjectType() const { return "ZrtpHostBridgeMinisip";}
-
-    /**
-     * Initialize the host bridge.
-     *
-     * This static method must be called before <e>any</e> use of the
-     * host bridge. If the caller does not provide a filename for the
-     * ZID file the method opens the ZID file with the default name
-     * <e> ~/.minisip.zid<e/>. This is a binary file.
-     *
-     * @param tp
-     *    The timeout provider to use. In this case it shall be the
-     *    same as defined for the SIP stack.
-     * @param zidFilename
-     *    Optional filename for the ZID file.
-     * @return
-     *    TODO
-     */
-    static int32_t initialize(MRef<TimeoutProvider<std::string,
-MRef<StateMachine<SipSMCommand,std::string>*> > *> tp,
-		     const char *zidFilename =NULL);
-
-    ZrtpHostBridgeMinisip(std::string id, MRef<CommandReceiver*> callback);
-    ~ZrtpHostBridgeMinisip();
-
-
-    void start();
-    void stop();
-
-    void setReceiver(MRef<MediaStreamReceiver *> r);
-    void setSsrcReceiver(uint32_t ssrc)             { receiverSsrc = ssrc; };
-    uint32_t getSsrcReceiver()                      { return receiverSsrc; };
-
-    void setSender(MRef<MediaStreamSender *> s);
-    void setSsrcSender(uint32_t ssrc)               { senderSsrc = ssrc; };
-    uint32_t getSsrcSender()                        { return senderSsrc; };
-
-    bool isSecureState();
-
-    void setCallId(std::string id)                  { callId = id; }
-    /**
-     * Set the IP address of our remote peer.
-     *
-     * The host (Minisip) shall call this mehtod to set the IP address
-     * of the remote peer. We use the address to find the right ZRTP
-     * host bridge when we receive packets on the receiver port
-     * allocated by the MediaStreamReceiver.
-     *
-     * This is (fairly) save because one remote peer shall not have
-     * several different RTP sessions for one of my receiver ports.
-     *
-     * @param ra
-     *    The IP address of our remote peer
-     */
-    void setRemoteAddress(MRef<IPAddress *> ra) { remoteAddress = ra; };
-
-    /**
-     * Get the IP address of our remote peer.
-     *
-     * @return
-     *    The IP address of our remote peer.
-     */
-    MRef<IPAddress *> getRemoteAddress() { return remoteAddress; };
-
-    /**
-     * Process a received packet with an extension header.
-     *
-     * This packet has an extension header and may have payload data
-     * to process.  The method checks if it is a ZRTP packet, if yes
-     * process it. Otherwise just return to the caller for further
-     * processing of the packet.
-     *
-     * <p/>
-     *
-     * Depending on the contents of the packet and the protocol state
-     * the method returns a indication to either dismiss the payload
-     * data or process it as usual.
-     *
-     * @param packet
-     *   A (S)Rtp packet to process
-     * @return
-     *    Returns 0 if the caller shall dismiss the payload, 1 otherwise.
-     */
-    int32_t processPacket(MRef<SRtpPacket *> packet);
-
-    /**
-     * Handle timeout event forwarded by Minisip's (SipStack)
-     * TimeoutProvider.
-     *
-     * Just call the ZRTP engine for further processing.
-     */
-    void handleTimeout(const std::string & /* c */ ) {
-        if (zrtpEngine != NULL) {
-            zrtpEngine->processTimeout();
-        }
-    }
-
-    /*
-     * Refer to ZrtpCallback.h
-     */
-    int32_t sendDataRTP(const unsigned char* data, int32_t length);
-
-    int32_t sendDataSRTP(const unsigned char* dataHeader, int32_t lengthHeader,
-		         char *dataContent, int32_t lengthContent);
-
-    int32_t activateTimer(int32_t time) {
-	std::string s("ZRTP");
-	requestTimeout(time, s);
-	return 1;
-    };
-
-    int32_t cancelTimer() {
-	std::string s("ZRTP");
-	cancelTimeout(s);
-	return 1;
-    };
-
-    void sendInfo(MessageSeverity severity, char* msg) {
-	fprintf(stderr, "Severity: %d - %s\n", severity, msg);
-    }
-
-    /**
-     * This method shall handle GoClear requests.
-     *
-     * According to the ZRTP specification the user must be informed about
-     * this message because the ZRTP implementation switches off security
-     * if it could authenticate the GoClear packet.
-     *
-     */
-    void handleGoClear() {
-        fprintf(stderr, "Need to process a GoClear message!");
-    }
-
-    /**
-     * Switch on the security for the defined part.
-     *
-     * Create an CryproContext with the negotiated ZRTP data and
-     * register it with the respective part (sender or receiver) thus
-     * replacing the current active context (usually an empty
-     * context). This effectively enables SRTP.
-     *
-     * @param secrets
-     *    The secret keys and salt negotiated by ZRTP
-     * @param part
-     *    An enum that defines sender, receiver, or both.
-     */
-    void srtpSecretsReady(SrtpSecret_t* secrets, EnableSecurity part);
-
-    /**
-     * This method shall switch on GUI inidicators.
-     *
-     * @param c
-     *    The name of the used cipher algorithm and mode, or NULL
-     * @param s
-     *    The SAS string or NULL
-     */
-    virtual void srtpSecretsOn(const char* c, const char* s);
-
-
-    /**
-     * Switch off the security for the defined part.
-     *
-     * Create an empty CryproContext and register it with the
-     * repective part (sender or receiver) thus replacing the current
-     * active context. This effectively disables SRTP.
-     *
-     * @param part
-     *    An enum that defines sender, receiver, or both.
-     */
-    void srtpSecretsOff(EnableSecurity part);
-
-    /**
-     * ZRTP calls this if the negotiation failed.
-     *
-     * ZRTP calls this method in case ZRTP negotiation failed. The parameters
-     * show the severity as well as some explanatory text.
-     * Refer to the <code>MessageSeverity</code> enum above.
-     *
-     * @param severity
-     *     This defines the message's severity
-     * @param msg
-     *     The message string, terminated with a null byte.
-         */
-    void zrtpNegotiationFailed(MessageSeverity severity, char* msg);
-
-    /**
-     * ZRTP calls this methof if the other side does not support ZRTP.
-     *
-     * If the other side does not answer the ZRTP <em>Hello</em> packets then
-     * ZRTP calls this method,
-     *
-     */
-    void zrtpNotSuppOther();
-
-    /**
-     * This method switches off secure state because of a session
-     * error.
-     *
-     * The receiver detected a wrong SSRC during a session with our
-     * remote peer. This could indicate a security problem - just
-     * disable SRTP and alert the user.
-     */
-    void rtpSessionError();
-
-    /**
-     * Set the zfoneDeadBeef flag.
-     *
-     * This flag indicates the special Zfone maker SSRC 0xdeadbeef.
-     *
-     * @param onOff
-     *     A value of one indicates that we detected a marker SSRC.
-     */
-    void setZfoneDeadBeef(int8_t onOff)  { zfoneDeadBeef = onOff; }
-
-    /**
-     * Get the zfoneDeadBeef flag.
-     *
-     * This flag indicates the special Zfone maker SSRC 0xdeadbeef.
-     *
-     * @return the value of zfoneDeadBeef flag. One indicates that
-     *     we detected a marker SSRC
-     */
-    int8_t getZfoneDeadBeef()           {return zfoneDeadBeef; }
-
-    uint16_t getZrtpSendSeqNo()         { return senderZrtpSeqNo++; }
-
-    uint32_t getZrtpSendSsrc()          { return senderZrtpSsrc; }
-
-    MRef<CryptoContext *> newCryptoContextForRecvSSRC(uint32_t ssrc, int roc, uint16_t seq,
-                                                      int64_t keyDerivRate);
-
-    bool isZrtpPacket(MRef<SRtpPacket *> packet);
-
- private:
-    ZRtp *zrtpEngine;
-    SrtpSecret_t secret;
-    int32_t secureParts;
-
-    MRef<IPAddress *> remoteAddress;
-
-    MRef<MediaStreamReceiver *> rStream;
-    uint32_t receiverSsrc;
-    uint32_t receiverSecure;
-    uint16_t receiverSeqNo;
-
-    MRef<MediaStreamSender *> sStream;
-    uint32_t senderSsrc;
-    uint32_t senderSecure;
-
-    bool enableZrtp;
-
-    uint32_t recvZrtpSsrc;
-    uint16_t recvZrtpSeqNo;
-    MRef<CryptoContext *> recvCryptoContext;
-
-    uint32_t senderZrtpSsrc;
-    uint16_t senderZrtpSeqNo;
-    MRef<CryptoContext *> senderCryptoContext;
-
-    /*
-     * The call id of our call
-     */
-    std::string callId;
-
-    MRef<CommandReceiver*> messageRouterCallback;
-
-    /**
-     * This flag is true if we saw the special <em>0xdeadbeef</em> marker
-     * SSRC. The Zfone implementation uses this in its ZRTP packets. Other
-     * ZRTP implementation may not require such a marker SSRC.
-     * (maybe even Zfone could live without it but ...)
-     */
-    int8_t zfoneDeadBeef;
-};
-
-#endif // ZRTP_SUPPORT
-
-#endif // _ZIDHOSTBRIDGEMINISIP_H_

Copied: trunk/libminisip/include/libminisip/media/zrtp/ZrtpHostBridgeMinisip.h (from rev 3244, trunk/libminisip/include/libminisip/signaling/zrtp/ZrtpHostBridgeMinisip.h)

Modified: trunk/libminisip/source/Minisip.cxx
===================================================================
--- trunk/libminisip/source/Minisip.cxx	2007-03-12 23:08:04 UTC (rev 3244)
+++ trunk/libminisip/source/Minisip.cxx	2007-03-13 01:12:23 UTC (rev 3245)
@@ -75,7 +75,7 @@
 #include<libminisip/media/codecs/Codec.h>
 
 #ifdef ZRTP_SUPPORT
-#include<libminisip/signaling/zrtp/ZrtpHostBridgeMinisip.h>
+#include<libminisip/media/zrtp/ZrtpHostBridgeMinisip.h>
 #endif
 
 #include<stdlib.h>

Modified: trunk/libminisip/source/subsystem_media/Session.cxx
===================================================================
--- trunk/libminisip/source/subsystem_media/Session.cxx	2007-03-12 23:08:04 UTC (rev 3244)
+++ trunk/libminisip/source/subsystem_media/Session.cxx	2007-03-13 01:12:23 UTC (rev 3245)
@@ -50,7 +50,7 @@
 #include<libmutil/Timestamp.h>
 
 #ifdef ZRTP_SUPPORT
-#include <libminisip/signaling/zrtp/ZrtpHostBridgeMinisip.h>
+#include <libminisip/media/zrtp/ZrtpHostBridgeMinisip.h>
 #endif
 
 #ifdef _WIN32_WCE

Copied: trunk/libminisip/source/subsystem_media/zrtp (from rev 3242, trunk/libminisip/source/subsystem_signaling/zrtp)

Deleted: trunk/libminisip/source/subsystem_media/zrtp/ZrtpHostBridgeMinisip.cxx
===================================================================
--- trunk/libminisip/source/subsystem_signaling/zrtp/ZrtpHostBridgeMinisip.cxx	2007-03-12 22:09:23 UTC (rev 3242)
+++ trunk/libminisip/source/subsystem_media/zrtp/ZrtpHostBridgeMinisip.cxx	2007-03-13 01:12:23 UTC (rev 3245)
@@ -1,363 +0,0 @@
-/*
-  Copyright (C) 2006 Werner Dittmann
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
- */
-
-/*
- * Authors: Werner Dittmann <Werner.Dittmann at t-online.de>
- */
-
-#include <config.h>
-
-#include <libminisip/zrtp/ZrtpHostBridgeMinisip.h>
-#include <libzrtpcpp/ZIDFile.h>
-#include <libzrtpcpp/ZrtpStateClass.h>
-
-#include <libmikey/MikeyPayloadSP.h>
-#include <libminisip/configbackend/UserConfig.h>
-#include <libmutil/CommandString.h>
-
-#ifdef ZRTP_SUPPORT
-
-static MRef<TimeoutProvider<std::string, MRef<StateMachine<SipSMCommand,std::string>*> > *>staticTimeoutProvider;
-
-int32_t ZrtpHostBridgeMinisip::initialize(MRef<TimeoutProvider<std::string,
-                                          MRef<StateMachine<SipSMCommand,std::string>*> > *>tp,
-                                          const char *zidFilename) {
-
-    std::string fname;
-    staticTimeoutProvider = tp;
-    if (zidFilename == NULL) {
-        fname = UserConfig::getFileName("minisip.zid");
-        zidFilename = fname.c_str();
-    }
-    ZIDFile *zf = ZIDFile::getInstance();
-    zf->open((char *)zidFilename);
-    return 1;
-}
-
-ZrtpHostBridgeMinisip::ZrtpHostBridgeMinisip(std::string id, MRef<CommandReceiver*> callback):
-        StateMachine<SipSMCommand, std::string>(staticTimeoutProvider),
-        callId(id),
-        messageRouterCallback(callback) {
-
-    secureParts = 0;
-    zrtpEngine = NULL;
-
-    senderSecure = 0;
-    receiverSecure = 0;
-
-    receiverSsrc = 0;
-    senderSsrc = 0;
-
-    rStream = NULL;
-    sStream = NULL;
-
-    senderCryptoContext = NULL;
-    senderZrtpSsrc = 0xdeadbeef;         // may be a different value (random) as well
-    senderZrtpSeqNo = 1;
-
-    recvCryptoContext = NULL;
-}
-
-ZrtpHostBridgeMinisip::~ZrtpHostBridgeMinisip() {
-
-    cancelTimer();
-    freeStateMachine();		// to clean up the TimeoutProvider
-    delete zrtpEngine;
-}
-
-void ZrtpHostBridgeMinisip::setReceiver(MRef<MediaStreamReceiver *> r) {
-	rStream = r;
-}
-
-void ZrtpHostBridgeMinisip::setSender(MRef<MediaStreamSender *> s) {
-	sStream = s;
-}
-
-void ZrtpHostBridgeMinisip::start() {
-    ZIDFile *zid = ZIDFile::getInstance();
-    const uint8_t* ownZid = zid->getZid();
-
-    if (zrtpEngine == NULL) {
-        zrtpEngine = new ZRtp((uint8_t*)ownZid, (ZrtpCallback*)this);
-        zrtpEngine->setClientId(clientId);
-        zrtpEngine->startZrtpEngine();
-    }
-}
-
-void ZrtpHostBridgeMinisip::stop() {
-    zrtpEngine->stopZrtp();
-    delete zrtpEngine;
-}
-
-bool ZrtpHostBridgeMinisip::isZrtpPacket(MRef<SRtpPacket *> packet) {
-    unsigned char* extHeader = packet->getExtensionHeader();
-    uint16_t magic = *((uint16_t*)extHeader);
-
-    magic = ntoh16(magic);
-
-    // If not a ZRTP packet - back to caller for further actions
-    if (magic == ZRTP_EXT_PACKET) {
-        return true;
-    }
-    return false;
-}
-
-int32_t ZrtpHostBridgeMinisip::processPacket(MRef<SRtpPacket *> packet) {
-
-    unsigned char* extHeader = packet->getExtensionHeader();
-    uint16_t magic = *((uint16_t*)extHeader);
-
-    magic = ntoh16(magic);
-
-    // If not a ZRTP packet - back to caller for further actions
-    if (magic != ZRTP_EXT_PACKET) {
-	return 1;
-    }
-    /*
-     * It's a ZRTP packet, check if ZRTP already started. If not and no other
-     * content return zero to dismiss packet, otherwise return 1 for further
-     * actions. This can happen for "piggy-back" ZRTP packets.
-     */
-    if (zrtpEngine == NULL) {
-        if (packet->getContentLength() > 0) {
-            return  1;
-        }
-        else {
-            return 0;
-        }
-    }
-    recvZrtpSeqNo = packet->getHeader().getSeqNo();
-    recvZrtpSsrc = packet->getHeader().getSSRC();
-
-    if (zrtpEngine->handleGoClear(extHeader)) {
-        return 0;
-    }
-    int ret = zrtpEngine->processExtensionHeader(extHeader, packet->getContent());
-
-    // Fail is only a fail of the protocol state, already handled but
-    // payload usually not affected - thus caller may process it, e.g.
-    // in case of "piggy-back" ZRTP packets.
-    return ((ret == Fail || ret == Done) ? 1 : 0);
-}
-
-bool ZrtpHostBridgeMinisip::isSecureState()
-{
-    return zrtpEngine->checkState(SecureState);
-}
-
-int32_t ZrtpHostBridgeMinisip::sendDataRTP(const unsigned char *data, int32_t length) {
-    sStream->sendZrtp((unsigned char*)data, length, NULL, 0);
-    return 1;
-}
-
-int32_t ZrtpHostBridgeMinisip::sendDataSRTP(const unsigned char *dataHeader, int32_t lengthHeader,
-					    char *dataContent, int32_t lengthContent) {
-    sStream->sendZrtp((unsigned char*)dataHeader, lengthHeader,
-		       (unsigned char*)dataContent, lengthContent);
-    return 1;
-}
-
-void ZrtpHostBridgeMinisip::srtpSecretsReady(SrtpSecret_t* secrets, EnableSecurity part) {
-
-    MRef<CryptoContext *> pcc;
-
-    if (part == ForSender) {
-    // encrypting packets, intiator uses initiator keys, responder uses responders keys
-	if (secrets->role == Initiator) {
-            senderCryptoContext = new CryptoContext(
-		    0,
-                    0,
-                    0,
-                    0L,                                      // keydr << 48,
-                    MIKEY_SRTP_EALG_AESCM,                   // encryption algo
-                    MIKEY_SRTP_AALG_SHA1HMAC,                // authtication algo
-                    (unsigned char*)secrets->keyInitiator,   // Master Key
-                    secrets->initKeyLen / 8,                 // Master Key length
-                    (unsigned char*)secrets->saltInitiator,  // Master Salt
-                    secrets->initSaltLen / 8,                // Master Salt length
-                    secrets->initKeyLen / 8,                 // encryption keyl
-                    20,                                      // authentication key len
-                    secrets->initSaltLen / 8,                // session salt len
-                    1,
-                    1,
-                    secrets->srtpAuthTagLen / 8);            // authentication tag lenA
-	}
-        else {
-            senderCryptoContext = new CryptoContext(
-		    0,
-                    0,
-                    0,
-                    0L,                                      // keydr << 48,
-                    MIKEY_SRTP_EALG_AESCM,                   // encryption algo
-                    MIKEY_SRTP_AALG_SHA1HMAC,                // authtication algo
-                    (unsigned char*)secrets->keyResponder,   // Master Key
-                    secrets->respKeyLen / 8,                 // Master Key length
-                    (unsigned char*)secrets->saltResponder,  // Master Salt
-                    secrets->respSaltLen / 8,                // Master Salt length
-                    secrets->respKeyLen / 8,                 // encryption keyl
-                    20,                                      // authentication key len
-                    secrets->respSaltLen / 8,                // session salt len
-                    1,
-                    1,
-                    secrets->srtpAuthTagLen / 8);            // authentication tag len
-        }
-        pcc = senderCryptoContext->newCryptoContextForSSRC(senderZrtpSsrc, 0, senderZrtpSeqNo, 0L);
-        pcc->derive_srtp_keys(senderZrtpSeqNo);
-        sStream->setKeyAgreementZrtp(pcc);
-
-        // create a crypto context for real SSRC sender stream. Note: this
-        // can be done at this point only if the key derivation rate is 0
-        // (disabled) or greater 2^16. For ZRTP this is the case: the key
-        // derivation is defined as 2^48 which is effectively 0.
-        pcc = senderCryptoContext->newCryptoContextForSSRC(senderSsrc, 0, sStream->getSeqNo(), 0L);
-        pcc->derive_srtp_keys(sStream->getSeqNo());
-        sStream->setKeyAgreementZrtp(pcc);
-
-        secureParts++;
-    }
-    if (part == ForReceiver) {
-    // decrypting packets, intiator uses responder keys, responder initiator keys
-	if (secrets->role == Initiator) {
-            recvCryptoContext = new CryptoContext(
-		    0,
-                    0,
-                    0,
-                    0L,                                      // keydr << 48,
-                    MIKEY_SRTP_EALG_AESCM,                   // encryption algo
-                    MIKEY_SRTP_AALG_SHA1HMAC,                // authtication algo
-                    (unsigned char*)secrets->keyResponder,   // Master Key
-                    secrets->respKeyLen / 8,                 // Master Key length
-                    (unsigned char*)secrets->saltResponder,  // Master Salt
-                    secrets->respSaltLen / 8,                // Master Salt length
-                    secrets->respKeyLen / 8,                 // encryption keyl
-                    20,                                      // authentication key len
-                    secrets->respSaltLen / 8,                // session salt len
-                    1,
-                    1,
-                    secrets->srtpAuthTagLen / 8);            // authentication tag len
-	}
-	else {
-            recvCryptoContext = new CryptoContext(
-		    0,
-                    0,
-                    0,
-                    0L,                                      // keydr << 48,
-                    MIKEY_SRTP_EALG_AESCM,                   // encryption algo
-                    MIKEY_SRTP_AALG_SHA1HMAC,                // authtication algo
-                    (unsigned char*)secrets->keyInitiator,   // Master Key
-                    secrets->initKeyLen / 8,                 // Master Key length
-                    (unsigned char*)secrets->saltInitiator,  // Master Salt
-                    secrets->initSaltLen / 8,                // Master Salt length
-                    secrets->initKeyLen / 8,                 // encryption keyl
-                    20,                                      // authentication key len
-                    secrets->initSaltLen / 8,                // session salt len
-                    1,
-                    1,
-                    secrets->srtpAuthTagLen / 8);            // authentication tag len
-	}
-        pcc = recvCryptoContext->newCryptoContextForSSRC(recvZrtpSsrc, 0, recvZrtpSeqNo, 0L);
-        pcc->derive_srtp_keys(recvZrtpSeqNo);
-        rStream->setKeyAgreementZrtp(pcc);
-
-        secureParts++;
-    }
-}
-
-MRef<CryptoContext *>
-ZrtpHostBridgeMinisip::newCryptoContextForRecvSSRC(uint32_t ssrc, int roc,
-                                                   uint16_t seq,
-                                                   int64_t keyDerivRate)
-{
-    MRef<CryptoContext *> pcc;
-
-    pcc = recvCryptoContext->newCryptoContextForSSRC(ssrc, roc, seq, keyDerivRate);
-    pcc->derive_srtp_keys(seq);
-    rStream->setKeyAgreementZrtp(pcc);
-    return pcc;
-}
-
-void ZrtpHostBridgeMinisip::srtpSecretsOn(const char* c, const char* s)
-{
-
-    if (s != NULL) {
-        CommandString cmd(callId, "zrtp_security_change", "secure", s);
-        messageRouterCallback->handleCommand("gui", cmd);
-    }
-//    if (s != NULL && zrtpUserCallback != NULL) {
-//        zrtpUserCallback->showSAS(s);
-//    }
-}
-
-void ZrtpHostBridgeMinisip::srtpSecretsOff(EnableSecurity part) {
-    MRef<CryptoContext *> cryptoContext;
-
-    if (part == ForSender) {
-	cryptoContext = new CryptoContext(senderSsrc);
-	sStream->setKeyAgreementZrtp(cryptoContext);
-
-        cryptoContext = new CryptoContext(senderZrtpSsrc);
-        sStream->setKeyAgreementZrtp(cryptoContext);
-        secureParts--;
-    }
-    if (part == ForReceiver) {
-	cryptoContext = new CryptoContext(receiverSsrc);
-	sStream->setKeyAgreementZrtp(cryptoContext);
-
-        cryptoContext = new CryptoContext(recvZrtpSsrc);
-        sStream->setKeyAgreementZrtp(cryptoContext);
-        secureParts--;
-    }
-
-    CommandString cmd(callId, "zrtp_security_change", "insecure");
-    messageRouterCallback->handleCommand("gui", cmd);
-
-}
-
-void ZrtpHostBridgeMinisip::rtpSessionError() {
-    MRef<CryptoContext *> cryptoContext;
-
-    cryptoContext = new CryptoContext(senderZrtpSsrc);
-    sStream->setKeyAgreementZrtp(cryptoContext);
-
-    cryptoContext = new CryptoContext(senderSsrc);
-    sStream->setKeyAgreementZrtp(cryptoContext);
-
-    cryptoContext = new CryptoContext(recvZrtpSsrc);
-    sStream->setKeyAgreementZrtp(cryptoContext);
-
-    cryptoContext = new CryptoContext(receiverSsrc);
-    sStream->setKeyAgreementZrtp(cryptoContext);
-
-    sendInfo(Alert, "RTP session error - security switched off!");
-
-    CommandString cmd(callId, "zrtp_security_change", "insecure");
-    messageRouterCallback->handleCommand("gui", cmd);
-}
-
-void ZrtpHostBridgeMinisip::zrtpNegotiationFailed(MessageSeverity severity, char* msg)
-{
-    fprintf(stderr, "Severity: %d - %s\n", severity, msg);
-}
-
-void ZrtpHostBridgeMinisip::zrtpNotSuppOther() {
-
-    fprintf(stderr, "The other (remote) client does not support ZRTP\n");
-}
-
-#endif
-

Copied: trunk/libminisip/source/subsystem_media/zrtp/ZrtpHostBridgeMinisip.cxx (from rev 3244, trunk/libminisip/source/subsystem_signaling/zrtp/ZrtpHostBridgeMinisip.cxx)
===================================================================
--- trunk/libminisip/source/subsystem_signaling/zrtp/ZrtpHostBridgeMinisip.cxx	2007-03-12 23:08:04 UTC (rev 3244)
+++ trunk/libminisip/source/subsystem_media/zrtp/ZrtpHostBridgeMinisip.cxx	2007-03-13 01:12:23 UTC (rev 3245)
@@ -0,0 +1,363 @@
+/*
+  Copyright (C) 2006 Werner Dittmann
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ */
+
+/*
+ * Authors: Werner Dittmann <Werner.Dittmann at t-online.de>
+ */
+
+#include <config.h>
+
+#include <libminisip/media/zrtp/ZrtpHostBridgeMinisip.h>
+#include <libzrtpcpp/ZIDFile.h>
+#include <libzrtpcpp/ZrtpStateClass.h>
+
+#include <libmikey/MikeyPayloadSP.h>
+#include <libminisip/config/UserConfig.h>
+#include <libmutil/CommandString.h>
+
+#ifdef ZRTP_SUPPORT
+
+static MRef<TimeoutProvider<std::string, MRef<StateMachine<SipSMCommand,std::string>*> > *>staticTimeoutProvider;
+
+int32_t ZrtpHostBridgeMinisip::initialize(MRef<TimeoutProvider<std::string,
+                                          MRef<StateMachine<SipSMCommand,std::string>*> > *>tp,
+                                          const char *zidFilename) {
+
+    std::string fname;
+    staticTimeoutProvider = tp;
+    if (zidFilename == NULL) {
+        fname = UserConfig::getFileName("minisip.zid");
+        zidFilename = fname.c_str();
+    }
+    ZIDFile *zf = ZIDFile::getInstance();
+    zf->open((char *)zidFilename);
+    return 1;
+}
+
+ZrtpHostBridgeMinisip::ZrtpHostBridgeMinisip(std::string id, MRef<CommandReceiver*> callback):
+        StateMachine<SipSMCommand, std::string>(staticTimeoutProvider),
+        callId(id),
+        messageRouterCallback(callback) {
+
+    secureParts = 0;
+    zrtpEngine = NULL;
+
+    senderSecure = 0;
+    receiverSecure = 0;
+
+    receiverSsrc = 0;
+    senderSsrc = 0;
+
+    rStream = NULL;
+    sStream = NULL;
+
+    senderCryptoContext = NULL;
+    senderZrtpSsrc = 0xdeadbeef;         // may be a different value (random) as well
+    senderZrtpSeqNo = 1;
+
+    recvCryptoContext = NULL;
+}
+
+ZrtpHostBridgeMinisip::~ZrtpHostBridgeMinisip() {
+
+    cancelTimer();
+    freeStateMachine();		// to clean up the TimeoutProvider
+    delete zrtpEngine;
+}
+
+void ZrtpHostBridgeMinisip::setReceiver(MRef<MediaStreamReceiver *> r) {
+	rStream = r;
+}
+
+void ZrtpHostBridgeMinisip::setSender(MRef<MediaStreamSender *> s) {
+	sStream = s;
+}
+
+void ZrtpHostBridgeMinisip::start() {
+    ZIDFile *zid = ZIDFile::getInstance();
+    const uint8_t* ownZid = zid->getZid();
+
+    if (zrtpEngine == NULL) {
+        zrtpEngine = new ZRtp((uint8_t*)ownZid, (ZrtpCallback*)this);
+        zrtpEngine->setClientId(clientId);
+        zrtpEngine->startZrtpEngine();
+    }
+}
+
+void ZrtpHostBridgeMinisip::stop() {
+    zrtpEngine->stopZrtp();
+    delete zrtpEngine;
+}
+
+bool ZrtpHostBridgeMinisip::isZrtpPacket(MRef<SRtpPacket *> packet) {
+    unsigned char* extHeader = packet->getExtensionHeader();
+    uint16_t magic = *((uint16_t*)extHeader);
+
+    magic = ntoh16(magic);
+
+    // If not a ZRTP packet - back to caller for further actions
+    if (magic == ZRTP_EXT_PACKET) {
+        return true;
+    }
+    return false;
+}
+
+int32_t ZrtpHostBridgeMinisip::processPacket(MRef<SRtpPacket *> packet) {
+
+    unsigned char* extHeader = packet->getExtensionHeader();
+    uint16_t magic = *((uint16_t*)extHeader);
+
+    magic = ntoh16(magic);
+
+    // If not a ZRTP packet - back to caller for further actions
+    if (magic != ZRTP_EXT_PACKET) {
+	return 1;
+    }
+    /*
+     * It's a ZRTP packet, check if ZRTP already started. If not and no other
+     * content return zero to dismiss packet, otherwise return 1 for further
+     * actions. This can happen for "piggy-back" ZRTP packets.
+     */
+    if (zrtpEngine == NULL) {
+        if (packet->getContentLength() > 0) {
+            return  1;
+        }
+        else {
+            return 0;
+        }
+    }
+    recvZrtpSeqNo = packet->getHeader().getSeqNo();
+    recvZrtpSsrc = packet->getHeader().getSSRC();
+
+    if (zrtpEngine->handleGoClear(extHeader)) {
+        return 0;
+    }
+    int ret = zrtpEngine->processExtensionHeader(extHeader, packet->getContent());
+
+    // Fail is only a fail of the protocol state, already handled but
+    // payload usually not affected - thus caller may process it, e.g.
+    // in case of "piggy-back" ZRTP packets.
+    return ((ret == Fail || ret == Done) ? 1 : 0);
+}
+
+bool ZrtpHostBridgeMinisip::isSecureState()
+{
+    return zrtpEngine->checkState(SecureState);
+}
+
+int32_t ZrtpHostBridgeMinisip::sendDataRTP(const unsigned char *data, int32_t length) {
+    sStream->sendZrtp((unsigned char*)data, length, NULL, 0);
+    return 1;
+}
+
+int32_t ZrtpHostBridgeMinisip::sendDataSRTP(const unsigned char *dataHeader, int32_t lengthHeader,
+					    char *dataContent, int32_t lengthContent) {
+    sStream->sendZrtp((unsigned char*)dataHeader, lengthHeader,
+		       (unsigned char*)dataContent, lengthContent);
+    return 1;
+}
+
+void ZrtpHostBridgeMinisip::srtpSecretsReady(SrtpSecret_t* secrets, EnableSecurity part) {
+
+    MRef<CryptoContext *> pcc;
+
+    if (part == ForSender) {
+    // encrypting packets, intiator uses initiator keys, responder uses responders keys
+	if (secrets->role == Initiator) {
+            senderCryptoContext = new CryptoContext(
+		    0,
+                    0,
+                    0,
+                    0L,                                      // keydr << 48,
+                    MIKEY_SRTP_EALG_AESCM,                   // encryption algo
+                    MIKEY_SRTP_AALG_SHA1HMAC,                // authtication algo
+                    (unsigned char*)secrets->keyInitiator,   // Master Key
+                    secrets->initKeyLen / 8,                 // Master Key length
+                    (unsigned char*)secrets->saltInitiator,  // Master Salt
+                    secrets->initSaltLen / 8,                // Master Salt length
+                    secrets->initKeyLen / 8,                 // encryption keyl
+                    20,                                      // authentication key len
+                    secrets->initSaltLen / 8,                // session salt len
+                    1,
+                    1,
+                    secrets->srtpAuthTagLen / 8);            // authentication tag lenA
+	}
+        else {
+            senderCryptoContext = new CryptoContext(
+		    0,
+                    0,
+                    0,
+                    0L,                                      // keydr << 48,
+                    MIKEY_SRTP_EALG_AESCM,                   // encryption algo
+                    MIKEY_SRTP_AALG_SHA1HMAC,                // authtication algo
+                    (unsigned char*)secrets->keyResponder,   // Master Key
+                    secrets->respKeyLen / 8,                 // Master Key length
+                    (unsigned char*)secrets->saltResponder,  // Master Salt
+                    secrets->respSaltLen / 8,                // Master Salt length
+                    secrets->respKeyLen / 8,                 // encryption keyl
+                    20,                                      // authentication key len
+                    secrets->respSaltLen / 8,                // session salt len
+                    1,
+                    1,
+                    secrets->srtpAuthTagLen / 8);            // authentication tag len
+        }
+        pcc = senderCryptoContext->newCryptoContextForSSRC(senderZrtpSsrc, 0, senderZrtpSeqNo, 0L);
+        pcc->derive_srtp_keys(senderZrtpSeqNo);
+        sStream->setKeyAgreementZrtp(pcc);
+
+        // create a crypto context for real SSRC sender stream. Note: this
+        // can be done at this point only if the key derivation rate is 0
+        // (disabled) or greater 2^16. For ZRTP this is the case: the key
+        // derivation is defined as 2^48 which is effectively 0.
+        pcc = senderCryptoContext->newCryptoContextForSSRC(senderSsrc, 0, sStream->getSeqNo(), 0L);
+        pcc->derive_srtp_keys(sStream->getSeqNo());
+        sStream->setKeyAgreementZrtp(pcc);
+
+        secureParts++;
+    }
+    if (part == ForReceiver) {
+    // decrypting packets, intiator uses responder keys, responder initiator keys
+	if (secrets->role == Initiator) {
+            recvCryptoContext = new CryptoContext(
+		    0,
+                    0,
+                    0,
+                    0L,                                      // keydr << 48,
+                    MIKEY_SRTP_EALG_AESCM,                   // encryption algo
+                    MIKEY_SRTP_AALG_SHA1HMAC,                // authtication algo
+                    (unsigned char*)secrets->keyResponder,   // Master Key
+                    secrets->respKeyLen / 8,                 // Master Key length
+                    (unsigned char*)secrets->saltResponder,  // Master Salt
+                    secrets->respSaltLen / 8,                // Master Salt length
+                    secrets->respKeyLen / 8,                 // encryption keyl
+                    20,                                      // authentication key len
+                    secrets->respSaltLen / 8,                // session salt len
+                    1,
+                    1,
+                    secrets->srtpAuthTagLen / 8);            // authentication tag len
+	}
+	else {
+            recvCryptoContext = new CryptoContext(
+		    0,
+                    0,
+                    0,
+                    0L,                                      // keydr << 48,
+                    MIKEY_SRTP_EALG_AESCM,                   // encryption algo
+                    MIKEY_SRTP_AALG_SHA1HMAC,                // authtication algo
+                    (unsigned char*)secrets->keyInitiator,   // Master Key
+                    secrets->initKeyLen / 8,                 // Master Key length
+                    (unsigned char*)secrets->saltInitiator,  // Master Salt
+                    secrets->initSaltLen / 8,                // Master Salt length
+                    secrets->initKeyLen / 8,                 // encryption keyl
+                    20,                                      // authentication key len
+                    secrets->initSaltLen / 8,                // session salt len
+                    1,
+                    1,
+                    secrets->srtpAuthTagLen / 8);            // authentication tag len
+	}
+        pcc = recvCryptoContext->newCryptoContextForSSRC(recvZrtpSsrc, 0, recvZrtpSeqNo, 0L);
+        pcc->derive_srtp_keys(recvZrtpSeqNo);
+        rStream->setKeyAgreementZrtp(pcc);
+
+        secureParts++;
+    }
+}
+
+MRef<CryptoContext *>
+ZrtpHostBridgeMinisip::newCryptoContextForRecvSSRC(uint32_t ssrc, int roc,
+                                                   uint16_t seq,
+                                                   int64_t keyDerivRate)
+{
+    MRef<CryptoContext *> pcc;
+
+    pcc = recvCryptoContext->newCryptoContextForSSRC(ssrc, roc, seq, keyDerivRate);
+    pcc->derive_srtp_keys(seq);
+    rStream->setKeyAgreementZrtp(pcc);
+    return pcc;
+}
+
+void ZrtpHostBridgeMinisip::srtpSecretsOn(const char* c, const char* s)
+{
+
+    if (s != NULL) {
+        CommandString cmd(callId, "zrtp_security_change", "secure", s);
+        messageRouterCallback->handleCommand("gui", cmd);
+    }
+//    if (s != NULL && zrtpUserCallback != NULL) {
+//        zrtpUserCallback->showSAS(s);
+//    }
+}
+
+void ZrtpHostBridgeMinisip::srtpSecretsOff(EnableSecurity part) {
+    MRef<CryptoContext *> cryptoContext;
+
+    if (part == ForSender) {
+	cryptoContext = new CryptoContext(senderSsrc);
+	sStream->setKeyAgreementZrtp(cryptoContext);
+
+        cryptoContext = new CryptoContext(senderZrtpSsrc);
+        sStream->setKeyAgreementZrtp(cryptoContext);
+        secureParts--;
+    }
+    if (part == ForReceiver) {
+	cryptoContext = new CryptoContext(receiverSsrc);
+	sStream->setKeyAgreementZrtp(cryptoContext);
+
+        cryptoContext = new CryptoContext(recvZrtpSsrc);
+        sStream->setKeyAgreementZrtp(cryptoContext);
+        secureParts--;
+    }
+
+    CommandString cmd(callId, "zrtp_security_change", "insecure");
+    messageRouterCallback->handleCommand("gui", cmd);
+
+}
+
+void ZrtpHostBridgeMinisip::rtpSessionError() {
+    MRef<CryptoContext *> cryptoContext;
+
+    cryptoContext = new CryptoContext(senderZrtpSsrc);
+    sStream->setKeyAgreementZrtp(cryptoContext);
+
+    cryptoContext = new CryptoContext(senderSsrc);
+    sStream->setKeyAgreementZrtp(cryptoContext);
+
+    cryptoContext = new CryptoContext(recvZrtpSsrc);
+    sStream->setKeyAgreementZrtp(cryptoContext);
+
+    cryptoContext = new CryptoContext(receiverSsrc);
+    sStream->setKeyAgreementZrtp(cryptoContext);
+
+    sendInfo(Alert, "RTP session error - security switched off!");
+
+    CommandString cmd(callId, "zrtp_security_change", "insecure");
+    messageRouterCallback->handleCommand("gui", cmd);
+}
+
+void ZrtpHostBridgeMinisip::zrtpNegotiationFailed(MessageSeverity severity, char* msg)
+{
+    fprintf(stderr, "Severity: %d - %s\n", severity, msg);
+}
+
+void ZrtpHostBridgeMinisip::zrtpNotSuppOther() {
+
+    fprintf(stderr, "The other (remote) client does not support ZRTP\n");
+}
+
+#endif
+



More information about the Minisip-devel mailing list