Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebRTC-Direct ufrag/STUN username field not prefixed with libp2p+webrtc+v1/ #2827

Closed
Tracked by #2581 ...
achingbrain opened this issue Jun 7, 2024 · 0 comments · Fixed by #2832
Closed
Tracked by #2581 ...

WebRTC-Direct ufrag/STUN username field not prefixed with libp2p+webrtc+v1/ #2827

achingbrain opened this issue Jun 7, 2024 · 0 comments · Fixed by #2832

Comments

@achingbrain
Copy link
Member

Point 4 in the Browser to public Server connection protocol says:

A generates a random string prefixed with "libp2p+webrtc+v1/". The prefix allows us to use the ufrag as an upgrade mechanism to role out a new version of the libp2p WebRTC protocol on a live network. While a hack, this might be very useful in the future. A sets the string as the username (ufrag or username fragment) and password on the SDP of the remote's answer.

Looking at where this is done in go-libp2p when it's trying to dial a remote WebRTC-Direct address:

func genUfrag() string {
const (
uFragAlphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
uFragPrefix = "libp2p+webrtc+v1/"
uFragIdLength = 32
uFragIdOffset = len(uFragPrefix)
uFragLength = uFragIdOffset + uFragIdLength
)
seed := [8]byte{}
rand.Read(seed[:])
r := mrand.New(mrand.NewSource(binary.BigEndian.Uint64(seed[:])))
b := make([]byte, uFragLength)
for i := uFragIdOffset; i < uFragLength; i++ {
b[i] = uFragAlphabet[r.Intn(len(uFragAlphabet))]
}
return string(b)
}

It creates a []byte of length uFragLength where uFragLength is uFragIdOffset + uFragIdLength and uFragIdOffset is the length of the "libp2p+webrtc+v1/" prefix string, then writes the random uFrag into the []byte starting at the uFragIdOffset index.

It doesn't seem to add the prefix string to the start of the []byte though, so it's missing from the STUN packets received by the server. See all the 00 00 00... at the start of the attribute value:

attr StunByteStringAttribute {
  [Symbol(kAttributeType)]: 6,
  [Symbol(kValue)]: <Buffer 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 6e 43 56 56 46 58 4d 6d 37 76 66 77 37 75 56 45 67 71 5a 72 51 37 6f 4c 36 48 69 67 67 59 70 61 3a ... 49 more bytes>
}
attr value nCVVFXMm7vfw7uVEgqZrQ7oL6HiggYpa:nCVVFXMm7vfw7uVEgqZrQ7oL6HiggYpa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant