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

how pass X509Certificate2 to potocol gateway #93

Open
zxarcg opened this issue May 12, 2017 · 2 comments
Open

how pass X509Certificate2 to potocol gateway #93

zxarcg opened this issue May 12, 2017 · 2 comments

Comments

@zxarcg
Copy link

zxarcg commented May 12, 2017

my device is in internal network, and only through internal protocol gateway to access iot hub. every device has X509Certificate2 , how can i pass this X509Certificate2 to gateway ,then gateway act as proxy to use these X509Certificate2 to authen toward iot hub ?

protocol gateway default support sastoken, i used the following code, it work well, but i have choice to pass X509Certificate2 to protocol gateway ? i don't want to modify any device client relatived code, i want to let device client to keep transpent(regardless protocol gateway or iot hub)

sample code as followed:

private const string DeviceConnectionString = "GatewayHostName=127.0.0.1;HostName=xxx.azure-devices.cn;DeviceId=xxx;SharedAccessKey=xxx";

var x509Certificate = new X509Certificate2(@"E:\xxx.cer");
var setting = new MqttTransportSettings(TransportType.Mqtt_Tcp_Only);
setting.RemoteCertificateValidationCallback += (sender, cert, chain, error) => { return true; };
setting.ClientCertificate = x509Certificate;
var settings = new ITransportSettings[]
{
setting
};

            DeviceClient deviceClient = DeviceClient.CreateFromConnectionString(DeviceConnectionString, settings);

deviceClient.OpenAsync();
deviceClient.SendEvent(...);

@zxarcg
Copy link
Author

zxarcg commented May 12, 2017

i can pass certificate by willmessage in connectpacket, but i don't like this approch, anything else?
code as followed:

var x509Certificate = new X509Certificate2(@"E:\LLNC1AAA0EA001030.cer");
var buf = x509Certificate.GetRawCertData();
var setting = new MqttTransportSettings(TransportType.Mqtt_Tcp_Only);
setting.RemoteCertificateValidationCallback += (sender, cert, chain, error) => { return true; };
setting.HasWill = true;
setting.WillMessage = new WillMessage(QualityOfService.AtMostOnce, new Message(buf));

@nayato
Copy link
Member

nayato commented Aug 3, 2017

there's no good way to pass-through client certificate. Either use Hub-scoped credentials on the way to backend or if you can, store client certs locally on PG nodes for lookup/pull for forwarding.

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

No branches or pull requests

2 participants