0
1

More than 3 years have passed since last update.

NXP SE050検証(テストWEBサーバーへの接続)(NXP SE050 WEB server connection test)

Posted at

はじめに

2019/12/14に開かれた IoTSecJPにてお時間をいただき
セキュアエレメントとIoTデバイスセキュリティ
と題してお話させていただきました。
その内容をベースにまとめていきたいと思います。

テストWEBサーバーの準備

SE050に書き込んだ証明書を使って、テスト接続するWEBサーバーを構築する。

自分用ngrokをauthtoken対応にする(self hosted ngrok)で作った自分用ngrokを使い、独自ドメインで証明書を作成、適当なポート番号で手元のラズパイゼロにTCP通信をあける。今回は50020とした。

ラズパイゼロにnginxでテストサーバーを構築していく。
以下を参考にさせていただいた。
https://emc-craft.xyz/raspberrypi/nginx-inst03/
https://qiita.com/ochomaki/items/b9e1353a50ea43c50a35

最終的なConfigは下記の通り。クライアント認証を必須にする設定を行い、クライアント証明書がない普通のブラウザから接続してみてエラーが出るのを確認する。

$ cat /etc/nginx/conf.d/ssl.conf
server {
    listen       50020 ssl;
    server_name  <独自ドメイン>;

    ssl_certificate     /home/pi/pizerocontents/server.chain;
    ssl_certificate_key /home/pi/pizerocontents/server.key;
    ssl_protocols       TLSv1.2;
    ssl_ciphers         'ECDHE-ECDSA-AES128-SHA256 ECDH !aNULL !eNULL !SSLv2 !SSLv3';
    ssl_verify_client on;
    ssl_verify_depth 2;

    ssl_client_certificate /home/pi/pizerocontents/signer-ca.crt;
    ssl_trusted_certificate /home/pi/pizerocontents/root-ca.crt;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

ESP32側の設定ポイント

基本は、NXP Plug&Trust MWのssl接続テストコードを使い、

    mbedtls_ssl_conf_authmode(&conf, MBEDTLS_SSL_VERIFY_REQUIRED);

証明書ベリファイ強制必須にし、サーバー側が、今回のESP32プログラムが理解できない楕円暗号を選ばないように下記で提示する楕円暗号リストを決め打ちする。
これがないと、ESP32側はprime256v1で待っているのにサーバー側がsecp521r1で返してくる現象が起こった。

    // Set the allowed curves in order of preference.
    static const mbedtls_ecp_group_id curve[] =
    {
        MBEDTLS_ECP_DP_SECP256R1, MBEDTLS_ECP_DP_NONE
    };
    mbedtls_ssl_conf_curves(&conf, curve);

これでプログラムを作成し、ビルドしてみた。

コードはNXP-SE050-https-Connection-Test

ssl_tls.c:8558: |2| <= read
 845 bytes read

HTTP/1.1 200 OK
Server: nginx/1.16.1
Date: Thu, 26 Mar 2020 22:58:02 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 13 Aug 2019 10:05:00 GMT
Connection: close
ETag: "5d528b4c-264"
Accept-Ranges: bytes

<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
  . Closing the connection...ssl_tls.c:8725: |2| => write close notify

nginxのテストページを読み込めた。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1