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

crypto/tls: ConnectionState struct can not be json encoded in 1.11rc1 #27125

Closed
briankassouf opened this issue Aug 21, 2018 · 7 comments
Closed

crypto/tls: ConnectionState struct can not be json encoded in 1.11rc1 #27125

briankassouf opened this issue Aug 21, 2018 · 7 comments

Comments

@briankassouf
Copy link

@briankassouf briankassouf commented Aug 21, 2018

What version of Go are you using (go version)?

go1.11rc1

Does this issue reproduce with the latest release?

go1.11rc1 - yes
go1.10.3 - no

What operating system and processor architecture are you using (go env)?

darwin/amd64

What did you do?

package main

import (
	"crypto/tls"
	"encoding/json"
	"fmt"
)

func main() {
	connState := &tls.ConnectionState{}
	_, err := json.Marshal(connState)
	if err != nil {
		fmt.Println(err)
	}
}

Prints json: unsupported type: func(string, []uint8, int) ([]uint8, bool)

What did you expect to see?

in go1.10.3 nothing is printed

@FiloSottile

This comment has been minimized.

Copy link
Member

@FiloSottile FiloSottile commented Aug 21, 2018

@bradfitz @andybons WDYT? Should we add a json:"-" tag? It does solve the issue for encoding/json, but not for all the other reflect based encodings.

Also, does it qualify for backport?

@FiloSottile FiloSottile added this to the Go1.11 milestone Aug 21, 2018
@bradfitz

This comment has been minimized.

Copy link
Contributor

@bradfitz bradfitz commented Aug 21, 2018

Yeah, let's add that json struct tag to that one field only in master & cherry-pick it to Go 1.11.

In the same CL, fix the typo in the documentation. The doc says "ExportKeyMaterial" but the field is named "ExportKeyingMaterial".

@FiloSottile FiloSottile modified the milestones: Go1.11, Go1.12 Aug 21, 2018
@bradfitz

This comment has been minimized.

Copy link
Contributor

@bradfitz bradfitz commented Aug 21, 2018

Actually the ExportKeyingMaterial field is kinda weird. Why isn't it a method on the ConnectionState?

@bradfitz

This comment has been minimized.

Copy link
Contributor

@bradfitz bradfitz commented Aug 21, 2018

Could we unexport that field instead and add a method that used the unexported field?

Then we're back to having no func types in that previously-data-only struct.

And then we don't have to add JSON stuff, and we don't need to worry about XML or protobuf, etc.

@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Aug 21, 2018

Change https://golang.org/cl/130535 mentions this issue: crypto/tls: hide ConnectionState.ExportKeyingMaterial from encoding/json

@FiloSottile

This comment has been minimized.

Copy link
Member

@FiloSottile FiloSottile commented Aug 21, 2018

Yeah, I don't see any rationale in https://go-review.googlesource.com/c/go/+/85115, so I tend to agree. Does adding an unexported field to a struct that previously had none cause issues?

@bradfitz

This comment has been minimized.

Copy link
Contributor

@bradfitz bradfitz commented Aug 21, 2018

@FiloSottile, adding an unexported field to a struct without them isn't something we do lightly. (going from fully public to partially private is a big step) But in this case I think it's better.

The other big thing we consider is breaking comparability (notably going from being able to use types as map keys to not being able to). But we already have slices in this, so that's already out the window.

I see no problems with a hidden field here, and I think a method would be better API anyway.

@gopherbot gopherbot closed this in de16b32 Aug 22, 2018
FiloSottile added a commit to FiloSottile/go that referenced this issue Oct 12, 2018
The unexported field is hidden from reflect based marshalers, which
would break otherwise. Also, make it return an error, as there are
multiple reasons it might fail.

Fixes golang#27125

Change-Id: I92adade2fe456103d2d5c0315629ca0256953764
Reviewed-on: https://go-review.googlesource.com/130535
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
FiloSottile added a commit to FiloSottile/go that referenced this issue Oct 12, 2018
The unexported field is hidden from reflect based marshalers, which
would break otherwise. Also, make it return an error, as there are
multiple reasons it might fail.

Fixes golang#27125

Change-Id: I92adade2fe456103d2d5c0315629ca0256953764
Reviewed-on: https://go-review.googlesource.com/130535
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
@golang golang locked and limited conversation to collaborators Aug 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.