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

Problem with RPC: Add abilty to exclude certain types/ methods #15

Closed
lu4p opened this issue Apr 10, 2020 · 6 comments
Closed

Problem with RPC: Add abilty to exclude certain types/ methods #15

lu4p opened this issue Apr 10, 2020 · 6 comments

Comments

@lu4p
Copy link
Member

lu4p commented Apr 10, 2020

When I garble the ToRat client, compiling works even with cgo (many thanks).
However I communicate over RPC with the server and the server needs the API function names to stay the same.

I get the following error when a garbled client connects:
"Invalid Hostname rpc: can't find service API.Hostname"

Client RPC Api definition: https://github.com/lu4p/ToRat/blob/master/torat_client/rpcapi.go
Example Server RPC Call: https://github.com/lu4p/ToRat/blob/c23e742bc5937c40320bf437479cd7083c83e78d/torat_server/shell.go#L199

Any Ideas on how certain types and their methods could be excluded?

@lu4p lu4p changed the title Problem with RPC Problem with RPC: Add abilty to exclude certain types/ methods Apr 10, 2020
@mvdan
Copy link
Member

mvdan commented Apr 12, 2020

The methods are exported, so they shouldn't be getting randomized. This is because of interfaces.

The type API is exported, but that doesn't affect interfaces, so we do randomize that name. I assume that's where your problem arises:

	rpc.Register(api)

This is good old reflect, so there's no way we can detect this. We could give up and never garble exported types, but that would be pretty flawed.

I'm not a big fan of special comments telling tools what to do, so I'd rather not add something like //go:garble off. When looking at the source statically, at the moment, there's no way to tell that you need the API name to remain as-is, unless we special case what rpc.Register does. That would work for your use case, but it wouldn't work for others.

Something that comes to mind is having garble not touch a type T, if one does reflect.TypeOf(t) where t has type T. Since we garble one package at a time, we would only search for such TypeOf calls in the package where T is defined. So, in your case, you could add something like:

// Make sure API is never garbled.
var _ = reflect.TypeOf(API{})

@lu4p
Copy link
Member Author

lu4p commented Apr 12, 2020

Will try the workaround.

@mvdan
Copy link
Member

mvdan commented Apr 12, 2020

If you mean the reflect.TypeOf line, that won't work. It's just an idea I was suggesting outloud.

@lu4p
Copy link
Member Author

lu4p commented Apr 12, 2020

I thought this is implemented already, my bad

@cytown
Copy link

cytown commented May 18, 2020

It's a must feature. Especially we can use garble to build a plugin.

@mvdan
Copy link
Member

mvdan commented May 25, 2020

@cytown plugins already work, if you avoid building separate files as per #19. If they don't work, please file a separate issue as it doesn't seem related to this one.

@mvdan mvdan closed this as completed in 8b898ad May 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants