sdp icon indicating copy to clipboard operation
sdp copied to clipboard

Add GetFingerprint() to SessionDescription

Open daonb opened this issue 3 years ago • 4 comments

Summary

I need to get the fingerprint of a given sessions description.

Motivation

I authorize clients based on their fingerprints - I need a way to get the client's fingerprint so I can check if it's in my authorized fingerprints file.

Describe alternatives you've considered

I'm using regex do get the fingerprint directly from the description's string.

Additional Context

There is already WithFingerprint() function to set the sd's fingerprint, this complements it.

daonb avatar Jan 18 '21 12:01 daonb

fp,ok:=s.MediaDescriptions[0].Attribute("fingerprint")

jerry-tao avatar Mar 18 '21 06:03 jerry-tao

fp,ok:=s.MediaDescriptions[0].Attribute("fingerprint")

Thanks!

I've tried using it instead of the regex I have now but I keep getting a !ok. Here's my code

func GetFingerprint(sd *webrtc.SessionDescription) (string, error) {
    s, err := sd.Unmarshal()
    if err != nil {
       return "", fmt.Errorf("Failed to unmarshal sdp: %w", err)
    }

    fp, ok := s.MediaDescriptions[0].Attribute("fingerprint")
    if !ok {
         return "", fmt.Errorf("Failed to get fingerprint from sdp")
    }
    ...

daonb avatar Mar 23 '21 20:03 daonb

Hey @daonb mind trying at the global level also?

pion/webrtc does that here

It might be nice to add AttributeRecursive? This would be useful for ice as well!

Sean-Der avatar Mar 23 '21 23:03 Sean-Der

Hey @daonb mind trying at the global level also? pion/webrtc does that here

It works! Thanks. I've ended up using the global level Attribute as terminal7 has no media.

It might be nice to add AttributeRecursive? This would be useful for ice as well!

I'd be happy to help, but I think we should find a better name as it's not really recursive. How about CollectAttribute?

daonb avatar Mar 24 '21 14:03 daonb