mosquitto_pub拒绝iot.eclipse.org mqtt服务器证书说"未知CA"

时间:2017-12-08 11:08:48

标签: ssl https mosquitto ca

我试图在Ubuntu linux机器上运行mosquitto_pub,如下所示:

vbhadra@vbhadra-VirtualBox:~$ mosquitto_pub  -h iot.eclipse.org -p 8883 --capath /etc/ssl/certs/ -t house/s1 -m "test message" -d
Client mosqpub/9204-vbhadra-Vi sending CONNECT
Client mosqpub/9204-vbhadra-Vi received CONNACK
Client mosqpub/9204-vbhadra-Vi sending PUBLISH (d0, q0, r0, m1, 'house/s1', ... (12 bytes))
Client mosqpub/9204-vbhadra-Vi sending DISCONNECT

可以看出mosquitto_pub的工作文件。现在我想尝试手动下载iot.eclipse.org证书,然后使用mosquitto_pub而不是使用Ubuntus / etc / ssl / certs / certificate。

所以我做了以下事情:

ex +'/BEGIN CERTIFICATE/,/END CERTIFICATE/p' <(echo | openssl s_client -showcerts -connect iot.eclipse.org:8883) -scq > file.crt

将file.crt保存在以下位置:/ home / vbhadra / remote_certificate /。

现在,我再试一次:

mosquitto_pub  -h iot.eclipse.org -p 8883 --capath /home/vbhadra/remote_certificate/ -t house/s1 -m "test message" -d 

但是上面的失败是悲惨的。通过捕获tcpdump,我可以在Wireshark中看到我的Ubuntu客户端正在发送&#34;致命:未知的CA&#34;回到iot.eclipse.org。

根据我迄今为止的小小理解,我认为证书不是由任何CA签署的,因此mosquitto客户拒绝它。我一直试图弄清楚如何才能获得签署的证书(自签?)但到目前为止还没有任何线索。

我尝试使用openssl verify验证我保存的file.crt证书文件,如下所示:

openssl verify -CApath /home/vbhadra/remote_certs/ /home/vbhadra/remote_certs/file2.crt  
/home/vbhadra/remote_certs/file2.crt: CN = iot.eclipse.org
error 20 at 0 depth lookup:unable to get local issuer certificate

此时我有点迷茫。人们似乎建议使用.pem证书文件与openssl验证,但不知道如何做到这一点,基本上我迷路了。请帮助任何指针进一步采取它。

2 个答案:

答案 0 :(得分:0)

当您运行echo | openssl s_client -showcerts -connect iot.eclipse.org:8883命令并查看输出时,它包含多个证书,我认为这可能是您使用ex切断它的方式的问题。

您需要这两个证书才能提供完整的证书链来验证iot.eclipse.org的最终用户证书。

您是否也在包含ca文件的目录中运行ca_rehash(或ubuntu上的c_rehash)?

  

- capath

     

定义包含受信任的PEM编码CA证书的目录的路径。用于启用SSL通信。

     

要使--capath正常工作,证书文件必须以“.crt”作为文件结尾,并且必须运行“c_rehash”   每次添加/删除证书时。

我必须将文件重命名为.pem(因为这实际上是它们)并将DST_Root_CA_X3.pem文件从/ etc / ssl / certs复制到ca目录中。< / p>

此外,如果您想使用自己的私有CA,那么使用--cafile可能会更简单一些。

答案 1 :(得分:0)

这些是我在上面的hardillb回答之后所做的步骤:

vbhadra@vbhadra-VirtualBox:~/remote_certs$ openssl s_client -showcerts -CApath /etc/ssl/certs/ -connect iot.eclipse.org:8883
CONNECTED(00000003)
depth=2 O = Digital Signature Trust Co., CN = DST Root CA X3
verify return:1
depth=1 C = US, O = Let's Encrypt, CN = Let's Encrypt Authority X3
verify return:1
depth=0 CN = iot.eclipse.org
verify return:1
---
Certificate chain
 0 s:/CN=iot.eclipse.org
   i:/C=US/O=Let's Encrypt/CN=Let's Encrypt Authority X3
-----BEGIN CERTIFICATE-----
MIIFATCCA+mgAwIBAgISBC9SZX2gUAjJc1w00bxPBlvYMA0GCSqGSIb3DQEBCwUA
MEoxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MSMwIQYDVQQD
ExpMZXQncyBFbmNyeXB0IEF1dGhvcml0eSBYMzAeFw0xNzExMDMwOTE1MzFaFw0x
ODAyMDEwOTE1MzFaMBoxGDAWBgNVBAMTD2lvdC5lY2xpcHNlLm9yZzCCASIwDQYJ
KoZIhvcNAQEBBQADggEPADCCAQoCggEBAMIBN2DDEwV17T9JnHRe7OL4Cz4tKxc8
oB+wV+QFmXjObtYTlH9bbT+TidNHhHnnUKtVr/2hOyoEwNpjQsRmToesIWARfzyU
1RlGLKT4bWcheVzda5IoYqEDT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hrr1lpVPdUDh
JPduBX+8rtzgs3uA2PdwvoEAQsbb2ulcVBe10wF0W0bUky6ZHutDp/GK9pHiWWTu
RFYkJ74rzuPVNvFJ1jS4ow7gIg3rY6mLpMwcSQo7t2sb54i63PggzepPenqJkXC9
YwWJJs/zovrZjioMXKC/Lp+ROSK8L2Z+JzyQp0Yu/vyebHZ4WL0xlXBPrRvVx5J1
3+ebwxdehisKt78Xo/HgCiwyloCQILimldCLR5LdpgPS4N0Ang==
-----END CERTIFICATE-----
 1 s:/C=US/O=Let's Encrypt/CN=Let's Encrypt Authority X3
   i:/O=Digital Signature Trust Co./CN=DST Root CA X3
-----BEGIN CERTIFICATE-----
MIIEkjCCA3qgAwIBAgIQCgFBQgAAAVOFc2oLheynCDANBgkqhkiG9w0BAQsFADA/
MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT
DkRTVCBSb290IENBIFgzMB4XDTE2MDMxNzE2NDA0NloXDTIxMDMxNzE2NDA0Nlow
SjELMAkGA1UEBhMCVVMxFjAUBgNVBAoTDUxldCdzIEVuY3J5cHQxIzAhBgNVBAMT
GkxldCdzIEVuY3J5cHQgQXV0aG9yaXR5IFgzMIIBIjANBgkqhkiG9w0BAQEFAAOC
AQ8AMIIBCgKCAQEAnNMM8FrlLke3cl03g7NoYzDq1zUmGSXhvb418XCSL7e4S0EF
q6meNQhY7LEqxGiHC6PjdeTm86dicbp5gWAf15Gan/PQeGdxyGkOlZHP/uaZ6WA8
SMx+yk13EiSdRxta67nsHjcAHJyse6cF6s5K671B5TaYucv9bTyWaN8jKkKQDIZ0
Z8h/pZq4UmEUEz9l6YKHy9v6Dlb2honzhT+Xhq+w3Brvaw2VFn3EK6BlspkENnWA
a6xK8xuQSXgvopZPKiAlKQTGdMDQMc2PMTiVFrqoM7hD8bEfwzB/onkxEz0tNvjj
/PIzark5McWvxI0NHWQWM6r6hCm21AvA2H3DkwIDAQABo4IBfTCCAXkwEgYDVR0T
AQH/BAgwBgEB/wIBADAOBgNVHQ8BAf8EBAMCAYYwfwYIKwYBBQUHAQEEczBxMDIG
CCsGAQUFBzABhiZodHRwOi8vaXNyZy50cnVzdGlkLm9jc3AuaWRlbnRydXN0LmNv
bTA7BggrBgEFBQcwAoYvaHR0cDovL2FwcHMuaWRlbnRydXN0LmNvbS9yb290cy9k
c3Ryb290Y2F4My5wN2MwHwYDVR0jBBgwFoAUxKexpHsscfrb4UuQdf/EFWCFiRAw
VAYDVR0gBE0wSzAIBgZngQwBAgEwPwYLKwYBBAGC3xMBAQEwMDAuBggrBgEFBQcC
ARYiaHR0cDovL2Nwcy5yb290LXgxLmxldHNlbmNyeXB0Lm9yZzA8BgNVHR8ENTAz
MDGgL6AthitodHRwOi8vY3JsLmlkZW50cnVzdC5jb20vRFNUUk9PVENBWDNDUkwu
Y3JsMB0GA1UdDgQWBBSoSmpjBH3duubRObemRWXv86jsoTANBgkqhkiG9w0BAQsF
AAOCAQEA3TPXEfNjWDjdGBX7CVW+dla5cEilaUcne8IkCJLxWh9KEik3JHRRHGJo
uM2VcGfl96S8TihRzZvoroed6ti6WqEBmtzw3Wodatg+VyOeph4EYpr/1wXKtx8/
wApIvJSwtmVi4MFU5aMqrSDE6ea73Mj2tcMyo5jMd6jmeWUHK8so/joWUoHOUgwu
X4Po1QYz+3dszkDqMp4fklxBwXRsW10KXzPMTZ+sOPAveyxindmjkW8lGy+QsRlG
PfZ+G6Z6h7mjem0Y+iWlkYcV4PIWL1iwBi8saCbGS5jN2p8M+X+Q7UNKEkROb3N6
KOqkqm57TH2H3eDJAkSnh6/DNFu0Qg==
-----END CERTIFICATE-----
---
Server certificate
subject=/CN=iot.eclipse.org
issuer=/C=US/O=Let's Encrypt/CN=Let's Encrypt Authority X3
---
No client certificate CA names sent
---
SSL handshake has read 3137 bytes and written 421 bytes
---
New, TLSv1/SSLv3, Cipher is ECDHE-RSA-AES256-GCM-SHA384
Server public key is 2048 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
SSL-Session:
    Protocol  : TLSv1.2
    Cipher    : ECDHE-RSA-AES256-GCM-SHA384
    Session-ID: 1341B87702E30012B8FB0B98090FAB047CA84AB74566837F5600DD9C8B5BE5F5
    Session-ID-ctx: 
    Master-Key: 8806ABE0992E57E28B628CE5A1AE29642298C37363C530DED1EB7322E023CD297687D0A0C662B7875DA00F4FA4ACE9A9
    Key-Arg   : None
    PSK identity: None
    PSK identity hint: None
    SRP username: None
    TLS session ticket lifetime hint: 300 (seconds)
    TLS session ticket:
    0000 - ca de e0 ec 30 a1 17 f3-a9 e7 eb 0b 57 5c f0 8a   ....0.......W\..
    0010 - 2f ad 59 79 87 11 5c f6-05 39 fa 5c 0c 6b dd 6d   /.Yy..\..9.\.k.m
    0020 - 64 f3 4d 93 e9 1b 30 9a-08 fc e5 87 ca 34 d5 e3   d.M...0......4..
    0030 - 82 4b 60 67 b1 44 e6 4e-31 63 03 ec d8 e3 b4 0d   .K`g.D.N1c......
    0040 - 8d 03 e3 e2 a3 fb 6c ed-1f 0d 25 03 43 a8 b6 ff   ......l...%.C...
    0050 - 01 6a d0 48 a7 10 72 8c-6d aa ff 85 4e e8 b5 91   .j.H..r.m...N...
    0060 - 53 da 88 f2 03 88 88 54-94 f0 d5 e9 bd a0 55 06   S......T......U.
    0070 - 16 04 87 d8 ec 99 e5 cd-fc 9c 46 ff 1f cc 63 9e   ..........F...c.
    0080 - c3 cb 18 72 c9 ec ff fd-82 5a 79 fc 10 90 5a 10   ...r.....Zy...Z.
    0090 - 4d b8 5b 1e 9e 09 93 b6-cc 6d f8 06 10 6e f0 a4   M.[......m...n..
    00a0 - ab 71 c2 a8 58 01 25 43-3a b9 1d 38 52 b2 56 52   .q..X.%C:..8R.VR

    Start Time: 1513006076
    Timeout   : 300 (sec)
    Verify return code: 0 (ok)
---
closed

请注意,BEGIN和END CERTIFICATE部分之间有两个证书。将证书复制到两个单独的文件中,就像我复制并将两个证书保存在名为cert.pem和cert2.pem的两个不同文件中,这两个文件位于我的主目录中名为remote_certificates的文件夹中。现在将DST_Root_CA_X3.pem文件从/ etc / ssl / certs /文件夹复制到remote_certificates文件夹。

现在,正如@hardillb在上述评论中所建议的那样,运行c_rehash:

vbhadra@vbhadra-VirtualBox:~/remote_certs$ c_rehash .
Doing .
DST_Root_CA_X3.crt => 2e5ac55d.0
DST_Root_CA_X3.crt => 12d55845.0
iot.cert2.pem => 4f06f81d.0
iot.cert2.pem => 4a0a35c0.0
iot.cert1.pem => c6cb63f9.0
iot.cert1.pem => 8a8c4ac3.0

现在,我在remote_certificates文件夹中有以下文件:

vbhadra@vbhadra-VirtualBox:~/remote_certs$ ls -la 
total 20
drwxrwxr-x  2 vbhadra vbhadra 4096 Dec 11 15:38 .
drwxr-xr-x 40 vbhadra vbhadra 4096 Dec 11 15:38 ..
lrwxrwxrwx  1 vbhadra vbhadra   18 Dec 11 15:38 12d55845.0 -> DST_Root_CA_X3.crt
lrwxrwxrwx  1 vbhadra vbhadra   18 Dec 11 15:38 2e5ac55d.0 -> DST_Root_CA_X3.crt
lrwxrwxrwx  1 vbhadra vbhadra   13 Dec 11 15:38 4a0a35c0.0 -> iot.cert2.pem
lrwxrwxrwx  1 vbhadra vbhadra   13 Dec 11 15:38 4f06f81d.0 -> iot.cert2.pem
lrwxrwxrwx  1 vbhadra vbhadra   13 Dec 11 15:38 8a8c4ac3.0 -> iot.cert1.pem
lrwxrwxrwx  1 vbhadra vbhadra   13 Dec 11 15:38 c6cb63f9.0 -> iot.cert1.pem
-rw-r--r--  1 vbhadra vbhadra 1200 Dec 11 15:33 DST_Root_CA_X3.crt
-rw-rw-r--  1 vbhadra vbhadra 1798 Dec 11 15:37 iot.cert1.pem
-rw-rw-r--  1 vbhadra vbhadra 1648 Dec 11 15:37 iot.cert2.pem

现在我运行如下的mosquitto_pub命令,它可以工作:

vbhadra@vbhadra-VirtualBox:~/remote_certs$ mosquitto_pub  -h iot.eclipse.org -p 8883 --capath /home/vbhadra/remote_certs/ -t house/s1 -m "test message" -d 
Client mosqpub/3728-vbhadra-Vi sending CONNECT
Client mosqpub/3728-vbhadra-Vi received CONNACK
Client mosqpub/3728-vbhadra-Vi sending PUBLISH (d0, q0, r0, m1, 'house/s1', ... (12 bytes))
Client mosqpub/3728-vbhadra-Vi sending DISCONNECT
vbhadra@vbhadra-VirtualBox:~/remote_certs$ 

再次感谢@hardillb。