MayamaTakeshi / sip-lab

A node module that helps to write SIP functional tests
3 stars 2 forks source link

Add SRTP support #58

Closed MayamaTakeshi closed 5 months ago

MayamaTakeshi commented 6 months ago

We already link to pjmedia with SRTP support but we need to actually use it when setting up calls. This might go in the media description with a new parameter "secure" (that could be set to "true" or specifying which ciphers to offer/accept).

[
  {
    type: 'audio',
    secure: true
    fields: [
      'a=sendrecv',
      'a=mid:1',
    ],
  },
]

Or maybe for flexibility we should just use a=crypto in the fields:

[
  {
    type: 'audio',
    fields: [
      "a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:k436fLbKPMbchV79TI5yRLTxtPHG08jvl12DKWNg",
      "a=crypto:2 AES_CM_128_HMAC_SHA1_32 inline:gabwSsJ598QLtWzFOv/psvxcfFy7iWXBBrcmUO1O"
    ]
  }
]

(however, we cannot set anything. It must be what libsrtp/pjmedia supports).

MayamaTakeshi commented 6 months ago

Documentation is good: https://docs.pjsip.org/en/latest/specific-guides/security/srtp.html This example app requires the SRTP keys to be passed to the app: https://github.com/pjsip/pjproject/blob/master/pjsip-apps/src/samples/streamutil.c I think we should create the keys ourselves and set them in the a=crypto fields:

m=audio 59454 RTP/SAVP 3 18 101
a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:k436fLbKPMbchV79TI5yRLTxtPHG08jvl12DKWNg
a=crypto:2 AES_CM_128_HMAC_SHA1_32 inline:gabwSsJ598QLtWzFOv/psvxcfFy7iWXBBrcmUO1O

So we might go with:

[
  {
    type: 'audio',
    fields: [
      "a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:k436fLbKPMbchV79TI5yRLTxtPHG08jvl12DKWNg",
      "a=crypto:2 AES_CM_128_HMAC_SHA1_32 inline:gabwSsJ598QLtWzFOv/psvxcfFy7iWXBBrcmUO1O"
    ]
  }
]
MayamaTakeshi commented 5 months ago

Done. For now, we will just allow to specify if the media (currently, only for audio) should be secure or not:

        media: [
            {
                type: 'audio',
                secure: true,
            },
        ]

See samples/srtp.js.