0

When I directly access to http://example.com/mycertificate.crt, it's well recognized and installed as a certificate.
Now, when I just access to http://example.com, my index.php seems not send it correctly.
My remote device download the file as I can see it but when I click on it, it says it cannot install it because the file is not readable. What's wrong?

Edit Below I modified my code removing html tags, but I still see few non printable characters at the begining and at the end of my certificate.

<?php
    if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'android') !== false) {
        if (file_exists('./mycertificate.crt')) {
            header($_SERVER["SERVER_PROTOCOL"] . " 200 OK");
            header("Content-Type: application/x-x509-ca-cert");
            header("Content-Transfer-Encoding: Binary");
            header("Content-Length:".filesize('./mycertificate.crt'));
            header("Content-Disposition: attachment; filename=mycertificate.crt");
            readfile('./mycertificate.crt');
        } else {
            die('ERROR');
        }
    } else {
        die('Bad device');
    }
 ?>
fralbo
  • 2,534
  • 4
  • 41
  • 73
  • Note that the user might not agree to install the certificate, and that user-installed certificates are ignored by default on Android 7.0+. As I wrote in [a comment on your previous question in this area](https://stackoverflow.com/questions/39980088/installing-a-certificate-with-my-app), why do you think that you need the user to install a certificate on the device, rather than just use the certificate yourself in your app's SSL communications? – CommonsWare Oct 11 '16 at 18:12
  • @CommonsWare Here is for a different usage. It's to connect a device to a secure proxy, not through an application. In that case, the user is informed that he needs to install the certificate to access this resource. – fralbo Oct 13 '16 at 12:13

0 Answers0