All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.microsoft.azure.iothub.DefaultCertificate Maven / Gradle / Ivy

There is a newer version: 1.0.16
Show newest version
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

package com.microsoft.azure.iothub;

import java.io.*;

public class DefaultCertificate {
    private final String certPath = "cert.crt";
    private final String cert =
                    /* Baltimore */
                    "-----BEGIN CERTIFICATE-----\r\n" +
                    "MIIDdzCCAl+gAwIBAgIEAgAAuTANBgkqhkiG9w0BAQUFADBaMQswCQYDVQQGEwJJ\r\n" +
                    "RTESMBAGA1UEChMJQmFsdGltb3JlMRMwEQYDVQQLEwpDeWJlclRydXN0MSIwIAYD\r\n" +
                    "VQQDExlCYWx0aW1vcmUgQ3liZXJUcnVzdCBSb290MB4XDTAwMDUxMjE4NDYwMFoX\r\n" +
                    "DTI1MDUxMjIzNTkwMFowWjELMAkGA1UEBhMCSUUxEjAQBgNVBAoTCUJhbHRpbW9y\r\n" +
                    "ZTETMBEGA1UECxMKQ3liZXJUcnVzdDEiMCAGA1UEAxMZQmFsdGltb3JlIEN5YmVy\r\n" +
                    "VHJ1c3QgUm9vdDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKMEuyKr\r\n" +
                    "mD1X6CZymrV51Cni4eiVgLGw41uOKymaZN+hXe2wCQVt2yguzmKiYv60iNoS6zjr\r\n" +
                    "IZ3AQSsBUnuId9Mcj8e6uYi1agnnc+gRQKfRzMpijS3ljwumUNKoUMMo6vWrJYeK\r\n" +
                    "mpYcqWe4PwzV9/lSEy/CG9VwcPCPwBLKBsua4dnKM3p31vjsufFoREJIE9LAwqSu\r\n" +
                    "XmD+tqYF/LTdB1kC1FkYmGP1pWPgkAx9XbIGevOF6uvUA65ehD5f/xXtabz5OTZy\r\n" +
                    "dc93Uk3zyZAsuT3lySNTPx8kmCFcB5kpvcY67Oduhjprl3RjM71oGDHweI12v/ye\r\n" +
                    "jl0qhqdNkNwnGjkCAwEAAaNFMEMwHQYDVR0OBBYEFOWdWTCCR1jMrPoIVDaGezq1\r\n" +
                    "BE3wMBIGA1UdEwEB/wQIMAYBAf8CAQMwDgYDVR0PAQH/BAQDAgEGMA0GCSqGSIb3\r\n" +
                    "DQEBBQUAA4IBAQCFDF2O5G9RaEIFoN27TyclhAO992T9Ldcw46QQF+vaKSm2eT92\r\n" +
                    "9hkTI7gQCvlYpNRhcL0EYWoSihfVCr3FvDB81ukMJY2GQE/szKN+OMY3EU/t3Wgx\r\n" +
                    "jkzSswF07r51XgdIGn9w/xZchMB5hbgF/X++ZRGjD8ACtPhSNzkE1akxehi/oCr0\r\n" +
                    "Epn3o0WC4zxe9Z2etciefC7IpJ5OCBRLbf1wbWsaY71k5h+3zvDyny67G7fyUIhz\r\n" +
                    "ksLi4xaNmjICq44Y3ekQEe5+NauQrz4wlHrQMz2nZQ/1/I6eYs9HRCwBXbsdtTLS\r\n" +
                    "R9I4LtD+gdwyah617jzV/OeBHRnDJELqYzmp\r\n" +
                    "-----END CERTIFICATE-----\r\n";
    public DefaultCertificate()
    {

    }

    public String getDefaultCertificate() {
        File certificate = null;
        Writer writer = null;
        BufferedWriter bufferedWriter = null;
        try
        {
            certificate = new File(certPath);
            try {
                if (!certificate.exists()) {
                    certificate.createNewFile();
                }
            }
            catch(IOException e)
            {
                throw new IOError(e);
            }
            writer = new FileWriter(certificate);
            bufferedWriter = new BufferedWriter(writer);
            bufferedWriter.write(cert);
            bufferedWriter.close();
        }

        catch (IOException e)
        {
            throw new IOError(e);
        }

        finally
        {
           if (bufferedWriter != null)
           {
               try
               {
                   bufferedWriter.close();
               }
               catch(IOException e)
               {
                   throw new IOError(e);
               }
           }

            if (writer != null)
            {
                try
                {
                    writer.close();
                }
                catch(IOException e)
                {
                    throw new IOError(e);
                }
            }
        }

        return certificate.getAbsolutePath();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy