src/net/java/sip/communicator/impl/protocol/sip/CallPeerMediaHandlerSipImpl.java
/**
     * Updates the <tt>SrtpControls</tt> of this instance in accord with a
     * specific <tt>MediaDescription</tt> presented by a remote peer.
     *
     * @param mediaType the <tt>MediaType</tt> of the specified
     * <tt>MediaDescription</tt> to be analyzed
     * @param localMd the <tt>MediaDescription</tt> of the local peer that is
     * the answer to the offer presented by a remote peer represented by
     * <tt>remoteMd</tt> or <tt>null</tt> if the specified <tt>remoteMd</tt> is
     * an answer to an offer of the local peer
     * @param remoteMd the <tt>MediaDescription</tt> presented by a remote peer
     * to be analyzed
     */
Updates the SrtpControls of this instance in accord with a
specific MediaDescription presented by a remote peer.

@param mediaType the MediaType of the specified
MediaDescription to be analyzed
@param localMd the MediaDescription of the local peer that is
the answer to the offer presented by a remote peer represented by
remoteMd or null if the specified remoteMd is
an answer to an offer of the local peer
@param remoteMd the MediaDescription presented by a remote peer
to be analyzed
Updates the SrtpControls of this instance in accord with a specific MediaDescription presented by a remote peer . @param mediaType the MediaType of the specified MediaDescription to be analyzed @param localMd the MediaDescription of the local peer that is the answer to the offer presented by a remote peer represented by remoteMd or null if the specified remoteMd is an answer to an offer of the local peer @param remoteMd the MediaDescription presented by a remote peer to be analyzed
private void updateSrtpControlsForDtls(
            MediaType mediaType,
            MediaDescription localMd,
            MediaDescription remoteMd)
    {
        SrtpControls srtpControls = getSrtpControls();
        DtlsControl dtlsControl
            = (DtlsControl)
                srtpControls.get(mediaType, SrtpControlType.DTLS_SRTP);
        if (dtlsControl == null)
            return;
        boolean dtls = isDtlsMediaDescription(remoteMd);
        if (dtls)
        {
            if (localMd == null) 
            {
                /*
                 * RFC 5763 requires setup:actpass from the offerer i.e. the
                 * offerer is the DTLS server and recommends setup:active to the
                 * answerer i.e the answerer is the DTLS client. If the answerer
                 * chooses setup:passive i.e. the answerer is the DTLS server,
                 * the offerer has to become the DTLS client. 
                 */
                String setup;
                try
                {
                    setup = remoteMd.getAttribute(DTLS_SRTP_SETUP_ATTR);
                }
                catch (SdpParseException spe)
                {
                    setup = null;
                }
                if (DtlsControl.Setup.PASSIVE.toString().equals(setup))
                    dtlsControl.setSetup(DtlsControl.Setup.ACTIVE);
            }
            @SuppressWarnings("unchecked")
            Vector<Attribute> attrs = remoteMd.getAttributes(false);
            Map<String, String> remoteFingerprints
                = new LinkedHashMap<String, String>();
            if (attrs != null)
            {
                for (Attribute attr : attrs)
                {
                    String fingerprint;
                    try
                    {
                        if (DTLS_SRTP_FINGERPRINT_ATTR.equals(attr.getName()))
                        {
                            fingerprint = attr.getValue();
                            if (fingerprint == null)
                                continue;
                            else
                                fingerprint = fingerprint.trim();
                        }
                        else
                        {
                            continue;
                        }
                    }
                    catch (SdpParseException spe)
                    {
                        /*
                         * Whatever part of the SDP failed to parse, we would
                         * better not try to recover from it.
                         */
                        continue;
                    }
                    int spIndex = fingerprint.indexOf(' ');
                    if ((spIndex > 0) && (spIndex < fingerprint.length() - 1))
                    {
                        String hashFunction = fingerprint.substring(0, spIndex);
                        fingerprint = fingerprint.substring(spIndex + 1);
                        remoteFingerprints.put(hashFunction, fingerprint);
                    }
                }
            }
            dtlsControl.setRemoteFingerprints(remoteFingerprints);
            removeAndCleanupOtherSrtpControls(
                    mediaType,
                    SrtpControlType.DTLS_SRTP);
        }
        else
        {
            srtpControls.remove(mediaType, SrtpControlType.DTLS_SRTP);
            dtlsControl.cleanup(null);
        }
    }
private void updateSrtpControlsForDtls ( MediaType mediaType , MediaDescription localMd , MediaDescription remoteMd ) { SrtpControls srtpControls = getSrtpControls ( ) ; DtlsControl dtlsControl = ( DtlsControl ) srtpControls . get ( mediaType , SrtpControlType . DTLS_SRTP ) ; if ( dtlsControl == null ) return ; boolean dtls = isDtlsMediaDescription ( remoteMd ) ; if ( dtls ) { if ( localMd == null ) { /*
                 * RFC 5763 requires setup:actpass from the offerer i.e. the
                 * offerer is the DTLS server and recommends setup:active to the
                 * answerer i.e the answerer is the DTLS client. If the answerer
                 * chooses setup:passive i.e. the answerer is the DTLS server,
                 * the offerer has to become the DTLS client. 
                 */ String setup ; try { setup = remoteMd . getAttribute ( DTLS_SRTP_SETUP_ATTR ) ; } catch ( SdpParseException spe ) { setup = null ; } if ( DtlsControl . Setup . PASSIVE . toString ( ) . equals ( setup ) ) dtlsControl . setSetup ( DtlsControl . Setup . ACTIVE ) ; } @ SuppressWarnings ( "unchecked" ) Vector < Attribute > attrs = remoteMd . getAttributes ( false ) ; Map < String , String > remoteFingerprints = new LinkedHashMap < String , String > ( ) ; if ( attrs != null ) { for ( Attribute attr : attrs ) { String fingerprint ; try { if ( DTLS_SRTP_FINGERPRINT_ATTR . equals ( attr . getName ( ) ) ) { fingerprint = attr . getValue ( ) ; if ( fingerprint == null ) continue ; else fingerprint = fingerprint . trim ( ) ; } else { continue ; } } catch ( SdpParseException spe ) { /*
                         * Whatever part of the SDP failed to parse, we would
                         * better not try to recover from it.
                         */ continue ; } int spIndex = fingerprint . indexOf ( ' ' ) ; if ( ( spIndex > 0 ) && ( spIndex < fingerprint . length ( ) - 1 ) ) { String hashFunction = fingerprint . substring ( 0 , spIndex ) ; fingerprint = fingerprint . substring ( spIndex + 1 ) ; remoteFingerprints . put ( hashFunction , fingerprint ) ; } } } dtlsControl . setRemoteFingerprints ( remoteFingerprints ) ; removeAndCleanupOtherSrtpControls ( mediaType , SrtpControlType . DTLS_SRTP ) ; } else { srtpControls . remove ( mediaType , SrtpControlType . DTLS_SRTP ) ; dtlsControl . cleanup ( null ) ; } }
Updates the <tt>SrtpControls</tt> of this instance in accord with a
 specific <tt>MediaDescription</tt> presented by a remote peer.
Updates the <tt > SrtpControls< / tt > of this instance in accord with a specific <tt > MediaDescription< / tt > presented by a remote peer .
// answer // setup // fingerprint