src/net/java/sip/communicator/impl/protocol/sip/CallPeerMediaHandlerSipImpl.java
/**
     * Updates a specific local <tt>MediaDescription</tt> and the state of this
     * instance for the purposes of DTLS-SRTP.
     *
     * @param mediaType the <tt>MediaType</tt> of the media described by
     * <tt>localMd</tt> and <tt>remoteMd</tt>
     * @param localMd the local <tt>MediaDescription</tt> to be updated
     * @param remoteMd the remote <tt>MediaDescription</tt>, if any, associated
     * with <tt>localMd</tt>
     * @return <tt>true</tt> if the specified <tt>localMd</tt> and/or the state
     * of this instance was updated for the purposes of DTLS-SRTP or
     * <tt>false</tt> if the specified <tt>localMd</tt> (and <tt>remoteMd</tt>)
     * did not concern DTLS-SRTP
     */
Updates a specific local MediaDescription and the state of this
instance for the purposes of DTLS-SRTP.

@param mediaType the MediaType of the media described by
localMd and remoteMd
@param localMd the local MediaDescription to be updated
@param remoteMd the remote MediaDescription, if any, associated
with localMd
@return true if the specified localMd and/or the state
of this instance was updated for the purposes of DTLS-SRTP or
false if the specified localMd (and remoteMd)
did not concern DTLS-SRTP
Updates a specific local MediaDescription and the state of this instance for the purposes of DTLS - SRTP . @param mediaType the MediaType of the media described by localMd and remoteMd @param localMd the local MediaDescription to be updated @param remoteMd the remote MediaDescription if any associated with localMd @return true if the specified localMd and / or the state of this instance was updated for the purposes of DTLS - SRTP or false if the specified localMd ( and remoteMd ) did not concern DTLS - SRTP
private boolean updateMediaDescriptionForDtls(
            MediaType mediaType,
            MediaDescription localMd,
            MediaDescription remoteMd)
    {
        AccountID accountID = getPeer().getProtocolProvider().getAccountID();
        boolean b = false;
        if (accountID.getAccountPropertyBoolean(
                    ProtocolProviderFactory.DEFAULT_ENCRYPTION,
                    true)
                && accountID.isEncryptionProtocolEnabled(
                        SrtpControlType.DTLS_SRTP))
        {
            /*
             * The transport protocol of the media described by localMd should
             * be DTLS-SRTP in order to be of any concern here.
             */
            Media localMedia = localMd.getMedia();
            if (localMedia != null)
            {
                String proto;
                try
                {
                    proto = localMedia.getProtocol();
                }
                catch (SdpParseException e)
                {
                    /*
                     * Well, if the protocol of the Media cannot be parsed, then
                     * surely we do not want to have anything to do with it.
                     */
                    proto = null;
                }
                boolean dtls
                    = DtlsControl.UDP_TLS_RTP_SAVP.equals(proto)
                        || DtlsControl.UDP_TLS_RTP_SAVPF.equals(proto)
                        || SrtpControl.RTP_SAVPF.equals(proto);
                if (dtls && (remoteMd != null))
                    dtls = isDtlsMediaDescription(remoteMd);
                SrtpControls srtpControls = getSrtpControls();
                if (dtls)
                {
                    DtlsControl dtlsControl
                        = (DtlsControl)
                            srtpControls.getOrCreate(
                                    mediaType,
                                    SrtpControlType.DTLS_SRTP);
                    @SuppressWarnings("unchecked")
                    Vector<Attribute> attrs = localMd.getAttributes(true);
                    DtlsControl.Setup setup
                        = (remoteMd == null)
                            ? DtlsControl.Setup.ACTPASS
                            : DtlsControl.Setup.ACTIVE;
                    Attribute setupAttr
                        = SdpUtils.createAttribute(
                                DTLS_SRTP_SETUP_ATTR,
                                setup.toString());
                    attrs.add(setupAttr);
                    String hashFunction
                        = dtlsControl.getLocalFingerprintHashFunction();
                    String fingerprint = dtlsControl.getLocalFingerprint();
                    Attribute fingerprintAttr
                        = SdpUtils.createAttribute(
                                DTLS_SRTP_FINGERPRINT_ATTR,
                                hashFunction + " " + fingerprint);
                    attrs.add(fingerprintAttr);
                    dtlsControl.setSetup(setup);
                    if (remoteMd != null) 
                        updateSrtpControlsForDtls(mediaType, localMd, remoteMd);
                    b = true;
                }
                else if (remoteMd != null) 
                {
                    /*
                     * If DTLS-SRTP has been rejected as the transport protocol,
                     * then halt the operation of DTLS-SRTP.
                     */
                    SrtpControl dtlsControl
                        = srtpControls.remove(
                                mediaType,
                                SrtpControlType.DTLS_SRTP);
                    if (dtlsControl != null)
                        dtlsControl.cleanup(null);
                }
            }
        }
        return b;
    }
private boolean updateMediaDescriptionForDtls ( MediaType mediaType , MediaDescription localMd , MediaDescription remoteMd ) { AccountID accountID = getPeer ( ) . getProtocolProvider ( ) . getAccountID ( ) ; boolean b = false ; if ( accountID . getAccountPropertyBoolean ( ProtocolProviderFactory . DEFAULT_ENCRYPTION , true ) && accountID . isEncryptionProtocolEnabled ( SrtpControlType . DTLS_SRTP ) ) { /*
             * The transport protocol of the media described by localMd should
             * be DTLS-SRTP in order to be of any concern here.
             */ Media localMedia = localMd . getMedia ( ) ; if ( localMedia != null ) { String proto ; try { proto = localMedia . getProtocol ( ) ; } catch ( SdpParseException e ) { /*
                     * Well, if the protocol of the Media cannot be parsed, then
                     * surely we do not want to have anything to do with it.
                     */ proto = null ; } boolean dtls = DtlsControl . UDP_TLS_RTP_SAVP . equals ( proto ) || DtlsControl . UDP_TLS_RTP_SAVPF . equals ( proto ) || SrtpControl . RTP_SAVPF . equals ( proto ) ; if ( dtls && ( remoteMd != null ) ) dtls = isDtlsMediaDescription ( remoteMd ) ; SrtpControls srtpControls = getSrtpControls ( ) ; if ( dtls ) { DtlsControl dtlsControl = ( DtlsControl ) srtpControls . getOrCreate ( mediaType , SrtpControlType . DTLS_SRTP ) ; @ SuppressWarnings ( "unchecked" ) Vector < Attribute > attrs = localMd . getAttributes ( true ) ; DtlsControl . Setup setup = ( remoteMd == null ) ? DtlsControl . Setup . ACTPASS : DtlsControl . Setup . ACTIVE ; Attribute setupAttr = SdpUtils . createAttribute ( DTLS_SRTP_SETUP_ATTR , setup . toString ( ) ) ; attrs . add ( setupAttr ) ; String hashFunction = dtlsControl . getLocalFingerprintHashFunction ( ) ; String fingerprint = dtlsControl . getLocalFingerprint ( ) ; Attribute fingerprintAttr = SdpUtils . createAttribute ( DTLS_SRTP_FINGERPRINT_ATTR , hashFunction + " " + fingerprint ) ; attrs . add ( fingerprintAttr ) ; dtlsControl . setSetup ( setup ) ; if ( remoteMd != null ) updateSrtpControlsForDtls ( mediaType , localMd , remoteMd ) ; b = true ; } else if ( remoteMd != null ) { /*
                     * If DTLS-SRTP has been rejected as the transport protocol,
                     * then halt the operation of DTLS-SRTP.
                     */ SrtpControl dtlsControl = srtpControls . remove ( mediaType , SrtpControlType . DTLS_SRTP ) ; if ( dtlsControl != null ) dtlsControl . cleanup ( null ) ; } } } return b ; }
Updates a specific local <tt>MediaDescription</tt> and the state of this
 instance for the purposes of DTLS-SRTP.
Updates a specific local <tt > MediaDescription< / tt > and the state of this instance for the purposes of DTLS - SRTP .
// SDP attributes // setup // fingerprint // answer // answer