| 48 | } |
| 49 | |
| 50 | func (ca *ClientAuth) AuthKey() string { |
| 51 | buf := bytes.NewBuffer(nil) |
| 52 | |
| 53 | buf.WriteByte(1) |
| 54 | |
| 55 | if ca.Web { |
| 56 | buf.WriteByte(1) |
| 57 | } else { |
| 58 | buf.WriteByte(0) |
| 59 | } |
| 60 | |
| 61 | buf.WriteByte(byte(ca.ReceiverStunAddr.Addr().BitLen() / 8)) |
| 62 | if ca.ReceiverStunAddr.Addr().BitLen() > 0 { |
| 63 | stunBytes, err := ca.ReceiverStunAddr.MarshalBinary() |
| 64 | if err != nil { |
| 65 | panic(fmt.Sprint("failed to marshal stun addr:", err)) |
| 66 | } |
| 67 | buf.Write(stunBytes) |
| 68 | } |
| 69 | |
| 70 | derpBuf := [2]byte{} |
| 71 | binary.BigEndian.PutUint16(derpBuf[:], ca.ReceiverDERPRegionID) |
| 72 | buf.Write(derpBuf[:]) |
| 73 | |
| 74 | pub := ca.ReceiverPublicKey.Raw32() |
| 75 | buf.Write(pub[:]) |
| 76 | |
| 77 | priv := ca.OverlayPrivateKey.Raw32() |
| 78 | buf.Write(priv[:]) |
| 79 | |
| 80 | return base58.Encode(buf.Bytes()) |
| 81 | } |
| 82 | |
| 83 | func (ca *ClientAuth) Parse(authKey string) error { |
| 84 | if len(authKey) == 0 { |