src/net/java/sip/communicator/impl/protocol/jabber/CallPeerMediaHandlerJabberImpl.java
/**
     * Detects and adds DTLS-SRTP available encryption method present in the
     * transport (description) given in parameter.
     *
     * @param isInitiator <tt>true</tt> if the local call instance is the
     * initiator of the call; <tt>false</tt>, otherwise.
     * @param remoteTransport the TRANSPORT element
     * @param mediaType The type of media (AUDIO or VIDEO).
     */
Detects and adds DTLS-SRTP available encryption method present in the
transport (description) given in parameter.

@param isInitiator true if the local call instance is the
initiator of the call; false, otherwise.
@param remoteTransport the TRANSPORT element
@param mediaType The type of media (AUDIO or VIDEO).
Detects and adds DTLS - SRTP available encryption method present in the transport ( description ) given in parameter . @param isInitiator true if the local call instance is the initiator of the call ; false otherwise . @param remoteTransport the TRANSPORT element @param mediaType The type of media ( AUDIO or VIDEO ) .
boolean addDtlsAdvertisedEncryptions(
            boolean isInitiator,
            IceUdpTransportPacketExtension remoteTransport,
            MediaType mediaType,
            boolean rtcpmux)
    {
        SrtpControls srtpControls = getSrtpControls();
        boolean b = false;
        if (remoteTransport != null)
        {
            List<DtlsFingerprintPacketExtension> remoteFingerpintPEs
                = remoteTransport.getChildExtensionsOfType(
                        DtlsFingerprintPacketExtension.class);
            if (!remoteFingerpintPEs.isEmpty())
            {
                AccountID accountID
                    = getPeer().getProtocolProvider().getAccountID();
                if (accountID.getAccountPropertyBoolean(
                            ProtocolProviderFactory.DEFAULT_ENCRYPTION,
                            true)
                        && accountID.isEncryptionProtocolEnabled(
                                SrtpControlType.DTLS_SRTP))
                {
                    Map<String,String> remoteFingerprints
                        = new LinkedHashMap<String,String>();
                    for (DtlsFingerprintPacketExtension remoteFingerprintPE
                            : remoteFingerpintPEs)
                    {
                        String remoteFingerprint
                            = remoteFingerprintPE.getFingerprint();
                        String remoteHash = remoteFingerprintPE.getHash();
                        remoteFingerprints.put(
                                remoteHash,
                                remoteFingerprint);
                    }
                    DtlsControl dtlsControl;
                    DtlsControl.Setup setup;
                    if (isInitiator)
                    {
                        dtlsControl
                            = (DtlsControl)
                                srtpControls.get(
                                        mediaType,
                                        SrtpControlType.DTLS_SRTP);
                        setup = DtlsControl.Setup.PASSIVE;
                    }
                    else
                    {
                        dtlsControl
                            = (DtlsControl)
                                srtpControls.getOrCreate(
                                        mediaType,
                                        SrtpControlType.DTLS_SRTP);
                        setup = DtlsControl.Setup.ACTIVE;
                    }
                    if (dtlsControl != null)
                    {
                        dtlsControl.setRemoteFingerprints(remoteFingerprints);
                        dtlsControl.setSetup(setup);
                        if (rtcpmux)
                        {
                            dtlsControl.setRtcpmux(true);
                        }
                        removeAndCleanupOtherSrtpControls(
                                mediaType,
                                SrtpControlType.DTLS_SRTP);
                        addAdvertisedEncryptionMethod(
                                SrtpControlType.DTLS_SRTP);
                        b = true;
                    }
                }
            }
        }
        /*
         * If they haven't advertised DTLS-SRTP in their (media) description,
         * then DTLS-SRTP shouldn't be functioning as far as we're concerned.
         */
        if (!b)
        {
            SrtpControl dtlsControl
                = srtpControls.get(mediaType, SrtpControlType.DTLS_SRTP);
            if (dtlsControl != null)
            {
                srtpControls.remove(mediaType, SrtpControlType.DTLS_SRTP);
                dtlsControl.cleanup(null);
            }
        }
        return b;
    }
boolean addDtlsAdvertisedEncryptions ( boolean isInitiator , IceUdpTransportPacketExtension remoteTransport , MediaType mediaType , boolean rtcpmux ) { SrtpControls srtpControls = getSrtpControls ( ) ; boolean b = false ; if ( remoteTransport != null ) { List < DtlsFingerprintPacketExtension > remoteFingerpintPEs = remoteTransport . getChildExtensionsOfType ( DtlsFingerprintPacketExtension . class ) ; if ( ! remoteFingerpintPEs . isEmpty ( ) ) { AccountID accountID = getPeer ( ) . getProtocolProvider ( ) . getAccountID ( ) ; if ( accountID . getAccountPropertyBoolean ( ProtocolProviderFactory . DEFAULT_ENCRYPTION , true ) && accountID . isEncryptionProtocolEnabled ( SrtpControlType . DTLS_SRTP ) ) { Map < String , String > remoteFingerprints = new LinkedHashMap < String , String > ( ) ; for ( DtlsFingerprintPacketExtension remoteFingerprintPE : remoteFingerpintPEs ) { String remoteFingerprint = remoteFingerprintPE . getFingerprint ( ) ; String remoteHash = remoteFingerprintPE . getHash ( ) ; remoteFingerprints . put ( remoteHash , remoteFingerprint ) ; } DtlsControl dtlsControl ; DtlsControl . Setup setup ; if ( isInitiator ) { dtlsControl = ( DtlsControl ) srtpControls . get ( mediaType , SrtpControlType . DTLS_SRTP ) ; setup = DtlsControl . Setup . PASSIVE ; } else { dtlsControl = ( DtlsControl ) srtpControls . getOrCreate ( mediaType , SrtpControlType . DTLS_SRTP ) ; setup = DtlsControl . Setup . ACTIVE ; } if ( dtlsControl != null ) { dtlsControl . setRemoteFingerprints ( remoteFingerprints ) ; dtlsControl . setSetup ( setup ) ; if ( rtcpmux ) { dtlsControl . setRtcpmux ( true ) ; } removeAndCleanupOtherSrtpControls ( mediaType , SrtpControlType . DTLS_SRTP ) ; addAdvertisedEncryptionMethod ( SrtpControlType . DTLS_SRTP ) ; b = true ; } } } } /*
         * If they haven't advertised DTLS-SRTP in their (media) description,
         * then DTLS-SRTP shouldn't be functioning as far as we're concerned.
         */ if ( ! b ) { SrtpControl dtlsControl = srtpControls . get ( mediaType , SrtpControlType . DTLS_SRTP ) ; if ( dtlsControl != null ) { srtpControls . remove ( mediaType , SrtpControlType . DTLS_SRTP ) ; dtlsControl . cleanup ( null ) ; } } return b ; }
Detects and adds DTLS-SRTP available encryption method present in the
 transport (description) given in parameter.
Detects and adds DTLS - SRTP available encryption method present in the transport ( description ) given in parameter .
// TODO Read the setup from the remote DTLS fingerprint // packet extension.