project-imas / mdm-server

Sample iOS MDM server
601 stars 150 forks source link

Read mdm.cer in MDM_Vendor_Sign.py fails in Windows #25

Open TomSelleck opened 9 years ago

TomSelleck commented 9 years ago

Problem code is:

p('Verifying %s ... ' % cli_args['mdm'])
mdm_cert_file = open(cli_args['mdm']).read()
args = ['openssl', 'x509', '-noout', '-inform', 'DER' ]
command = subprocess.Popen(args, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.STDOUT)
output, error = command.communicate(input = mdm_cert_file)  

Error is as follows:

'unable to load certificate\r\n8240:error:0D06B08E:asn1 encoding   routines:ASN1_D2I_READ_BIO:not enough data:.\\crypto\\asn1\\a_d2i_fp.c:234:\r\n'

Simple and quick solution is to read file as binary as follows:

with open(cli_args['mdm'], 'rb') as f:
        mdm_cert_file = f.read()
        args = ['openssl', 'x509', '-noout', '-inform', 'DER' ]
        command = subprocess.Popen(args, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.STDOUT)
        output, error = command.communicate(input = mdm_cert_file)  
         ....
MaximilianoRios commented 9 years ago

I've already pushed a request to fix it because I noted that some time ago. Hope someone merges it.

thrasr commented 9 years ago

I haven't seen a pull request fixing this issue. Can you resubmit it?

MaximilianoRios commented 9 years ago

The fix is pushed to grinich/mdmvendorsign, where the code is located.

https://github.com/grinich/mdmvendorsign/pulls

Regards.

On Tue, Jun 16, 2015 at 11:47 PM, Rory Thrasher notifications@github.com wrote:

I haven't seen a pull request fixing this issue. Can you resubmit it?

— Reply to this email directly or view it on GitHub https://github.com/project-imas/mdm-server/issues/25#issuecomment-112629739 .

thrasr commented 9 years ago

Ahhhh, I misunderstood where the error was. I'll leave this open so that others can see it until the request is accepted.