Android WebRTC cannot connect to coTURN server: error 401: Unauthorized

1.3k views Asked by At

I have setup a coTURN server with lt-cred-mech option (use TURN REST API). My generated user look like:

  • user: 1601871288:4e4d54c1-7b69-40a2-b355-ff2b40e003c4
  • pass: doSnY8s16/vK6ynnALMkbl0DcLo=

I have test with trickle-ice and my browser can connect to my server: enter image description here

Log from coTURN server:

240848: session 001000000000000929: realm <> user <>: incoming packet BINDING processed, success
240849: session 001000000000000928: realm <> user <>: incoming packet BINDING processed, success
240851: IPv4. Local relay addr: 172.30.0.9:49063
240851: session 000000000000000589: new, realm=<>, username=<1601871288:4e4d54c1-7b69-40a2-b355-ff2b40e003c4>, lifetime=3600
240851: session 000000000000000589: realm <> user <1601871288:4e4d54c1-7b69-40a2-b355-ff2b40e003c4>: incoming packet ALLOCATE processed, success
240851: IPv4. Local relay addr: 172.30.0.9:49021
240851: session 000000000000000590: new, realm=<>, username=<1601871288:4e4d54c1-7b69-40a2-b355-ff2b40e003c4>, lifetime=3600
240851: session 000000000000000590: realm <> user <1601871288:4e4d54c1-7b69-40a2-b355-ff2b40e003c4>: incoming packet ALLOCATE processed, success
240851: session 000000000000000589: refreshed, realm=<>, username=<1601871288:4e4d54c1-7b69-40a2-b355-ff2b40e003c4>, lifetime=0
240851: session 000000000000000589: realm <> user <1601871288:4e4d54c1-7b69-40a2-b355-ff2b40e003c4>: incoming packet REFRESH processed, success
240851: session 000000000000000589: TCP socket closed remotely x.x.x.x:44301
240851: session 000000000000000589: usage: realm=<>, username=<1601871288:4e4d54c1-7b69-40a2-b355-ff2b40e003c4>, rp=3, rb=324, sp=3, sb=312
240851: session 000000000000000589: peer usage: realm=<>, username=<1601871288:4e4d54c1-7b69-40a2-b355-ff2b40e003c4>, rp=0, rb=0, sp=0, sb=0
240851: session 000000000000000589: closed (2nd stage), user <1601871288:4e4d54c1-7b69-40a2-b355-ff2b40e003c4> realm <> origin <>, local 172.30.0.9:3478, remote x.x.x.x:44301, reason: TCP connection closed by client (callback)
240851: session 000000000000000589: delete: realm=<>, username=<1601871288:4e4d54c1-7b69-40a2-b355-ff2b40e003c4>

But when I use Android app to make voice call, app cannot connect.

My android code:

PeerConnection.IceServer iceServer = PeerConnection.IceServer
        .builder("turn:x.x.x.x:3478")
        .setUsername("1601871288:4e4d54c1-7b69-40a2-b355-ff2b40e003c4")
        .setPassword("doSnY8s16/vK6ynnALMkbl0DcLo=")
        .setTlsCertPolicy(PeerConnection.TlsCertPolicy.TLS_CERT_POLICY_INSECURE_NO_CHECK)
        .createIceServer();

iceServers.add(iceServer);

PeerConnection.RTCConfiguration rtcConfig = new PeerConnection.RTCConfiguration(iceServers);

// TCP candidates are only useful when connecting to a server that supports
// ICE-TCP.
rtcConfig.tcpCandidatePolicy = PeerConnection.TcpCandidatePolicy.DISABLED;
rtcConfig.bundlePolicy = PeerConnection.BundlePolicy.MAXBUNDLE;
rtcConfig.rtcpMuxPolicy = PeerConnection.RtcpMuxPolicy.REQUIRE;
rtcConfig.continualGatheringPolicy = PeerConnection.ContinualGatheringPolicy.GATHER_CONTINUALLY;
rtcConfig.iceTransportsType = PeerConnection.IceTransportsType.ALL;
// Use ECDSA encryption.
 rtcConfig.keyType = PeerConnection.KeyType.ECDSA;

// Disable when use loopback
rtcConfig.enableDtlsSrtp = true;
rtcConfig.sdpSemantics = PeerConnection.SdpSemantics.UNIFIED_PLAN;

peerConnection = factory.createPeerConnection(rtcConfig, pcObserver);

But I got error from server: error 401: Unauthorized

Log from server:

241236: session 001000000000000943: realm <> user <>: incoming packet message processed, error 401: Unauthorized
241236: session 001000000000000944: realm <> user <>: incoming packet message processed, error 401: Unauthorized
241236: session 001000000000000943: realm <> user <>: incoming packet message processed, error 401: Unauthorized
241236: session 000000000000000591: realm <> user <>: incoming packet message processed, error 401: Unauthorized
241236: session 001000000000000944: realm <> user <>: incoming packet message processed, error 401: Unauthorized

Can someone tell me where is my mistake?

Thank in advance.

0

There are 0 answers